Skip to content

Commit

Permalink
feat: dependencies default order strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
squakez committed Jul 2, 2024
1 parent e3a7df2 commit 4df6a07
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 8 deletions.
2 changes: 1 addition & 1 deletion e2e/common/misc/rest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,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)))
Expand Down
16 changes: 12 additions & 4 deletions e2e/common/traits/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ func TestBuilderTrait(t *testing.T) {
WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) {
t.Run("Run build strategy routine", func(t *testing.T) {
name := RandomizedSuffixName("java")
g.Expect(KamelRun(t, ctx, ns, "files/Java.java", "--name", name, "-t", "builder.order-strategy=sequential", "-t", "builder.strategy=routine").Execute()).To(Succeed())
g.Expect(KamelRun(t, ctx, 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))
Expand All @@ -66,7 +70,8 @@ func TestBuilderTrait(t *testing.T) {
"--name", name,
// This is required in order to avoid reusing a Kit already existing (which is the default behavior)
"--build-property", "strategy=dependencies",
"-t", "builder.order-strategy=dependencies").Execute()).To(Succeed())
"-t", "builder.order-strategy=dependencies",
).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))
Expand Down Expand Up @@ -133,7 +138,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"))
Expand All @@ -150,7 +154,11 @@ func TestBuilderTrait(t *testing.T) {

t.Run("Run custom pipeline task", func(t *testing.T) {
name := RandomizedSuffixName("java-pipeline")
g.Expect(KamelRun(t, ctx, ns, "files/Java.java", "--name", name, "-t", "builder.tasks=custom1;alpine;tree", "-t", "builder.tasks=custom2;alpine;cat maven/pom.xml", "-t", "builder.strategy=pod").Execute()).To(Succeed())
g.Expect(KamelRun(t, ctx, ns, "files/Java.java", "--name", name,
"-t", "builder.tasks=custom1;alpine;tree",
"-t", "builder.tasks=custom2;alpine;cat maven/pom.xml",
"-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), TestTimeoutLong).Should(Equal(corev1.ConditionTrue))
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/camel/v1/trait/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pkg/platform/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/platform/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions pkg/trait/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 4df6a07

Please sign in to comment.