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 1f6790c1df59d4a65b5581284a29370c9d1f0efd Author: Pasquale Congiusti <[email protected]> AuthorDate: Wed Jun 26 12:28:02 2024 +0200 fix(e2e): group refactoring --- e2e/advanced/build_max_pipelines_test.go | 212 ++++++++++ e2e/advanced/build_order_strategy_test.go | 56 +-- e2e/advanced/build_test.go | 436 --------------------- e2e/advanced/builder_test.go | 7 +- e2e/advanced/catalog_builder_test.go | 22 +- e2e/advanced/debug_test.go | 22 +- e2e/advanced/deployment_test.go | 83 ---- e2e/advanced/dump_test.go | 13 +- e2e/advanced/environment_test.go | 15 +- e2e/advanced/incremental_build_test.go | 51 +-- e2e/advanced/kamelet_repo_test.go | 16 +- e2e/advanced/main_test.go | 77 ---- e2e/advanced/maven_http_proxy_test.go | 80 +--- e2e/advanced/operator_id_filtering_test.go | 21 +- e2e/advanced/operator_metrics_test.go | 17 +- e2e/advanced/platform_traits_test.go | 11 +- e2e/advanced/promote_test.go | 4 +- e2e/advanced/registry_test.go | 78 ---- e2e/advanced/reset_test.go | 22 +- e2e/advanced/synthetic_test.go | 16 +- e2e/advanced/tekton_test.go | 9 +- .../misc}/integration_profile_test.go | 51 +-- e2e/common/traits/deployment_test.go | 42 ++ e2e/support/test_support.go | 179 +-------- e2e/support/test_util.go | 105 +++++ script/Makefile | 6 +- 26 files changed, 487 insertions(+), 1164 deletions(-) diff --git a/e2e/advanced/build_max_pipelines_test.go b/e2e/advanced/build_max_pipelines_test.go new file mode 100644 index 000000000..d9c666dd1 --- /dev/null +++ b/e2e/advanced/build_max_pipelines_test.go @@ -0,0 +1,212 @@ +//go:build integration +// +build integration + +// To enable compilation of this file in Goland, go to "Settings -> Go -> Vendoring & Build Tags -> Custom Tags" and add "integration" + +/* +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package advanced + +import ( + "context" + "errors" + "fmt" + "testing" + "time" + + . "github.com/onsi/gomega" + + . "github.com/apache/camel-k/v2/e2e/support" + v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" + corev1 "k8s.io/api/core/v1" +) + +type kitOptions struct { + dependencies []string + traits []string +} + +func kitMaxBuildLimit(t *testing.T, maxRunningBuilds int32, buildOrderStrategy v1.BuildOrderStrategy) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { + InstallOperator(t, g, ns) + + pl := Platform(t, ctx, ns)() + // set maximum number of running builds and order strategy + pl.Spec.Build.MaxRunningBuilds = maxRunningBuilds + pl.Spec.Build.BuildConfiguration.OrderStrategy = buildOrderStrategy + if err := TestClient(t).Update(ctx, pl); err != nil { + t.Error(err) + t.FailNow() + } + + buildA := "integration-a" + buildB := "integration-b" + buildC := "integration-c" + + doKitBuildInNamespace(t, ctx, g, buildA, ns, TestTimeoutShort, kitOptions{ + dependencies: []string{ + "camel:timer", "camel:log", + }, + traits: []string{ + "builder.properties=build-property=A", + }, + }, v1.BuildPhaseRunning, v1.IntegrationKitPhaseBuildRunning) + + doKitBuildInNamespace(t, ctx, g, buildB, ns, TestTimeoutShort, kitOptions{ + dependencies: []string{ + "camel:timer", "camel:log", + }, + traits: []string{ + "builder.properties=build-property=B", + }, + }, v1.BuildPhaseRunning, v1.IntegrationKitPhaseBuildRunning) + + doKitBuildInNamespace(t, ctx, g, buildC, ns, TestTimeoutShort, kitOptions{ + dependencies: []string{ + "camel:timer", "camel:log", + }, + traits: []string{ + "builder.properties=build-property=C", + }, + }, v1.BuildPhaseScheduling, v1.IntegrationKitPhaseNone) + + var notExceedsMaxBuildLimit = func(runningBuilds int) bool { + return runningBuilds <= 2 + } + + limit := 0 + for limit < 5 && BuildPhase(t, ctx, ns, buildA)() == v1.BuildPhaseRunning { + // verify that number of running builds does not exceed max build limit + g.Consistently(BuildsRunning(BuildPhase(t, ctx, ns, buildA), BuildPhase(t, ctx, ns, buildB), BuildPhase(t, ctx, ns, buildC)), TestTimeoutShort, 10*time.Second).Should(Satisfy(notExceedsMaxBuildLimit)) + limit++ + } + + // make sure we have verified max build limit at least once + if limit == 0 { + t.Error(errors.New(fmt.Sprintf("Unexpected build phase '%s' for %s - not able to verify max builds limit", BuildPhase(t, ctx, ns, buildA)(), buildA))) + t.FailNow() + } + + // verify that all builds are successful + g.Eventually(BuildPhase(t, ctx, ns, buildA), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded)) + g.Eventually(KitPhase(t, ctx, ns, buildA), TestTimeoutLong).Should(Equal(v1.IntegrationKitPhaseReady)) + g.Eventually(BuildPhase(t, ctx, ns, buildB), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded)) + g.Eventually(KitPhase(t, ctx, ns, buildB), TestTimeoutLong).Should(Equal(v1.IntegrationKitPhaseReady)) + g.Eventually(BuildPhase(t, ctx, ns, buildC), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded)) + g.Eventually(KitPhase(t, ctx, ns, buildC), TestTimeoutLong).Should(Equal(v1.IntegrationKitPhaseReady)) + }) +} + +func TestKitMaxBuildLimitSequential(t *testing.T) { + kitMaxBuildLimit(t, 2, v1.BuildOrderStrategySequential) +} + +func TestKitMaxBuildLimitFIFO(t *testing.T) { + kitMaxBuildLimit(t, 2, v1.BuildOrderStrategyFIFO) +} + +func TestKitMaxBuildLimitDependencies(t *testing.T) { + kitMaxBuildLimit(t, 2, v1.BuildOrderStrategyDependencies) +} + +func TestMaxBuildLimitWaitingBuilds(t *testing.T) { + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { + InstallOperator(t, g, ns) + + pl := Platform(t, ctx, ns)() + // set maximum number of running builds and order strategy + pl.Spec.Build.MaxRunningBuilds = 1 + pl.Spec.Build.BuildConfiguration.OrderStrategy = v1.BuildOrderStrategyFIFO + if err := TestClient(t).Update(ctx, pl); err != nil { + t.Error(err) + t.FailNow() + } + + buildA := "integration-a" + buildB := "integration-b" + buildC := "integration-c" + + doKitBuildInNamespace(t, ctx, g, buildA, ns, TestTimeoutShort, kitOptions{ + dependencies: []string{ + "camel:timer", "camel:log", + }, + traits: []string{ + "builder.properties=build-property=A", + }, + }, v1.BuildPhaseRunning, v1.IntegrationKitPhaseBuildRunning) + + doKitBuildInNamespace(t, ctx, g, buildB, ns, TestTimeoutShort, kitOptions{ + dependencies: []string{ + "camel:cron", "camel:log", "camel:joor", + }, + traits: []string{ + "builder.properties=build-property=B", + }, + }, v1.BuildPhaseScheduling, v1.IntegrationKitPhaseNone) + + doKitBuildInNamespace(t, ctx, g, buildC, ns, TestTimeoutShort, kitOptions{ + dependencies: []string{ + "camel:timer", "camel:log", "camel:joor", "camel:http", + }, + traits: []string{ + "builder.properties=build-property=C", + }, + }, v1.BuildPhaseScheduling, v1.IntegrationKitPhaseNone) + + // verify that last build is waiting + g.Eventually(BuildConditions(t, ctx, ns, buildC), TestTimeoutMedium).ShouldNot(BeNil()) + g.Eventually( + BuildCondition(t, ctx, ns, buildC, v1.BuildConditionType(v1.BuildConditionScheduled))().Status, + TestTimeoutShort).Should(Equal(corev1.ConditionFalse)) + g.Eventually( + BuildCondition(t, ctx, ns, buildC, v1.BuildConditionType(v1.BuildConditionScheduled))().Reason, + TestTimeoutShort).Should(Equal(v1.BuildConditionWaitingReason)) + + // verify that last build is scheduled + g.Eventually(BuildPhase(t, ctx, ns, buildC), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded)) + g.Eventually(KitPhase(t, ctx, ns, buildC), TestTimeoutLong).Should(Equal(v1.IntegrationKitPhaseReady)) + + g.Eventually(BuildConditions(t, ctx, ns, buildC), TestTimeoutLong).ShouldNot(BeNil()) + g.Eventually( + BuildCondition(t, ctx, ns, buildC, v1.BuildConditionType(v1.BuildConditionScheduled))().Status, + TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + g.Eventually( + BuildCondition(t, ctx, ns, buildC, v1.BuildConditionType(v1.BuildConditionScheduled))().Reason, + TestTimeoutShort).Should(Equal(v1.BuildConditionReadyReason)) + }) +} + +func doKitBuildInNamespace(t *testing.T, ctx context.Context, g *WithT, name string, ns string, testTimeout time.Duration, options kitOptions, buildPhase v1.BuildPhase, kitPhase v1.IntegrationKitPhase) { + buildKitArgs := []string{"kit", "create", name, "-n", ns} + for _, dependency := range options.dependencies { + buildKitArgs = append(buildKitArgs, "-d", dependency) + } + for _, trait := range options.traits { + buildKitArgs = append(buildKitArgs, "-t", trait) + } + + g.Expect(Kamel(t, ctx, buildKitArgs...).Execute()).To(Succeed()) + + g.Eventually(Build(t, ctx, ns, name), testTimeout).ShouldNot(BeNil()) + if buildPhase != v1.BuildPhaseNone { + g.Eventually(BuildPhase(t, ctx, ns, name), testTimeout).Should(Equal(buildPhase)) + } + if kitPhase != v1.IntegrationKitPhaseNone { + g.Eventually(KitPhase(t, ctx, ns, name), testTimeout).Should(Equal(kitPhase)) + } +} diff --git a/e2e/advanced/build_order_strategy_test.go b/e2e/advanced/build_order_strategy_test.go index 5a2031410..1c3dcbf26 100644 --- a/e2e/advanced/build_order_strategy_test.go +++ b/e2e/advanced/build_order_strategy_test.go @@ -36,31 +36,35 @@ import ( ) func TestRunBuildOrderStrategyMatchingDependencies(t *testing.T) { - t.Parallel() - WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { - operatorID := "camel-k-build-order-deps" - g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, ctx, operatorID, ns, "--max-running-pipelines", "4", "--build-order-strategy", string(v1.BuildOrderStrategyDependencies))).To(Succeed()) - g.Eventually(PlatformPhase(t, ctx, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) - - g.Expect(CreateTimerKameletWithID(t, ctx, operatorID, ns, "timer-source")()).To(Succeed()) - + InstallOperator(t, g, ns) + + // Update platform with parameters required by this test + pl := Platform(t, ctx, ns)() + pl.Spec.Build.MaxRunningBuilds = 4 + pl.Spec.Build.BuildConfiguration.OrderStrategy = v1.BuildOrderStrategyDependencies + if err := TestClient(t).Update(ctx, pl); err != nil { + t.Error(err) + t.FailNow() + } + g.Eventually(PlatformPhase(t, ctx, ns), TestTimeoutShort).Should(Equal(v1.IntegrationPlatformPhaseReady)) + + g.Expect(CreateTimerKamelet(t, ctx, ns, "timer-source")()).To(Succeed()) integrationA := RandomizedSuffixName("java-a") - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", integrationA).Execute()).To(Succeed()) + g.Expect(KamelRun(t, ctx, ns, "files/Java.java", "--name", integrationA).Execute()).To(Succeed()) g.Eventually(IntegrationKit(t, ctx, ns, integrationA), TestTimeoutMedium).ShouldNot(BeEmpty()) integrationKitNameA := IntegrationKit(t, ctx, ns, integrationA)() g.Eventually(Build(t, ctx, ns, integrationKitNameA), TestTimeoutMedium).ShouldNot(BeNil()) integrationB := RandomizedSuffixName("java-b") - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", integrationB, "-d", "camel:cron").Execute()).To(Succeed()) + g.Expect(KamelRun(t, ctx, ns, "files/Java.java", "--name", integrationB, "-d", "camel:cron").Execute()).To(Succeed()) integrationC := RandomizedSuffixName("java-c") - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", integrationC, "-d", "camel:cron", "-d", "camel:zipfile").Execute()).To(Succeed()) + g.Expect(KamelRun(t, ctx, ns, "files/Java.java", "--name", integrationC, "-d", "camel:cron", "-d", "camel:zipfile").Execute()).To(Succeed()) integrationZ := RandomizedSuffixName("yaml-z") - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/timer-source.yaml", "--name", integrationZ).Execute()).To(Succeed()) + g.Expect(KamelRun(t, ctx, ns, "files/timer-source.yaml", "--name", integrationZ).Execute()).To(Succeed()) g.Eventually(IntegrationKit(t, ctx, ns, integrationB), TestTimeoutMedium).ShouldNot(BeEmpty()) g.Eventually(IntegrationKit(t, ctx, ns, integrationC), TestTimeoutMedium).ShouldNot(BeEmpty()) @@ -104,33 +108,37 @@ func TestRunBuildOrderStrategyMatchingDependencies(t *testing.T) { g.Expect(buildB.Status.StartedAt.Before(buildC.Status.StartedAt)).Should(BeTrue()) g.Expect(buildZ.Status.StartedAt.Before(buildB.Status.StartedAt)).Should(BeTrue()) g.Expect(buildZ.Status.StartedAt.Before(buildC.Status.StartedAt)).Should(BeTrue()) - - g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } func TestRunBuildOrderStrategyFIFO(t *testing.T) { WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { - operatorID := "camel-k-build-order-fifo" - g.Expect(KamelInstallWithID(t, ctx, operatorID, ns, "--build-order-strategy", string(v1.BuildOrderStrategyFIFO))).To(Succeed()) - g.Eventually(PlatformPhase(t, ctx, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) - - g.Expect(CreateTimerKameletWithID(t, ctx, operatorID, ns, "timer-source")()).To(Succeed()) + InstallOperator(t, g, ns) + // Update platform with parameters required by this test + pl := Platform(t, ctx, ns)() + pl.Spec.Build.BuildConfiguration.OrderStrategy = v1.BuildOrderStrategyFIFO + if err := TestClient(t).Update(ctx, pl); err != nil { + t.Error(err) + t.FailNow() + } + g.Eventually(PlatformPhase(t, ctx, ns), TestTimeoutShort).Should(Equal(v1.IntegrationPlatformPhaseReady)) + + g.Expect(CreateTimerKamelet(t, ctx, ns, "timer-source")()).To(Succeed()) integrationA := RandomizedSuffixName("java-a") - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", + g.Expect(KamelRun(t, ctx, ns, "files/Java.java", "--name", integrationA, ).Execute()).To(Succeed()) g.Eventually(IntegrationPhase(t, ctx, ns, integrationA)).Should(Equal(v1.IntegrationPhaseBuildingKit)) integrationB := RandomizedSuffixName("java-b") - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", + g.Expect(KamelRun(t, ctx, ns, "files/Java.java", "--name", integrationB, "-d", "camel:joor", ).Execute()).To(Succeed()) integrationZ := RandomizedSuffixName("yaml-z") - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/timer-source.yaml", + g.Expect(KamelRun(t, ctx, ns, "files/timer-source.yaml", "--name", integrationZ, ).Execute()).To(Succeed()) @@ -162,7 +170,5 @@ func TestRunBuildOrderStrategyFIFO(t *testing.T) { g.Eventually(IntegrationConditionStatus(t, ctx, ns, integrationZ, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) g.Eventually(IntegrationLogs(t, ctx, ns, integrationZ), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) g.Eventually(Kit(t, ctx, ns, integrationKitNameZ)().Status.BaseImage).Should(Equal(defaults.BaseImage())) - - g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/advanced/build_test.go b/e2e/advanced/build_test.go deleted file mode 100644 index 4bf2d60d7..000000000 --- a/e2e/advanced/build_test.go +++ /dev/null @@ -1,436 +0,0 @@ -//go:build integration -// +build integration - -// To enable compilation of this file in Goland, go to "Settings -> Go -> Vendoring & Build Tags -> Custom Tags" and add "integration" - -/* -Licensed to the Apache Software Foundation (ASF) under one or more -contributor license agreements. See the NOTICE file distributed with -this work for additional information regarding copyright ownership. -The ASF licenses this file to You under the Apache License, Version 2.0 -(the "License"); you may not use this file except in compliance with -the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package advanced - -import ( - "context" - "errors" - "fmt" - "testing" - "time" - - . "github.com/onsi/gomega" - - . "github.com/apache/camel-k/v2/e2e/support" - v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" - corev1 "k8s.io/api/core/v1" -) - -type kitOptions struct { - operatorID string - dependencies []string - traits []string -} - -func TestKitMaxBuildLimit(t *testing.T) { - WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { - createOperator(t, ctx, g, ns, "8m0s", "--global", "--force") - - pl := Platform(t, ctx, ns)() - // set maximum number of running builds and order strategy - pl.Spec.Build.MaxRunningBuilds = 2 - pl.Spec.Build.BuildConfiguration.OrderStrategy = v1.BuildOrderStrategySequential - if err := TestClient(t).Update(ctx, pl); err != nil { - t.Error(err) - t.FailNow() - } - - buildA := "integration-a" - buildB := "integration-b" - buildC := "integration-c" - - WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns1 string) { - WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns2 string) { - pl1 := v1.NewIntegrationPlatform(ns1, fmt.Sprintf("camel-k-%s", ns)) - pl.Spec.DeepCopyInto(&pl1.Spec) - pl1.Spec.Build.Maven.Settings = v1.ValueSource{} - pl1.SetOperatorID(fmt.Sprintf("camel-k-%s", ns)) - if err := TestClient(t).Create(ctx, &pl1); err != nil { - t.Error(err) - t.FailNow() - } - - g.Eventually(PlatformPhase(t, ctx, ns1), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) - - pl2 := v1.NewIntegrationPlatform(ns2, fmt.Sprintf("camel-k-%s", ns)) - pl.Spec.DeepCopyInto(&pl2.Spec) - pl2.Spec.Build.Maven.Settings = v1.ValueSource{} - pl2.SetOperatorID(fmt.Sprintf("camel-k-%s", ns)) - if err := TestClient(t).Create(ctx, &pl2); err != nil { - t.Error(err) - t.FailNow() - } - - g.Eventually(PlatformPhase(t, ctx, ns2), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) - - doKitBuildInNamespace(t, ctx, g, buildA, ns, TestTimeoutShort, kitOptions{ - operatorID: fmt.Sprintf("camel-k-%s", ns), - dependencies: []string{ - "camel:timer", "camel:log", - }, - traits: []string{ - "builder.properties=build-property=A", - }, - }, v1.BuildPhaseRunning, v1.IntegrationKitPhaseBuildRunning) - - doKitBuildInNamespace(t, ctx, g, buildB, ns1, TestTimeoutShort, kitOptions{ - operatorID: fmt.Sprintf("camel-k-%s", ns), - dependencies: []string{ - "camel:timer", "camel:log", - }, - traits: []string{ - "builder.properties=build-property=B", - }, - }, v1.BuildPhaseRunning, v1.IntegrationKitPhaseBuildRunning) - - doKitBuildInNamespace(t, ctx, g, buildC, ns2, TestTimeoutShort, kitOptions{ - operatorID: fmt.Sprintf("camel-k-%s", ns), - dependencies: []string{ - "camel:timer", "camel:log", - }, - traits: []string{ - "builder.properties=build-property=C", - }, - }, v1.BuildPhaseScheduling, v1.IntegrationKitPhaseNone) - - var notExceedsMaxBuildLimit = func(runningBuilds int) bool { - return runningBuilds <= 2 - } - - limit := 0 - for limit < 5 && BuildPhase(t, ctx, ns, buildA)() == v1.BuildPhaseRunning { - // verify that number of running builds does not exceed max build limit - g.Consistently(BuildsRunning(BuildPhase(t, ctx, ns, buildA), BuildPhase(t, ctx, ns1, buildB), BuildPhase(t, ctx, ns2, buildC)), TestTimeoutShort, 10*time.Second).Should(Satisfy(notExceedsMaxBuildLimit)) - limit++ - } - - // make sure we have verified max build limit at least once - if limit == 0 { - t.Error(errors.New(fmt.Sprintf("Unexpected build phase '%s' for %s - not able to verify max builds limit", BuildPhase(t, ctx, ns, buildA)(), buildA))) - t.FailNow() - } - - // verify that all builds are successful - g.Eventually(BuildPhase(t, ctx, ns, buildA), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded)) - g.Eventually(KitPhase(t, ctx, ns, buildA), TestTimeoutLong).Should(Equal(v1.IntegrationKitPhaseReady)) - - g.Eventually(BuildPhase(t, ctx, ns1, buildB), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded)) - g.Eventually(KitPhase(t, ctx, ns1, buildB), TestTimeoutLong).Should(Equal(v1.IntegrationKitPhaseReady)) - - g.Eventually(BuildPhase(t, ctx, ns2, buildC), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded)) - g.Eventually(KitPhase(t, ctx, ns2, buildC), TestTimeoutLong).Should(Equal(v1.IntegrationKitPhaseReady)) - }) - }) - }) -} - -func TestKitMaxBuildLimitFIFOStrategy(t *testing.T) { - WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { - createOperator(t, ctx, g, ns, "8m0s", "--global", "--force") - - pl := Platform(t, ctx, ns)() - // set maximum number of running builds and order strategy - pl.Spec.Build.MaxRunningBuilds = 2 - pl.Spec.Build.BuildConfiguration.OrderStrategy = v1.BuildOrderStrategyFIFO - if err := TestClient(t).Update(ctx, pl); err != nil { - t.Error(err) - t.FailNow() - } - - buildA := "integration-a" - buildB := "integration-b" - buildC := "integration-c" - - doKitBuildInNamespace(t, ctx, g, buildA, ns, TestTimeoutShort, kitOptions{ - operatorID: fmt.Sprintf("camel-k-%s", ns), - dependencies: []string{ - "camel:timer", "camel:log", - }, - traits: []string{ - "builder.properties=build-property=A", - }, - }, v1.BuildPhaseRunning, v1.IntegrationKitPhaseBuildRunning) - - doKitBuildInNamespace(t, ctx, g, buildB, ns, TestTimeoutShort, kitOptions{ - operatorID: fmt.Sprintf("camel-k-%s", ns), - dependencies: []string{ - "camel:timer", "camel:log", - }, - traits: []string{ - "builder.properties=build-property=B", - }, - }, v1.BuildPhaseRunning, v1.IntegrationKitPhaseBuildRunning) - - doKitBuildInNamespace(t, ctx, g, buildC, ns, TestTimeoutShort, kitOptions{ - operatorID: fmt.Sprintf("camel-k-%s", ns), - dependencies: []string{ - "camel:timer", "camel:log", - }, - traits: []string{ - "builder.properties=build-property=C", - }, - }, v1.BuildPhaseScheduling, v1.IntegrationKitPhaseNone) - - var notExceedsMaxBuildLimit = func(runningBuilds int) bool { - return runningBuilds <= 2 - } - - limit := 0 - for limit < 5 && BuildPhase(t, ctx, ns, buildA)() == v1.BuildPhaseRunning { - // verify that number of running builds does not exceed max build limit - g.Consistently(BuildsRunning(BuildPhase(t, ctx, ns, buildA), BuildPhase(t, ctx, ns, buildB), BuildPhase(t, ctx, ns, buildC)), TestTimeoutShort, 10*time.Second).Should(Satisfy(notExceedsMaxBuildLimit)) - limit++ - } - - // make sure we have verified max build limit at least once - if limit == 0 { - t.Error(errors.New(fmt.Sprintf("Unexpected build phase '%s' for %s - not able to verify max builds limit", BuildPhase(t, ctx, ns, buildA)(), buildA))) - t.FailNow() - } - - // verify that all builds are successful - g.Eventually(BuildPhase(t, ctx, ns, buildA), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded)) - g.Eventually(KitPhase(t, ctx, ns, buildA), TestTimeoutLong).Should(Equal(v1.IntegrationKitPhaseReady)) - g.Eventually(BuildPhase(t, ctx, ns, buildB), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded)) - g.Eventually(KitPhase(t, ctx, ns, buildB), TestTimeoutLong).Should(Equal(v1.IntegrationKitPhaseReady)) - g.Eventually(BuildPhase(t, ctx, ns, buildC), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded)) - g.Eventually(KitPhase(t, ctx, ns, buildC), TestTimeoutLong).Should(Equal(v1.IntegrationKitPhaseReady)) - }) -} - -func TestKitMaxBuildLimitDependencyMatchingStrategy(t *testing.T) { - WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { - createOperator(t, ctx, g, ns, "8m0s", "--global", "--force") - - pl := Platform(t, ctx, ns)() - // set maximum number of running builds and order strategy - pl.Spec.Build.MaxRunningBuilds = 2 - pl.Spec.Build.BuildConfiguration.OrderStrategy = v1.BuildOrderStrategyDependencies - if err := TestClient(t).Update(ctx, pl); err != nil { - t.Error(err) - t.FailNow() - } - - buildA := "integration-a" - buildB := "integration-b" - buildC := "integration-c" - - doKitBuildInNamespace(t, ctx, g, buildA, ns, TestTimeoutShort, kitOptions{ - operatorID: fmt.Sprintf("camel-k-%s", ns), - dependencies: []string{ - "camel:timer", "camel:log", - }, - traits: []string{ - "builder.properties=build-property=A", - }, - }, v1.BuildPhaseRunning, v1.IntegrationKitPhaseBuildRunning) - - doKitBuildInNamespace(t, ctx, g, buildB, ns, TestTimeoutShort, kitOptions{ - operatorID: fmt.Sprintf("camel-k-%s", ns), - dependencies: []string{ - "camel:cron", "camel:log", "camel:joor", - }, - traits: []string{ - "builder.properties=build-property=B", - }, - }, v1.BuildPhaseRunning, v1.IntegrationKitPhaseBuildRunning) - - doKitBuildInNamespace(t, ctx, g, buildC, ns, TestTimeoutShort, kitOptions{ - operatorID: fmt.Sprintf("camel-k-%s", ns), - dependencies: []string{ - "camel:timer", "camel:log", "camel:joor", "camel:http", - }, - traits: []string{ - "builder.properties=build-property=C", - }, - }, v1.BuildPhaseScheduling, v1.IntegrationKitPhaseNone) - - var notExceedsMaxBuildLimit = func(runningBuilds int) bool { - return runningBuilds <= 2 - } - - limit := 0 - for limit < 5 && BuildPhase(t, ctx, ns, buildA)() == v1.BuildPhaseRunning { - // verify that number of running builds does not exceed max build limit - g.Consistently(BuildsRunning(BuildPhase(t, ctx, ns, buildA), BuildPhase(t, ctx, ns, buildB), BuildPhase(t, ctx, ns, buildC)), TestTimeoutShort, 10*time.Second).Should(Satisfy(notExceedsMaxBuildLimit)) - limit++ - } - - // make sure we have verified max build limit at least once - if limit == 0 { - t.Error(errors.New(fmt.Sprintf("Unexpected build phase '%s' for %s - not able to verify max builds limit", BuildPhase(t, ctx, ns, buildA)(), buildA))) - t.FailNow() - } - - // verify that all builds are successful - g.Eventually(BuildPhase(t, ctx, ns, buildA), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded)) - g.Eventually(KitPhase(t, ctx, ns, buildA), TestTimeoutLong).Should(Equal(v1.IntegrationKitPhaseReady)) - g.Eventually(BuildPhase(t, ctx, ns, buildB), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded)) - g.Eventually(KitPhase(t, ctx, ns, buildB), TestTimeoutLong).Should(Equal(v1.IntegrationKitPhaseReady)) - g.Eventually(BuildPhase(t, ctx, ns, buildC), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded)) - g.Eventually(KitPhase(t, ctx, ns, buildC), TestTimeoutLong).Should(Equal(v1.IntegrationKitPhaseReady)) - }) -} - -func TestMaxBuildLimitWaitingBuilds(t *testing.T) { - WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { - createOperator(t, ctx, g, ns, "8m0s", "--global", "--force") - - pl := Platform(t, ctx, ns)() - // set maximum number of running builds and order strategy - pl.Spec.Build.MaxRunningBuilds = 1 - pl.Spec.Build.BuildConfiguration.OrderStrategy = v1.BuildOrderStrategyFIFO - if err := TestClient(t).Update(ctx, pl); err != nil { - t.Error(err) - t.FailNow() - } - - buildA := "integration-a" - buildB := "integration-b" - buildC := "integration-c" - - doKitBuildInNamespace(t, ctx, g, buildA, ns, TestTimeoutShort, kitOptions{ - operatorID: fmt.Sprintf("camel-k-%s", ns), - dependencies: []string{ - "camel:timer", "camel:log", - }, - traits: []string{ - "builder.properties=build-property=A", - }, - }, v1.BuildPhaseRunning, v1.IntegrationKitPhaseBuildRunning) - - doKitBuildInNamespace(t, ctx, g, buildB, ns, TestTimeoutShort, kitOptions{ - operatorID: fmt.Sprintf("camel-k-%s", ns), - dependencies: []string{ - "camel:cron", "camel:log", "camel:joor", - }, - traits: []string{ - "builder.properties=build-property=B", - }, - }, v1.BuildPhaseScheduling, v1.IntegrationKitPhaseNone) - - doKitBuildInNamespace(t, ctx, g, buildC, ns, TestTimeoutShort, kitOptions{ - operatorID: fmt.Sprintf("camel-k-%s", ns), - dependencies: []string{ - "camel:timer", "camel:log", "camel:joor", "camel:http", - }, - traits: []string{ - "builder.properties=build-property=C", - }, - }, v1.BuildPhaseScheduling, v1.IntegrationKitPhaseNone) - - // verify that last build is waiting - g.Eventually(BuildConditions(t, ctx, ns, buildC), TestTimeoutMedium).ShouldNot(BeNil()) - g.Eventually( - BuildCondition(t, ctx, ns, buildC, v1.BuildConditionType(v1.BuildConditionScheduled))().Status, - TestTimeoutShort).Should(Equal(corev1.ConditionFalse)) - g.Eventually( - BuildCondition(t, ctx, ns, buildC, v1.BuildConditionType(v1.BuildConditionScheduled))().Reason, - TestTimeoutShort).Should(Equal(v1.BuildConditionWaitingReason)) - - // verify that last build is scheduled - g.Eventually(BuildPhase(t, ctx, ns, buildC), TestTimeoutLong).Should(Equal(v1.BuildPhaseSucceeded)) - g.Eventually(KitPhase(t, ctx, ns, buildC), TestTimeoutLong).Should(Equal(v1.IntegrationKitPhaseReady)) - - g.Eventually(BuildConditions(t, ctx, ns, buildC), TestTimeoutLong).ShouldNot(BeNil()) - g.Eventually( - BuildCondition(t, ctx, ns, buildC, v1.BuildConditionType(v1.BuildConditionScheduled))().Status, - TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually( - BuildCondition(t, ctx, ns, buildC, v1.BuildConditionType(v1.BuildConditionScheduled))().Reason, - TestTimeoutShort).Should(Equal(v1.BuildConditionReadyReason)) - }) -} - -func TestKitTimerToLogFullBuild(t *testing.T) { - doKitFullBuild(t, "timer-to-log", "8m0s", TestTimeoutLong, kitOptions{ - dependencies: []string{ - "camel:timer", "camel:log", - }, - }, v1.BuildPhaseSucceeded, v1.IntegrationKitPhaseReady) -} - -func TestKitKnativeFullBuild(t *testing.T) { - doKitFullBuild(t, "knative", "8m0s", TestTimeoutLong, kitOptions{ - dependencies: []string{ - "camel-quarkus-knative", - }, - }, v1.BuildPhaseSucceeded, v1.IntegrationKitPhaseReady) -} - -func TestKitTimerToLogFullNativeBuild(t *testing.T) { - doKitFullBuild(t, "timer-to-log", "15m0s", TestTimeoutLong*3, kitOptions{ - dependencies: []string{ - "camel:timer", "camel:log", - }, - traits: []string{ - "quarkus.build-mode=native", - }, - }, v1.BuildPhaseSucceeded, v1.IntegrationKitPhaseReady) -} - -func doKitFullBuild(t *testing.T, name string, buildTimeout string, testTimeout time.Duration, - options kitOptions, buildPhase v1.BuildPhase, kitPhase v1.IntegrationKitPhase) { - t.Helper() - - WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { - createOperator(t, ctx, g, ns, buildTimeout) - doKitBuildInNamespace(t, ctx, g, name, ns, testTimeout, options, buildPhase, kitPhase) - }) -} - -func createOperator(t *testing.T, ctx context.Context, g *WithT, ns string, buildTimeout string, installArgs ...string) { - args := []string{"--build-timeout", buildTimeout} - args = append(args, installArgs...) - - operatorID := fmt.Sprintf("camel-k-%s", ns) - g.Expect(KamelInstallWithID(t, ctx, operatorID, ns, args...)).To(Succeed()) - g.Eventually(PlatformPhase(t, ctx, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) -} - -func doKitBuildInNamespace(t *testing.T, ctx context.Context, g *WithT, name string, ns string, testTimeout time.Duration, options kitOptions, buildPhase v1.BuildPhase, kitPhase v1.IntegrationKitPhase) { - - buildKitArgs := []string{"kit", "create", name, "-n", ns} - for _, dependency := range options.dependencies { - buildKitArgs = append(buildKitArgs, "-d", dependency) - } - for _, trait := range options.traits { - buildKitArgs = append(buildKitArgs, "-t", trait) - } - - if options.operatorID != "" { - buildKitArgs = append(buildKitArgs, "--operator-id", options.operatorID) - } else { - buildKitArgs = append(buildKitArgs, "--operator-id", fmt.Sprintf("camel-k-%s", ns)) - } - - g.Expect(Kamel(t, ctx, buildKitArgs...).Execute()).To(Succeed()) - - g.Eventually(Build(t, ctx, ns, name), testTimeout).ShouldNot(BeNil()) - if buildPhase != v1.BuildPhaseNone { - g.Eventually(BuildPhase(t, ctx, ns, name), testTimeout).Should(Equal(buildPhase)) - } - if kitPhase != v1.IntegrationKitPhaseNone { - g.Eventually(KitPhase(t, ctx, ns, name), testTimeout).Should(Equal(kitPhase)) - } -} diff --git a/e2e/advanced/builder_test.go b/e2e/advanced/builder_test.go index 409278035..a97945aab 100644 --- a/e2e/advanced/builder_test.go +++ b/e2e/advanced/builder_test.go @@ -40,9 +40,7 @@ func TestBuilderTimeout(t *testing.T) { t.Parallel() WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { - operatorID := fmt.Sprintf("camel-k-%s", ns) - g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) + InstallOperator(t, g, ns) g.Eventually(OperatorPod(t, ctx, ns)).ShouldNot(BeNil()) g.Eventually(Platform(t, ctx, ns)).ShouldNot(BeNil()) g.Eventually(PlatformConditionStatus(t, ctx, ns, v1.IntegrationPlatformConditionTypeCreated), TestTimeoutShort). @@ -66,7 +64,7 @@ func TestBuilderTimeout(t *testing.T) { t.Run("run yaml", func(t *testing.T) { name := RandomizedSuffixName("yaml") - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/yaml.yaml", "--name", name, "-t", "builder.strategy=pod").Execute()).To(Succeed()) + g.Expect(KamelRun(t, ctx, ns, "files/yaml.yaml", "--name", name, "-t", "builder.strategy=pod").Execute()).To(Succeed()) // As the build hits timeout, it keeps trying building g.Eventually(IntegrationPhase(t, ctx, ns, name)).Should(Equal(v1.IntegrationPhaseBuildingKit)) integrationKitName := IntegrationKit(t, ctx, ns, name)() @@ -88,6 +86,7 @@ func TestMavenProfile(t *testing.T) { t.Parallel() WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { + InstallOperator(t, g, ns) t.Run("Run maven profile", func(t *testing.T) { name := RandomizedSuffixName("java-maven-profile") diff --git a/e2e/advanced/catalog_builder_test.go b/e2e/advanced/catalog_builder_test.go index 7b85e0ef5..4a100412c 100644 --- a/e2e/advanced/catalog_builder_test.go +++ b/e2e/advanced/catalog_builder_test.go @@ -40,10 +40,7 @@ func TestCamelCatalogBuilder(t *testing.T) { t.Parallel() WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { - operatorID := fmt.Sprintf("camel-k-%s", ns) - g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) + InstallOperator(t, g, ns) g.Eventually(OperatorPod(t, ctx, ns)).ShouldNot(BeNil()) g.Eventually(Platform(t, ctx, ns)).ShouldNot(BeNil()) g.Eventually(PlatformConditionStatus(t, ctx, ns, v1.IntegrationPlatformConditionTypeCreated), TestTimeoutShort). @@ -59,7 +56,7 @@ func TestCamelCatalogBuilder(t *testing.T) { name := RandomizedSuffixName("java-1-15") nonCompatibleCatalogName := "camel-catalog-1.15.0" g.Expect( - KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name, "-t", "camel.runtime-version=1.15.0").Execute()).To(Succeed()) + 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(CamelCatalogPhase(t, ctx, ns, nonCompatibleCatalogName)).Should(Equal(v1.CamelCatalogPhaseError)) @@ -71,9 +68,6 @@ func TestCamelCatalogBuilder(t *testing.T) { g.Eventually(KitCondition(t, ctx, ns, kitName, v1.IntegrationKitConditionCatalogAvailable)().Reason).Should(Equal("Camel Catalog 1.15.0 error")) g.Eventually(IntegrationPhase(t, ctx, ns, name)).Should(Equal(v1.IntegrationPhaseError)) g.Eventually(IntegrationCondition(t, ctx, ns, name, v1.IntegrationConditionKitAvailable)().Status).Should(Equal(corev1.ConditionFalse)) - - // Clean up - g.Eventually(DeleteIntegrations(t, ctx, ns)).Should(Equal(0)) }) // Run an integration with a compatible catalog @@ -88,7 +82,7 @@ func TestCamelCatalogBuilder(t *testing.T) { g.Eventually(CamelCatalog(t, ctx, ns, compatibleCatalogName)).Should(BeNil()) g.Expect( - KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name, "-t", "camel.runtime-version="+compatibleVersion).Execute()).To(Succeed()) + KamelRun(t, ctx, ns, "files/Java.java", "--name", name, "-t", "camel.runtime-version="+compatibleVersion).Execute()).To(Succeed()) g.Eventually(CamelCatalog(t, ctx, ns, compatibleCatalogName)).ShouldNot(BeNil()) g.Eventually(CamelCatalogPhase(t, ctx, ns, compatibleCatalogName)).Should(Equal(v1.CamelCatalogPhaseReady)) @@ -97,9 +91,6 @@ func TestCamelCatalogBuilder(t *testing.T) { g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutMedium). Should(Equal(corev1.ConditionTrue)) g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutMedium).Should(ContainSubstring("Magicstring!")) - - // Clean up - g.Eventually(DeleteIntegrations(t, ctx, ns)).Should(Equal(0)) }) t.Run("Run catalog container exists", func(t *testing.T) { @@ -112,7 +103,7 @@ func TestCamelCatalogBuilder(t *testing.T) { g.Eventually(CamelCatalog(t, ctx, ns, compatibleCatalogName)).Should(BeNil()) g.Expect( - KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name, "-t", "camel.runtime-version="+compatibleVersion).Execute()).To(Succeed()) + KamelRun(t, ctx, ns, "files/Java.java", "--name", name, "-t", "camel.runtime-version="+compatibleVersion).Execute()).To(Succeed()) g.Eventually(CamelCatalog(t, ctx, ns, compatibleCatalogName)).ShouldNot(BeNil()) g.Eventually(CamelCatalogPhase(t, ctx, ns, compatibleCatalogName)).Should(Equal(v1.CamelCatalogPhaseReady)) @@ -127,11 +118,6 @@ func TestCamelCatalogBuilder(t *testing.T) { g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). Should(Equal(corev1.ConditionTrue)) g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - - // Clean up - g.Eventually(DeleteIntegrations(t, ctx, ns)).Should(Equal(0)) }) - - g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/advanced/debug_test.go b/e2e/advanced/debug_test.go index 086aa037e..fa084a71e 100644 --- a/e2e/advanced/debug_test.go +++ b/e2e/advanced/debug_test.go @@ -24,7 +24,6 @@ package advanced import ( "context" - "fmt" "net" "testing" "time" @@ -32,7 +31,6 @@ import ( corev1 "k8s.io/api/core/v1" . "github.com/apache/camel-k/v2/e2e/support" - v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" . "github.com/onsi/gomega" ) @@ -40,15 +38,10 @@ func TestKamelCLIDebug(t *testing.T) { t.Parallel() WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { - operatorID := fmt.Sprintf("camel-k-%s", ns) - g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - - g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + InstallOperator(t, g, ns) t.Run("debug local default port check", func(t *testing.T) { - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/yaml.yaml").Execute()).To(Succeed()) + g.Expect(KamelRun(t, ctx, ns, "files/yaml.yaml").Execute()).To(Succeed()) g.Eventually(IntegrationPodPhase(t, ctx, ns, "yaml"), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) g.Expect(portIsInUse("127.0.0.1", "5005")()).To(BeFalse()) @@ -62,7 +55,7 @@ func TestKamelCLIDebug(t *testing.T) { }) t.Run("debug local port check", func(t *testing.T) { - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/yaml.yaml").Execute()).To(Succeed()) + g.Expect(KamelRun(t, ctx, ns, "files/yaml.yaml").Execute()).To(Succeed()) g.Eventually(IntegrationPodPhase(t, ctx, ns, "yaml"), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) g.Expect(portIsInUse("127.0.0.1", "5006")()).To(BeFalse()) @@ -76,7 +69,7 @@ func TestKamelCLIDebug(t *testing.T) { }) t.Run("debug logs check", func(t *testing.T) { - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/yaml.yaml").Execute()).To(Succeed()) + g.Expect(KamelRun(t, ctx, ns, "files/yaml.yaml").Execute()).To(Succeed()) g.Eventually(IntegrationPodPhase(t, ctx, ns, "yaml"), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) debugTestContext, cancel := context.WithCancel(ctx) @@ -89,7 +82,7 @@ func TestKamelCLIDebug(t *testing.T) { }) t.Run("Pod config test", func(t *testing.T) { - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/yaml.yaml").Execute()).To(Succeed()) + g.Expect(KamelRun(t, ctx, ns, "files/yaml.yaml").Execute()).To(Succeed()) g.Eventually(IntegrationPodPhase(t, ctx, ns, "yaml"), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) debugTestContext, cancel := context.WithCancel(ctx) @@ -100,12 +93,7 @@ func TestKamelCLIDebug(t *testing.T) { return IntegrationPod(t, ctx, ns, "yaml")().Spec.Containers[0].Args[0] }).Should(ContainSubstring("-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005")) g.Expect(IntegrationPod(t, ctx, ns, "yaml")().GetLabels()["camel.apache.org/debug"]).To(Not(BeNil())) - g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) - g.Eventually(IntegrationPods(t, ctx, ns, "yaml"), TestTimeoutMedium, 5*time.Second).Should(HaveLen(0)) }) - - g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) - g.Eventually(IntegrationPods(t, ctx, ns, "yaml"), TestTimeoutMedium, 5*time.Second).Should(HaveLen(0)) }) } diff --git a/e2e/advanced/deployment_test.go b/e2e/advanced/deployment_test.go deleted file mode 100644 index 6821b26b7..000000000 --- a/e2e/advanced/deployment_test.go +++ /dev/null @@ -1,83 +0,0 @@ -//go:build integration -// +build integration - -// To enable compilation of this file in Goland, go to "Settings -> Go -> Vendoring & Build Tags -> Custom Tags" and add "integration" - -/* -Licensed to the Apache Software Foundation (ASF) under one or more -contributor license agreements. See the NOTICE file distributed with -this work for additional information regarding copyright ownership. -The ASF licenses this file to You under the Apache License, Version 2.0 -(the "License"); you may not use this file except in compliance with -the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package advanced - -import ( - "context" - "testing" - - "os/exec" - - . "github.com/onsi/gomega" - corev1 "k8s.io/api/core/v1" - - . "github.com/apache/camel-k/v2/e2e/support" - v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" -) - -func TestDeploymentFailureShouldReportIntegrationCondition(t *testing.T) { - t.Parallel() - - WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { - operatorID := "camel-k-failing-deploy" - nsRestr := "restr" - g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, ctx, operatorID, ns, "--global", "--force")).To(Succeed()) - // Create restricted namespace - ExpectExecSucceed(t, g, - exec.Command( - "kubectl", - "create", - "ns", - nsRestr, - ), - ) - ExpectExecSucceed(t, g, - exec.Command( - "kubectl", - "label", - "--overwrite", - "ns", - nsRestr, - "pod-security.kubernetes.io/enforce=baseline", - "pod-security.kubernetes.io/enforce-version=latest", - "pod-security.kubernetes.io/enforce=restricted", - "pod-security.kubernetes.io/warn-version=latest", - "pod-security.kubernetes.io/audit=restricted", - "pod-security.kubernetes.io/audit-version=latest", - ), - ) - // Create an Integration into a restricted namespace - name := RandomizedSuffixName("java-fail") - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name, "-n", nsRestr).Execute()).To(Succeed()) - // Check the error is reported into the Integration - g.Eventually(IntegrationPhase(t, ctx, nsRestr, name), TestTimeoutMedium).Should(Equal(v1.IntegrationPhaseError)) - g.Eventually(IntegrationCondition(t, ctx, nsRestr, name, v1.IntegrationConditionReady)().Status). - Should(Equal(corev1.ConditionFalse)) - g.Eventually(IntegrationCondition(t, ctx, nsRestr, name, v1.IntegrationConditionReady)().Message). - Should(ContainSubstring("is forbidden: violates PodSecurity")) - // Clean up - g.Eventually(DeleteIntegrations(t, ctx, nsRestr)).Should(Equal(0)) - }) -} diff --git a/e2e/advanced/dump_test.go b/e2e/advanced/dump_test.go index fd9b5c4af..11b3c9e23 100644 --- a/e2e/advanced/dump_test.go +++ b/e2e/advanced/dump_test.go @@ -24,11 +24,8 @@ package advanced import ( "context" - "fmt" "testing" - v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" - . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" @@ -47,14 +44,10 @@ func TestKamelCLIDump(t *testing.T) { g.Expect(dump).To(ContainSubstring("Found 0 deployments:")) }) - t.Run("dump non-empty namespace", func(t *testing.T) { - operatorID := fmt.Sprintf("camel-k-%s", ns) - g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + InstallOperator(t, g, ns) - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/yaml.yaml").Execute()).To(Succeed()) + t.Run("dump non-empty namespace", func(t *testing.T) { + g.Expect(KamelRun(t, ctx, ns, "files/yaml.yaml").Execute()).To(Succeed()) g.Eventually(IntegrationPodPhase(t, ctx, ns, "yaml"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) g.Eventually(IntegrationLogs(t, ctx, ns, "yaml")).Should(ContainSubstring("Magicstring!")) diff --git a/e2e/advanced/environment_test.go b/e2e/advanced/environment_test.go index 27efc987f..980c87f35 100644 --- a/e2e/advanced/environment_test.go +++ b/e2e/advanced/environment_test.go @@ -24,7 +24,6 @@ package advanced import ( "context" - "fmt" "os" "strings" "testing" @@ -66,16 +65,12 @@ func TestEnvironmentTrait(t *testing.T) { } // Install Camel K with the HTTP proxy environment variable - operatorID := "camel-k-trait-environment" - g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, ctx, operatorID, ns, "--operator-env-vars", fmt.Sprintf("HTTP_PROXY=%s", httpProxy), "--operator-env-vars", "NO_PROXY="+strings.Join(noProxy, ","))).To(Succeed()) - - g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + //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, g, ns) t.Run("Run integration with default environment", func(t *testing.T) { name := RandomizedSuffixName("java-default") - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "--name", name, "files/Java.java").Execute()).To(Succeed()) + g.Expect(KamelRun(t, ctx, ns, "--name", name, "files/Java.java").Execute()).To(Succeed()) g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) @@ -101,7 +96,7 @@ func TestEnvironmentTrait(t *testing.T) { t.Run("Run integration with custom environment", func(t *testing.T) { name := RandomizedSuffixName("java-custom-proxy") - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name, "-t", "environment.vars=HTTP_PROXY=http://custom.proxy").Execute()).To(Succeed()) + g.Expect(KamelRun(t, ctx, ns, "files/Java.java", "--name", name, "-t", "environment.vars=HTTP_PROXY=http://custom.proxy").Execute()).To(Succeed()) g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) @@ -127,7 +122,7 @@ func TestEnvironmentTrait(t *testing.T) { t.Run("Run integration without default HTTP proxy environment", func(t *testing.T) { name := RandomizedSuffixName("java-no-proxy") - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name, "-t", "environment.http-proxy=false").Execute()).To(Succeed()) + g.Expect(KamelRun(t, ctx, ns, "files/Java.java", "--name", name, "-t", "environment.http-proxy=false").Execute()).To(Succeed()) g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) diff --git a/e2e/advanced/incremental_build_test.go b/e2e/advanced/incremental_build_test.go index 249e4e4df..aed9771a3 100644 --- a/e2e/advanced/incremental_build_test.go +++ b/e2e/advanced/incremental_build_test.go @@ -40,13 +40,10 @@ func TestRunIncrementalBuildRoutine(t *testing.T) { t.Parallel() WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { - operatorID := "camel-k-incremental-build-routine" - g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + InstallOperator(t, g, ns) name := RandomizedSuffixName("java") - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name).Execute()).To(Succeed()) + g.Expect(KamelRun(t, ctx, ns, "files/Java.java", "--name", name).Execute()).To(Succeed()) g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) @@ -56,7 +53,7 @@ func TestRunIncrementalBuildRoutine(t *testing.T) { t.Run("Reuse previous kit", func(t *testing.T) { nameClone := "java-clone" - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", nameClone).Execute()).To(Succeed()) + g.Expect(KamelRun(t, ctx, ns, "files/Java.java", "--name", nameClone).Execute()).To(Succeed()) g.Eventually(IntegrationPodPhase(t, ctx, ns, nameClone), TestTimeoutLong).Should(Equal(corev1.PodRunning)) g.Eventually(IntegrationConditionStatus(t, ctx, ns, nameClone, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) g.Eventually(IntegrationLogs(t, ctx, ns, nameClone), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) @@ -68,7 +65,7 @@ func TestRunIncrementalBuildRoutine(t *testing.T) { // Another integration that should be built on top of the previous IntegrationKit // just add a new random dependency nameIncremental := RandomizedSuffixName("java-incremental") - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", nameIncremental, "-d", "camel:zipfile").Execute()).To(Succeed()) + g.Expect(KamelRun(t, ctx, ns, "files/Java.java", "--name", nameIncremental, "-d", "camel:zipfile").Execute()).To(Succeed()) g.Eventually(IntegrationPodPhase(t, ctx, ns, nameIncremental), TestTimeoutLong).Should(Equal(corev1.PodRunning)) g.Eventually(IntegrationConditionStatus(t, ctx, ns, nameIncremental, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) g.Eventually(IntegrationLogs(t, ctx, ns, nameIncremental), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) @@ -79,8 +76,6 @@ func TestRunIncrementalBuildRoutine(t *testing.T) { g.Eventually(Kit(t, ctx, ns, integrationIncrementalKitName)().Status.BaseImage).Should(ContainSubstring(integrationKitName)) g.Eventually(Kit(t, ctx, ns, integrationIncrementalKitName)().Status.RootImage).Should(Equal(defaults.BaseImage())) }) - - g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } @@ -88,13 +83,10 @@ func TestRunIncrementalBuildPod(t *testing.T) { t.Parallel() WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { - operatorID := "camel-k-incremental-build-pod" - g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + InstallOperator(t, g, ns) name := RandomizedSuffixName("java") - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name, "-t", "builder.strategy=pod").Execute()).To(Succeed()) + g.Expect(KamelRun(t, ctx, ns, "files/Java.java", "--name", name, "-t", "builder.strategy=pod").Execute()).To(Succeed()) g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) @@ -105,7 +97,7 @@ func TestRunIncrementalBuildPod(t *testing.T) { t.Run("Reuse previous kit", func(t *testing.T) { nameClone := RandomizedSuffixName("java-clone") - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", nameClone, "-t", "builder.strategy=pod").Execute()).To(Succeed()) + g.Expect(KamelRun(t, ctx, ns, "files/Java.java", "--name", nameClone, "-t", "builder.strategy=pod").Execute()).To(Succeed()) g.Eventually(IntegrationPodPhase(t, ctx, ns, nameClone), TestTimeoutLong).Should(Equal(corev1.PodRunning)) g.Eventually(IntegrationConditionStatus(t, ctx, ns, nameClone, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) g.Eventually(IntegrationLogs(t, ctx, ns, nameClone), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) @@ -118,7 +110,7 @@ func TestRunIncrementalBuildPod(t *testing.T) { // Another integration that should be built on top of the previous IntegrationKit // just add a new random dependency nameIncremental := RandomizedSuffixName("java-incremental") - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", nameIncremental, "-d", "camel:zipfile", "-t", "builder.strategy=pod").Execute()).To(Succeed()) + g.Expect(KamelRun(t, ctx, ns, "files/Java.java", "--name", nameIncremental, "-d", "camel:zipfile", "-t", "builder.strategy=pod").Execute()).To(Succeed()) g.Eventually(IntegrationPodPhase(t, ctx, ns, nameIncremental), TestTimeoutLong).Should(Equal(corev1.PodRunning)) g.Eventually(IntegrationConditionStatus(t, ctx, ns, nameIncremental, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) g.Eventually(IntegrationLogs(t, ctx, ns, nameIncremental), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) @@ -130,8 +122,6 @@ func TestRunIncrementalBuildPod(t *testing.T) { g.Eventually(Kit(t, ctx, ns, integrationIncrementalKitName)().Status.RootImage).Should(Equal(defaults.BaseImage())) g.Eventually(BuilderPodsCount(t, ctx, ns)).Should(Equal(2)) }) - - g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } @@ -139,13 +129,10 @@ func TestRunIncrementalBuildOff(t *testing.T) { t.Parallel() WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { - operatorID := "camel-k-standard-build" - g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + InstallOperator(t, g, ns) name := RandomizedSuffixName("java") - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name).Execute()).To(Succeed()) + g.Expect(KamelRun(t, ctx, ns, "files/Java.java", "--name", name).Execute()).To(Succeed()) g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) @@ -154,7 +141,7 @@ func TestRunIncrementalBuildOff(t *testing.T) { t.Run("Don't reuse previous kit", func(t *testing.T) { nameClone := RandomizedSuffixName("java-clone") - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", nameClone, "-t", "builder.incremental-image-build=false").Execute()).To(Succeed()) + g.Expect(KamelRun(t, ctx, ns, "files/Java.java", "--name", nameClone, "-t", "builder.incremental-image-build=false").Execute()).To(Succeed()) g.Eventually(IntegrationPodPhase(t, ctx, ns, nameClone), TestTimeoutLong).Should(Equal(corev1.PodRunning)) g.Eventually(IntegrationConditionStatus(t, ctx, ns, nameClone, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) g.Eventually(IntegrationLogs(t, ctx, ns, nameClone), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) @@ -166,15 +153,13 @@ func TestRunIncrementalBuildOff(t *testing.T) { // Another integration that should be built on top of the previous IntegrationKit // just add a new random dependency nameIncremental := RandomizedSuffixName("java-incremental") - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", nameIncremental, "-d", "camel:zipfile", "-t", "builder.incremental-image-build=false").Execute()).To(Succeed()) + g.Expect(KamelRun(t, ctx, ns, "files/Java.java", "--name", nameIncremental, "-d", "camel:zipfile", "-t", "builder.incremental-image-build=false").Execute()).To(Succeed()) g.Eventually(IntegrationPodPhase(t, ctx, ns, nameIncremental), TestTimeoutLong).Should(Equal(corev1.PodRunning)) g.Eventually(IntegrationConditionStatus(t, ctx, ns, nameIncremental, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) g.Eventually(IntegrationLogs(t, ctx, ns, nameIncremental), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) integrationIncrementalKitName := IntegrationKit(t, ctx, ns, nameIncremental)() g.Eventually(Kit(t, ctx, ns, integrationIncrementalKitName)().Status.BaseImage).Should(Equal(defaults.BaseImage())) }) - - g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } @@ -182,13 +167,10 @@ func TestRunIncrementalBuildWithDifferentBaseImages(t *testing.T) { t.Parallel() WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { - operatorID := "camel-k-incremental-different-base" - g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + InstallOperator(t, g, ns) name := RandomizedSuffixName("java") - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name).Execute()).To(Succeed()) + g.Expect(KamelRun(t, ctx, ns, "files/Java.java", "--name", name).Execute()).To(Succeed()) g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) @@ -200,7 +182,7 @@ func TestRunIncrementalBuildWithDifferentBaseImages(t *testing.T) { // Another integration that should be built on top of the previous IntegrationKit // just add a new random dependency nameIncremental := RandomizedSuffixName("java-incremental") - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", nameIncremental, "-d", "camel:zipfile").Execute()).To(Succeed()) + g.Expect(KamelRun(t, ctx, ns, "files/Java.java", "--name", nameIncremental, "-d", "camel:zipfile").Execute()).To(Succeed()) g.Eventually(IntegrationPodPhase(t, ctx, ns, nameIncremental), TestTimeoutLong).Should(Equal(corev1.PodRunning)) g.Eventually(IntegrationConditionStatus(t, ctx, ns, nameIncremental, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) g.Eventually(IntegrationLogs(t, ctx, ns, nameIncremental), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) @@ -216,7 +198,7 @@ func TestRunIncrementalBuildWithDifferentBaseImages(t *testing.T) { // We should spin off a new hierarchy of builds newBaseImage := "eclipse-temurin:17.0.8.1_1-jdk-ubi9-minimal" name = RandomizedSuffixName("java-new") - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name, "-d", "camel:mongodb", "-t", fmt.Sprintf("builder.base-image=%s", newBaseImage)).Execute()).To(Succeed()) + g.Expect(KamelRun(t, ctx, ns, "files/Java.java", "--name", name, "-d", "camel:mongodb", "-t", fmt.Sprintf("builder.base-image=%s", newBaseImage)).Execute()).To(Succeed()) g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) @@ -224,6 +206,5 @@ func TestRunIncrementalBuildWithDifferentBaseImages(t *testing.T) { g.Eventually(Kit(t, ctx, ns, integrationKitName)().Status.BaseImage).Should(Equal(newBaseImage)) g.Eventually(Kit(t, ctx, ns, integrationKitName)().Status.RootImage).Should(Equal(newBaseImage)) }) - g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/advanced/kamelet_repo_test.go b/e2e/advanced/kamelet_repo_test.go index d85a2c2bb..6ec87fc85 100644 --- a/e2e/advanced/kamelet_repo_test.go +++ b/e2e/advanced/kamelet_repo_test.go @@ -24,40 +24,32 @@ package advanced import ( "context" - "fmt" "testing" . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" . "github.com/apache/camel-k/v2/e2e/support" - v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" ) func TestKameletFromCustomRepository(t *testing.T) { t.Parallel() WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { - operatorID := fmt.Sprintf("camel-k-%s", ns) - g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(PlatformPhase(t, ctx, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + InstallOperator(t, g, ns) kameletName := "timer-custom-source" removeKamelet(t, ctx, kameletName, ns) - g.Eventually(Kamelet(t, ctx, kameletName, ns)).Should(BeNil()) // Add the custom repository - g.Expect(Kamel(t, ctx, "kamelet", "add-repo", "github:squakez/ck-kamelet-test-repo/kamelets", "-n", ns, "-x", operatorID).Execute()).To(Succeed()) - - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/TimerCustomKameletIntegration.java").Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "kamelet", "add-repo", "github:squakez/ck-kamelet-test-repo/kamelets", "-n", ns).Execute()).To(Succeed()) + g.Expect(KamelRun(t, ctx, ns, "files/TimerCustomKameletIntegration.java").Execute()).To(Succeed()) g.Eventually(IntegrationPodPhase(t, ctx, ns, "timer-custom-kamelet-integration"), TestTimeoutLong). Should(Equal(corev1.PodRunning)) g.Eventually(IntegrationLogs(t, ctx, ns, "timer-custom-kamelet-integration")).Should(ContainSubstring("hello world")) // Remove the custom repository - g.Expect(Kamel(t, ctx, "kamelet", "remove-repo", "github:squakez/ck-kamelet-test-repo/kamelets", "-n", ns, "-x", operatorID).Execute()).To(Succeed()) + g.Expect(Kamel(t, ctx, "kamelet", "remove-repo", "github:squakez/ck-kamelet-test-repo/kamelets", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/advanced/main_test.go b/e2e/advanced/main_test.go deleted file mode 100644 index ba95c61ca..000000000 --- a/e2e/advanced/main_test.go +++ /dev/null @@ -1,77 +0,0 @@ -//go:build integration -// +build integration - -// To enable compilation of this file in Goland, go to "Settings -> Go -> Vendoring & Build Tags -> Custom Tags" and add "integration" - -/* -Licensed to the Apache Software Foundation (ASF) under one or more -contributor license agreements. See the NOTICE file distributed with -this work for additional information regarding copyright ownership. -The ASF licenses this file to You under the Apache License, Version 2.0 -(the "License"); you may not use this file except in compliance with -the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package advanced - -import ( - "fmt" - "os" - "testing" - - "github.com/apache/camel-k/v2/pkg/util/boolean" - - . "github.com/onsi/gomega" - - . "github.com/apache/camel-k/v2/e2e/support" - v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" - "github.com/apache/camel-k/v2/pkg/platform" - - corev1 "k8s.io/api/core/v1" -) - -func TestMain(m *testing.M) { - - justCompile := GetEnvOrDefault("CAMEL_K_E2E_JUST_COMPILE", boolean.FalseString) - if justCompile == "true" { - os.Exit(m.Run()) - } - - fastSetup := GetEnvOrDefault("CAMEL_K_E2E_FAST_SETUP", boolean.FalseString) - if fastSetup == "true" { - operatorID := platform.DefaultPlatformName - ns := GetEnvOrDefault("CAMEL_K_GLOBAL_OPERATOR_NS", TestDefaultNamespace) - - g := NewGomega(func(message string, callerSkip ...int) { - fmt.Printf("Test fast setup failed! - %s\n", message) - }) - - var t *testing.T - g.Expect(TestClient(t)).ShouldNot(BeNil()) - ctx := TestContext() - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ctx, ns, "java"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ctx, ns, "java", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ctx, ns, "java"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/yaml.yaml").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ctx, ns, "yaml"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ctx, ns, "yaml", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ctx, ns, "yaml"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/timer-source.yaml").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ctx, ns, "timer-source"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationConditionStatus(t, ctx, ns, "timer-source", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - g.Eventually(IntegrationLogs(t, ctx, ns, "timer-source"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - } - - os.Exit(m.Run()) -} diff --git a/e2e/advanced/maven_http_proxy_test.go b/e2e/advanced/maven_http_proxy_test.go index 551934a93..a7467af68 100644 --- a/e2e/advanced/maven_http_proxy_test.go +++ b/e2e/advanced/maven_http_proxy_test.go @@ -31,24 +31,19 @@ import ( "encoding/pem" "fmt" "math/big" - "reflect" "strings" "testing" "time" "github.com/apache/camel-k/v2/pkg/util" "github.com/apache/camel-k/v2/pkg/util/envvar" - "github.com/apache/camel-k/v2/pkg/util/kubernetes" - "github.com/apache/camel-k/v2/pkg/util/olm" . "github.com/onsi/gomega" . "github.com/onsi/gomega/gstruct" - configv1 "github.com/openshift/api/config/v1" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/intstr" ctrl "sigs.k8s.io/controller-runtime/pkg/client" @@ -64,7 +59,6 @@ func TestMavenProxy(t *testing.T) { WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { hostname := fmt.Sprintf("%s.%s.svc", "proxy", ns) - // Generate the TLS certificate serialNumber := big.NewInt(util.RandomInt63()) cert := &x509.Certificate{ @@ -117,15 +111,12 @@ func TestMavenProxy(t *testing.T) { }, } g.Expect(TestClient(t).Create(ctx, secret)).To(Succeed()) - // HTTPD ConfigMap config := newHTTPDConfigMap(ns, hostname) g.Expect(TestClient(t).Create(ctx, config)).To(Succeed()) - // HTTPD Deployment deployment := newHTTPDDeployment(ns, config.Name, secret.Name) g.Expect(TestClient(t).Create(ctx, deployment)).To(Succeed()) - service := newHTTPDService(deployment) g.Expect(TestClient(t).Create(ctx, service)).To(Succeed()) @@ -150,43 +141,7 @@ func TestMavenProxy(t *testing.T) { } noProxy = append(noProxy, svc.Spec.ClusterIPs...) - // Install Camel K with the HTTP proxy - operatorID := "camel-k-maven-proxy" - olm, olmErr := olm.IsAPIAvailable(TestClient(t)) - installed, inErr := kubernetes.IsAPIResourceInstalled(TestClient(t), configv1.GroupVersion.String(), reflect.TypeOf(configv1.Proxy{}).Name()) - permission, pErr := kubernetes.CheckPermission(ctx, TestClient(t), configv1.GroupName, reflect.TypeOf(configv1.Proxy{}).Name(), "", "cluster", "edit") - olmInstall := pErr == nil && olmErr == nil && inErr == nil && olm && installed && permission - var defaultProxy configv1.Proxy - if olmInstall { - // use OLM autoconfiguration - defaultProxy = configv1.Proxy{} - key := ctrl.ObjectKey{ - Name: "cluster", - } - g.Expect(TestClient(t).Get(ctx, key, &defaultProxy)).To(Succeed()) - - newProxy := defaultProxy.DeepCopy() - newProxy.Spec.HTTPProxy = fmt.Sprintf("http://%s", hostname) - newProxy.Spec.NoProxy = strings.Join(noProxy, ",") - g.Expect(TestClient(t).Update(ctx, newProxy)) - - defer func() { - // - // Patching the proxy back to default - // Note. A merge patch or client update making spec and status empty - // does not work on some platforms, eg. OCP4 - // - patch := []byte(`[{"op": "replace","path": "/spec","value": {}},{"op": "replace","path": "/status","value": {}}]`) - TestClient(t).Patch(ctx, &defaultProxy, ctrl.RawPatch(types.JSONPatchType, patch)) - }() - - // ENV values should be injected by the OLM - g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - } else { - g.Expect(KamelInstallWithID(t, ctx, operatorID, ns, "--operator-env-vars", fmt.Sprintf("HTTP_PROXY=http://%s", hostname), "--operator-env-vars", "NO_PROXY="+strings.Join(noProxy, ","))).To(Succeed()) - } - - g.Eventually(PlatformPhase(t, ctx, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + InstallOperator(t, g, ns) // Check that operator pod has env_vars g.Eventually(OperatorPodHas(t, ctx, ns, func(op *corev1.Pod) bool { @@ -206,7 +161,7 @@ func TestMavenProxy(t *testing.T) { // Run the Integration name := RandomizedSuffixName("java") - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name).Execute()).To(Succeed()) + g.Expect(KamelRun(t, ctx, ns, "files/Java.java", "--name", name).Execute()).To(Succeed()) g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) @@ -224,13 +179,6 @@ func TestMavenProxy(t *testing.T) { ) g.Expect(err).To(Succeed()) g.Expect(proxies.Items).To(HaveLen(1)) - - // Clean up - g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) - g.Expect(TestClient(t).Delete(ctx, deployment)).To(Succeed()) - g.Expect(TestClient(t).Delete(ctx, service)).To(Succeed()) - g.Expect(TestClient(t).Delete(ctx, secret)).To(Succeed()) - g.Expect(TestClient(t).Delete(ctx, config)).To(Succeed()) }) } @@ -238,8 +186,7 @@ func TestMavenProxyNotPresent(t *testing.T) { t.Parallel() WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { - hostname := fmt.Sprintf("%s.%s.svc", "proxy-fake", ns) - + //hostname := fmt.Sprintf("%s.%s.svc", "proxy-fake", ns) svc := Service(t, ctx, TestDefaultNamespace, "kubernetes")() g.Expect(svc).NotTo(BeNil()) // It may be needed to populate the values from the cluster, machine and service network CIDRs @@ -250,32 +197,17 @@ func TestMavenProxyNotPresent(t *testing.T) { } noProxy = append(noProxy, svc.Spec.ClusterIPs...) - // Install Camel K with the HTTP proxy that does not exists - operatorID := "camel-k-maven-no-proxy" - olm, olmErr := olm.IsAPIAvailable(TestClient(t)) - installed, inErr := kubernetes.IsAPIResourceInstalled(TestClient(t), configv1.GroupVersion.String(), reflect.TypeOf(configv1.Proxy{}).Name()) - permission, pErr := kubernetes.CheckPermission(ctx, TestClient(t), configv1.GroupName, reflect.TypeOf(configv1.Proxy{}).Name(), "", "cluster", "edit") - olmInstall := pErr == nil && olmErr == nil && inErr == nil && olm && installed && permission - if olmInstall { - // ENV values should be injected by the OLM - g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - } else { - g.Expect(KamelInstallWithID(t, ctx, operatorID, ns, "--operator-env-vars", fmt.Sprintf("HTTP_PROXY=http://%s", hostname), "--operator-env-vars", "NO_PROXY="+strings.Join(noProxy, ","))).To(Succeed()) - } - - g.Eventually(PlatformPhase(t, ctx, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + InstallOperator(t, g, ns) + //g.Expect(KamelInstallWithID(t, ctx, operatorID, ns, "--operator-env-vars", fmt.Sprintf("HTTP_PROXY=http://%s", hostname), "--operator-env-vars", "NO_PROXY="+strings.Join(noProxy, ","))).To(Succeed()) // Run the Integration name := RandomizedSuffixName("java") - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name).Execute()).To(Succeed()) + g.Expect(KamelRun(t, ctx, ns, "files/Java.java", "--name", name).Execute()).To(Succeed()) // Should not be able to build g.Eventually(IntegrationPhase(t, ctx, ns, name), TestTimeoutMedium).Should(Equal(v1.IntegrationPhaseError)) g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionKitAvailable), TestTimeoutShort). Should(Equal(corev1.ConditionFalse)) - - // Clean up - g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/advanced/operator_id_filtering_test.go b/e2e/advanced/operator_id_filtering_test.go index 074c90c21..281b4ef1f 100644 --- a/e2e/advanced/operator_id_filtering_test.go +++ b/e2e/advanced/operator_id_filtering_test.go @@ -24,7 +24,6 @@ package advanced import ( "context" - "fmt" "testing" "time" @@ -36,32 +35,18 @@ import ( v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" ) -func TestOperatorIDCamelCatalogReconciliation(t *testing.T) { - t.Parallel() - - WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { - operatorID := fmt.Sprintf("camel-k-%s", ns) - g.Expect(KamelInstallWithID(t, ctx, operatorID, ns, "--global", "--force")).To(Succeed()) - g.Eventually(PlatformPhase(t, ctx, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) - g.Eventually(DefaultCamelCatalogPhase(t, ctx, ns), TestTimeoutMedium).Should(Equal(v1.CamelCatalogPhaseReady)) - }) -} - func TestOperatorIDFiltering(t *testing.T) { t.Parallel() WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { WithNewTestNamespace(t, func(ctx context.Context, g *WithT, nsop1 string) { operator1 := "operator-1" - g.Expect(CopyCamelCatalog(t, ctx, nsop1, operator1)).To(Succeed()) - g.Expect(KamelInstallWithIDAndKameletCatalog(t, ctx, operator1, nsop1, "--global", "--force")).To(Succeed()) + InstallOperatorWithID(t, g, nsop1, operator1) g.Eventually(PlatformPhase(t, ctx, nsop1), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) WithNewTestNamespace(t, func(ctx context.Context, g *WithT, nsop2 string) { operator2 := "operator-2" - g.Expect(CopyCamelCatalog(t, ctx, nsop2, operator2)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ctx, nsop2, operator2)).To(Succeed()) - g.Expect(KamelInstallWithIDAndKameletCatalog(t, ctx, operator2, nsop2, "--global", "--force")).To(Succeed()) + InstallOperatorWithID(t, g, nsop2, operator2) g.Eventually(PlatformPhase(t, ctx, nsop2), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) t.Run("Operators ignore non-scoped integrations", func(t *testing.T) { @@ -135,7 +120,5 @@ func TestOperatorIDFiltering(t *testing.T) { }) }) }) - - g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/advanced/operator_metrics_test.go b/e2e/advanced/operator_metrics_test.go index ca84c2704..4f8b8fa62 100644 --- a/e2e/advanced/operator_metrics_test.go +++ b/e2e/advanced/operator_metrics_test.go @@ -42,19 +42,18 @@ import ( . "github.com/apache/camel-k/v2/e2e/support" . "github.com/apache/camel-k/v2/e2e/support/util" v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" + "github.com/apache/camel-k/v2/pkg/platform" ) func TestMetrics(t *testing.T) { t.Parallel() WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { - name := RandomizedSuffixName("java") - operatorID := "camel-k-metrics" - g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, ctx, operatorID, ns, "--log-level", "debug")).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + //g.Expect(InstallOperator(t, ctx, operatorID, ns, "--log-level", "debug")).To(Succeed()) + InstallOperator(t, g, ns) - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name, "-t", "prometheus.enabled=true", "-t", "prometheus.pod-monitor=false").Execute()).To(Succeed()) + 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()) g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort). Should(Equal(corev1.ConditionTrue)) @@ -62,7 +61,6 @@ func TestMetrics(t *testing.T) { pod := OperatorPod(t, ctx, ns)() g.Expect(pod).NotTo(BeNil()) - // pod.Namespace could be different from ns if using global operator fmt.Printf("Fetching logs for operator pod %s in namespace %s", pod.Name, pod.Namespace) logOptions := &corev1.PodLogOptions{ @@ -200,7 +198,7 @@ func TestMetrics(t *testing.T) { "LoggerName": Equal("camel-k.controller.integrationplatform"), "Message": Equal("Reconciling IntegrationPlatform"), "RequestNamespace": Equal(ns), - "RequestName": Equal(operatorID), + "RequestName": Equal(platform.DefaultPlatformName), })) g.Expect(err).To(BeNil()) @@ -538,9 +536,6 @@ func TestMetrics(t *testing.T) { }, )) }) - - // Clean up - g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/advanced/platform_traits_test.go b/e2e/advanced/platform_traits_test.go index 56e9a7689..175f741e6 100644 --- a/e2e/advanced/platform_traits_test.go +++ b/e2e/advanced/platform_traits_test.go @@ -40,29 +40,24 @@ func TestTraitOnIntegrationPlatform(t *testing.T) { t.Parallel() WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { - operatorID := "camel-k-platform-trait-test" - g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) + InstallOperator(t, g, ns) containerTestName := "testname" g.Eventually(PlatformPhase(t, ctx, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) - g.Expect(UpdatePlatform(t, ctx, ns, operatorID, func(ip *v1.IntegrationPlatform) { + g.Expect(UpdatePlatform(t, ctx, ns, func(ip *v1.IntegrationPlatform) { ip.Spec.Traits = v1.Traits{Logging: &trait.LoggingTrait{Level: "DEBUG"}, Container: &trait.ContainerTrait{Name: containerTestName}} })).To(Succeed()) g.Eventually(PlatformPhase(t, ctx, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) name := RandomizedSuffixName("java") t.Run("Run integration with platform traits", func(t *testing.T) { - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name).Execute()).To(Succeed()) + g.Expect(KamelRun(t, ctx, ns, "files/Java.java", "--name", name).Execute()).To(Succeed()) g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) g.Expect(IntegrationPod(t, ctx, ns, name)().Spec.Containers[0].Name).To(BeEquivalentTo(containerTestName)) g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("DEBUG")) - - g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) }) } diff --git a/e2e/advanced/promote_test.go b/e2e/advanced/promote_test.go index f8523720f..85504344b 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" - g.Expect(KamelInstallWithID(t, ctx, operatorDevID, nsDev)).To(Succeed()) + InstallOperatorWithID(t, g, nsDev, operatorDevID) 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" - g.Expect(KamelInstallWithID(t, ctx, operatorProdID, nsProd)).To(Succeed()) + InstallOperatorWithID(t, g, nsProd, operatorProdID) 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/registry_test.go b/e2e/advanced/registry_test.go deleted file mode 100644 index 717f68e83..000000000 --- a/e2e/advanced/registry_test.go +++ /dev/null @@ -1,78 +0,0 @@ -//go:build integration -// +build integration - -// To enable compilation of this file in Goland, go to "Settings -> Go -> Vendoring & Build Tags -> Custom Tags" and add "integration" - -/* -Licensed to the Apache Software Foundation (ASF) under one or more -contributor license agreements. See the NOTICE file distributed with -this work for additional information regarding copyright ownership. -The ASF licenses this file to You under the Apache License, Version 2.0 -(the "License"); you may not use this file except in compliance with -the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package advanced - -import ( - "context" - "os" - "testing" - - . "github.com/onsi/gomega" - - v1 "k8s.io/api/core/v1" - - . "github.com/apache/camel-k/v2/e2e/support" -) - -func TestRunWithDockerHubRegistry(t *testing.T) { - user := os.Getenv("TEST_DOCKER_HUB_USERNAME") - pass := os.Getenv("TEST_DOCKER_HUB_PASSWORD") - if user == "" || pass == "" { - t.Skip("no docker hub credentials: skipping") - return - } - - WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { - operatorID := "camel-k-docker-hub" - g.Expect(KamelInstallWithID(t, ctx, operatorID, ns, "--registry", "docker.io", "--organization", user, "--registry-auth-username", user, "--registry-auth-password", pass, "--cluster-type", "kubernetes")).To(Succeed()) - - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/example.yaml").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ctx, ns, "example"), TestTimeoutLong).Should(Equal(v1.PodRunning)) - g.Eventually(IntegrationLogs(t, ctx, ns, "example"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - g.Eventually(IntegrationPodImage(t, ctx, ns, "example"), TestTimeoutShort).Should(HavePrefix("docker.io")) - - g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) - }) -} - -func TestRunWithGithubPackagesRegistry(t *testing.T) { - user := os.Getenv("TEST_GITHUB_PACKAGES_USERNAME") - pass := os.Getenv("TEST_GITHUB_PACKAGES_PASSWORD") - repo := os.Getenv("TEST_GITHUB_PACKAGES_REPO") - if user == "" || pass == "" || repo == "" { - t.Skip("no github packages data: skipping") - return - } - - WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { - operatorID := "camel-k-github-registry" - g.Expect(KamelInstallWithID(t, ctx, operatorID, ns, "--registry", "docker.pkg.github.com", "--organization", repo, "--registry-auth-username", user, "--registry-auth-password", pass, "--cluster-type", "kubernetes")).To(Succeed()) - - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/example.yaml").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ctx, ns, "example"), TestTimeoutLong).Should(Equal(v1.PodRunning)) - g.Eventually(IntegrationLogs(t, ctx, ns, "example"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - g.Eventually(IntegrationPodImage(t, ctx, ns, "example"), TestTimeoutShort).Should(HavePrefix("docker.pkg.github.com")) - - g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) - }) -} diff --git a/e2e/advanced/reset_test.go b/e2e/advanced/reset_test.go index 8724addcd..e6ff6c8ef 100644 --- a/e2e/advanced/reset_test.go +++ b/e2e/advanced/reset_test.go @@ -30,66 +30,52 @@ import ( corev1 "k8s.io/api/core/v1" . "github.com/apache/camel-k/v2/e2e/support" - v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" ) func TestKamelReset(t *testing.T) { t.Parallel() WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { - operatorID := "camel-k-cli-reset" - g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - - g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + InstallOperator(t, g, ns) t.Run("Reset the whole platform", func(t *testing.T) { name := RandomizedSuffixName("yaml1") - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/yaml.yaml", "--name", name).Execute()).To(Succeed()) + g.Expect(KamelRun(t, ctx, 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!")) - g.Eventually(Kit(t, ctx, ns, IntegrationKit(t, ctx, ns, name)())).Should(Not(BeNil())) g.Eventually(Integration(t, ctx, ns, name)).Should(Not(BeNil())) g.Expect(Kamel(t, ctx, "reset", "-n", ns).Execute()).To(Succeed()) - g.Expect(Integration(t, ctx, ns, name)()).To(BeNil()) g.Expect(Kits(t, ctx, ns)()).To(HaveLen(0)) }) t.Run("Reset skip-integrations", func(t *testing.T) { name := RandomizedSuffixName("yaml2") - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/yaml.yaml", "--name", name).Execute()).To(Succeed()) + g.Expect(KamelRun(t, ctx, 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!")) - g.Eventually(Kit(t, ctx, ns, IntegrationKit(t, ctx, ns, name)())).Should(Not(BeNil())) g.Eventually(Integration(t, ctx, ns, name)).Should(Not(BeNil())) g.Expect(Kamel(t, ctx, "reset", "-n", ns, "--skip-integrations").Execute()).To(Succeed()) - g.Expect(Integration(t, ctx, ns, name)()).To(Not(BeNil())) g.Expect(Kits(t, ctx, ns)()).To(HaveLen(0)) }) t.Run("Reset skip-kits", func(t *testing.T) { name := RandomizedSuffixName("yaml3") - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/yaml.yaml", "--name", name).Execute()).To(Succeed()) + g.Expect(KamelRun(t, ctx, 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!")) - kitName := IntegrationKit(t, ctx, ns, name)() g.Eventually(Kit(t, ctx, ns, kitName)).Should(Not(BeNil())) g.Eventually(Integration(t, ctx, ns, name)).Should(Not(BeNil())) g.Expect(Kamel(t, ctx, "reset", "-n", ns, "--skip-kits").Execute()).To(Succeed()) - g.Expect(Integration(t, ctx, ns, name)()).To(BeNil()) g.Expect(Kit(t, ctx, ns, kitName)()).To(Not(BeNil())) }) - // Clean up - g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/advanced/synthetic_test.go b/e2e/advanced/synthetic_test.go index 74ba8f341..bc69f2f78 100644 --- a/e2e/advanced/synthetic_test.go +++ b/e2e/advanced/synthetic_test.go @@ -41,11 +41,7 @@ func TestSyntheticIntegrationOff(t *testing.T) { WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { // Install Camel K without synthetic Integration feature variable (default) - operatorID := "camel-k-synthetic-env-off" - g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) + InstallOperator(t, g, ns) // Run the external deployment ExpectExecSucceed(t, g, Kubectl("apply", "-f", "files/deploy.yaml", "-n", ns)) @@ -65,12 +61,10 @@ func TestSyntheticIntegrationFromDeployment(t *testing.T) { WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { // Install Camel K with the synthetic Integration feature variable - operatorID := "camel-k-synthetic-env" - g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed()) - g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed()) - g.Expect(KamelInstallWithID(t, ctx, operatorID, ns, - "--operator-env-vars", "CAMEL_K_SYNTHETIC_INTEGRATIONS=true", - )).To(Succeed()) + // g.Expect(InstallOperator(t, ctx, operatorID, ns, + // "--operator-env-vars", "CAMEL_K_SYNTHETIC_INTEGRATIONS=true", + // )).To(Succeed()) + InstallOperator(t, g, ns) 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/advanced/tekton_test.go b/e2e/advanced/tekton_test.go index a2692fb6b..ccdbd8c86 100644 --- a/e2e/advanced/tekton_test.go +++ b/e2e/advanced/tekton_test.go @@ -41,10 +41,7 @@ func TestTektonLikeBehavior(t *testing.T) { t.Parallel() WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { - operatorID := "camel-k-tekton-like" - - g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed()) - g.Eventually(OperatorPod(t, ctx, ns)).ShouldNot(BeNil()) + InstallOperator(t, g, ns) // Store a configmap holding an integration source var cmData = make(map[string][]byte) @@ -63,7 +60,7 @@ func TestTektonLikeBehavior(t *testing.T) { } t.Run("Run tekton task like delegate build and run to operator", func(t *testing.T) { name := RandomizedSuffixName("java-tekton-basic") - g.Expect(CreateKamelPodWithIntegrationSource(t, ctx, ns, "tekton-task-basic", integration, "run", "/tmp/Java.java", "--name", name, "--operator-id", operatorID)).To(Succeed()) + g.Expect(CreateKamelPodWithIntegrationSource(t, ctx, ns, "tekton-task-basic", integration, "run", "/tmp/Java.java", "--name", name)).To(Succeed()) g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) @@ -72,7 +69,7 @@ func TestTektonLikeBehavior(t *testing.T) { name := RandomizedSuffixName("java-tekton-run") // Use an external image as source externalImage := "quay.io/fuse_qe/echo-server:0.3.3" - g.Expect(CreateKamelPodWithIntegrationSource(t, ctx, ns, "tekton-task-run", integration, "run", "/tmp/Java.java", "-t", "container.image="+externalImage, "--name", name, "--operator-id", operatorID)).To(Succeed()) + g.Expect(CreateKamelPodWithIntegrationSource(t, ctx, ns, "tekton-task-run", integration, "run", "/tmp/Java.java", "-t", "container.image="+externalImage, "--name", name)).To(Succeed()) g.Eventually(IntegrationPodPhase(t, ctx, ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) g.Eventually(IntegrationLogs(t, ctx, ns, name), TestTimeoutShort).Should(ContainSubstring("Echo")) diff --git a/e2e/advanced/integration_profile_test.go b/e2e/common/misc/integration_profile_test.go similarity index 83% rename from e2e/advanced/integration_profile_test.go rename to e2e/common/misc/integration_profile_test.go index 3844a060d..7b65fcf0e 100644 --- a/e2e/advanced/integration_profile_test.go +++ b/e2e/common/misc/integration_profile_test.go @@ -20,12 +20,13 @@ See the License for the specific language governing permissions and limitations under the License. */ -package advanced +package misc import ( "context" "testing" + "github.com/apache/camel-k/v2/pkg/platform" "github.com/apache/camel-k/v2/pkg/util/defaults" . "github.com/onsi/gomega" @@ -37,13 +38,8 @@ import ( ) func TestIntegrationProfile(t *testing.T) { - t.Parallel() - + operatorID := platform.DefaultPlatformName WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { - operatorID := "camel-k-integration-profile" - g.Expect(KamelInstallWithID(t, ctx, operatorID, ns, "--global", "--force")).To(Succeed()) - g.Eventually(PlatformPhase(t, ctx, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) - integrationProfile := v1.NewIntegrationProfile(ns, "ipr-global") integrationProfile.SetOperatorID(operatorID) integrationProfile.Spec.Traits.Container = &traitv1.ContainerTrait{ @@ -64,7 +60,7 @@ func TestIntegrationProfile(t *testing.T) { g.Eventually(SelectedIntegrationProfilePhase(t, ctx, ns1, "ipr-local"), TestTimeoutMedium).Should(Equal(v1.IntegrationProfilePhaseReady)) t.Run("Run integration with global integration profile", func(t *testing.T) { - g.Expect(KamelRunWithID(t, ctx, operatorID, ns1, "--name", "limited", "--integration-profile", "ipr-global", "files/yaml.yaml").Execute()).To(Succeed()) + g.Expect(KamelRun(t, ctx, ns1, "--name", "limited", "--integration-profile", "ipr-global", "files/yaml.yaml").Execute()).To(Succeed()) g.Eventually(IntegrationPod(t, ctx, ns1, "limited"), TestTimeoutMedium).Should(Not(BeNil())) g.Eventually(IntegrationPodHas(t, ctx, ns1, "limited", func(pod *corev1.Pod) bool { @@ -85,7 +81,7 @@ func TestIntegrationProfile(t *testing.T) { }) t.Run("Run integration with namespace local integration profile", func(t *testing.T) { - g.Expect(KamelRunWithID(t, ctx, operatorID, ns1, "--name", "limited", "--integration-profile", "ipr-local", "files/yaml.yaml").Execute()).To(Succeed()) + g.Expect(KamelRun(t, ctx, ns1, "--name", "limited", "--integration-profile", "ipr-local", "files/yaml.yaml").Execute()).To(Succeed()) g.Eventually(IntegrationPod(t, ctx, ns1, "limited"), TestTimeoutMedium).Should(Not(BeNil())) g.Eventually(IntegrationPodHas(t, ctx, ns1, "limited", func(pod *corev1.Pod) bool { @@ -106,20 +102,24 @@ func TestIntegrationProfile(t *testing.T) { g.Expect(Kamel(t, ctx, "delete", "limited", "-n", ns1).Execute()).To(Succeed()) }) - // Clean up - g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns1).Execute()).To(Succeed()) + t.Run("Run integration without integration profile", func(t *testing.T) { + g.Expect(KamelRun(t, ctx, ns1, "--name", "normal", "files/yaml.yaml").Execute()).To(Succeed()) + g.Eventually(IntegrationPod(t, ctx, ns1, "normal"), TestTimeoutShort).Should(Not(BeNil())) + g.Eventually(IntegrationPodHas(t, ctx, ns1, "normal", func(pod *corev1.Pod) bool { + if len(pod.Spec.Containers) != 1 { + return false + } + cpuLimits := pod.Spec.Containers[0].Resources.Limits.Cpu() + return cpuLimits == nil || cpuLimits.IsZero() + }), TestTimeoutShort).Should(BeTrue()) + }) }) }) } func TestIntegrationProfileInfluencesKit(t *testing.T) { - t.Parallel() - + operatorID := platform.DefaultPlatformName WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { - operatorID := "camel-k-ipr-kit" - g.Expect(KamelInstallWithID(t, ctx, operatorID, ns, "--global", "--force")).To(Succeed()) - g.Eventually(PlatformPhase(t, ctx, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) - integrationProfile := v1.NewIntegrationProfile(ns, "ipr-global") integrationProfile.SetOperatorID(operatorID) integrationProfile.Spec.Traits.Builder = &traitv1.BuilderTrait{ @@ -129,7 +129,7 @@ func TestIntegrationProfileInfluencesKit(t *testing.T) { g.Expect(CreateIntegrationProfile(t, ctx, &integrationProfile)).To(Succeed()) g.Eventually(SelectedIntegrationProfilePhase(t, ctx, ns, "ipr-global"), TestTimeoutMedium).Should(Equal(v1.IntegrationProfilePhaseReady)) - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "--name", "normal", "files/yaml.yaml").Execute()).To(Succeed()) + g.Expect(KamelRun(t, ctx, ns, "--name", "normal", "files/yaml.yaml").Execute()).To(Succeed()) g.Eventually(IntegrationPod(t, ctx, ns, "normal"), TestTimeoutMedium).Should(Not(BeNil())) g.Eventually(IntegrationPodPhase(t, ctx, ns, "normal"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) g.Eventually(IntegrationConditionStatus(t, ctx, ns, "normal", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) @@ -139,7 +139,7 @@ func TestIntegrationProfileInfluencesKit(t *testing.T) { g.Eventually(Kit(t, ctx, ns, integrationKitName)().Status.BaseImage).Should(Equal(defaults.BaseImage())) g.Eventually(Kit(t, ctx, ns, integrationKitName)().Status.RootImage).Should(Equal(defaults.BaseImage())) - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "--name", "simple", "--integration-profile", "ipr-global", "files/yaml.yaml").Execute()).To(Succeed()) + g.Expect(KamelRun(t, ctx, ns, "--name", "simple", "--integration-profile", "ipr-global", "files/yaml.yaml").Execute()).To(Succeed()) g.Eventually(IntegrationPod(t, ctx, ns, "simple"), TestTimeoutMedium).Should(Not(BeNil())) g.Eventually(IntegrationPodPhase(t, ctx, ns, "simple"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) @@ -151,20 +151,12 @@ func TestIntegrationProfileInfluencesKit(t *testing.T) { g.Eventually(integrationKitNameWithProfile).ShouldNot(Equal(integrationKitName)) g.Eventually(Kit(t, ctx, ns, integrationKitNameWithProfile)().Status.BaseImage).Should(ContainSubstring(integrationKitName)) g.Eventually(Kit(t, ctx, ns, integrationKitNameWithProfile)().Status.RootImage).Should(Equal(defaults.BaseImage())) - - // Clean up - g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } func TestPropagateIntegrationProfileChanges(t *testing.T) { - t.Parallel() - + operatorID := platform.DefaultPlatformName WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { - operatorID := "camel-k-ipr-changes" - g.Expect(KamelInstallWithID(t, ctx, operatorID, ns, "--global", "--force")).To(Succeed()) - g.Eventually(PlatformPhase(t, ctx, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) - integrationProfile := v1.NewIntegrationProfile(ns, "debug-profile") integrationProfile.SetOperatorID(operatorID) integrationProfile.Spec.Traits.Container = &traitv1.ContainerTrait{ @@ -201,8 +193,5 @@ func TestPropagateIntegrationProfileChanges(t *testing.T) { containerName := pod.Spec.Containers[0].Name return containerName == "ck-ipr-new" }), TestTimeoutShort).Should(BeTrue()) - - // Clean up - g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/traits/deployment_test.go b/e2e/common/traits/deployment_test.go index 31791ae91..fc66e5437 100644 --- a/e2e/common/traits/deployment_test.go +++ b/e2e/common/traits/deployment_test.go @@ -24,6 +24,7 @@ package traits import ( "context" + "os/exec" "testing" appsv1 "k8s.io/api/apps/v1" @@ -89,3 +90,44 @@ func TestRollingUpdateDeploymentStrategyTrait(t *testing.T) { }) }) } + +func TestDeploymentFailureShouldReportIntegrationCondition(t *testing.T) { + t.Parallel() + + WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) { + nsRestr := "restr" + // Create restricted namespace + ExpectExecSucceed(t, g, + exec.Command( + "kubectl", + "create", + "ns", + nsRestr, + ), + ) + ExpectExecSucceed(t, g, + exec.Command( + "kubectl", + "label", + "--overwrite", + "ns", + nsRestr, + "pod-security.kubernetes.io/enforce=baseline", + "pod-security.kubernetes.io/enforce-version=latest", + "pod-security.kubernetes.io/enforce=restricted", + "pod-security.kubernetes.io/warn-version=latest", + "pod-security.kubernetes.io/audit=restricted", + "pod-security.kubernetes.io/audit-version=latest", + ), + ) + // Create an Integration into a restricted namespace + name := RandomizedSuffixName("java-fail") + g.Expect(KamelRun(t, ctx, ns, "files/Java.java", "--name", name, "-n", nsRestr).Execute()).To(Succeed()) + // Check the error is reported into the Integration + g.Eventually(IntegrationPhase(t, ctx, nsRestr, name), TestTimeoutMedium).Should(Equal(v1.IntegrationPhaseError)) + g.Eventually(IntegrationCondition(t, ctx, nsRestr, name, v1.IntegrationConditionReady)().Status). + Should(Equal(corev1.ConditionFalse)) + g.Eventually(IntegrationCondition(t, ctx, nsRestr, name, v1.IntegrationConditionReady)().Message). + Should(ContainSubstring("is forbidden: violates PodSecurity")) + }) +} diff --git a/e2e/support/test_support.go b/e2e/support/test_support.go index 075204cc2..e8893d11e 100644 --- a/e2e/support/test_support.go +++ b/e2e/support/test_support.go @@ -37,7 +37,6 @@ import ( "regexp" "runtime/debug" "strings" - "sync" "testing" "time" @@ -79,9 +78,7 @@ import ( "github.com/apache/camel-k/v2/pkg/cmd" "github.com/apache/camel-k/v2/pkg/install" "github.com/apache/camel-k/v2/pkg/platform" - pkgutil "github.com/apache/camel-k/v2/pkg/util" v2util "github.com/apache/camel-k/v2/pkg/util" - "github.com/apache/camel-k/v2/pkg/util/boolean" "github.com/apache/camel-k/v2/pkg/util/defaults" "github.com/apache/camel-k/v2/pkg/util/kubernetes" "github.com/apache/camel-k/v2/pkg/util/log" @@ -140,9 +137,6 @@ var NoOlmOperatorImage string var testContext = context.TODO() var testClient client.Client -var testSetupMutex = sync.Mutex{} -var kamelInstallMutex = sync.Mutex{} - func init() { // This line prevents controller-runtime from complaining about log.SetLogger never being called logf.SetLogger(zap.New(zap.UseDevMode(true))) @@ -275,95 +269,6 @@ func Kamel(t *testing.T, ctx context.Context, args ...string) *cobra.Command { return KamelWithContext(t, ctx, args...) } -func KamelInstall(t *testing.T, ctx context.Context, namespace string, args ...string) error { - return KamelInstallWithID(t, ctx, platform.DefaultPlatformName, namespace, args...) -} - -func KamelInstallWithID(t *testing.T, ctx context.Context, operatorID string, namespace string, args ...string) error { - return kamelInstallWithContext(t, ctx, operatorID, namespace, true, args...) -} - -func KamelInstallWithIDAndKameletCatalog(t *testing.T, ctx context.Context, operatorID string, namespace string, args ...string) error { - return kamelInstallWithContext(t, ctx, operatorID, namespace, false, args...) -} - -func kamelInstallWithContext(t *testing.T, ctx context.Context, operatorID string, namespace string, skipKameletCatalog bool, args ...string) error { - kamelInstallMutex.Lock() - defer kamelInstallMutex.Unlock() - - var installArgs []string - - installArgs = []string{"install", "-n", namespace, "--operator-id", operatorID} - - if !pkgutil.StringSliceExists(args, "--build-timeout") { - // if --build-timeout is not explicitly passed as an argument, try to configure it - buildTimeout := os.Getenv("CAMEL_K_TEST_BUILD_TIMEOUT") - if buildTimeout == "" { - // default Build Timeout for tests - buildTimeout = "10m" - } - fmt.Printf("Setting build timeout to %s\n", buildTimeout) - installArgs = append(installArgs, "--build-timeout", buildTimeout) - } - - if skipKameletCatalog { - installArgs = append(installArgs, "--skip-default-kamelets-setup") - } - - logLevel := os.Getenv("CAMEL_K_TEST_LOG_LEVEL") - if len(logLevel) > 0 { - fmt.Printf("Setting log-level to %s\n", logLevel) - installArgs = append(installArgs, "--log-level", logLevel) - } - - mvnCLIOptions := os.Getenv("CAMEL_K_TEST_MAVEN_CLI_OPTIONS") - if len(mvnCLIOptions) > 0 { - // Split the string by spaces - mvnCLIArr := strings.Split(mvnCLIOptions, " ") - for _, mc := range mvnCLIArr { - mc = strings.Trim(mc, " ") - if len(mc) == 0 { - continue - } - - fmt.Printf("Adding maven cli option %s\n", mc) - installArgs = append(installArgs, "--maven-cli-option", mc) - } - } - - runtimeVersion := os.Getenv("CAMEL_K_TEST_RUNTIME_VERSION") - if runtimeVersion != "" { - fmt.Printf("Setting runtime version to %s\n", runtimeVersion) - installArgs = append(installArgs, "--runtime-version", runtimeVersion) - } - baseImage := os.Getenv("CAMEL_K_TEST_BASE_IMAGE") - if baseImage != "" { - fmt.Printf("Setting base image to %s\n", baseImage) - installArgs = append(installArgs, "--base-image", baseImage) - } - opImage := os.Getenv("CAMEL_K_TEST_OPERATOR_IMAGE") - if opImage != "" { - fmt.Printf("Setting operator image to %s\n", opImage) - installArgs = append(installArgs, "--operator-image", opImage) - } - opImagePullPolicy := os.Getenv("CAMEL_K_TEST_OPERATOR_IMAGE_PULL_POLICY") - if opImagePullPolicy != "" { - fmt.Printf("Setting operator image pull policy to %s\n", opImagePullPolicy) - installArgs = append(installArgs, "--operator-image-pull-policy", opImagePullPolicy) - } - if len(os.Getenv("CAMEL_K_TEST_MAVEN_CA_PEM_PATH")) > 0 { - certName := "myCert" - secretName := "maven-ca-certs" - CreateSecretDecoded(t, ctx, namespace, os.Getenv("CAMEL_K_TEST_MAVEN_CA_PEM_PATH"), secretName, certName) - installArgs = append(installArgs, "--maven-repository", os.Getenv("KAMEL_INSTALL_MAVEN_REPOSITORIES"), - "--maven-ca-secret", secretName+"/"+certName) - } - - installArgs = append(installArgs, args...) - installCommand := KamelWithContext(t, ctx, installArgs...) - return installCommand.Execute() -} - func KamelRun(t *testing.T, ctx context.Context, namespace string, args ...string) *cobra.Command { return KamelRunWithID(t, ctx, platform.DefaultPlatformName, namespace, args...) } @@ -488,7 +393,6 @@ func MakeWithContext(t *testing.T, rule string, args ...string) *exec.Cmd { } args = append([]string{"-C", makeDir, rule}, args...) - return exec.Command("make", args...) } @@ -2035,67 +1939,6 @@ func PlatformByName(t *testing.T, ctx context.Context, ns string, name string) f } } -func CopyIntegrationKits(t *testing.T, ctx context.Context, ns, operatorID string) error { - if value, ok := os.LookupEnv("CAMEL_K_TEST_COPY_INTEGRATION_KITS"); ok && value == boolean.FalseString { - fmt.Println("Copy integration kits optimization is disabled") - return nil - } - - opns := GetEnvOrDefault("CAMEL_K_GLOBAL_OPERATOR_NS", TestDefaultNamespace) - - lst := v1.NewIntegrationKitList() - if err := TestClient(t).List(ctx, &lst, ctrl.InNamespace(opns)); err != nil { - failTest(t, err) - } - for _, kit := range lst.Items { - if kit.Status.Image != "" && kit.Status.Phase == v1.IntegrationKitPhaseReady { - copyKit := v1.IntegrationKit{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: ns, - Name: kit.Name, - Labels: kit.Labels, - }, - Spec: *kit.Spec.DeepCopy(), - Status: *kit.Status.DeepCopy(), - } - - v1.SetAnnotation(©Kit.ObjectMeta, v1.OperatorIDAnnotation, operatorID) - fmt.Printf("Copy integration kit %s from namespace %s\n", kit.Name, opns) - if err := CreateIntegrationKit(t, ctx, ©Kit)(); err != nil { - return err - } - } - } - - return nil -} - -func CopyCamelCatalog(t *testing.T, ctx context.Context, ns, operatorID string) error { - if value, ok := os.LookupEnv("CAMEL_K_TEST_COPY_CATALOG"); ok && value == boolean.FalseString { - fmt.Println("Copy catalog optimization is disabled") - return nil - } - - catalogName := fmt.Sprintf("camel-catalog-%s", strings.ToLower(defaults.DefaultRuntimeVersion)) - opns := GetEnvOrDefault("CAMEL_K_GLOBAL_OPERATOR_NS", TestDefaultNamespace) - - defaultCatalog := CamelCatalog(t, ctx, opns, catalogName)() - if defaultCatalog != nil { - fmt.Printf("Copy catalog %s from namespace %s\n", catalogName, opns) - catalog := v1.CamelCatalog{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: ns, - Name: catalogName, - }, - Spec: *defaultCatalog.Spec.DeepCopy(), - } - v1.SetAnnotation(&catalog.ObjectMeta, v1.OperatorIDAnnotation, operatorID) - return CreateCamelCatalog(t, ctx, &catalog)() - } - - return nil -} - func IntegrationProfileByName(t *testing.T, ctx context.Context, ns string, name string) func() *v1.IntegrationProfile { return func() *v1.IntegrationProfile { lst := v1.NewIntegrationProfileList() @@ -2164,22 +2007,6 @@ func UpdateIntegrationProfile(t *testing.T, ctx context.Context, ns string, upd return TestClient(t).Patch(ctx, target, ctrl.RawPatch(types.MergePatchType, p)) } -func CreateCamelCatalog(t *testing.T, ctx context.Context, catalog *v1.CamelCatalog) func() error { - return func() error { - testSetupMutex.Lock() - defer testSetupMutex.Unlock() - return TestClient(t).Create(ctx, catalog) - } -} - -func CreateIntegrationKit(t *testing.T, ctx context.Context, kit *v1.IntegrationKit) func() error { - return func() error { - testSetupMutex.Lock() - defer testSetupMutex.Unlock() - return TestClient(t).Create(ctx, kit) - } -} - func DeleteCamelCatalog(t *testing.T, ctx context.Context, ns, name string) func() bool { return func() bool { cat := CamelCatalog(t, ctx, ns, name)() @@ -2262,10 +2089,10 @@ func DeletePlatform(t *testing.T, ctx context.Context, ns string) func() bool { } } -func UpdatePlatform(t *testing.T, ctx context.Context, ns string, name string, upd func(ip *v1.IntegrationPlatform)) error { - ip := PlatformByName(t, ctx, ns, name)() +func UpdatePlatform(t *testing.T, ctx context.Context, ns string, upd func(ip *v1.IntegrationPlatform)) error { + ip := PlatformByName(t, ctx, ns, platform.DefaultPlatformName)() if ip == nil { - return fmt.Errorf("unable to locate Integration Platform %s in %s", name, ns) + return fmt.Errorf("unable to locate Integration Platform %s in %s", platform.DefaultPlatformName, ns) } target := ip.DeepCopy() upd(target) diff --git a/e2e/support/test_util.go b/e2e/support/test_util.go index 88bca3ec7..d4433540d 100644 --- a/e2e/support/test_util.go +++ b/e2e/support/test_util.go @@ -24,9 +24,11 @@ package support import ( "context" + "fmt" "os" "os/exec" "strings" + "sync" "testing" "github.com/apache/camel-k/v2/pkg/util/log" @@ -39,6 +41,10 @@ import ( "github.com/stretchr/testify/require" ) +var ( + lock sync.Mutex +) + func init() { } @@ -60,6 +66,105 @@ 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, g *WithT, ns string) { + lock.Lock() + defer lock.Unlock() + KAMEL_INSTALL_REGISTRY := os.Getenv("KAMEL_INSTALL_REGISTRY") + 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"), + ) +} + +// InstallOperatorWitID is in charge to install a namespaced operator with a given operator ID name. +func InstallOperatorWithID(t *testing.T, g *WithT, ns, operatorID string) { + t.Skip("Not yet supported") +} + +func installOperatorWithContext(t *testing.T, ctx context.Context, operatorID string, namespace string) error { + KAMEL_INSTALL_REGISTRY := os.Getenv("KAMEL_INSTALL_REGISTRY") + // os.Setenv("CAMEL_K_TEST_MAKE_DIR", "../../../") + err := Make(t, + fmt.Sprintf("NAMESPACE=%s", namespace), + fmt.Sprintf("REGISTRY=%s", KAMEL_INSTALL_REGISTRY), + "install-k8s-ns").Run() + fmt.Println(err) + return err + /* + if !pkgutil.StringSliceExists(args, "--build-timeout") { + // if --build-timeout is not explicitly passed as an argument, try to configure it + buildTimeout := os.Getenv("CAMEL_K_TEST_BUILD_TIMEOUT") + if buildTimeout == "" { + // default Build Timeout for tests + buildTimeout = "10m" + } + fmt.Printf("Setting build timeout to %s\n", buildTimeout) + installArgs = append(installArgs, "--build-timeout", buildTimeout) + } + + if skipKameletCatalog { + installArgs = append(installArgs, "--skip-default-kamelets-setup") + } + + logLevel := os.Getenv("CAMEL_K_TEST_LOG_LEVEL") + if len(logLevel) > 0 { + fmt.Printf("Setting log-level to %s\n", logLevel) + installArgs = append(installArgs, "--log-level", logLevel) + } + + mvnCLIOptions := os.Getenv("CAMEL_K_TEST_MAVEN_CLI_OPTIONS") + if len(mvnCLIOptions) > 0 { + // Split the string by spaces + mvnCLIArr := strings.Split(mvnCLIOptions, " ") + for _, mc := range mvnCLIArr { + mc = strings.Trim(mc, " ") + if len(mc) == 0 { + continue + } + + fmt.Printf("Adding maven cli option %s\n", mc) + installArgs = append(installArgs, "--maven-cli-option", mc) + } + } + + runtimeVersion := os.Getenv("CAMEL_K_TEST_RUNTIME_VERSION") + if runtimeVersion != "" { + fmt.Printf("Setting runtime version to %s\n", runtimeVersion) + installArgs = append(installArgs, "--runtime-version", runtimeVersion) + } + baseImage := os.Getenv("CAMEL_K_TEST_BASE_IMAGE") + if baseImage != "" { + fmt.Printf("Setting base image to %s\n", baseImage) + installArgs = append(installArgs, "--base-image", baseImage) + } + opImage := os.Getenv("CAMEL_K_TEST_OPERATOR_IMAGE") + if opImage != "" { + fmt.Printf("Setting operator image to %s\n", opImage) + installArgs = append(installArgs, "--operator-image", opImage) + } + opImagePullPolicy := os.Getenv("CAMEL_K_TEST_OPERATOR_IMAGE_PULL_POLICY") + if opImagePullPolicy != "" { + fmt.Printf("Setting operator image pull policy to %s\n", opImagePullPolicy) + installArgs = append(installArgs, "--operator-image-pull-policy", opImagePullPolicy) + } + if len(os.Getenv("CAMEL_K_TEST_MAVEN_CA_PEM_PATH")) > 0 { + certName := "myCert" + secretName := "maven-ca-certs" + CreateSecretDecoded(t, ctx, namespace, os.Getenv("CAMEL_K_TEST_MAVEN_CA_PEM_PATH"), secretName, certName) + installArgs = append(installArgs, "--maven-repository", os.Getenv("KAMEL_INSTALL_MAVEN_REPOSITORIES"), + "--maven-ca-secret", secretName+"/"+certName) + } + + installArgs = append(installArgs, args...) + */ +} + func ExpectExecSucceed(t *testing.T, g *WithT, command *exec.Cmd) { t.Helper() diff --git a/script/Makefile b/script/Makefile index 52540f2c8..d8a4ae6ea 100644 --- a/script/Makefile +++ b/script/Makefile @@ -105,7 +105,7 @@ KAMELET_CATALOG_REPO_TAG := v4.0.1 DO_TEST_PREBUILD ?= true TEST_PREBUILD = build # Tests may run in parallel to each other. This count sets the amount of tests run in parallel. (default value usually is GOMAXPROCS) -TEST_COMMON_PARALLEL_COUNT ?= 1 +TEST_COMMON_PARALLEL_COUNT ?= 2 TEST_ADVANCED_PARALLEL_COUNT ?= 4 # OLM (Operator Lifecycle Manager and Operator Hub): uncomment to override operator settings at build time @@ -294,7 +294,7 @@ test-smoke: echo "TEST_SKIP_AFTER_FAILURE_COUNT=$$TEST_SKIP_AFTER_FAILURE_COUNT"; \ go test -timeout 10m -count=1 -v ./e2e/common/main_test.go -tags=integration $(TEST_INTEGRATION_COMMON_LANG_RUN) $(GOTESTFMT) || ((FAILED++)); \ if [ $$FAILED -le $$TEST_SKIP_AFTER_FAILURE_COUNT ]; then \ - go test -timeout 30m -count=1 -v ./e2e/common/languages -tags=integration -parallel=$(TEST_COMMON_PARALLEL_COUNT) $(TEST_INTEGRATION_COMMON_LANG_RUN) $(GOTESTFMT) || ((FAILED++)); \ + go test -p=$(TEST_COMMON_PARALLEL_COUNT) -timeout 30m -count=1 -v ./e2e/common/languages -tags=integration $(TEST_INTEGRATION_COMMON_LANG_RUN) $(GOTESTFMT) || ((FAILED++)); \ fi; \ if [ $$FAILED -le $$TEST_SKIP_AFTER_FAILURE_COUNT ]; then \ go test -timeout 30m -count=1 -v \ @@ -318,7 +318,7 @@ test-smoke: # test-advanced: FAILED=0; STAGING_RUNTIME_REPO="$(STAGING_RUNTIME_REPO)"; \ - go test -timeout 90m -v ./e2e/advanced -tags=integration -parallel=$(TEST_ADVANCED_PARALLEL_COUNT) $(TEST_INSTALL_RUN) $(GOTESTFMT) || ((FAILED++)); \ + go test -p=$(TEST_ADVANCED_PARALLEL_COUNT) -timeout 90m -v ./e2e/advanced -tags=integration $(TEST_INSTALL_RUN) $(GOTESTFMT) || ((FAILED++)); \ exit $${FAILED} #
