diff --git a/pkg/apis/camel/v1alpha1/integrationplatform_types.go b/pkg/apis/camel/v1alpha1/integrationplatform_types.go index 19dbcab0fe..5c4674df0f 100644 --- a/pkg/apis/camel/v1alpha1/integrationplatform_types.go +++ b/pkg/apis/camel/v1alpha1/integrationplatform_types.go @@ -105,6 +105,7 @@ type IntegrationPlatformBuildSpec struct { PersistentVolumeClaim string `json:"persistentVolumeClaim,omitempty"` Maven MavenSpec `json:"maven,omitempty"` HTTPProxySecret string `json:"httpProxySecret,omitempty"` + KanikoBuildCache bool `json:"kanikoBuildCache,omitempty"` } // IntegrationPlatformRegistrySpec -- diff --git a/pkg/builder/kaniko/publisher.go b/pkg/builder/kaniko/publisher.go index 1951f5bea1..724e5f759d 100644 --- a/pkg/builder/kaniko/publisher.go +++ b/pkg/builder/kaniko/publisher.go @@ -21,6 +21,7 @@ import ( "fmt" "io/ioutil" "path" + "strconv" "time" "github.com/apache/camel-k/pkg/builder" @@ -79,7 +80,7 @@ func publisher(ctx *builder.Context) error { "--dockerfile=Dockerfile", "--context=" + contextDir, "--destination=" + image, - "--cache", + "--cache=" + strconv.FormatBool(ctx.Build.Platform.Build.KanikoBuildCache), "--cache-dir=/workspace/cache", } diff --git a/pkg/cmd/install.go b/pkg/cmd/install.go index 25e94b3d94..162c211b9f 100644 --- a/pkg/cmd/install.go +++ b/pkg/cmd/install.go @@ -74,6 +74,7 @@ func newCmdInstall(rootCmdOptions *RootCmdOptions) *cobra.Command { cmd.Flags().StringVar(&impl.buildStrategy, "build-strategy", "", "Set the build strategy") cmd.Flags().StringVar(&impl.buildTimeout, "build-timeout", "", "Set how long the build process can last") cmd.Flags().StringVar(&impl.traitProfile, "trait-profile", "", "The profile to use for traits") + cmd.Flags().BoolVar(&impl.kanikoBuildCache, "kaniko-build-cache", true, "To enable or disable the Kaniko Cache in building phase") cmd.Flags().StringVar(&impl.httpProxySecret, "http-proxy-secret", "", "Configure the source of the secret holding HTTP proxy server details "+ "(HTTP_PROXY|HTTPS_PROXY|NO_PROXY)") @@ -102,6 +103,7 @@ type installCmdOptions struct { skipClusterSetup bool exampleSetup bool global bool + kanikoBuildCache bool outputFormat string camelVersion string runtimeVersion string @@ -120,7 +122,7 @@ type installCmdOptions struct { } // nolint: gocyclo -func (o *installCmdOptions) install(_ *cobra.Command, _ []string) error { +func (o *installCmdOptions) install(cobraCmd *cobra.Command, _ []string) error { var collection *kubernetes.Collection if o.outputFormat != "" { collection = kubernetes.NewCollection() @@ -235,6 +237,14 @@ func (o *installCmdOptions) install(_ *cobra.Command, _ []string) error { platform.Spec.Build.HTTPProxySecret = o.httpProxySecret } + kanikoBuildCacheFlag := cobraCmd.Flags().Lookup("kaniko-build-cache") + + if kanikoBuildCacheFlag.Changed { + platform.Spec.Build.KanikoBuildCache = o.kanikoBuildCache + } else { + platform.Spec.Build.KanikoBuildCache = true + } + platform.Spec.Resources.Kits = o.kits err = install.RuntimeObjectOrCollect(o.Context, c, namespace, collection, platform) diff --git a/pkg/controller/integrationplatform/initialize.go b/pkg/controller/integrationplatform/initialize.go index 3e2d404691..1a270db7b6 100644 --- a/pkg/controller/integrationplatform/initialize.go +++ b/pkg/controller/integrationplatform/initialize.go @@ -137,7 +137,7 @@ func (action *initializeAction) Handle(ctx context.Context, platform *v1alpha1.I } // Check if the operator is running in the same namespace before starting the cache warmer - if platform.Namespace == platformutil.GetOperatorNamespace() { + if platform.Namespace == platformutil.GetOperatorNamespace() && platform.Spec.Build.KanikoBuildCache { // Create the Kaniko warmer pod that caches the base image into the Camel K builder volume action.L.Info("Create Kaniko cache warmer pod") err = createKanikoCacheWarmerPod(ctx, action.client, platform)