Skip to content

Commit

Permalink
🌱 test: drop handling for old k8s version (#2925)
Browse files Browse the repository at this point in the history
* test: drop handling for old k8s version

* chore: clean up test func

* chore: remove v2 test func
  • Loading branch information
Eileen-Yu authored Sep 12, 2022
1 parent e7c871e commit a6251f0
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 223 deletions.
16 changes: 0 additions & 16 deletions test/e2e/deployimage/plugin_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,6 @@ var _ = Describe("kubebuilder", func() {
})

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

var err error

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

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

var err error

By("initializing a project with go/v3")
Expand Down
113 changes: 3 additions & 110 deletions test/e2e/v3/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,103 +34,8 @@ import (
"sigs.k8s.io/kubebuilder/v3/test/e2e/utils"
)

// GenerateV2 implements a go/v2 plugin project defined by a TestContext.
func GenerateV2(kbc *utils.TestContext) {
var err error

By("initializing a project")
err = kbc.Init(
"--plugins", "go/v2",
"--project-version", "3",
"--domain", kbc.Domain,
"--fetch-deps=false",
)
ExpectWithOffset(1, err).NotTo(HaveOccurred())

By("creating API definition")
err = kbc.CreateAPI(
"--group", kbc.Group,
"--version", kbc.Version,
"--kind", kbc.Kind,
"--namespaced",
"--resource",
"--controller",
"--make=false",
)
ExpectWithOffset(1, err).NotTo(HaveOccurred())

By("implementing the API")
ExpectWithOffset(1, pluginutil.InsertCode(
filepath.Join(kbc.Dir, "api", kbc.Version, fmt.Sprintf("%s_types.go", strings.ToLower(kbc.Kind))),
fmt.Sprintf(`type %sSpec struct {
`, kbc.Kind),
` // +optional
Count int `+"`"+`json:"count,omitempty"`+"`"+`
`)).Should(Succeed())

By("scaffolding mutating and validating webhooks")
err = kbc.CreateWebhook(
"--group", kbc.Group,
"--version", kbc.Version,
"--kind", kbc.Kind,
"--defaulting",
"--programmatic-validation",
)
ExpectWithOffset(1, err).NotTo(HaveOccurred())

By("implementing the mutating and validating webhooks")
err = pluginutil.ImplementWebhooks(filepath.Join(
kbc.Dir, "api", kbc.Version,
fmt.Sprintf("%s_webhook.go", strings.ToLower(kbc.Kind))))
ExpectWithOffset(1, err).NotTo(HaveOccurred())

By("uncomment kustomization.yaml to enable webhook and ca injection")
ExpectWithOffset(1, pluginutil.UncommentCode(
filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
"#- ../webhook", "#")).To(Succeed())
ExpectWithOffset(1, pluginutil.UncommentCode(
filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
"#- ../certmanager", "#")).To(Succeed())
ExpectWithOffset(1, pluginutil.UncommentCode(
filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
"#- ../prometheus", "#")).To(Succeed())
ExpectWithOffset(1, pluginutil.UncommentCode(
filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
"#- manager_webhook_patch.yaml", "#")).To(Succeed())
ExpectWithOffset(1, pluginutil.UncommentCode(
filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
"#- webhookcainjection_patch.yaml", "#")).To(Succeed())
ExpectWithOffset(1, pluginutil.UncommentCode(filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
`#- name: CERTIFICATE_NAMESPACE # namespace of the certificate CR
# objref:
# kind: Certificate
# group: cert-manager.io
# version: v1alpha2
# name: serving-cert # this name should match the one in certificate.yaml
# fieldref:
# fieldpath: metadata.namespace
#- name: CERTIFICATE_NAME
# objref:
# kind: Certificate
# group: cert-manager.io
# version: v1alpha2
# name: serving-cert # this name should match the one in certificate.yaml
#- name: SERVICE_NAMESPACE # namespace of the service
# objref:
# kind: Service
# version: v1
# name: webhook-service
# fieldref:
# fieldpath: metadata.namespace
#- name: SERVICE_NAME
# objref:
# kind: Service
# version: v1
# name: webhook-service`, "#")).To(Succeed())
}

// GenerateV3 implements a go/v3(-alpha) plugin project defined by a TestContext.
func GenerateV3(kbc *utils.TestContext, crdAndWebhookVersion string) {
func GenerateV3(kbc *utils.TestContext) {
var err error

By("initializing a project")
Expand All @@ -151,7 +56,6 @@ func GenerateV3(kbc *utils.TestContext, crdAndWebhookVersion string) {
"--resource",
"--controller",
"--make=false",
"--crd-version", crdAndWebhookVersion,
)
ExpectWithOffset(1, err).NotTo(HaveOccurred())

Expand All @@ -171,7 +75,6 @@ Count int `+"`"+`json:"count,omitempty"`+"`"+`
"--kind", kbc.Kind,
"--defaulting",
"--programmatic-validation",
"--webhook-version", crdAndWebhookVersion,
)
ExpectWithOffset(1, err).NotTo(HaveOccurred())

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

if crdAndWebhookVersion == "v1beta1" {
_ = pluginutil.RunCmd("Update dependencies", "go", "mod", "tidy")
}

if kbc.IsRestricted {
By("uncomment kustomize files to ensure that pods are restricted")
uncommentPodStandards(kbc)
}
}

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

By("initializing a project")
Expand All @@ -258,7 +157,6 @@ func GenerateV3ComponentConfig(kbc *utils.TestContext, crdAndWebhookVersion stri
"--resource",
"--controller",
"--make=false",
"--crd-version", crdAndWebhookVersion,
)
ExpectWithOffset(1, err).NotTo(HaveOccurred())

Expand All @@ -278,7 +176,6 @@ Count int `+"`"+`json:"count,omitempty"`+"`"+`
"--kind", kbc.Kind,
"--defaulting",
"--programmatic-validation",
"--webhook-version", crdAndWebhookVersion,
)
ExpectWithOffset(1, err).NotTo(HaveOccurred())

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

if crdAndWebhookVersion == "v1beta1" {
_ = pluginutil.RunCmd("Update dependencies", "go", "mod", "tidy")
}

if kbc.IsRestricted {
By("uncomment kustomize files to ensure that pods are restricted")
uncommentPodStandards(kbc)
Expand Down
84 changes: 3 additions & 81 deletions test/e2e/v3/plugin_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,38 +78,6 @@ var _ = Describe("kubebuilder", func() {
kbc.Destroy()
})

//TODO: remove me when the plugin go/v2 be removed
//go:deprecated this plugin is deprecated
Context("plugin go.kubebuilder.io/v2", func() {
// Use cert-manager with v1beta2 CRs.
BeforeEach(func() {
// Skip if cluster version >= 1.22 because pre v1 CRDs and webhooks no longer exist.
if srvVer := kbc.K8sVersion.ServerVersion; srvVer.GetMajorInt() >= 1 && srvVer.GetMinorInt() >= 22 {
Skip(fmt.Sprintf("cluster version %s does not support pre v1 CRDs or webhooks", srvVer.GitVersion))
}
By("installing the v1beta2 cert-manager bundle")
Expect(kbc.InstallCertManager(true)).To(Succeed())
})
AfterEach(func() {
// Skip if cluster version >= 1.22 because pre v1 CRDs and webhooks no longer exist.
if srvVer := kbc.K8sVersion.ServerVersion; srvVer.GetMajorInt() >= 1 && srvVer.GetMinorInt() >= 22 {
Skip(fmt.Sprintf("cluster version %s does not support pre v1 CRDs or webhooks", srvVer.GitVersion))
}
By("uninstalling the v1beta2 cert-manager bundle")
kbc.UninstallCertManager(true)
})

It("should generate a runnable project go/v2 with default SA", func() {
// go/v3 uses a unqiue-per-project service account name,
// while go/v2 still uses "default".
tmp := kbc.Kubectl.ServiceAccount
kbc.Kubectl.ServiceAccount = "default"
defer func() { kbc.Kubectl.ServiceAccount = tmp }()
GenerateV2(kbc)
Run(kbc)
})
})

Context("plugin go.kubebuilder.io/v3", func() {
// Use cert-manager with v1 CRs.
BeforeEach(func() {
Expand All @@ -122,65 +90,19 @@ var _ = Describe("kubebuilder", func() {
})

It("should generate a runnable project go/v3 with v1 CRDs and Webhooks", func() {
// Skip if cluster version < 1.16, when v1 CRDs and webhooks did not exist.
if srvVer := kbc.K8sVersion.ServerVersion; srvVer.GetMajorInt() <= 1 && srvVer.GetMinorInt() < 16 {
Skip(fmt.Sprintf("cluster version %s does not support v1 CRDs or webhooks",
srvVer.GitVersion))
}

GenerateV3(kbc, "v1")
Run(kbc)
})
It("should generate a runnable project with v1beta1 CRDs and Webhooks", func() {
// Skip if cluster version < 1.15, when `.spec.preserveUnknownFields` was not a v1beta1 CRD field.
// Skip if cluster version >= 1.22 because pre v1 CRDs and webhooks no longer exist.
if srvVer := kbc.K8sVersion.ServerVersion; srvVer.GetMajorInt() <= 1 && srvVer.GetMinorInt() < 15 ||
srvVer.GetMajorInt() <= 1 && srvVer.GetMinorInt() >= 22 {
Skip(fmt.Sprintf("cluster version %s does not support project defaults ",
srvVer.GitVersion))
}

GenerateV3(kbc, "v1beta1")
GenerateV3(kbc)
Run(kbc)
})

It("should generate a runnable project go/v3 with v1 CRDs and Webhooks with restricted pods", func() {
// Skip if cluster version < 1.16, when v1 CRDs and webhooks did not exist.
// Skip if cluster version < 1.19, because securityContext.seccompProfile only works from 1.19
// Otherwise, unknown field "seccompProfile" in io.k8s.api.core.v1.PodSecurityContext will be faced
if srvVer := kbc.K8sVersion.ServerVersion; srvVer.GetMajorInt() <= 1 && srvVer.GetMinorInt() < 19 {
Skip(fmt.Sprintf("cluster version %s does not support v1 CRDs or webhooks"+
"and securityContext.seccompProfile", srvVer.GitVersion))
}

kbc.IsRestricted = true
GenerateV3(kbc, "v1")
GenerateV3(kbc)
Run(kbc)
})
It("should generate a runnable project with v1beta1 CRDs and Webhooks with restricted pods", func() {
// Skip if cluster version < 1.15, when `.spec.preserveUnknownFields` was not a v1beta1 CRD field.
// Skip if cluster version < 1.19, because securityContext.seccompProfile only works from 1.19
// Otherwise, unknown field "seccompProfile" in io.k8s.api.core.v1.PodSecurityContext will be faced
// Skip if cluster version >= 1.22 because pre v1 CRDs and webhooks no longer exist.
if srvVer := kbc.K8sVersion.ServerVersion; srvVer.GetMajorInt() <= 1 && srvVer.GetMinorInt() < 19 ||
srvVer.GetMajorInt() <= 1 && srvVer.GetMinorInt() >= 22 {
Skip(fmt.Sprintf("cluster version %s does not support project defaults "+
"and securityContext.seccompProfile", srvVer.GitVersion))
}

kbc.IsRestricted = true
GenerateV3(kbc, "v1beta1")
Run(kbc)
})
It("should generate a runnable project go/v3 with v1 CRDs and Webhooks"+
"with --component-config flag enabled", func() {
// Skip if cluster version < 1.16, when v1 CRDs and webhooks did not exist.
if srvVer := kbc.K8sVersion.ServerVersion; srvVer.GetMajorInt() <= 1 && srvVer.GetMinorInt() < 16 {
Skip(fmt.Sprintf("cluster version %s does not support v1 CRDs or webhooks",
srvVer.GitVersion))
}

GenerateV3ComponentConfig(kbc, "v1")
GenerateV3ComponentConfig(kbc)
Run(kbc)
})
})
Expand Down
16 changes: 0 additions & 16 deletions test/e2e/v4/plugin_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,29 +83,13 @@ var _ = Describe("kubebuilder", func() {
})
It("should generate a runnable project"+
" with restricted pods", func() {
// Skip if cluster version < 1.16, when v1 CRDs and webhooks did not exist.
// Skip if cluster version < 1.19, because securityContext.seccompProfile only works from 1.19
// Otherwise, unknown field "seccompProfile" in io.k8s.api.core.v1.PodSecurityContext will be faced
if srvVer := kbc.K8sVersion.ServerVersion; srvVer.GetMajorInt() <= 1 && srvVer.GetMinorInt() < 19 {
Skip(fmt.Sprintf("cluster version %s does not support v1 CRDs or webhooks "+
"and securityContext.seccompProfile", srvVer.GitVersion))
}

kbc.IsRestricted = true
GenerateV4(kbc)
Run(kbc)
})

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

kbc.IsRestricted = true
GenerateV4ComponentConfig(kbc)
Run(kbc)
Expand Down

0 comments on commit a6251f0

Please sign in to comment.