|
| 1 | +//go:build integration |
| 2 | +// +build integration |
| 3 | + |
| 4 | +// To enable compilation of this file in Goland, go to "Settings -> Go -> Vendoring & Build Tags -> Custom Tags" and add "integration" |
| 5 | + |
| 6 | +/* |
| 7 | +Licensed to the Apache Software Foundation (ASF) under one or more |
| 8 | +contributor license agreements. See the NOTICE file distributed with |
| 9 | +this work for additional information regarding copyright ownership. |
| 10 | +The ASF licenses this file to You under the Apache License, Version 2.0 |
| 11 | +(the "License"); you may not use this file except in compliance with |
| 12 | +the License. You may obtain a copy of the License at |
| 13 | +
|
| 14 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 15 | +
|
| 16 | +Unless required by applicable law or agreed to in writing, software |
| 17 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 18 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 19 | +See the License for the specific language governing permissions and |
| 20 | +limitations under the License. |
| 21 | +*/ |
| 22 | + |
| 23 | +package kustomize |
| 24 | + |
| 25 | +import ( |
| 26 | + "context" |
| 27 | + "fmt" |
| 28 | + "testing" |
| 29 | + "time" |
| 30 | + |
| 31 | + corev1 "k8s.io/api/core/v1" |
| 32 | + |
| 33 | + . "github.com/apache/camel-k/v2/e2e/support" |
| 34 | + testutil "github.com/apache/camel-k/v2/e2e/support/util" |
| 35 | + v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" |
| 36 | + |
| 37 | + . "github.com/onsi/gomega" |
| 38 | +) |
| 39 | + |
| 40 | +func TestKustomizeMultiNamespace(t *testing.T) { |
| 41 | + kustomizeDir := testutil.MakeTempCopyDir(t, "../../../install") |
| 42 | + |
| 43 | + // The operator is expected to be installed in "operators" namespace |
| 44 | + // it also expects to reconcile correctly an Integration in namespace "tenant-a" and "tenant-b" |
| 45 | + // but it won't reconcile in any other namespaces, for example, "tenant-z" |
| 46 | + WithNamedTestNamespace(t, func(ctx context.Context, g *WithT, operatorNs string) { |
| 47 | + WithNamedTestNamespace(t, func(ctx context.Context, g *WithT, tenantANs string) { |
| 48 | + WithNamedTestNamespace(t, func(ctx context.Context, g *WithT, tenantBNs string) { |
| 49 | + // Let's make sure no CRD is yet available in the cluster |
| 50 | + // as we must make the procedure to install them accordingly |
| 51 | + g.Eventually(CRDs(t)).Should(BeNil(), "No Camel K CRDs should be previously installed for this test") |
| 52 | + ExpectExecSucceed(t, g, Kubectl( |
| 53 | + "apply", |
| 54 | + "-k", |
| 55 | + fmt.Sprintf("%s/overlays/multi-namespace", kustomizeDir), |
| 56 | + "--server-side", |
| 57 | + )) |
| 58 | + g.Eventually(OperatorPod(t, ctx, operatorNs)).ShouldNot(BeNil()) |
| 59 | + g.Eventually(OperatorPodPhase(t, ctx, operatorNs)).Should(Equal(corev1.PodRunning)) |
| 60 | + |
| 61 | + WithNamedTestNamespace(t, func(ctx context.Context, g *WithT, tenantNs string) { |
| 62 | + // Test a simple integration in "tenant-z" is not reconciled |
| 63 | + g.Expect(KamelRun(t, ctx, tenantNs, "files/yaml.yaml").Execute()).To(Succeed()) |
| 64 | + g.Consistently(IntegrationPhase(t, ctx, tenantNs, "yaml"), 30*time.Second).Should(BeEmpty()) |
| 65 | + }, "tenant-z") |
| 66 | + |
| 67 | + // Test a simple integration in "tenant-a" is reconciled and runs correctly |
| 68 | + g.Expect(KamelRun(t, ctx, tenantANs, "files/yaml.yaml").Execute()).To(Succeed()) |
| 69 | + g.Eventually(IntegrationConditionStatus(t, ctx, tenantANs, "yaml", v1.IntegrationConditionReady), TestTimeoutMedium). |
| 70 | + Should(Equal(corev1.ConditionTrue)) |
| 71 | + g.Eventually(IntegrationLogs(t, ctx, tenantANs, "yaml"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) |
| 72 | + |
| 73 | + // Test a simple integration in "tenant-b" is reconciled and runs correctly |
| 74 | + g.Expect(KamelRun(t, ctx, tenantBNs, "files/yaml.yaml").Execute()).To(Succeed()) |
| 75 | + g.Eventually(IntegrationConditionStatus(t, ctx, tenantBNs, "yaml", v1.IntegrationConditionReady), TestTimeoutMedium). |
| 76 | + Should(Equal(corev1.ConditionTrue)) |
| 77 | + g.Eventually(IntegrationLogs(t, ctx, tenantBNs, "yaml"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) |
| 78 | + |
| 79 | + // Test operator only uninstall |
| 80 | + UninstallOperator(t, ctx, g, operatorNs, "../../../") |
| 81 | + |
| 82 | + g.Eventually(OperatorPod(t, ctx, operatorNs)).Should(BeNil()) |
| 83 | + g.Eventually(Integration(t, ctx, "tenant-a", "yaml"), TestTimeoutShort).ShouldNot(BeNil()) |
| 84 | + g.Eventually(IntegrationConditionStatus(t, ctx, "tenant-a", "yaml", v1.IntegrationConditionReady), TestTimeoutShort). |
| 85 | + Should(Equal(corev1.ConditionTrue)) |
| 86 | + g.Eventually(Integration(t, ctx, "tenant-b", "yaml"), TestTimeoutShort).ShouldNot(BeNil()) |
| 87 | + g.Eventually(IntegrationConditionStatus(t, ctx, "tenant-b", "yaml", v1.IntegrationConditionReady), TestTimeoutShort). |
| 88 | + Should(Equal(corev1.ConditionTrue)) |
| 89 | + |
| 90 | + // Test CRD uninstall (will remove Integrations as well) |
| 91 | + UninstallCRDs(t, ctx, g, "../../../") |
| 92 | + |
| 93 | + g.Eventually(OperatorPod(t, ctx, operatorNs)).Should(BeNil()) |
| 94 | + g.Eventually(CRDs(t)).Should(BeNil()) |
| 95 | + }, "tenant-b") |
| 96 | + }, "tenant-a") |
| 97 | + }, "operators") |
| 98 | +} |
0 commit comments