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 739ceb8d06100f22c7dfc71c77ab7ca6bb54cf22 Author: Pasquale Congiusti <pasquale.congiu...@gmail.com> AuthorDate: Fri Jun 28 09:52:53 2024 +0200 chore(e2e): enable custom conf operator --- e2e/advanced/catalog_builder_test.go | 2 +- e2e/advanced/environment_test.go | 10 +++-- e2e/advanced/integration_profile_test.go | 6 +-- e2e/advanced/operator_id_filtering_test.go | 4 +- e2e/advanced/operator_metrics_test.go | 8 +++- e2e/advanced/promote_test.go | 4 +- e2e/advanced/synthetic_test.go | 11 ++--- e2e/knative/knative_pipes_test.go | 2 +- e2e/support/test_util.go | 48 ++++++++++++---------- .../kubernetes/descoped/kustomization.yaml | 3 ++ .../descoped/patch-operator-id.yaml} | 11 ++--- .../overlays/openshift/descoped/kustomization.yaml | 8 ++++ .../{kustomization.yaml => patch-operator-id.yaml} | 11 ++--- .../openshift/namespaced/kustomization.yaml | 5 +++ .../patch-operator-id.yaml} | 11 ++--- .../config/manager/operator-deployment.yaml | 3 -- script/Makefile | 45 +++++++++++++------- 17 files changed, 109 insertions(+), 83 deletions(-) diff --git a/e2e/advanced/catalog_builder_test.go b/e2e/advanced/catalog_builder_test.go index 396fecfe8..a9597ca68 100644 --- a/e2e/advanced/catalog_builder_test.go +++ b/e2e/advanced/catalog_builder_test.go @@ -58,7 +58,7 @@ func TestCamelCatalogBuilder(t *testing.T) { g.Expect( KamelRun(t, ctx, ns, "files/Java.java", "--name", name, "-t", "camel.runtime-version=1.15.0").Execute()).To(Succeed()) - g.Eventually(CamelCatalog(t, ctx, ns, nonCompatibleCatalogName)).ShouldNot(BeNil()) + g.Eventually(CamelCatalog(t, ctx, ns, nonCompatibleCatalogName), TestTimeoutMedium).ShouldNot(BeNil()) g.Eventually(CamelCatalogPhase(t, ctx, ns, nonCompatibleCatalogName)).Should(Equal(v1.CamelCatalogPhaseError)) g.Eventually(CamelCatalogCondition(t, ctx, ns, nonCompatibleCatalogName, v1.CamelCatalogConditionReady)().Message).Should(ContainSubstring("Container image tool missing in catalog")) diff --git a/e2e/advanced/environment_test.go b/e2e/advanced/environment_test.go index 0735a094e..adf5c37d7 100644 --- a/e2e/advanced/environment_test.go +++ b/e2e/advanced/environment_test.go @@ -37,7 +37,7 @@ import ( "github.com/apache/camel-k/v2/pkg/util/defaults" ) -func TestEnvironmentTrait(t *testing.T) { +func TestHTTPProxy(t *testing.T) { t.Parallel() WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { @@ -65,8 +65,12 @@ func TestEnvironmentTrait(t *testing.T) { } // Install Camel K with the HTTP proxy environment variable - //g.Expect(InstallOperator(t, ctx, operatorID, ns, "--operator-env-vars", fmt.Sprintf("HTTP_PROXY=%s", httpProxy), "--operator-env-vars", "NO_PROXY="+strings.Join(noProxy, ","))).To(Succeed()) - InstallOperator(t, ctx, g, ns) + InstallOperatorWithConf(t, ctx, g, ns, "", + map[string]string{ + "HTTP_PROXY": httpProxy, + "NO_PROXY": strings.Join(noProxy, ","), + }, + ) t.Run("Run integration with default environment", func(t *testing.T) { name := RandomizedSuffixName("java-default") diff --git a/e2e/advanced/integration_profile_test.go b/e2e/advanced/integration_profile_test.go index 55fd47df5..61cc34fb4 100644 --- a/e2e/advanced/integration_profile_test.go +++ b/e2e/advanced/integration_profile_test.go @@ -41,7 +41,7 @@ func TestIntegrationProfile(t *testing.T) { WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-integration-profile" - InstallOperatorWithID(t, ctx, g, ns, operatorID) + InstallOperatorWithConf(t, ctx, g, ns, operatorID, nil) integrationProfile := v1.NewIntegrationProfile(ns, "ipr-global") integrationProfile.SetOperatorID(operatorID) @@ -125,7 +125,7 @@ func TestIntegrationProfileInfluencesKit(t *testing.T) { WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-ipr-kit" - InstallOperatorWithID(t, ctx, g, ns, operatorID) + InstallOperatorWithConf(t, ctx, g, ns, operatorID, nil) integrationProfile := v1.NewIntegrationProfile(ns, "ipr-global") integrationProfile.SetOperatorID(operatorID) @@ -166,7 +166,7 @@ func TestPropagateIntegrationProfileChanges(t *testing.T) { WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { operatorID := "camel-k-ipr-changes" - InstallOperatorWithID(t, ctx, g, ns, operatorID) + InstallOperatorWithConf(t, ctx, g, ns, operatorID, nil) integrationProfile := v1.NewIntegrationProfile(ns, "debug-profile") integrationProfile.SetOperatorID(operatorID) diff --git a/e2e/advanced/operator_id_filtering_test.go b/e2e/advanced/operator_id_filtering_test.go index c281390ff..83879f298 100644 --- a/e2e/advanced/operator_id_filtering_test.go +++ b/e2e/advanced/operator_id_filtering_test.go @@ -41,12 +41,12 @@ func TestOperatorIDFiltering(t *testing.T) { WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { WithNewTestNamespace(t, func(ctx context.Context, g *WithT, nsop1 string) { operator1 := "operator-1" - InstallOperatorWithID(t, ctx, g, nsop1, operator1) + InstallOperatorWithConf(t, ctx, g, nsop1, operator1, nil) g.Eventually(PlatformPhase(t, ctx, nsop1), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) WithNewTestNamespace(t, func(ctx context.Context, g *WithT, nsop2 string) { operator2 := "operator-2" - InstallOperatorWithID(t, ctx, g, nsop2, operator2) + InstallOperatorWithConf(t, ctx, g, nsop2, operator2, nil) g.Eventually(PlatformPhase(t, ctx, nsop2), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) t.Run("Operators ignore non-scoped integrations", func(t *testing.T) { diff --git a/e2e/advanced/operator_metrics_test.go b/e2e/advanced/operator_metrics_test.go index 9228bc7b6..5f1077acb 100644 --- a/e2e/advanced/operator_metrics_test.go +++ b/e2e/advanced/operator_metrics_test.go @@ -49,8 +49,12 @@ func TestMetrics(t *testing.T) { t.Parallel() WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { - //g.Expect(InstallOperator(t, ctx, operatorID, ns, "--log-level", "debug")).To(Succeed()) - InstallOperator(t, ctx, g, ns) + // Install Camel K with the log debug enabled + InstallOperatorWithConf(t, ctx, g, ns, "", + map[string]string{ + "LOG_LEVEL": "debug", + }, + ) name := RandomizedSuffixName("java") g.Expect(KamelRun(t, ctx, ns, "files/Java.java", "--name", name, "-t", "prometheus.enabled=true", "-t", "prometheus.pod-monitor=false").Execute()).To(Succeed()) diff --git a/e2e/advanced/promote_test.go b/e2e/advanced/promote_test.go index 13716f71d..f37a6fa00 100644 --- a/e2e/advanced/promote_test.go +++ b/e2e/advanced/promote_test.go @@ -42,7 +42,7 @@ func TestKamelCLIPromote(t *testing.T) { // Dev environment namespace WithNewTestNamespace(t, func(ctx context.Context, g *WithT, nsDev string) { operatorDevID := "camel-k-cli-promote-dev" - InstallOperatorWithID(t, ctx, g, nsDev, operatorDevID) + InstallOperatorWithConf(t, ctx, g, nsDev, operatorDevID, nil) g.Eventually(SelectedPlatformPhase(t, ctx, nsDev, operatorDevID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) // Dev content configmap @@ -88,7 +88,7 @@ func TestKamelCLIPromote(t *testing.T) { // Prod environment namespace WithNewTestNamespace(t, func(ctx context.Context, g *WithT, nsProd string) { operatorProdID := "camel-k-cli-promote-prod" - InstallOperatorWithID(t, ctx, g, nsProd, operatorProdID) + InstallOperatorWithConf(t, ctx, g, nsProd, operatorProdID, nil) g.Eventually(PlatformPhase(t, ctx, nsProd), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) t.Run("no configmap in destination", func(t *testing.T) { diff --git a/e2e/advanced/synthetic_test.go b/e2e/advanced/synthetic_test.go index 5c5ec8e33..f2e85b9d3 100644 --- a/e2e/advanced/synthetic_test.go +++ b/e2e/advanced/synthetic_test.go @@ -60,11 +60,12 @@ func TestSyntheticIntegrationFromDeployment(t *testing.T) { t.Parallel() WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { - // Install Camel K with the synthetic Integration feature variable - // g.Expect(InstallOperator(t, ctx, operatorID, ns, - // "--operator-env-vars", "CAMEL_K_SYNTHETIC_INTEGRATIONS=true", - // )).To(Succeed()) - InstallOperator(t, ctx, g, ns) + // Install Camel K with the proper configuration support + InstallOperatorWithConf(t, ctx, g, ns, "", + map[string]string{ + "CAMEL_K_SYNTHETIC_INTEGRATIONS": "true", + }, + ) g.Eventually(OperatorPodHas(t, ctx, ns, func(op *corev1.Pod) bool { if envVar := envvar.Get(op.Spec.Containers[0].Env, "CAMEL_K_SYNTHETIC_INTEGRATIONS"); envVar != nil { return envVar.Value == "true" diff --git a/e2e/knative/knative_pipes_test.go b/e2e/knative/knative_pipes_test.go index ce88f2bdf..1f4dc6b31 100644 --- a/e2e/knative/knative_pipes_test.go +++ b/e2e/knative/knative_pipes_test.go @@ -139,7 +139,7 @@ func TestRunBroker(t *testing.T) { WithNewTestNamespaceWithKnativeBroker(t, func(ctx context.Context, g *WithT, ns string) { // This test require an adhoc operator to run properly operatorID := fmt.Sprintf("camel-k-%s", ns) - InstallOperatorWithID(t, ctx, g, ns, operatorID) + InstallOperatorWithConf(t, ctx, g, ns, operatorID, nil) g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(camelv1.IntegrationPlatformPhaseReady)) g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/knativeevt1.yaml").Execute()).To(Succeed()) diff --git a/e2e/support/test_util.go b/e2e/support/test_util.go index 933cf1e4a..63d49f0fe 100644 --- a/e2e/support/test_util.go +++ b/e2e/support/test_util.go @@ -42,8 +42,7 @@ import ( ) var ( - lock sync.Mutex - lockID sync.Mutex + lock sync.Mutex ) func init() { @@ -70,36 +69,41 @@ func GetEnvOrDefault(key string, deflt string) string { // InstallOperator is in charge to install a namespaced operator. The func must be // executed in a critical section as there may be concurrent access to it. func InstallOperator(t *testing.T, ctx context.Context, g *WithT, ns string) { + InstallOperatorWithConf(t, ctx, g, ns, "", nil) +} + +// InstallOperatorWithConf is in charge to install a namespaced operator with additional configurations. +func InstallOperatorWithConf(t *testing.T, ctx context.Context, g *WithT, ns, operatorID string, envs map[string]string) { lock.Lock() defer lock.Unlock() KAMEL_INSTALL_REGISTRY := os.Getenv("KAMEL_INSTALL_REGISTRY") + args := []string{fmt.Sprintf("NAMESPACE=%s", ns)} + if KAMEL_INSTALL_REGISTRY != "" { + args = append(args, fmt.Sprintf("REGISTRY=%s", KAMEL_INSTALL_REGISTRY)) + } + if operatorID != "" { + fmt.Printf("Setting operator ID property as %s\n", operatorID) + args = append(args, fmt.Sprintf("OPERATOR_ID=%s", operatorID)) + } + if envs != nil { + envArgs := make([]string, len(envs)) + for k, v := range envs { + envArgs = append(envArgs, fmt.Sprintf("%s=%s", k, v)) + } + if len(envArgs) > 0 { + joinedArgs := strings.Join(envArgs, " ") + fmt.Printf("Setting operator env vars as %s\n", joinedArgs) + args = append(args, fmt.Sprintf("ENV=%s", joinedArgs)) + } + } os.Setenv("CAMEL_K_TEST_MAKE_DIR", "../../") - fmt.Printf("Installing namespaced operator in namespace %s with registry %s\n", ns, KAMEL_INSTALL_REGISTRY) ExpectExecSucceed(t, g, - Make(t, - fmt.Sprintf("NAMESPACE=%s", ns), - fmt.Sprintf("REGISTRY=%s", KAMEL_INSTALL_REGISTRY), - "install-k8s-ns"), + Make(t, "install-k8s-ns", args...), ) // Let's make sure the operator has been deployed g.Eventually(OperatorPod(t, ctx, ns)).ShouldNot(BeNil()) } -// InstallOperatorWitID is in charge to install a namespaced operator with a given operator ID name. -func InstallOperatorWithID(t *testing.T, ctx context.Context, g *WithT, ns, operatorID string) { - lockID.Lock() - defer lockID.Unlock() - os.Setenv("CAMEL_K_TEST_MAKE_DIR", "../../") - fmt.Printf("Setting operator ID property as %s\n", operatorID) - ExpectExecSucceed(t, g, - Make(t, - fmt.Sprintf("OPERATOR_ID=%s", operatorID), - "set-install-k8s-ns-operator-id"), - ) - - InstallOperator(t, ctx, g, ns) -} - func ExpectExecSucceed(t *testing.T, g *WithT, command *exec.Cmd) { t.Helper() diff --git a/install/overlays/kubernetes/descoped/kustomization.yaml b/install/overlays/kubernetes/descoped/kustomization.yaml index 421242eae..8ebdff72d 100644 --- a/install/overlays/kubernetes/descoped/kustomization.yaml +++ b/install/overlays/kubernetes/descoped/kustomization.yaml @@ -27,3 +27,6 @@ patches: - path: patch-watch-namespace-global.yaml target: kind: Deployment +- path: patch-operator-id.yaml + target: + kind: Deployment diff --git a/install/overlays/openshift/descoped/kustomization.yaml b/install/overlays/kubernetes/descoped/patch-operator-id.yaml similarity index 81% copy from install/overlays/openshift/descoped/kustomization.yaml copy to install/overlays/kubernetes/descoped/patch-operator-id.yaml index 7d893bc47..25c150420 100644 --- a/install/overlays/openshift/descoped/kustomization.yaml +++ b/install/overlays/kubernetes/descoped/patch-operator-id.yaml @@ -14,12 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # --------------------------------------------------------------------------- -apiVersion: kustomize.config.k8s.io/v1beta1 -kind: Kustomization -resources: -- ../../kubernetes/descoped -- ../../../base/config/rbac/openshift -- ../../../base/config/rbac/openshift/descoped - -namespace: camel-k +- op: add + path: /spec/template/spec/containers/0/env/2/value + value: camel-k diff --git a/install/overlays/openshift/descoped/kustomization.yaml b/install/overlays/openshift/descoped/kustomization.yaml index 7d893bc47..ff7ed314f 100644 --- a/install/overlays/openshift/descoped/kustomization.yaml +++ b/install/overlays/openshift/descoped/kustomization.yaml @@ -23,3 +23,11 @@ resources: - ../../../base/config/rbac/openshift/descoped namespace: camel-k + +patches: +- path: patch-watch-namespace-global.yaml + target: + kind: Deployment +- path: patch-operator-id.yaml + target: + kind: Deployment \ No newline at end of file diff --git a/install/overlays/openshift/descoped/kustomization.yaml b/install/overlays/openshift/descoped/patch-operator-id.yaml similarity index 81% copy from install/overlays/openshift/descoped/kustomization.yaml copy to install/overlays/openshift/descoped/patch-operator-id.yaml index 7d893bc47..25c150420 100644 --- a/install/overlays/openshift/descoped/kustomization.yaml +++ b/install/overlays/openshift/descoped/patch-operator-id.yaml @@ -14,12 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # --------------------------------------------------------------------------- -apiVersion: kustomize.config.k8s.io/v1beta1 -kind: Kustomization -resources: -- ../../kubernetes/descoped -- ../../../base/config/rbac/openshift -- ../../../base/config/rbac/openshift/descoped - -namespace: camel-k +- op: add + path: /spec/template/spec/containers/0/env/2/value + value: camel-k diff --git a/install/overlays/openshift/namespaced/kustomization.yaml b/install/overlays/openshift/namespaced/kustomization.yaml index fb7e659a9..ad71b3259 100644 --- a/install/overlays/openshift/namespaced/kustomization.yaml +++ b/install/overlays/openshift/namespaced/kustomization.yaml @@ -23,3 +23,8 @@ resources: - ../../../base/config/rbac/openshift/namespaced namespace: default + +patches: +- path: patch-operator-id.yaml + target: + kind: Deployment \ No newline at end of file diff --git a/install/overlays/openshift/descoped/kustomization.yaml b/install/overlays/openshift/namespaced/patch-operator-id.yaml similarity index 81% copy from install/overlays/openshift/descoped/kustomization.yaml copy to install/overlays/openshift/namespaced/patch-operator-id.yaml index 7d893bc47..25c150420 100644 --- a/install/overlays/openshift/descoped/kustomization.yaml +++ b/install/overlays/openshift/namespaced/patch-operator-id.yaml @@ -14,12 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # --------------------------------------------------------------------------- -apiVersion: kustomize.config.k8s.io/v1beta1 -kind: Kustomization -resources: -- ../../kubernetes/descoped -- ../../../base/config/rbac/openshift -- ../../../base/config/rbac/openshift/descoped - -namespace: camel-k +- op: add + path: /spec/template/spec/containers/0/env/2/value + value: camel-k diff --git a/pkg/resources/config/manager/operator-deployment.yaml b/pkg/resources/config/manager/operator-deployment.yaml index a02bc5d04..f76ab614d 100644 --- a/pkg/resources/config/manager/operator-deployment.yaml +++ b/pkg/resources/config/manager/operator-deployment.yaml @@ -72,9 +72,6 @@ spec: valueFrom: fieldRef: fieldPath: metadata.namespace - # Change to true to be able to create synthetic Integrations - - name: CAMEL_K_SYNTHETIC_INTEGRATIONS - value: "false" livenessProbe: httpGet: path: /healthz diff --git a/script/Makefile b/script/Makefile index c6e684b8c..15fca62f1 100644 --- a/script/Makefile +++ b/script/Makefile @@ -737,11 +737,35 @@ DEFAULT_NS = "camel-k" .PHONY: install install-k8s-global install-k8s-ns install-openshift-global install-openshift-ns -install-operator: - @echo "####### Installing operator..." +clone-kustomize-dir: $(eval KUST_TMP=$(shell mktemp -d)) @echo "... cloning installation files to $(KUST_TMP)" cp -Lr install $(KUST_TMP)/. + +# the set-operator targets are mostly thought as an utility for the e2e which require certain operator settings +set-operator-id: +ifdef OPERATOR_ID + @echo "INFO: setting operator ID to $(OPERATOR_ID)" + @sed -i 's/name: .*/name: $(OPERATOR_ID)/' $(KUST_TMP)/install/overlays/platform/integration-platform.yaml + @sed -i 's/value: .*/value: $(OPERATOR_ID)/' $(KUST_TMP)/$(KUSTOMIZE_DIR)/patch-operator-id.yaml +else + @echo "INFO: no operator ID variable \"OPERATOR_ID\" provided. Keeping default." +endif + +# ENV is expected to be in the formal ENV="myvar1=v1 myvar2=v2 ..." +set-operator-env: +ifdef ENV + @for n in $(ENV); do \ + k=$${n%=*}; \ + v=$${n#*=}; \ + echo "INFO: setting operator env var $${k}=$${v}"; \ + cd $(KUST_TMP)/$(KUSTOMIZE_DIR) && kustomize edit add patch --kind Deployment --patch \ + "[{\"op\": \"add\", \"path\": \"/spec/template/spec/containers/0/env/-\", \"value\": {\"name\": \"$${k}\", \"value\": \"$${v}\"}}]"; \ + done +endif + +install-operator: + @echo "####### Installing operator..." ifndef NAMESPACE @echo "WARN: no namespace specified, using default namespace $(DEFAULT_NS)" $(eval NAMESPACE=$(DEFAULT_NS)) @@ -765,30 +789,21 @@ ifneq ($(MINIKUBE_REGISTRY), "") endif endif -set-install-k8s-ns-operator-id: -ifdef OPERATOR_ID - @echo "INFO: setting operator ID to $(OPERATOR_ID)" - @sed -i 's/name: .*/name: $(OPERATOR_ID)/' install/overlays/platform/integration-platform.yaml - @sed -i 's/value: .*/value: $(OPERATOR_ID)/' install/overlays/kubernetes/namespaced/patch-operator-id.yaml -else - @echo "INFO: no operator ID variable \"OPERATOR_ID\" provided" -endif - install-k8s-global: DEFAULT_NS="camel-k" install-k8s-global: KUSTOMIZE_DIR="install/overlays/kubernetes/descoped" -install-k8s-global: install-operator install-registry +install-k8s-global: clone-kustomize-dir set-operator-id set-operator-env install-operator install-registry install-k8s-ns: DEFAULT_NS="default" install-k8s-ns: KUSTOMIZE_DIR="install/overlays/kubernetes/namespaced" -install-k8s-ns: install-operator install-registry +install-k8s-ns: clone-kustomize-dir set-operator-id set-operator-env install-operator install-registry install-openshift-global: DEFAULT_NS="camel-k" install-openshift-global: KUSTOMIZE_DIR="install/overlays/openshift/descoped" -install-openshift-global: install-operator +install-openshift-global: clone-kustomize-dir set-operator-id set-operator-env install-operator install-openshift-ns: DEFAULT_NS="default" install-openshift-ns: KUSTOMIZE_DIR="install/overlays/openshift/namespaced" -install-openshift-ns: install-operator +install-openshift-ns: clone-kustomize-dir set-operator-id set-operator-env install-operator uninstall: ifdef NAMESPACE