Skip to content

Commit

Permalink
Upgrade e2e test for latest Kubernetes versions
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Hickey <[email protected]>
  • Loading branch information
hickeyma committed Oct 4, 2021
1 parent 26803e6 commit 093f229
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 34 deletions.
2 changes: 1 addition & 1 deletion test/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if [ -n "$TRACE" ]; then
set -x
fi

k8s_version=1.16.4
k8s_version=1.19.2
goarch=amd64

if [[ "$OSTYPE" == "linux-gnu" ]]; then
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ source "$(dirname "$0")/../common.sh"
source "$(dirname "$0")/setup.sh"

export KIND_CLUSTER="local-kubebuilder-e2e"
create_cluster ${KIND_K8S_VERSION:-v1.18.15}
create_cluster ${KIND_K8S_VERSION:-v1.19.11}
if [ -z "${SKIP_KIND_CLEANUP:-}" ]; then
trap delete_cluster EXIT
fi
Expand Down
10 changes: 6 additions & 4 deletions test/e2e/utils/test_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ func (t *TestContext) Prepare() error {

const (
certmanagerVersionWithv1beta2CRs = "v0.11.0"
certmanagerVersion = "v1.0.4"
certmanagerLegacyVersion = "v1.0.4"
certmanagerVersion = "v1.5.3"

certmanagerURLTmplLegacy = "https://github.com/jetstack/cert-manager/releases/download/%s/cert-manager-legacy.yaml"
certmanagerURLTmpl = "https://github.com/jetstack/cert-manager/releases/download/%s/cert-manager.yaml"
Expand All @@ -122,7 +123,7 @@ func (t *TestContext) makeCertManagerURL(hasv1beta1CRs bool) string {
// Determine which URL to use for a manifest bundle with v1 CRs.
// The most up-to-date bundle uses v1 CRDs, which were introduced in k8s v1.16.
if ver := t.K8sVersion.ServerVersion; ver.GetMajorInt() <= 1 && ver.GetMinorInt() < 16 {
return fmt.Sprintf(certmanagerURLTmplLegacy, certmanagerVersion)
return fmt.Sprintf(certmanagerURLTmplLegacy, certmanagerLegacyVersion)
}
return fmt.Sprintf(certmanagerURLTmpl, certmanagerVersion)
}
Expand Down Expand Up @@ -158,8 +159,9 @@ func (t *TestContext) UninstallCertManager(hasv1beta1CRs bool) {
}

const (
prometheusOperatorVersion = "0.33"
prometheusOperatorURL = "https://raw.githubusercontent.com/coreos/prometheus-operator/release-%s/bundle.yaml"
prometheusOperatorVersion = "0.51"
prometheusOperatorURL = "https://raw.githubusercontent.com/prometheus-operator/" +
"prometheus-operator/release-%s/bundle.yaml"
)

// InstallPrometheusOperManager installs the prometheus manager bundle.
Expand Down
53 changes: 37 additions & 16 deletions test/e2e/v2/plugin_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,30 +46,41 @@ var _ = Describe("kubebuilder", func() {
Expect(err).NotTo(HaveOccurred())
Expect(kbc.Prepare()).To(Succeed())

// Install cert-manager with v1beta2 CRs.
By("installing cert manager bundle")
Expect(kbc.InstallCertManager(true)).To(Succeed())

By("installing prometheus operator")
Expect(kbc.InstallPrometheusOperManager()).To(Succeed())
// 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 {
// Install cert-manager with v1beta2 CRs.
By("installing cert manager bundle")
Expect(kbc.InstallCertManager(true)).To(Succeed())

By("installing prometheus operator")
Expect(kbc.InstallPrometheusOperManager()).To(Succeed())
}
})

AfterEach(func() {
By("clean up created API objects during test process")
kbc.CleanupManifests(filepath.Join("config", "default"))

By("uninstalling prometheus manager bundle")
kbc.UninstallPrometheusOperManager()
// 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 {
By("uninstalling prometheus manager bundle")
kbc.UninstallPrometheusOperManager()

// Uninstall cert-manager with v1beta2 CRs.
By("uninstalling cert manager bundle")
kbc.UninstallCertManager(true)
// Uninstall cert-manager with v1beta2 CRs.
By("uninstalling cert manager bundle")
kbc.UninstallCertManager(true)
}

By("remove container image and work dir")
kbc.Destroy()
})

It("should generate a runnable project", func() {
// Skip if cluster version >= 1.22, when pre v1 CRDs and webhooks did not 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))
}
var controllerPodName string
By("init v2 project")
err := kbc.Init(
Expand Down Expand Up @@ -217,11 +228,21 @@ var _ = Describe("kubebuilder", func() {
Expect(len(token)).To(BeNumerically(">", 0))

By("creating a pod with curl image")
cmdOpts := []string{
"run", "--generator=run-pod/v1", "curl", "--image=curlimages/curl:7.68.0", "--restart=OnFailure", "--",
"curl", "-v", "-k", "-H", fmt.Sprintf(`Authorization: Bearer %s`, token),
fmt.Sprintf("https://e2e-%v-controller-manager-metrics-service.e2e-%v-system.svc:8443/metrics",
kbc.TestSuffix, kbc.TestSuffix),
var cmdOpts []string
if clientVer := kbc.K8sVersion.ClientVersion; clientVer.GetMajorInt() <= 1 && clientVer.GetMinorInt() < 18 {
cmdOpts = []string{
"run", "--generator=run-pod/v1", "curl", "--image=curlimages/curl:7.68.0", "--restart=OnFailure", "--",
"curl", "-v", "-k", "-H", fmt.Sprintf(`Authorization: Bearer %s`, token),
fmt.Sprintf("https://e2e-%v-controller-manager-metrics-service.e2e-%v-system.svc:8443/metrics",
kbc.TestSuffix, kbc.TestSuffix),
}
} else {
cmdOpts = []string{
"run", "curl", "--image=curlimages/curl:7.68.0", "--restart=OnFailure", "--",
"curl", "-v", "-k", "-H", fmt.Sprintf(`Authorization: Bearer %s`, token),
fmt.Sprintf("https://e2e-%v-controller-manager-metrics-service.e2e-%v-system.svc:8443/metrics",
kbc.TestSuffix, kbc.TestSuffix),
}
}
_, err = kbc.Kubectl.CommandInNamespace(cmdOpts...)
Expect(err).NotTo(HaveOccurred())
Expand Down
48 changes: 36 additions & 12 deletions test/e2e/v3/plugin_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,26 @@ var _ = Describe("kubebuilder", func() {
Context("plugin go.kubebuilder.io/v2", func() {
// Use cert-manager with v1beta2 CRs.
BeforeEach(func() {
By("installing the v1beta2 cert-manager bundle")
Expect(kbc.InstallCertManager(true)).To(Succeed())
// 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 {
By("installing the v1beta2 cert-manager bundle")
Expect(kbc.InstallCertManager(true)).To(Succeed())
}
})
AfterEach(func() {
By("uninstalling the v1beta2 cert-manager bundle")
kbc.UninstallCertManager(true)
// 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 {
By("uninstalling the v1beta2 cert-manager bundle")
kbc.UninstallCertManager(true)
}
})

It("should generate a runnable project", 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))
}

// go/v3 uses a unqiue-per-project service account name,
// while go/v2 still uses "default".
tmp := kbc.Kubectl.ServiceAccount
Expand Down Expand Up @@ -109,7 +120,9 @@ var _ = Describe("kubebuilder", func() {
})
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.
if srvVer := kbc.K8sVersion.ServerVersion; srvVer.GetMajorInt() <= 1 && srvVer.GetMinorInt() < 16 {
// 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() < 16 ||
srvVer.GetMajorInt() <= 1 && srvVer.GetMinorInt() >= 22 {
Skip(fmt.Sprintf("cluster version %s does not support project defaults", srvVer.GitVersion))
}

Expand Down Expand Up @@ -306,12 +319,23 @@ func curlMetrics(kbc *utils.TestContext) string {
ExpectWithOffset(2, len(token)).To(BeNumerically(">", 0))

By("creating a curl pod")
cmdOpts := []string{
"run", "--generator=run-pod/v1", "curl", "--image=curlimages/curl:7.68.0", "--restart=OnFailure",
"--serviceaccount=" + kbc.Kubectl.ServiceAccount, "--",
"curl", "-v", "-k", "-H", fmt.Sprintf(`Authorization: Bearer %s`, token),
fmt.Sprintf("https://e2e-%s-controller-manager-metrics-service.%s.svc:8443/metrics",
kbc.TestSuffix, kbc.Kubectl.Namespace),
var cmdOpts []string
if clientVer := kbc.K8sVersion.ClientVersion; clientVer.GetMajorInt() <= 1 && clientVer.GetMinorInt() < 18 {
cmdOpts = []string{
"run", "--generator=run-pod/v1", "curl", "--image=curlimages/curl:7.68.0", "--restart=OnFailure",
"--serviceaccount=" + kbc.Kubectl.ServiceAccount, "--",
"curl", "-v", "-k", "-H", fmt.Sprintf(`Authorization: Bearer %s`, token),
fmt.Sprintf("https://e2e-%s-controller-manager-metrics-service.%s.svc:8443/metrics",
kbc.TestSuffix, kbc.Kubectl.Namespace),
}
} else {
cmdOpts = []string{
"run", "curl", "--image=curlimages/curl:7.68.0", "--restart=OnFailure",
"--serviceaccount=" + kbc.Kubectl.ServiceAccount, "--",
"curl", "-v", "-k", "-H", fmt.Sprintf(`Authorization: Bearer %s`, token),
fmt.Sprintf("https://e2e-%s-controller-manager-metrics-service.%s.svc:8443/metrics",
kbc.TestSuffix, kbc.Kubectl.Namespace),
}
}
_, err = kbc.Kubectl.CommandInNamespace(cmdOpts...)
ExpectWithOffset(2, err).NotTo(HaveOccurred())
Expand All @@ -328,7 +352,7 @@ func curlMetrics(kbc *utils.TestContext) string {
}
return nil
}
EventuallyWithOffset(2, verifyCurlUp, 30*time.Second, time.Second).Should(Succeed())
EventuallyWithOffset(2, verifyCurlUp, 240*time.Second, time.Second).Should(Succeed())

By("validating that the metrics endpoint is serving as expected")
var metricsOutput string
Expand Down

0 comments on commit 093f229

Please sign in to comment.