Skip to content

Commit a6251f0

Browse files
authored
🌱 test: drop handling for old k8s version (#2925)
* test: drop handling for old k8s version * chore: clean up test func * chore: remove v2 test func
1 parent e7c871e commit a6251f0

File tree

4 files changed

+6
-223
lines changed

4 files changed

+6
-223
lines changed

test/e2e/deployimage/plugin_cluster_test.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,6 @@ var _ = Describe("kubebuilder", func() {
7878
})
7979

8080
It("should generate a runnable project with deploy-image/v1-alpha options ", func() {
81-
// Skip if cluster version < 1.16, when v1 CRDs and webhooks did not exist.
82-
// Skip if cluster version < 1.19, because securityContext.seccompProfile only works from 1.19
83-
// Otherwise, unknown field "seccompProfile" in io.k8s.api.core.v1.PodSecurityContext will be faced
84-
if srvVer := kbc.K8sVersion.ServerVersion; srvVer.GetMajorInt() <= 1 && srvVer.GetMinorInt() < 19 {
85-
Skip(fmt.Sprintf("cluster version %s does not support "+
86-
"securityContext.seccompProfile", srvVer.GitVersion))
87-
}
88-
8981
var err error
9082

9183
By("initializing a project with go/v3")
@@ -123,14 +115,6 @@ var _ = Describe("kubebuilder", func() {
123115
})
124116

125117
It("should generate a runnable project with deploy-image/v1-alpha without options ", func() {
126-
// Skip if cluster version < 1.16, when v1 CRDs and webhooks did not exist.
127-
// Skip if cluster version < 1.19, because securityContext.seccompProfile only works from 1.19
128-
// Otherwise, unknown field "seccompProfile" in io.k8s.api.core.v1.PodSecurityContext will be faced
129-
if srvVer := kbc.K8sVersion.ServerVersion; srvVer.GetMajorInt() <= 1 && srvVer.GetMinorInt() < 19 {
130-
Skip(fmt.Sprintf("cluster version %s does not support "+
131-
"securityContext.seccompProfile", srvVer.GitVersion))
132-
}
133-
134118
var err error
135119

136120
By("initializing a project with go/v3")

test/e2e/v3/generate_test.go

Lines changed: 3 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -34,103 +34,8 @@ import (
3434
"sigs.k8s.io/kubebuilder/v3/test/e2e/utils"
3535
)
3636

37-
// GenerateV2 implements a go/v2 plugin project defined by a TestContext.
38-
func GenerateV2(kbc *utils.TestContext) {
39-
var err error
40-
41-
By("initializing a project")
42-
err = kbc.Init(
43-
"--plugins", "go/v2",
44-
"--project-version", "3",
45-
"--domain", kbc.Domain,
46-
"--fetch-deps=false",
47-
)
48-
ExpectWithOffset(1, err).NotTo(HaveOccurred())
49-
50-
By("creating API definition")
51-
err = kbc.CreateAPI(
52-
"--group", kbc.Group,
53-
"--version", kbc.Version,
54-
"--kind", kbc.Kind,
55-
"--namespaced",
56-
"--resource",
57-
"--controller",
58-
"--make=false",
59-
)
60-
ExpectWithOffset(1, err).NotTo(HaveOccurred())
61-
62-
By("implementing the API")
63-
ExpectWithOffset(1, pluginutil.InsertCode(
64-
filepath.Join(kbc.Dir, "api", kbc.Version, fmt.Sprintf("%s_types.go", strings.ToLower(kbc.Kind))),
65-
fmt.Sprintf(`type %sSpec struct {
66-
`, kbc.Kind),
67-
` // +optional
68-
Count int `+"`"+`json:"count,omitempty"`+"`"+`
69-
`)).Should(Succeed())
70-
71-
By("scaffolding mutating and validating webhooks")
72-
err = kbc.CreateWebhook(
73-
"--group", kbc.Group,
74-
"--version", kbc.Version,
75-
"--kind", kbc.Kind,
76-
"--defaulting",
77-
"--programmatic-validation",
78-
)
79-
ExpectWithOffset(1, err).NotTo(HaveOccurred())
80-
81-
By("implementing the mutating and validating webhooks")
82-
err = pluginutil.ImplementWebhooks(filepath.Join(
83-
kbc.Dir, "api", kbc.Version,
84-
fmt.Sprintf("%s_webhook.go", strings.ToLower(kbc.Kind))))
85-
ExpectWithOffset(1, err).NotTo(HaveOccurred())
86-
87-
By("uncomment kustomization.yaml to enable webhook and ca injection")
88-
ExpectWithOffset(1, pluginutil.UncommentCode(
89-
filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
90-
"#- ../webhook", "#")).To(Succeed())
91-
ExpectWithOffset(1, pluginutil.UncommentCode(
92-
filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
93-
"#- ../certmanager", "#")).To(Succeed())
94-
ExpectWithOffset(1, pluginutil.UncommentCode(
95-
filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
96-
"#- ../prometheus", "#")).To(Succeed())
97-
ExpectWithOffset(1, pluginutil.UncommentCode(
98-
filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
99-
"#- manager_webhook_patch.yaml", "#")).To(Succeed())
100-
ExpectWithOffset(1, pluginutil.UncommentCode(
101-
filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
102-
"#- webhookcainjection_patch.yaml", "#")).To(Succeed())
103-
ExpectWithOffset(1, pluginutil.UncommentCode(filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
104-
`#- name: CERTIFICATE_NAMESPACE # namespace of the certificate CR
105-
# objref:
106-
# kind: Certificate
107-
# group: cert-manager.io
108-
# version: v1alpha2
109-
# name: serving-cert # this name should match the one in certificate.yaml
110-
# fieldref:
111-
# fieldpath: metadata.namespace
112-
#- name: CERTIFICATE_NAME
113-
# objref:
114-
# kind: Certificate
115-
# group: cert-manager.io
116-
# version: v1alpha2
117-
# name: serving-cert # this name should match the one in certificate.yaml
118-
#- name: SERVICE_NAMESPACE # namespace of the service
119-
# objref:
120-
# kind: Service
121-
# version: v1
122-
# name: webhook-service
123-
# fieldref:
124-
# fieldpath: metadata.namespace
125-
#- name: SERVICE_NAME
126-
# objref:
127-
# kind: Service
128-
# version: v1
129-
# name: webhook-service`, "#")).To(Succeed())
130-
}
131-
13237
// GenerateV3 implements a go/v3(-alpha) plugin project defined by a TestContext.
133-
func GenerateV3(kbc *utils.TestContext, crdAndWebhookVersion string) {
38+
func GenerateV3(kbc *utils.TestContext) {
13439
var err error
13540

13641
By("initializing a project")
@@ -151,7 +56,6 @@ func GenerateV3(kbc *utils.TestContext, crdAndWebhookVersion string) {
15156
"--resource",
15257
"--controller",
15358
"--make=false",
154-
"--crd-version", crdAndWebhookVersion,
15559
)
15660
ExpectWithOffset(1, err).NotTo(HaveOccurred())
15761

@@ -171,7 +75,6 @@ Count int `+"`"+`json:"count,omitempty"`+"`"+`
17175
"--kind", kbc.Kind,
17276
"--defaulting",
17377
"--programmatic-validation",
174-
"--webhook-version", crdAndWebhookVersion,
17578
)
17679
ExpectWithOffset(1, err).NotTo(HaveOccurred())
17780

@@ -225,18 +128,14 @@ Count int `+"`"+`json:"count,omitempty"`+"`"+`
225128
# version: v1
226129
# name: webhook-service`, "#")).To(Succeed())
227130

228-
if crdAndWebhookVersion == "v1beta1" {
229-
_ = pluginutil.RunCmd("Update dependencies", "go", "mod", "tidy")
230-
}
231-
232131
if kbc.IsRestricted {
233132
By("uncomment kustomize files to ensure that pods are restricted")
234133
uncommentPodStandards(kbc)
235134
}
236135
}
237136

238-
// GenerateV3 implements a go/v3(-alpha) plugin project defined by a TestContext.
239-
func GenerateV3ComponentConfig(kbc *utils.TestContext, crdAndWebhookVersion string) {
137+
// GenerateV3ComponentConfig implements a go/v3(-alpha) plugin project defined by a TestContext with component config.
138+
func GenerateV3ComponentConfig(kbc *utils.TestContext) {
240139
var err error
241140

242141
By("initializing a project")
@@ -258,7 +157,6 @@ func GenerateV3ComponentConfig(kbc *utils.TestContext, crdAndWebhookVersion stri
258157
"--resource",
259158
"--controller",
260159
"--make=false",
261-
"--crd-version", crdAndWebhookVersion,
262160
)
263161
ExpectWithOffset(1, err).NotTo(HaveOccurred())
264162

@@ -278,7 +176,6 @@ Count int `+"`"+`json:"count,omitempty"`+"`"+`
278176
"--kind", kbc.Kind,
279177
"--defaulting",
280178
"--programmatic-validation",
281-
"--webhook-version", crdAndWebhookVersion,
282179
)
283180
ExpectWithOffset(1, err).NotTo(HaveOccurred())
284181

@@ -332,10 +229,6 @@ Count int `+"`"+`json:"count,omitempty"`+"`"+`
332229
# version: v1
333230
# name: webhook-service`, "#")).To(Succeed())
334231

335-
if crdAndWebhookVersion == "v1beta1" {
336-
_ = pluginutil.RunCmd("Update dependencies", "go", "mod", "tidy")
337-
}
338-
339232
if kbc.IsRestricted {
340233
By("uncomment kustomize files to ensure that pods are restricted")
341234
uncommentPodStandards(kbc)

test/e2e/v3/plugin_cluster_test.go

Lines changed: 3 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -78,38 +78,6 @@ var _ = Describe("kubebuilder", func() {
7878
kbc.Destroy()
7979
})
8080

81-
//TODO: remove me when the plugin go/v2 be removed
82-
//go:deprecated this plugin is deprecated
83-
Context("plugin go.kubebuilder.io/v2", func() {
84-
// Use cert-manager with v1beta2 CRs.
85-
BeforeEach(func() {
86-
// Skip if cluster version >= 1.22 because pre v1 CRDs and webhooks no longer exist.
87-
if srvVer := kbc.K8sVersion.ServerVersion; srvVer.GetMajorInt() >= 1 && srvVer.GetMinorInt() >= 22 {
88-
Skip(fmt.Sprintf("cluster version %s does not support pre v1 CRDs or webhooks", srvVer.GitVersion))
89-
}
90-
By("installing the v1beta2 cert-manager bundle")
91-
Expect(kbc.InstallCertManager(true)).To(Succeed())
92-
})
93-
AfterEach(func() {
94-
// Skip if cluster version >= 1.22 because pre v1 CRDs and webhooks no longer exist.
95-
if srvVer := kbc.K8sVersion.ServerVersion; srvVer.GetMajorInt() >= 1 && srvVer.GetMinorInt() >= 22 {
96-
Skip(fmt.Sprintf("cluster version %s does not support pre v1 CRDs or webhooks", srvVer.GitVersion))
97-
}
98-
By("uninstalling the v1beta2 cert-manager bundle")
99-
kbc.UninstallCertManager(true)
100-
})
101-
102-
It("should generate a runnable project go/v2 with default SA", func() {
103-
// go/v3 uses a unqiue-per-project service account name,
104-
// while go/v2 still uses "default".
105-
tmp := kbc.Kubectl.ServiceAccount
106-
kbc.Kubectl.ServiceAccount = "default"
107-
defer func() { kbc.Kubectl.ServiceAccount = tmp }()
108-
GenerateV2(kbc)
109-
Run(kbc)
110-
})
111-
})
112-
11381
Context("plugin go.kubebuilder.io/v3", func() {
11482
// Use cert-manager with v1 CRs.
11583
BeforeEach(func() {
@@ -122,65 +90,19 @@ var _ = Describe("kubebuilder", func() {
12290
})
12391

12492
It("should generate a runnable project go/v3 with v1 CRDs and Webhooks", func() {
125-
// Skip if cluster version < 1.16, when v1 CRDs and webhooks did not exist.
126-
if srvVer := kbc.K8sVersion.ServerVersion; srvVer.GetMajorInt() <= 1 && srvVer.GetMinorInt() < 16 {
127-
Skip(fmt.Sprintf("cluster version %s does not support v1 CRDs or webhooks",
128-
srvVer.GitVersion))
129-
}
130-
131-
GenerateV3(kbc, "v1")
132-
Run(kbc)
133-
})
134-
It("should generate a runnable project with v1beta1 CRDs and Webhooks", func() {
135-
// Skip if cluster version < 1.15, when `.spec.preserveUnknownFields` was not a v1beta1 CRD field.
136-
// Skip if cluster version >= 1.22 because pre v1 CRDs and webhooks no longer exist.
137-
if srvVer := kbc.K8sVersion.ServerVersion; srvVer.GetMajorInt() <= 1 && srvVer.GetMinorInt() < 15 ||
138-
srvVer.GetMajorInt() <= 1 && srvVer.GetMinorInt() >= 22 {
139-
Skip(fmt.Sprintf("cluster version %s does not support project defaults ",
140-
srvVer.GitVersion))
141-
}
142-
143-
GenerateV3(kbc, "v1beta1")
93+
GenerateV3(kbc)
14494
Run(kbc)
14595
})
14696

14797
It("should generate a runnable project go/v3 with v1 CRDs and Webhooks with restricted pods", func() {
148-
// Skip if cluster version < 1.16, when v1 CRDs and webhooks did not exist.
149-
// Skip if cluster version < 1.19, because securityContext.seccompProfile only works from 1.19
150-
// Otherwise, unknown field "seccompProfile" in io.k8s.api.core.v1.PodSecurityContext will be faced
151-
if srvVer := kbc.K8sVersion.ServerVersion; srvVer.GetMajorInt() <= 1 && srvVer.GetMinorInt() < 19 {
152-
Skip(fmt.Sprintf("cluster version %s does not support v1 CRDs or webhooks"+
153-
"and securityContext.seccompProfile", srvVer.GitVersion))
154-
}
155-
15698
kbc.IsRestricted = true
157-
GenerateV3(kbc, "v1")
99+
GenerateV3(kbc)
158100
Run(kbc)
159101
})
160-
It("should generate a runnable project with v1beta1 CRDs and Webhooks with restricted pods", func() {
161-
// Skip if cluster version < 1.15, when `.spec.preserveUnknownFields` was not a v1beta1 CRD field.
162-
// Skip if cluster version < 1.19, because securityContext.seccompProfile only works from 1.19
163-
// Otherwise, unknown field "seccompProfile" in io.k8s.api.core.v1.PodSecurityContext will be faced
164-
// Skip if cluster version >= 1.22 because pre v1 CRDs and webhooks no longer exist.
165-
if srvVer := kbc.K8sVersion.ServerVersion; srvVer.GetMajorInt() <= 1 && srvVer.GetMinorInt() < 19 ||
166-
srvVer.GetMajorInt() <= 1 && srvVer.GetMinorInt() >= 22 {
167-
Skip(fmt.Sprintf("cluster version %s does not support project defaults "+
168-
"and securityContext.seccompProfile", srvVer.GitVersion))
169-
}
170102

171-
kbc.IsRestricted = true
172-
GenerateV3(kbc, "v1beta1")
173-
Run(kbc)
174-
})
175103
It("should generate a runnable project go/v3 with v1 CRDs and Webhooks"+
176104
"with --component-config flag enabled", func() {
177-
// Skip if cluster version < 1.16, when v1 CRDs and webhooks did not exist.
178-
if srvVer := kbc.K8sVersion.ServerVersion; srvVer.GetMajorInt() <= 1 && srvVer.GetMinorInt() < 16 {
179-
Skip(fmt.Sprintf("cluster version %s does not support v1 CRDs or webhooks",
180-
srvVer.GitVersion))
181-
}
182-
183-
GenerateV3ComponentConfig(kbc, "v1")
105+
GenerateV3ComponentConfig(kbc)
184106
Run(kbc)
185107
})
186108
})

test/e2e/v4/plugin_cluster_test.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -83,29 +83,13 @@ var _ = Describe("kubebuilder", func() {
8383
})
8484
It("should generate a runnable project"+
8585
" with restricted pods", func() {
86-
// Skip if cluster version < 1.16, when v1 CRDs and webhooks did not exist.
87-
// Skip if cluster version < 1.19, because securityContext.seccompProfile only works from 1.19
88-
// Otherwise, unknown field "seccompProfile" in io.k8s.api.core.v1.PodSecurityContext will be faced
89-
if srvVer := kbc.K8sVersion.ServerVersion; srvVer.GetMajorInt() <= 1 && srvVer.GetMinorInt() < 19 {
90-
Skip(fmt.Sprintf("cluster version %s does not support v1 CRDs or webhooks "+
91-
"and securityContext.seccompProfile", srvVer.GitVersion))
92-
}
93-
9486
kbc.IsRestricted = true
9587
GenerateV4(kbc)
9688
Run(kbc)
9789
})
9890

9991
It("should generate a runnable project"+
10092
" with restricted pods and with --component-config field enabled", func() {
101-
// Skip if cluster version < 1.16, when v1 CRDs and webhooks did not exist.
102-
// Skip if cluster version < 1.19, because securityContext.seccompProfile only works from 1.19
103-
// Otherwise, unknown field "seccompProfile" in io.k8s.api.core.v1.PodSecurityContext will be faced
104-
if srvVer := kbc.K8sVersion.ServerVersion; srvVer.GetMajorInt() <= 1 && srvVer.GetMinorInt() < 19 {
105-
Skip(fmt.Sprintf("cluster version %s does not support v1 CRDs or webhooks "+
106-
"and securityContext.seccompProfile", srvVer.GitVersion))
107-
}
108-
10993
kbc.IsRestricted = true
11094
GenerateV4ComponentConfig(kbc)
11195
Run(kbc)

0 commit comments

Comments
 (0)