diff --git a/pkg/builder/buildah.go b/pkg/builder/buildah.go index 71d35a56fd..43f9c7087a 100644 --- a/pkg/builder/buildah.go +++ b/pkg/builder/buildah.go @@ -20,6 +20,7 @@ package builder const BuildahPlatform = "BuildahPlatform" const BuildahImage = "BuildahImage" const BuildahDefaultImageName = "quay.io/buildah/stable" +const BuildahDefaultBaseImageName = "docker.io/library/eclipse-temurin:11" var buildahSupportedOptions = map[string]PublishStrategyOption{ BuildahPlatform: { diff --git a/pkg/platform/defaults.go b/pkg/platform/defaults.go index f6d14829ac..aff2bf41b1 100644 --- a/pkg/platform/defaults.go +++ b/pkg/platform/defaults.go @@ -233,6 +233,10 @@ func applyPlatformSpec(source *v1.IntegrationPlatform, target *v1.IntegrationPla if target.Status.Build.BaseImage == "" { log.Debugf("Integration Platform %s [%s]: setting base image", target.Name, target.Namespace) target.Status.Build.BaseImage = source.Status.Build.BaseImage + // Workaround to ensure the default image from buildah is full name. Any baseImage override is in charge of it's validity + if target.Status.Build.PublishStrategy == v1.IntegrationPlatformBuildPublishStrategyBuildah && defaults.IsBaseImageDefault() { + target.Status.Build.BaseImage = builder.BuildahDefaultBaseImageName + } } if target.Status.Build.Maven.LocalRepository == "" { @@ -312,6 +316,10 @@ func setPlatformDefaults(p *v1.IntegrationPlatform, verbose bool) error { if p.Status.Build.BaseImage == "" { log.Debugf("Integration Platform %s [%s]: setting base image", p.Name, p.Namespace) p.Status.Build.BaseImage = defaults.BaseImage() + // Workaround to ensure the default image from buildah is full name. Any baseImage override is in charge of it's validity + if p.Status.Build.PublishStrategy == v1.IntegrationPlatformBuildPublishStrategyBuildah && defaults.IsBaseImageDefault() { + p.Status.Build.BaseImage = builder.BuildahDefaultBaseImageName + } } if p.Status.Build.Maven.LocalRepository == "" { log.Debugf("Integration Platform %s [%s]: setting local repository", p.Name, p.Namespace) diff --git a/pkg/platform/defaults_test.go b/pkg/platform/defaults_test.go index 79579b7ed6..b2a51fb221 100644 --- a/pkg/platform/defaults_test.go +++ b/pkg/platform/defaults_test.go @@ -27,6 +27,7 @@ import ( v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" "github.com/apache/camel-k/v2/pkg/apis/camel/v1/trait" + "github.com/apache/camel-k/v2/pkg/builder" "github.com/apache/camel-k/v2/pkg/util/test" ) @@ -96,6 +97,87 @@ func TestApplyGlobalPlatformSpec(t *testing.T) { assert.Equal(t, "global_value2", ip.Status.Build.Maven.Properties["global_prop2"]) } +func TestPlatformBuildahUpdateOverrideLocalPlatformSpec(t *testing.T) { + global := v1.IntegrationPlatform{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: "ns", + }, + Spec: v1.IntegrationPlatformSpec{ + Build: v1.IntegrationPlatformBuildSpec{ + PublishStrategy: v1.IntegrationPlatformBuildPublishStrategyBuildah, + }, + }, + } + + c, err := test.NewFakeClient(&global) + assert.Nil(t, err) + + err = ConfigureDefaults(context.TODO(), c, &global, false) + assert.Nil(t, err) + assert.Equal(t, builder.BuildahDefaultBaseImageName, global.Status.Build.BaseImage) + + ip := v1.IntegrationPlatform{ + ObjectMeta: metav1.ObjectMeta{ + Name: "local-camel-k", + Namespace: "ns", + }, + Spec: v1.IntegrationPlatformSpec{ + Build: v1.IntegrationPlatformBuildSpec{ + PublishStrategy: v1.IntegrationPlatformBuildPublishStrategyBuildah, + BaseImage: "overridden", + }, + }, + } + + ip.ResyncStatusFullConfig() + + applyPlatformSpec(&global, &ip) + + assert.Equal(t, v1.IntegrationPlatformBuildPublishStrategyBuildah, ip.Status.Build.PublishStrategy) + assert.Equal(t, "overridden", ip.Status.Build.BaseImage) +} + +func TestPlatformBuildahUpdateDefaultLocalPlatformSpec(t *testing.T) { + + global := v1.IntegrationPlatform{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: "ns", + }, + Spec: v1.IntegrationPlatformSpec{ + Build: v1.IntegrationPlatformBuildSpec{ + PublishStrategy: v1.IntegrationPlatformBuildPublishStrategyBuildah, + BaseImage: "overridden", + }, + }, + } + + c, err := test.NewFakeClient(&global) + assert.Nil(t, err) + + err = ConfigureDefaults(context.TODO(), c, &global, false) + assert.Nil(t, err) + assert.Equal(t, "overridden", global.Status.Build.BaseImage) + + ip := v1.IntegrationPlatform{ + ObjectMeta: metav1.ObjectMeta{ + Name: "local-camel-k", + Namespace: "ns", + }, + Spec: v1.IntegrationPlatformSpec{ + Build: v1.IntegrationPlatformBuildSpec{ + PublishStrategy: v1.IntegrationPlatformBuildPublishStrategyBuildah, + }, + }, + } + + ip.ResyncStatusFullConfig() + + applyPlatformSpec(&global, &ip) + + assert.Equal(t, v1.IntegrationPlatformBuildPublishStrategyBuildah, ip.Status.Build.PublishStrategy) + assert.Equal(t, builder.BuildahDefaultBaseImageName, ip.Status.Build.BaseImage) +} + func TestRetainLocalPlatformSpec(t *testing.T) { global := v1.IntegrationPlatform{ ObjectMeta: metav1.ObjectMeta{ diff --git a/pkg/util/defaults/defaults_support.go b/pkg/util/defaults/defaults_support.go index 1c2b28113a..ae81ac7323 100644 --- a/pkg/util/defaults/defaults_support.go +++ b/pkg/util/defaults/defaults_support.go @@ -29,6 +29,10 @@ func BaseImage() string { return envOrDefault(baseImage, "KAMEL_BASE_IMAGE", "RELATED_IMAGE_BASE") } +func IsBaseImageDefault() bool { + return baseImage == BaseImage() +} + func OperatorImage() string { return envOrDefault(fmt.Sprintf("%s:%s", ImageName, Version), "KAMEL_OPERATOR_IMAGE", "KAMEL_K_TEST_OPERATOR_CURRENT_IMAGE") } diff --git a/pkg/util/defaults/defaults_test.go b/pkg/util/defaults/defaults_test.go index 1bc8dbbb9a..de9d4f58e3 100644 --- a/pkg/util/defaults/defaults_test.go +++ b/pkg/util/defaults/defaults_test.go @@ -27,6 +27,7 @@ import ( func TestDefaultBaseImage(t *testing.T) { assert.NotEmpty(t, BaseImage()) + assert.True(t, IsBaseImageDefault()) } func TestOverriddenBaseImage(t *testing.T) { @@ -35,6 +36,7 @@ func TestOverriddenBaseImage(t *testing.T) { overriddenImage := "xxx" assert.NoError(t, os.Setenv(env, overriddenImage)) assert.Equal(t, overriddenImage, BaseImage()) + assert.False(t, IsBaseImageDefault()) assert.NoError(t, os.Setenv(env, oldEnvVal)) }