From 1b98aa8781c0f3f90981b64755de6b8847770cc9 Mon Sep 17 00:00:00 2001 From: Pasquale Congiusti Date: Wed, 26 Jun 2024 13:25:17 +0200 Subject: [PATCH] feat: dependencies default order strategy --- e2e/common/misc/rest_test.go | 21 +++++++++++++-------- e2e/common/traits/builder_test.go | 11 +++++++---- pkg/apis/camel/v1/trait/builder.go | 2 +- pkg/platform/defaults.go | 2 +- pkg/platform/defaults_test.go | 2 +- pkg/trait/builder_test.go | 10 ++++++++++ script/Makefile | 16 ++++++++-------- 7 files changed, 41 insertions(+), 23 deletions(-) diff --git a/e2e/common/misc/rest_test.go b/e2e/common/misc/rest_test.go index 680f06adb7..e67aa3c751 100644 --- a/e2e/common/misc/rest_test.go +++ b/e2e/common/misc/rest_test.go @@ -48,22 +48,27 @@ func TestRunRest(t *testing.T) { 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)) + g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID)).Should(Equal(v1.IntegrationPlatformPhaseReady)) ocp, err := openshift.IsOpenShift(TestClient(t)) require.NoError(t, err) - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/rest-consumer.yaml").Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ctx, ns, "rest-consumer"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/rest-consumer.yaml", + // Let's make sure to have this run via a plain Deployment + "-t", "knative-service.enabled=false", + ).Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "rest-consumer")).Should(Equal(corev1.PodRunning)) t.Run("Service works", func(t *testing.T) { name := RandomizedSuffixName("John") service := Service(t, ctx, ns, "rest-consumer") g.Eventually(service, TestTimeoutShort).ShouldNot(BeNil()) - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/rest-producer.yaml", "-p", "serviceName=rest-consumer", "-p", "name="+name).Execute()).To(Succeed()) - g.Eventually(IntegrationPodPhase(t, ctx, ns, "rest-producer"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - g.Eventually(IntegrationLogs(t, ctx, ns, "rest-consumer"), TestTimeoutLong).Should(ContainSubstring(fmt.Sprintf("get %s", name))) - g.Eventually(IntegrationLogs(t, ctx, ns, "rest-producer"), TestTimeoutLong).Should(ContainSubstring(fmt.Sprintf("%s Doe", name))) + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/rest-producer.yaml", + "-p", "serviceName=rest-consumer", "-p", "name="+name, + ).Execute()).To(Succeed()) + g.Eventually(IntegrationPodPhase(t, ctx, ns, "rest-producer")).Should(Equal(corev1.PodRunning)) + g.Eventually(IntegrationLogs(t, ctx, ns, "rest-consumer")).Should(ContainSubstring(fmt.Sprintf("get %s", name))) + g.Eventually(IntegrationLogs(t, ctx, ns, "rest-producer")).Should(ContainSubstring(fmt.Sprintf("%s Doe", name))) }) if ocp { @@ -71,7 +76,7 @@ func TestRunRest(t *testing.T) { name := RandomizedSuffixName("Peter") route := Route(t, ctx, ns, "rest-consumer") g.Eventually(route, TestTimeoutShort).ShouldNot(BeNil()) - g.Eventually(RouteStatus(t, ctx, ns, "rest-consumer"), TestTimeoutMedium).Should(Equal("True")) + g.Eventually(RouteStatus(t, ctx, ns, "rest-consumer")).Should(Equal("True")) url := fmt.Sprintf("http://%s/customers/%s", route().Spec.Host, name) g.Eventually(httpRequest(url), TestTimeoutMedium).Should(Equal(fmt.Sprintf("%s Doe", name))) g.Eventually(IntegrationLogs(t, ctx, ns, "rest-consumer"), TestTimeoutShort).Should(ContainSubstring(fmt.Sprintf("get %s", name))) diff --git a/e2e/common/traits/builder_test.go b/e2e/common/traits/builder_test.go index db8d42a00d..652a7f65b5 100644 --- a/e2e/common/traits/builder_test.go +++ b/e2e/common/traits/builder_test.go @@ -47,9 +47,13 @@ func TestBuilderTrait(t *testing.T) { g.Eventually(SelectedPlatformPhase(t, ctx, ns, operatorID), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady)) - t.Run("Run build strategy routine", func(t *testing.T) { - name := RandomizedSuffixName("java") - g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name, "-t", "builder.order-strategy=sequential", "-t", "builder.strategy=routine").Execute()).To(Succeed()) + t.Run("Run build order strategy sequential", func(t *testing.T) { + name := RandomizedSuffixName("java-dependencies-sequential") + g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name, + // This is required in order to avoid reusing a Kit already existing (which is the default behavior) + "--build-property", "strategy=sequential", + "-t", "builder.order-strategy=sequential", + ).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)) @@ -148,7 +152,6 @@ func TestBuilderTrait(t *testing.T) { builderKitName := fmt.Sprintf("camel-k-%s-builder", integrationKitName) g.Eventually(BuildConfig(t, ctx, integrationKitNamespace, integrationKitName)().Strategy, TestTimeoutShort).Should(Equal(v1.BuildStrategyPod)) - g.Eventually(BuildConfig(t, ctx, integrationKitNamespace, integrationKitName)().OrderStrategy, TestTimeoutShort).Should(Equal(v1.BuildOrderStrategySequential)) g.Eventually(BuildConfig(t, ctx, integrationKitNamespace, integrationKitName)().RequestCPU, TestTimeoutShort).Should(Equal("500m")) g.Eventually(BuildConfig(t, ctx, integrationKitNamespace, integrationKitName)().LimitCPU, TestTimeoutShort).Should(Equal("1000m")) g.Eventually(BuildConfig(t, ctx, integrationKitNamespace, integrationKitName)().RequestMemory, TestTimeoutShort).Should(Equal("2Gi")) diff --git a/pkg/apis/camel/v1/trait/builder.go b/pkg/apis/camel/v1/trait/builder.go index 12054f95d4..62b04d4fa5 100644 --- a/pkg/apis/camel/v1/trait/builder.go +++ b/pkg/apis/camel/v1/trait/builder.go @@ -36,7 +36,7 @@ type BuilderTrait struct { BaseImage string `property:"base-image" json:"baseImage,omitempty"` // Use the incremental image build option, to reuse existing containers (default `true`) IncrementalImageBuild *bool `property:"incremental-image-build" json:"incrementalImageBuild,omitempty"` - // The build order strategy to use, either `dependencies`, `fifo` or `sequential` (default `sequential`) + // The build order strategy to use, either `dependencies`, `fifo` or `sequential` (default is the platform default) // +kubebuilder:validation:Enum=dependencies;fifo;sequential OrderStrategy string `property:"order-strategy" json:"orderStrategy,omitempty"` // When using `pod` strategy, the minimum amount of CPU required by the pod builder. diff --git a/pkg/platform/defaults.go b/pkg/platform/defaults.go index f4e7cd218e..2814d72eb5 100644 --- a/pkg/platform/defaults.go +++ b/pkg/platform/defaults.go @@ -90,7 +90,7 @@ func ConfigureDefaults(ctx context.Context, c client.Client, p *v1.IntegrationPl } if p.Status.Build.BuildConfiguration.OrderStrategy == "" { - p.Status.Build.BuildConfiguration.OrderStrategy = v1.BuildOrderStrategySequential + p.Status.Build.BuildConfiguration.OrderStrategy = v1.BuildOrderStrategyDependencies log.Debugf("Integration Platform %s [%s]: setting build order strategy %s", p.Name, p.Namespace, p.Status.Build.BuildConfiguration.OrderStrategy) } diff --git a/pkg/platform/defaults_test.go b/pkg/platform/defaults_test.go index 36d366dd38..4a5c7ee5d2 100644 --- a/pkg/platform/defaults_test.go +++ b/pkg/platform/defaults_test.go @@ -49,7 +49,7 @@ func TestIntegrationPlatformDefaults(t *testing.T) { assert.Equal(t, v1.IntegrationPlatformClusterKubernetes, ip.Status.Cluster) assert.Equal(t, v1.TraitProfile(""), ip.Status.Profile) assert.Equal(t, v1.BuildStrategyRoutine, ip.Status.Build.BuildConfiguration.Strategy) - assert.Equal(t, v1.BuildOrderStrategySequential, ip.Status.Build.BuildConfiguration.OrderStrategy) + assert.Equal(t, v1.BuildOrderStrategyDependencies, ip.Status.Build.BuildConfiguration.OrderStrategy) assert.Equal(t, defaults.BaseImage(), ip.Status.Build.BaseImage) assert.Equal(t, defaults.LocalRepository, ip.Status.Build.Maven.LocalRepository) assert.Equal(t, int32(3), ip.Status.Build.MaxRunningBuilds) // default for build strategy routine diff --git a/pkg/trait/builder_test.go b/pkg/trait/builder_test.go index fc6b18b56b..3ea5de9f03 100644 --- a/pkg/trait/builder_test.go +++ b/pkg/trait/builder_test.go @@ -684,3 +684,13 @@ func TestBuilderTraitPlatforms(t *testing.T) { assert.Equal(t, []string{"linux/amd64", "linux/arm64"}, env.Pipeline[2].Jib.Configuration.ImagePlatforms) } + +func TestBuilderTraitOrderStrategy(t *testing.T) { + env := createBuilderTestEnv(v1.IntegrationPlatformClusterKubernetes, v1.IntegrationPlatformBuildPublishStrategyJib, v1.BuildStrategyRoutine) + builderTrait := createNominalBuilderTraitTest() + builderTrait.OrderStrategy = "fifo" + err := builderTrait.Apply(env) + require.NoError(t, err) + + assert.Equal(t, v1.BuildOrderStrategyFIFO, env.Pipeline[0].Builder.Configuration.OrderStrategy) +} diff --git a/script/Makefile b/script/Makefile index 11b317fc9d..8f87a77575 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 ?= 4 +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 @@ -284,7 +284,7 @@ setup-yaks: # test-common: do-build FAILED=0; STAGING_RUNTIME_REPO="$(STAGING_RUNTIME_REPO)"; \ - go test -timeout 90m -v ./e2e/common/... -tags=integration -parallel=$(TEST_COMMON_PARALLEL_COUNT) $(TEST_INTEGRATION_COMMON_LANG_RUN) $(GOTESTFMT) || ((FAILED++)); \ + go test -p=$(TEST_COMMON_PARALLEL_COUNT) -timeout 90m -v ./e2e/common/... -tags=integration $(TEST_INTEGRATION_COMMON_LANG_RUN) $(GOTESTFMT) || ((FAILED++)); \ exit $${FAILED} # @@ -300,22 +300,22 @@ test-smoke: do-build 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 \ + go test -p=$(TEST_COMMON_PARALLEL_COUNT) -timeout 30m -count=1 -v \ ./e2e/common/misc/cron_test.go \ ./e2e/common/misc/kamelet_test.go \ ./e2e/common/misc/pipe_test.go \ - -tags=integration -parallel=$(TEST_COMMON_PARALLEL_COUNT) $(TEST_INTEGRATION_COMMON_LANG_RUN) $(GOTESTFMT) || ((FAILED++)); \ + -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 \ + go test -p=$(TEST_COMMON_PARALLEL_COUNT) -timeout 30m -count=1 -v \ ./e2e/common/traits/camel_test.go \ ./e2e/common/traits/container_test.go \ ./e2e/common/traits/openapi_test.go \ ./e2e/common/traits/service_test.go \ - -tags=integration -parallel=$(TEST_COMMON_PARALLEL_COUNT) $(TEST_INTEGRATION_COMMON_LANG_RUN) $(GOTESTFMT) || ((FAILED++)); \ + -tags=integration $(TEST_INTEGRATION_COMMON_LANG_RUN) $(GOTESTFMT) || ((FAILED++)); \ fi; \ exit $$FAILED @@ -324,7 +324,7 @@ test-smoke: do-build # test-advanced: do-build 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} #