Skip to content

Commit 00bf1ff

Browse files
committed
Add Conformance Test Framework
This commit adds the initial framework we need to run conformance tests. ALL CREDIT to sig-network-gatewaya-api community and folks who added conformance there. We have blatantly copied from them and adapted the suite to our needs. https://github.com/kubernetes-sigs/gateway-api/tree/main/conformance Signed-off-by: Surya Seetharaman <[email protected]>
1 parent 2f547fe commit 00bf1ff

File tree

12 files changed

+1092
-0
lines changed

12 files changed

+1092
-0
lines changed

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ help: ## Display this help.
2626

2727
##@ Development
2828

29+
# Command-line flags passed to "go test" for the conformance
30+
# test. These are passed after the "-args" flag.
31+
CONFORMANCE_FLAGS ?=
32+
2933
.PHONY: fmt
3034
fmt: ## Run go fmt against code.
3135
go fmt ./...
@@ -47,6 +51,10 @@ verify:
4751
crd-e2e:
4852
hack/crd-e2e.sh -v
4953

54+
.PHONY: conformance
55+
conformance:
56+
go test -v ./conformance/... -args ${CONFORMANCE_FLAGS}
57+
5058
##@ Deployment
5159
install: generate ## Install CRDs into the K8s cluster specified in ~/.kube/config.
5260
kubectl kustomize config/crd | kubectl apply -f -

conformance/base/manifests.yaml

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
# This file contains the base resources that most conformance tests will rely
2+
# on. This includes 4 namespaces along with Server and Client Deployments in
3+
# each of them that can be used as backends and probes for testing traffic.
4+
# Create 4 namespaces
5+
apiVersion: v1
6+
kind: Namespace
7+
metadata:
8+
name: network-policy-conformance-gryffindor
9+
labels:
10+
conformance-house: gryffindor
11+
---
12+
apiVersion: v1
13+
kind: Namespace
14+
metadata:
15+
name: network-policy-conformance-slytherin
16+
labels:
17+
conformance-house: slytherin
18+
---
19+
apiVersion: v1
20+
kind: Namespace
21+
metadata:
22+
name: network-policy-conformance-hufflepuff
23+
labels:
24+
conformance-house: hufflepuff
25+
---
26+
apiVersion: v1
27+
kind: Namespace
28+
metadata:
29+
name: network-policy-conformance-ravenclaw
30+
labels:
31+
conformance-house: ravenclaw
32+
# Create 4 deployments; 2 pods each under these namespaces
33+
---
34+
apiVersion: apps/v1
35+
kind: StatefulSet
36+
metadata:
37+
name: harry-potter
38+
namespace: network-policy-conformance-gryffindor
39+
spec:
40+
selector:
41+
matchLabels:
42+
conformance-house: gryffindor
43+
replicas: 2
44+
template:
45+
metadata:
46+
labels:
47+
conformance-house: gryffindor
48+
spec:
49+
containers:
50+
- name: harry-potter-client
51+
image: registry.k8s.io/e2e-test-images/agnhost:2.43
52+
- name: harry-potter-80
53+
image: registry.k8s.io/e2e-test-images/agnhost:2.43
54+
command: ["/bin/bash", "-c", "/agnhost serve-hostname --tcp --http=false --port 80"]
55+
- name: harry-potter-8080
56+
image: registry.k8s.io/e2e-test-images/agnhost:2.43
57+
command: ["/bin/bash", "-c", "/agnhost serve-hostname --tcp --http=false --port 8080"]
58+
- name: harry-potter-5353
59+
image: registry.k8s.io/e2e-test-images/agnhost:2.43
60+
command: ["/bin/bash", "-c", "/agnhost serve-hostname --udp --http=false --port 5353"]
61+
- name: harry-potter-53
62+
image: registry.k8s.io/e2e-test-images/agnhost:2.43
63+
command: ["/bin/bash", "-c", "/agnhost serve-hostname --udp --http=false --port 53"]
64+
- name: harry-potter-9003
65+
image: registry.k8s.io/e2e-test-images/agnhost:2.43
66+
command: ["/bin/bash", "-c", "/agnhost porter"]
67+
env:
68+
- name: SERVE_SCTP_PORT_9003
69+
value: "foo"
70+
- name: harry-potter-9005
71+
image: registry.k8s.io/e2e-test-images/agnhost:2.43
72+
command: ["/bin/bash", "-c", "/agnhost porter"]
73+
env:
74+
- name: SERVE_SCTP_PORT_9005
75+
value: "foo"
76+
---
77+
apiVersion: apps/v1
78+
kind: StatefulSet
79+
metadata:
80+
name: draco-malfoy
81+
namespace: network-policy-conformance-slytherin
82+
spec:
83+
selector:
84+
matchLabels:
85+
conformance-house: slytherin
86+
replicas: 2
87+
template:
88+
metadata:
89+
labels:
90+
conformance-house: slytherin
91+
spec:
92+
containers:
93+
- name: draco-malfoy-client
94+
image: registry.k8s.io/e2e-test-images/agnhost:2.43
95+
- name: draco-malfoy-80
96+
image: registry.k8s.io/e2e-test-images/agnhost:2.43
97+
command: ["/bin/bash", "-c", "/agnhost serve-hostname --tcp --http=false --port 80"]
98+
- name: draco-malfoy-8080
99+
image: registry.k8s.io/e2e-test-images/agnhost:2.43
100+
command: ["/bin/bash", "-c", "/agnhost serve-hostname --tcp --http=false --port 8080"]
101+
- name: draco-malfoy-5353
102+
image: registry.k8s.io/e2e-test-images/agnhost:2.43
103+
command: ["/bin/bash", "-c", "/agnhost serve-hostname --udp --http=false --port 5353"]
104+
- name: draco-malfoy-53
105+
image: registry.k8s.io/e2e-test-images/agnhost:2.43
106+
command: ["/bin/bash", "-c", "/agnhost serve-hostname --udp --http=false --port 53"]
107+
- name: draco-malfoy-9003
108+
image: registry.k8s.io/e2e-test-images/agnhost:2.43
109+
command: ["/bin/bash", "-c", "/agnhost porter"]
110+
env:
111+
- name: SERVE_SCTP_PORT_9003
112+
value: "foo"
113+
- name: draco-malfoy-9005
114+
image: registry.k8s.io/e2e-test-images/agnhost:2.43
115+
command: ["/bin/bash", "-c", "/agnhost porter"]
116+
env:
117+
- name: SERVE_SCTP_PORT_9005
118+
value: "foo"
119+
---
120+
apiVersion: apps/v1
121+
kind: StatefulSet
122+
metadata:
123+
name: cedric-diggory
124+
namespace: network-policy-conformance-hufflepuff
125+
spec:
126+
selector:
127+
matchLabels:
128+
conformance-house: hufflepuff
129+
replicas: 2
130+
template:
131+
metadata:
132+
labels:
133+
conformance-house: hufflepuff
134+
spec:
135+
containers:
136+
- name: cedric-diggory-client
137+
image: registry.k8s.io/e2e-test-images/agnhost:2.43
138+
- name: cedric-diggory-80
139+
image: registry.k8s.io/e2e-test-images/agnhost:2.43
140+
command: ["/bin/bash", "-c", "/agnhost serve-hostname --tcp --http=false --port 80"]
141+
- name: cedric-diggory-8080
142+
image: registry.k8s.io/e2e-test-images/agnhost:2.43
143+
command: ["/bin/bash", "-c", "/agnhost serve-hostname --tcp --http=false --port 8080"]
144+
- name: cedric-diggory-5353
145+
image: registry.k8s.io/e2e-test-images/agnhost:2.43
146+
command: ["/bin/bash", "-c", "/agnhost serve-hostname --udp --http=false --port 5353"]
147+
- name: cedric-diggory-53
148+
image: registry.k8s.io/e2e-test-images/agnhost:2.43
149+
command: ["/bin/bash", "-c", "/agnhost serve-hostname --udp --http=false --port 53"]
150+
- name: cedric-diggory-9003
151+
image: registry.k8s.io/e2e-test-images/agnhost:2.43
152+
command: ["/bin/bash", "-c", "/agnhost porter"]
153+
env:
154+
- name: SERVE_SCTP_PORT_9003
155+
value: "foo"
156+
- name: cedric-diggory-9005
157+
image: registry.k8s.io/e2e-test-images/agnhost:2.43
158+
command: ["/bin/bash", "-c", "/agnhost porter"]
159+
env:
160+
- name: SERVE_SCTP_PORT_9005
161+
value: "foo"
162+
---
163+
apiVersion: apps/v1
164+
kind: StatefulSet
165+
metadata:
166+
name: luna-lovegood
167+
namespace: network-policy-conformance-ravenclaw
168+
spec:
169+
selector:
170+
matchLabels:
171+
conformance-house: ravenclaw
172+
replicas: 2
173+
template:
174+
metadata:
175+
labels:
176+
conformance-house: ravenclaw
177+
spec:
178+
containers:
179+
- name: luna-lovegood-client
180+
image: registry.k8s.io/e2e-test-images/agnhost:2.43
181+
- name: luna-lovegood-80
182+
image: registry.k8s.io/e2e-test-images/agnhost:2.43
183+
command: ["/bin/bash", "-c", "/agnhost serve-hostname --tcp --http=false --port 80"]
184+
- name: luna-lovegood-8080
185+
image: registry.k8s.io/e2e-test-images/agnhost:2.43
186+
command: ["/bin/bash", "-c", "/agnhost serve-hostname --tcp --http=false --port 8080"]
187+
- name: luna-lovegood-5353
188+
image: registry.k8s.io/e2e-test-images/agnhost:2.43
189+
command: ["/bin/bash", "-c", "/agnhost serve-hostname --udp --http=false --port 5353"]
190+
- name: luna-lovegood-53
191+
image: registry.k8s.io/e2e-test-images/agnhost:2.43
192+
command: ["/bin/bash", "-c", "/agnhost serve-hostname --udp --http=false --port 53"]
193+
- name: luna-lovegood-9003
194+
image: registry.k8s.io/e2e-test-images/agnhost:2.43
195+
command: ["/bin/bash", "-c", "/agnhost porter"]
196+
env:
197+
- name: SERVE_SCTP_PORT_9003
198+
value: "foo"
199+
- name: luna-lovegood-9005
200+
image: registry.k8s.io/e2e-test-images/agnhost:2.43
201+
command: ["/bin/bash", "-c", "/agnhost porter"]
202+
env:
203+
- name: SERVE_SCTP_PORT_9005
204+
value: "foo"

conformance/conformance_test.go

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
Copyright 2022 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// conformance_test contains code to run the conformance tests. This is in its own package to avoid circular imports.
18+
package conformance_test
19+
20+
import (
21+
"flag"
22+
"strings"
23+
"testing"
24+
25+
"sigs.k8s.io/network-policy-api/apis/v1alpha1"
26+
"sigs.k8s.io/network-policy-api/conformance/tests"
27+
"sigs.k8s.io/network-policy-api/conformance/utils/flags"
28+
"sigs.k8s.io/network-policy-api/conformance/utils/suite"
29+
30+
"k8s.io/apimachinery/pkg/util/sets"
31+
_ "k8s.io/client-go/plugin/pkg/client/auth"
32+
"k8s.io/kubernetes/test/e2e/framework"
33+
e2econfig "k8s.io/kubernetes/test/e2e/framework/config"
34+
"sigs.k8s.io/controller-runtime/pkg/client"
35+
"sigs.k8s.io/controller-runtime/pkg/client/config"
36+
)
37+
38+
func TestConformance(t *testing.T) {
39+
cfg, err := config.GetConfig()
40+
if err != nil {
41+
t.Fatalf("Error loading Kubernetes config: %v", err)
42+
}
43+
client, err := client.New(cfg, client.Options{})
44+
if err != nil {
45+
t.Fatalf("Error initializing Kubernetes client: %v", err)
46+
}
47+
48+
v1alpha1.AddToScheme(client.Scheme())
49+
50+
supportedFeatures := parseSupportedFeatures(*flags.SupportedFeatures)
51+
exemptFeatures := parseSupportedFeatures(*flags.ExemptFeatures)
52+
53+
// Register test flags, then parse flags.
54+
handleFlags()
55+
56+
t.Logf("Running conformance tests with cleanup: %t\n debug: %t\n enable all features: %t \n supported features: [%v]\n exempt features: [%v]",
57+
*flags.CleanupBaseResources, *flags.ShowDebug, *flags.EnableAllSupportedFeatures, *flags.SupportedFeatures, *flags.ExemptFeatures)
58+
59+
cSuite := suite.New(suite.Options{
60+
Client: client,
61+
Debug: *flags.ShowDebug,
62+
CleanupBaseResources: *flags.CleanupBaseResources,
63+
SupportedFeatures: supportedFeatures,
64+
ExemptFeatures: exemptFeatures,
65+
EnableAllSupportedFeatures: *flags.EnableAllSupportedFeatures,
66+
})
67+
cSuite.Setup(t)
68+
69+
cSuite.Run(t, tests.ConformanceTests)
70+
}
71+
72+
// parseSupportedFeatures parses flag arguments and converts the string to
73+
// sets.Set[suite.SupportedFeature]
74+
func parseSupportedFeatures(f string) sets.Set[suite.SupportedFeature] {
75+
if f == "" {
76+
return nil
77+
}
78+
res := sets.Set[suite.SupportedFeature]{}
79+
for _, value := range strings.Split(f, ",") {
80+
res.Insert(suite.SupportedFeature(value))
81+
}
82+
return res
83+
}
84+
85+
// handleFlags sets up all flags and parses the command line.
86+
func handleFlags() {
87+
e2econfig.CopyFlags(e2econfig.Flags, flag.CommandLine)
88+
framework.RegisterCommonFlags(flag.CommandLine)
89+
flag.Parse()
90+
}

conformance/embed.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
Copyright 2022 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package conformance
18+
19+
import "embed"
20+
21+
//go:embed tests/* base/*
22+
var Manifests embed.FS

conformance/tests/main.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
Copyright 2022 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package tests
18+
19+
import "sigs.k8s.io/network-policy-api/conformance/utils/suite"
20+
21+
var ConformanceTests []suite.ConformanceTest

0 commit comments

Comments
 (0)