This is an automated email from the ASF dual-hosted git repository. pcongiusti pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit bc094e8318ae8acad8dd4bfebc620439929d6dc7 Author: Pasquale Congiusti <[email protected]> AuthorDate: Mon Jul 1 17:18:05 2024 +0200 fix(helm): account for operator id value --- e2e/common/misc/cron_test.go | 26 +++++++++++------------ e2e/install/helm/setup_test.go | 8 +++++++- e2e/install/kustomize/setup_test.go | 40 ++++++++---------------------------- e2e/support/test_util.go | 24 ++++++++++++++++++++++ helm/camel-k/templates/operator.yaml | 2 +- helm/camel-k/templates/platform.yaml | 2 +- script/Makefile | 2 +- 7 files changed, 55 insertions(+), 49 deletions(-) diff --git a/e2e/common/misc/cron_test.go b/e2e/common/misc/cron_test.go index ebff1852a..37b3a2031 100644 --- a/e2e/common/misc/cron_test.go +++ b/e2e/common/misc/cron_test.go @@ -42,36 +42,36 @@ func TestRunCronExample(t *testing.T) { WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { t.Run("cron-yaml", func(t *testing.T) { g.Expect(KamelRun(t, ctx, ns, "files/cron-yaml.yaml").Execute()).To(Succeed()) - g.Eventually(IntegrationCronJob(t, ctx, ns, "cron-yaml"), TestTimeoutLong).ShouldNot(BeNil()) - g.Eventually(IntegrationConditionStatus(t, ctx, ns, "cron-yaml", v1.IntegrationConditionReady), TestTimeoutMedium).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ctx, ns, "cron-yaml"), TestTimeoutMedium).Should(ContainSubstring("Magicstring!")) + g.Eventually(IntegrationCronJob(t, ctx, ns, "cron-yaml")).ShouldNot(BeNil()) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "cron-yaml", v1.IntegrationConditionReady)).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "cron-yaml")).Should(ContainSubstring("Magicstring!")) }) t.Run("cron-timer", func(t *testing.T) { g.Expect(KamelRun(t, ctx, ns, "files/cron-timer.yaml").Execute()).To(Succeed()) g.Eventually(IntegrationCronJob(t, ctx, ns, "cron-timer"), TestTimeoutLong).ShouldNot(BeNil()) - g.Eventually(IntegrationConditionStatus(t, ctx, ns, "cron-timer", v1.IntegrationConditionReady), TestTimeoutMedium).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ctx, ns, "cron-timer"), TestTimeoutMedium).Should(ContainSubstring("Magicstring!")) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "cron-timer", v1.IntegrationConditionReady)).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "cron-timer")).Should(ContainSubstring("Magicstring!")) }) t.Run("cron-fallback", func(t *testing.T) { g.Expect(KamelRun(t, ctx, ns, "files/cron-fallback.yaml").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ctx, ns, "cron-fallback"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ctx, ns, "cron-fallback", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ctx, ns, "cron-fallback"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "cron-fallback")).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "cron-fallback", v1.IntegrationConditionReady)).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "cron-fallback")).Should(ContainSubstring("Magicstring!")) }) t.Run("cron-quartz", func(t *testing.T) { g.Expect(KamelRun(t, ctx, ns, "files/cron-quartz.yaml").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ctx, ns, "cron-quartz"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ctx, ns, "cron-quartz", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ctx, ns, "cron-quartz"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "cron-quartz")).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "cron-quartz", v1.IntegrationConditionReady)).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationLogs(t, ctx, ns, "cron-quartz")).Should(ContainSubstring("Magicstring!")) }) t.Run("cron-trait-yaml", func(t *testing.T) { g.Expect(KamelRun(t, ctx, ns, "files/cron-trait-yaml.yaml", "-t", "cron.enabled=true", "-t", "cron.schedule=0/2 * * * *").Execute()).To(Succeed()) - g.Eventually(IntegrationConditionStatus(t, ctx, ns, "cron-trait-yaml", v1.IntegrationConditionReady), TestTimeoutMedium).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationCronJob(t, ctx, ns, "cron-trait-yaml"), TestTimeoutLong).ShouldNot(BeNil()) + g.Eventually(IntegrationConditionStatus(t, ctx, ns, "cron-trait-yaml", v1.IntegrationConditionReady)).Should(Equal(corev1.ConditionTrue)) + g.Eventually(IntegrationCronJob(t, ctx, ns, "cron-trait-yaml")).ShouldNot(BeNil()) // Verify that `-t cron.schedule` overrides the schedule in the yaml // diff --git a/e2e/install/helm/setup_test.go b/e2e/install/helm/setup_test.go index b21646abd..19e942b1e 100644 --- a/e2e/install/helm/setup_test.go +++ b/e2e/install/helm/setup_test.go @@ -41,6 +41,10 @@ func TestHelmInstallation(t *testing.T) { KAMEL_INSTALL_REGISTRY := os.Getenv("KAMEL_INSTALL_REGISTRY") WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { + // Let's make sure no CRD is yet available in the cluster + // as we must make the Helm procedure to install them accordingly + g.Eventually(CRDs(t)).Should(BeNil()) + operatorID := "helm-ck" g.Expect(KAMEL_INSTALL_REGISTRY).NotTo(Equal("")) os.Setenv("CAMEL_K_TEST_MAKE_DIR", "../../../") ExpectExecSucceed(t, g, Make(t, "release-helm")) @@ -54,6 +58,8 @@ func TestHelmInstallation(t *testing.T) { fmt.Sprintf("platform.build.registry.address=%s", KAMEL_INSTALL_REGISTRY), "--set", "platform.build.registry.insecure=true", + "--set", + fmt.Sprintf("operator.operatorId=%s", operatorID), "-n", ns, ), @@ -70,7 +76,7 @@ func TestHelmInstallation(t *testing.T) { //Test a simple route t.Run("simple route", func(t *testing.T) { name := RandomizedSuffixName("yaml") - g.Expect(KamelRun(t, ctx, ns, "files/yaml.yaml", "--name", name).Execute()).To(Succeed()) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/yaml.yaml", "--name", name).Execute()).To(Succeed()) g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) }) diff --git a/e2e/install/kustomize/setup_test.go b/e2e/install/kustomize/setup_test.go index dadb28c5a..7383bb5e1 100644 --- a/e2e/install/kustomize/setup_test.go +++ b/e2e/install/kustomize/setup_test.go @@ -102,28 +102,16 @@ func TestKustomizeNamespaced(t *testing.T) { g.Eventually(IntegrationLogs(t, ctx, ns, "yaml"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) // Test operator only uninstall - ExpectExecSucceed(t, g, Kubectl( - "delete", - "deploy,configmap,secret,sa,rolebindings,clusterrolebindings,roles,clusterroles,integrationplatform", - "-l", - "app=camel-k", - "-n", - ns, - )) + UninstallOperator(t, ctx, g, ns, "../../../") + g.Eventually(OperatorPod(t, ctx, ns)).Should(BeNil()) g.Eventually(Platform(t, ctx, ns)).Should(BeNil()) g.Eventually(Integration(t, ctx, ns, "yaml"), TestTimeoutShort).ShouldNot(BeNil()) g.Eventually(IntegrationConditionStatus(t, ctx, ns, "yaml", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) // Test CRD uninstall (will remove Integrations as well) - ExpectExecSucceed(t, g, Kubectl( - "delete", - "crd", - "-l", - "app=camel-k", - "-n", - ns, - )) + UninstallCRDs(t, ctx, g, "../../../") + g.Eventually(OperatorPod(t, ctx, ns)).Should(BeNil()) g.Eventually(Integration(t, ctx, ns, "yaml"), TestTimeoutShort).Should(BeNil()) g.Eventually(CRDs(t)).Should(BeNil()) @@ -212,28 +200,16 @@ func TestKustomizeDescoped(t *testing.T) { g.Eventually(IntegrationLogs(t, ctx, nsIntegration, "yaml"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) // Test operator only uninstall - ExpectExecSucceed(t, g, Kubectl( - "delete", - "deploy,configmap,secret,sa,rolebindings,clusterrolebindings,roles,clusterroles,integrationplatform", - "-l", - "app=camel-k", - "-n", - ns, - )) + UninstallOperator(t, ctx, g, ns, "../../../") + g.Eventually(OperatorPod(t, ctx, ns)).Should(BeNil()) g.Eventually(Platform(t, ctx, ns)).Should(BeNil()) g.Eventually(Integration(t, ctx, nsIntegration, "yaml"), TestTimeoutShort).ShouldNot(BeNil()) g.Eventually(IntegrationConditionStatus(t, ctx, nsIntegration, "yaml", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) // Test CRD uninstall (will remove Integrations as well) - ExpectExecSucceed(t, g, Kubectl( - "delete", - "crd", - "-l", - "app=camel-k", - "-n", - ns, - )) + UninstallCRDs(t, ctx, g, "../../../") + g.Eventually(OperatorPod(t, ctx, ns)).Should(BeNil()) g.Eventually(Integration(t, ctx, nsIntegration, "yaml"), TestTimeoutShort).Should(BeNil()) g.Eventually(CRDs(t)).Should(BeNil()) diff --git a/e2e/support/test_util.go b/e2e/support/test_util.go index 084b3b04d..63566d37a 100644 --- a/e2e/support/test_util.go +++ b/e2e/support/test_util.go @@ -99,6 +99,7 @@ func InstallOperatorWithConf(t *testing.T, ctx context.Context, g *WithT, ns, op fmt.Printf("Preparing for global installation") makeRule = "install-k8s-global" } + // TODO make this a func input variable instead os.Setenv("CAMEL_K_TEST_MAKE_DIR", "../../") ExpectExecSucceed(t, g, Make(t, makeRule, args...), @@ -107,6 +108,29 @@ func InstallOperatorWithConf(t *testing.T, ctx context.Context, g *WithT, ns, op g.Eventually(OperatorPod(t, ctx, ns)).ShouldNot(BeNil()) } +// InstallOperator will delete operator resources from namespace (keeps CRDs). +func UninstallOperator(t *testing.T, ctx context.Context, g *WithT, ns, makedir string) { + lock.Lock() + defer lock.Unlock() + args := []string{fmt.Sprintf("NAMESPACE=%s", ns)} + + os.Setenv("CAMEL_K_TEST_MAKE_DIR", makedir) + ExpectExecSucceed(t, g, + Make(t, "uninstall", args...), + ) +} + +// UninstallCRDs will delete Camel K installed CRDs. +func UninstallCRDs(t *testing.T, ctx context.Context, g *WithT, makedir string) { + lock.Lock() + defer lock.Unlock() + + os.Setenv("CAMEL_K_TEST_MAKE_DIR", makedir) + ExpectExecSucceed(t, g, + Make(t, "uninstall-crds"), + ) +} + func ExpectExecSucceed(t *testing.T, g *WithT, command *exec.Cmd) { t.Helper() diff --git a/helm/camel-k/templates/operator.yaml b/helm/camel-k/templates/operator.yaml index defeb4aa5..b22f98732 100644 --- a/helm/camel-k/templates/operator.yaml +++ b/helm/camel-k/templates/operator.yaml @@ -71,7 +71,7 @@ spec: valueFrom: fieldRef: fieldPath: metadata.namespace - - name: KAMEL_OPERATOR_ID + - name: OPERATOR_ID value: {{ .Values.operator.operatorId }} image: {{ .Values.operator.image }} imagePullPolicy: IfNotPresent diff --git a/helm/camel-k/templates/platform.yaml b/helm/camel-k/templates/platform.yaml index 3dcf2578f..2786fd3bf 100644 --- a/helm/camel-k/templates/platform.yaml +++ b/helm/camel-k/templates/platform.yaml @@ -21,6 +21,6 @@ metadata: labels: app: "camel-k" {{- include "camel-k.labels" . | nindent 4 }} - name: camel-k + name: {{ .Values.operator.operatorId }} spec: {{- toYaml .Values.platform | nindent 2}} \ No newline at end of file diff --git a/script/Makefile b/script/Makefile index f55a04222..82ed600ab 100644 --- a/script/Makefile +++ b/script/Makefile @@ -107,7 +107,7 @@ TEST_PREBUILD = build # Tests may run in parallel to each other. This count sets the amount of tests run in parallel. # (default value would be otherwise GOMAXPROCS) TEST_COMMON_PARALLEL_COUNT ?= 2 -TEST_ADVANCED_PARALLEL_COUNT ?= 3 +TEST_ADVANCED_PARALLEL_COUNT ?= 2 # OLM (Operator Lifecycle Manager and Operator Hub): uncomment to override operator settings at build time #GOLDFLAGS += -X github.com/apache/camel-k/v2/pkg/util/olm.DefaultOperatorName=camel-k-operator
