diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index 662d1d4..e882146 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -18,6 +18,7 @@ package e2e import ( "fmt" + "os" "os/exec" "github.com/functions-dev/func-operator/test/utils" @@ -30,6 +31,26 @@ const namespace = "func-operator-system" // serviceAccountName created for the project const serviceAccountName = "func-operator-controller-manager" +func deployerIsKedaOrRaw() bool { + d := os.Getenv("DEFAULT_DEPLOYER") + return d == "keda" || d == "raw" +} + +// Newest knative/func that still ships go/http middleware func-go v0.21.3 +// and has knative, raw, and keda deployers. Current CLI (1.23+) ships +// v0.22.0, so a seed with this version makes the operator redeploy. +const staleFuncCLI = "v1.22.2" +const staleMiddlewareVersion = "v0.21.3" + +// workloadKind is the cluster object that holds the function pod template. +// keda/raw use a Deployment; knative uses a Service (ksvc). +func workloadKind() string { + if deployerIsKedaOrRaw() { + return "deploy" + } + return "ksvc" +} + // logFailedTestDetails logs function resource and controller logs on test failure func logFailedTestDetails(functionName, functionNamespace string) { specReport := CurrentSpecReport() diff --git a/test/e2e/func_deploy_test.go b/test/e2e/func_deploy_test.go index 9d324fa..f77e061 100644 --- a/test/e2e/func_deploy_test.go +++ b/test/e2e/func_deploy_test.go @@ -752,24 +752,18 @@ var _ = Describe("Operator", func() { // --image-pull-secret to the func CLI during a redeploy, which causes the // func CLI to set imagePullSecrets on the function's pod spec. // - // It uses a dummy dockerconfigjson secret and the unauthenticated kind-registry - // because the kind-registry's built-in htpasswd auth is all-or-nothing (no - // per-repository scoping), so enabling auth would break all other tests. The - // unit tests in function_controller_test.go verify the --image-pull-secret flag - // is passed; this test confirms the Knative Service's pod template actually - // receives the imagePullSecrets after a real redeploy. + // It uses a dummy dockerconfigjson secret. Kind uses an unauthenticated + // registry (htpasswd is all-or-nothing, so enabling auth would break + // other tests). Unit tests in function_controller_test.go verify the + // flag; this test confirms the workload pod template receives + // imagePullSecrets after a real redeploy (KService for knative, + // Deployment for keda/raw). Context("with a registry auth secret", func() { var repoURL string var repoDir string var functionName, functionNamespace string BeforeEach(func() { - if os.Getenv("DEFAULT_DEPLOYER") == "keda" || - os.Getenv("DEFAULT_DEPLOYER") == "raw" { - Skip("Skipping registry auth test for Keda & raw deployer, " + - "as test inspect KService directly") - } - var err error username, password, _, cleanup, err := repoProvider.CreateRandomUser() @@ -784,19 +778,17 @@ var _ = Describe("Operator", func() { Expect(err).NotTo(HaveOccurred()) utils.DeferCleanupOnSuccess(cleanupNamespaces, functionNamespace) - oldFuncVersion := "v1.20.2" + // Seed with staleFuncCLI so middleware is outdated and the operator + // actually runs deploy() (the path that passes --image-pull-secret). repoDir, err = utils.InitializeRepoWithFunction( - repoURL, - username, - password, - "go", - utils.WithCliVersion(oldFuncVersion)) + repoURL, username, password, "go", + utils.WithCliVersion(staleFuncCLI)) Expect(err).NotTo(HaveOccurred()) utils.DeferCleanupOnSuccess(os.RemoveAll, repoDir) out, err := utils.RunFuncDeploy(repoDir, utils.WithNamespace(functionNamespace), - utils.WithDeployCliVersion(oldFuncVersion)) + utils.WithDeployCliVersion(staleFuncCLI)) Expect(err).NotTo(HaveOccurred()) _, _ = fmt.Fprint(GinkgoWriter, out) @@ -812,7 +804,7 @@ var _ = Describe("Operator", func() { logFailedTestDetails(functionName, functionNamespace) }) - It("should set imagePullSecrets on the Knative Service", func() { + It("should set imagePullSecrets on the function workload", func() { funcMetadata, err := funcfn.NewFunction(repoDir) Expect(err).NotTo(HaveOccurred()) deployedFunctionName := funcMetadata.Name @@ -860,14 +852,14 @@ var _ = Describe("Operator", func() { Eventually(functionBecomesReady(functionName, functionNamespace)).Should(Succeed()) - // Verify the Knative Service has imagePullSecrets set on its pod template. + // Verify the workload pod template has imagePullSecrets. Eventually(func(g Gomega) { - cmd := exec.Command("kubectl", "get", "ksvc", deployedFunctionName, + cmd := exec.Command("kubectl", "get", workloadKind(), deployedFunctionName, "-n", functionNamespace, "-o", "jsonpath={.spec.template.spec.imagePullSecrets}") out, err := utils.Run(cmd) g.Expect(err).NotTo(HaveOccurred()) - g.Expect(out).NotTo(BeEmpty(), "imagePullSecrets not set on Knative Service %s", deployedFunctionName) + g.Expect(out).NotTo(BeEmpty(), "imagePullSecrets not set on %s %s", workloadKind(), deployedFunctionName) var pullSecrets []v1.LocalObjectReference g.Expect(json.Unmarshal([]byte(out), &pullSecrets)).To(Succeed()) diff --git a/test/e2e/func_middleware_update_test.go b/test/e2e/func_middleware_update_test.go index 053f3a0..f345ea7 100644 --- a/test/e2e/func_middleware_update_test.go +++ b/test/e2e/func_middleware_update_test.go @@ -45,11 +45,6 @@ var _ = Describe("Middleware Update", func() { var functionName, functionNamespace string BeforeEach(func() { - if os.Getenv("DEFAULT_DEPLOYER") == "keda" || os.Getenv("DEFAULT_DEPLOYER") == "raw" { - Skip("Skipping middleware test for Keda & raw deployer, " + - "as those are not supported on used CLI version (1.20.x) of this tests") - } - var err error // Create repository provider resources with automatic cleanup @@ -65,22 +60,20 @@ var _ = Describe("Middleware Update", func() { Expect(err).NotTo(HaveOccurred()) utils.DeferCleanupOnSuccess(cleanupNamespaces, functionNamespace) - // Initialize repository with function code using OLD func CLI version - // v1.20.2 has no middleware-version label and uses instance-compatible templates - oldFuncVersion := "v1.20.2" + // Seed with staleFuncCLI (func-go v0.21.3, knative/raw/keda). + // Operator current CLI is 1.23+ (func-go v0.22.0) so it must redeploy. repoDir, err = utils.InitializeRepoWithFunction( repoURL, username, password, "go", - utils.WithCliVersion(oldFuncVersion)) + utils.WithCliVersion(staleFuncCLI)) Expect(err).NotTo(HaveOccurred()) utils.DeferCleanupOnSuccess(os.RemoveAll, repoDir) - // Deploy function using the same OLD func CLI version out, err := utils.RunFuncDeploy(repoDir, utils.WithNamespace(functionNamespace), - utils.WithDeployCliVersion(oldFuncVersion)) + utils.WithDeployCliVersion(staleFuncCLI)) Expect(err).NotTo(HaveOccurred()) _, _ = fmt.Fprint(GinkgoWriter, out) @@ -120,7 +113,7 @@ var _ = Describe("Middleware Update", func() { // We use skopeo with localhost:5001 (port-forward to the registry) to // directly inspect the OCI image labels and verify the middleware was updated. - // Get initial image digest from func describe (deployed with v1.20.2) + // Get initial image digest from func describe (seeded with staleFuncCLI) out, err := utils.RunFunc("describe", deployedFunctionName, "-n", functionNamespace, "-o", "yaml") Expect(err).NotTo(HaveOccurred()) @@ -130,9 +123,9 @@ var _ = Describe("Middleware Update", func() { initialImage := initialInstance.Image Expect(initialImage).NotTo(BeEmpty(), "Initial image should be available from func describe") - _, _ = fmt.Fprintf(GinkgoWriter, "Initial image (deployed with v1.20.2): %s\n", initialImage) + _, _ = fmt.Fprintf(GinkgoWriter, "Initial image (deployed with %s): %s\n", staleFuncCLI, initialImage) - // Verify initial image has no middleware-version label (v1.20.2 doesn't set it) + // Verify initial image is labeled with stale middleware (func-go v0.21.3) initialImageLocal := strings.Replace(initialImage, "kind-registry:5000", "localhost:5001", 1) // Remove tag if both tag and digest are present (skopeo doesn't support this format) if strings.Contains(initialImageLocal, "@") { @@ -161,8 +154,9 @@ var _ = Describe("Middleware Update", func() { Expect(err).NotTo(HaveOccurred()) initialMiddlewareVersion := initialImageLabels.Labels[funcfn.MiddlewareVersionLabelKey] - _, _ = fmt.Fprintf(GinkgoWriter, "Initial middleware-version label: '%s' (expected empty for v1.20.2)\n", - initialMiddlewareVersion) + _, _ = fmt.Fprintf(GinkgoWriter, "Initial middleware-version label: '%s' (expected %s)\n", + initialMiddlewareVersion, staleMiddlewareVersion) + Expect(initialMiddlewareVersion).To(Equal(staleMiddlewareVersion)) // Create a Function resource fn := &functionsdevv1alpha1.Function{ @@ -233,8 +227,8 @@ var _ = Describe("Middleware Update", func() { updatedMiddlewareVersion := updatedImageLabels.Labels[funcfn.MiddlewareVersionLabelKey] _, _ = fmt.Fprintf(GinkgoWriter, "Updated middleware-version label: '%s'\n", updatedMiddlewareVersion) - // The operator should have set a middleware version Expect(updatedMiddlewareVersion).NotTo(BeEmpty(), "Operator should have deployed with middleware-version label set") + Expect(updatedMiddlewareVersion).NotTo(Equal(initialMiddlewareVersion), "Operator should have bumped middleware") Eventually(functionMiddlewareUpToDate(functionName, functionNamespace), 2*time.Minute).Should(Succeed()) }) @@ -253,11 +247,6 @@ var _ = Describe("Middleware Update", func() { var originalConfigMapData map[string]string BeforeEach(func() { - if os.Getenv("DEFAULT_DEPLOYER") == "keda" || os.Getenv("DEFAULT_DEPLOYER") == "raw" { - Skip("Skipping middleware test for Keda & raw deployer, " + - "as those are not supported on used CLI version (1.20.x) of this tests") - } - var err error // Save original ConfigMap data to restore later @@ -300,22 +289,18 @@ var _ = Describe("Middleware Update", func() { Expect(err).NotTo(HaveOccurred()) utils.DeferCleanupOnSuccess(cleanupNamespaces, functionNamespace) - // Initialize repository with function code using OLD func CLI version - // to ensure middleware will be outdated - oldFuncVersion := "v1.20.2" repoDir, err = utils.InitializeRepoWithFunction( repoURL, username, password, "go", - utils.WithCliVersion(oldFuncVersion)) + utils.WithCliVersion(staleFuncCLI)) Expect(err).NotTo(HaveOccurred()) utils.DeferCleanupOnSuccess(os.RemoveAll, repoDir) - // Deploy function using the same OLD func CLI version out, err := utils.RunFuncDeploy(repoDir, utils.WithNamespace(functionNamespace), - utils.WithDeployCliVersion(oldFuncVersion)) + utils.WithDeployCliVersion(staleFuncCLI)) Expect(err).NotTo(HaveOccurred()) _, _ = fmt.Fprint(GinkgoWriter, out) @@ -433,7 +418,6 @@ var _ = Describe("Middleware Update", func() { }, fn) g.Expect(err).NotTo(HaveOccurred()) - // The image should have changed (middleware was updated) g.Expect(fn.Status.Deployment.Image).NotTo(BeEmpty()) g.Expect(fn.Status.Deployment.Image).NotTo(Equal(imageBefore), "Image should have changed after middleware update")