[camel-k] branch release-1.3.x updated: Fix #1707: add a way to override the base image in the operator

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[camel-k] branch release-1.3.x updated: Fix #1707: add a way to override the base image in the operator

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

nferraro pushed a commit to branch release-1.3.x
in repository https://gitbox.apache.org/repos/asf/camel-k.git


The following commit(s) were added to refs/heads/release-1.3.x by this push:
     new 5ff89b5  Fix #1707: add a way to override the base image in the operator
5ff89b5 is described below

commit 5ff89b552be1dfeceb53114cc098e43c47d6c8c2
Author: nicolaferraro <[hidden email]>
AuthorDate: Mon Jan 11 11:57:23 2021 +0100

    Fix #1707: add a way to override the base image in the operator
---
 pkg/platform/defaults.go                           |  2 +-
 pkg/util/defaults/defaults.go                      |  4 +--
 .../defaults/{defaults.go => defaults_support.go}  | 42 +++++++++-------------
 .../defaults/{defaults.go => defaults_test.go}     | 41 +++++++++------------
 pkg/util/docker/docker.go                          |  2 +-
 script/Makefile                                    |  4 +--
 6 files changed, 39 insertions(+), 56 deletions(-)

diff --git a/pkg/platform/defaults.go b/pkg/platform/defaults.go
index db3dfab..9da4e88 100644
--- a/pkg/platform/defaults.go
+++ b/pkg/platform/defaults.go
@@ -166,7 +166,7 @@ func setPlatformDefaults(ctx context.Context, c client.Client, p *v1.Integration
  p.Status.Build.RuntimeVersion = defaults.DefaultRuntimeVersion
  }
  if p.Status.Build.BaseImage == "" {
- p.Status.Build.BaseImage = defaults.BaseImage
+ p.Status.Build.BaseImage = defaults.BaseImage()
  }
  if p.Status.Build.Maven.LocalRepository == "" {
  p.Status.Build.Maven.LocalRepository = defaults.LocalRepository
diff --git a/pkg/util/defaults/defaults.go b/pkg/util/defaults/defaults.go
index 872f923..73e3f96 100644
--- a/pkg/util/defaults/defaults.go
+++ b/pkg/util/defaults/defaults.go
@@ -34,8 +34,8 @@ const (
  // KanikoVersion --
  KanikoVersion = "0.17.1"
 
- // BaseImage --
- BaseImage = "adoptopenjdk/openjdk11:slim"
+ // baseImage --
+ baseImage = "adoptopenjdk/openjdk11:slim"
 
  // LocalRepository --
  LocalRepository = "/tmp/artifacts/m2"
diff --git a/pkg/util/defaults/defaults.go b/pkg/util/defaults/defaults_support.go
similarity index 62%
copy from pkg/util/defaults/defaults.go
copy to pkg/util/defaults/defaults_support.go
index 872f923..ec2a397 100644
--- a/pkg/util/defaults/defaults.go
+++ b/pkg/util/defaults/defaults_support.go
@@ -17,29 +17,19 @@ limitations under the License.
 
 package defaults
 
-// ***********************
-//  DO NOT EDIT THIS FILE
-// ***********************
-
-const (
- // Version --
- Version = "1.3.1-SNAPSHOT"
-
- // DefaultRuntimeVersion --
- DefaultRuntimeVersion = "1.6.0"
-
- // BuildahVersion --
- BuildahVersion = "1.14.0"
-
- // KanikoVersion --
- KanikoVersion = "0.17.1"
-
- // BaseImage --
- BaseImage = "adoptopenjdk/openjdk11:slim"
-
- // LocalRepository --
- LocalRepository = "/tmp/artifacts/m2"
-
- // ImageName --
- ImageName = "docker.io/apache/camel-k"
-)
+import "os"
+
+var baseImageOverrideEnvs = []string{"BASE_IMAGE", "RELATED_IMAGE_BASE"}
+
+func BaseImage() string {
+ return envOrDefault(baseImage, baseImageOverrideEnvs...)
+}
+
+func envOrDefault(def string, envs ...string) string {
+ for i := range envs {
+ if val := os.Getenv(envs[i]); val != "" {
+ return val
+ }
+ }
+ return def
+}
diff --git a/pkg/util/defaults/defaults.go b/pkg/util/defaults/defaults_test.go
similarity index 62%
copy from pkg/util/defaults/defaults.go
copy to pkg/util/defaults/defaults_test.go
index 872f923..90dba55 100644
--- a/pkg/util/defaults/defaults.go
+++ b/pkg/util/defaults/defaults_test.go
@@ -17,29 +17,22 @@ limitations under the License.
 
 package defaults
 
-// ***********************
-//  DO NOT EDIT THIS FILE
-// ***********************
+import (
+ "os"
+ "testing"
 
-const (
- // Version --
- Version = "1.3.1-SNAPSHOT"
-
- // DefaultRuntimeVersion --
- DefaultRuntimeVersion = "1.6.0"
-
- // BuildahVersion --
- BuildahVersion = "1.14.0"
-
- // KanikoVersion --
- KanikoVersion = "0.17.1"
-
- // BaseImage --
- BaseImage = "adoptopenjdk/openjdk11:slim"
-
- // LocalRepository --
- LocalRepository = "/tmp/artifacts/m2"
-
- // ImageName --
- ImageName = "docker.io/apache/camel-k"
+ "github.com/stretchr/testify/assert"
 )
+
+func TestDefaultBaseImage(t *testing.T) {
+ assert.NotEmpty(t, BaseImage())
+}
+
+func TestOverriddenBaseImage(t *testing.T) {
+ env := "RELATED_IMAGE_BASE"
+ oldEnvVal := os.Getenv(env)
+ overriddenImage := "xxx"
+ assert.NoError(t, os.Setenv(env, overriddenImage))
+ assert.Equal(t, overriddenImage, BaseImage())
+ assert.NoError(t, os.Setenv(env, oldEnvVal))
+}
diff --git a/pkg/util/docker/docker.go b/pkg/util/docker/docker.go
index 90ce1f3..7a48b6b 100644
--- a/pkg/util/docker/docker.go
+++ b/pkg/util/docker/docker.go
@@ -32,7 +32,7 @@ func CreateBaseImageDockerFile() error {
  dockerFile := []string{}
 
  // Base image is a java-only image since the integration command is just a java command.
- dockerFile = append(dockerFile, FROM(defaults.BaseImage))
+ dockerFile = append(dockerFile, FROM(defaults.BaseImage()))
 
  // Ensure Maven is already installed.
  dockerFile = append(dockerFile, RUNMavenInstall())
diff --git a/script/Makefile b/script/Makefile
index c6ae0c4..aaa0d52 100644
--- a/script/Makefile
+++ b/script/Makefile
@@ -107,8 +107,8 @@ codegen:
  @echo "  // KanikoVersion -- " >> $(VERSIONFILE)
  @echo "  KanikoVersion = \"$(KANIKO_VERSION)\"" >> $(VERSIONFILE)
  @echo "" >> $(VERSIONFILE)
- @echo "  // BaseImage -- " >> $(VERSIONFILE)
- @echo "  BaseImage = \"$(BASE_IMAGE)\"" >> $(VERSIONFILE)
+ @echo "  // baseImage -- " >> $(VERSIONFILE)
+ @echo "  baseImage = \"$(BASE_IMAGE)\"" >> $(VERSIONFILE)
  @echo "" >> $(VERSIONFILE)
  @echo "  // LocalRepository -- " >> $(VERSIONFILE)
  @echo "  LocalRepository = \"$(LOCAL_REPOSITORY)\"" >> $(VERSIONFILE)