You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by as...@apache.org on 2019/10/03 12:30:52 UTC

[camel-k] 01/02: chore(cache): avoid kaniko cache nil references when upgrading from older versions

This is an automated email from the ASF dual-hosted git repository.

astefanutti pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit 085e4458346065dc631d747a315d63f9e0de97f7
Author: nferraro <ni...@gmail.com>
AuthorDate: Thu Oct 3 10:47:27 2019 +0200

    chore(cache): avoid kaniko cache nil references when upgrading from older versions
---
 pkg/apis/camel/v1alpha1/integrationplatform_types_support.go | 9 +++++++++
 pkg/builder/kaniko/publisher.go                              | 2 +-
 pkg/controller/integrationplatform/initialize.go             | 2 +-
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/pkg/apis/camel/v1alpha1/integrationplatform_types_support.go b/pkg/apis/camel/v1alpha1/integrationplatform_types_support.go
index 3a5def0..e752347 100644
--- a/pkg/apis/camel/v1alpha1/integrationplatform_types_support.go
+++ b/pkg/apis/camel/v1alpha1/integrationplatform_types_support.go
@@ -159,3 +159,12 @@ func (in *IntegrationPlatformStatus) RemoveCondition(condType IntegrationPlatfor
 
 	in.Conditions = newConditions
 }
+
+// IsKanikoCacheEnabled tells if the KanikoCache is enabled on the integration platform build spec
+func (b IntegrationPlatformBuildSpec) IsKanikoCacheEnabled() bool {
+	if b.KanikoBuildCache == nil {
+		// Cache is enabled unless explicitly disabled
+		return true
+	}
+	return *b.KanikoBuildCache
+}
diff --git a/pkg/builder/kaniko/publisher.go b/pkg/builder/kaniko/publisher.go
index 5a6e139..6529dcb 100644
--- a/pkg/builder/kaniko/publisher.go
+++ b/pkg/builder/kaniko/publisher.go
@@ -88,7 +88,7 @@ func publisher(ctx *builder.Context) error {
 		"--dockerfile=Dockerfile",
 		"--context=" + contextDir,
 		"--destination=" + image,
-		"--cache=" + strconv.FormatBool(*ctx.Build.Platform.Build.KanikoBuildCache),
+		"--cache=" + strconv.FormatBool(ctx.Build.Platform.Build.IsKanikoCacheEnabled()),
 		"--cache-dir=/workspace/cache",
 	}
 
diff --git a/pkg/controller/integrationplatform/initialize.go b/pkg/controller/integrationplatform/initialize.go
index d90a06c..c76c5a2 100644
--- a/pkg/controller/integrationplatform/initialize.go
+++ b/pkg/controller/integrationplatform/initialize.go
@@ -136,7 +136,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() && *platform.Spec.Build.KanikoBuildCache {
+		if platform.Namespace == platformutil.GetOperatorNamespace() && platform.Spec.Build.IsKanikoCacheEnabled() {
 			// 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)