This is an automated email from the ASF dual-hosted git repository.
ricardozanini pushed a commit to branch main
in repository
https://gitbox.apache.org/repos/asf/incubator-kie-kogito-serverless-operator.git
The following commit(s) were added to refs/heads/main by this push:
new c08fa39b Issue-434: Forcing pulling images from BC when latest is set
(#435)
c08fa39b is described below
commit c08fa39bea6a58afc867147d8b9aec07f01ac9df
Author: Ricardo Zanini <[email protected]>
AuthorDate: Fri Apr 5 12:05:06 2024 -0300
Issue-434: Forcing pulling images from BC when latest is set (#435)
---
.github/workflows/check-container-builder.yml | 4 +++-
controllers/builder/openshiftbuilder.go | 2 ++
controllers/builder/openshiftbuilder_test.go | 33 +++++++++++++++++++++++++++
controllers/platform/platformutils.go | 8 +++++--
utils/kubernetes/image.go | 16 +++++++++++--
utils/kubernetes/image_test.go | 1 +
workflowproj/go.mod | 2 ++
7 files changed, 61 insertions(+), 5 deletions(-)
diff --git a/.github/workflows/check-container-builder.yml
b/.github/workflows/check-container-builder.yml
index 2891c2db..7665259d 100644
--- a/.github/workflows/check-container-builder.yml
+++ b/.github/workflows/check-container-builder.yml
@@ -11,6 +11,7 @@ on:
env:
REGISTRY_STORAGE_DELETE_ENABLED : true
+ GO_VERSION: 1.21
jobs:
unit-tests:
@@ -32,7 +33,8 @@ jobs:
- name: Setup golang
uses: actions/setup-go@v5
with:
- go-version: 1.21
+ go-version: ${{ env.GO_VERSION }}
+ cache: true
- name: Checkout code
uses: actions/checkout@v4
with:
diff --git a/controllers/builder/openshiftbuilder.go
b/controllers/builder/openshiftbuilder.go
index 44077d46..bb84b2c5 100644
--- a/controllers/builder/openshiftbuilder.go
+++ b/controllers/builder/openshiftbuilder.go
@@ -151,6 +151,7 @@ func (o *openshiftBuilderManager) Schedule(build
*operatorapi.SonataFlowBuild) e
func (o *openshiftBuilderManager) newDefaultBuildConfig(build
*operatorapi.SonataFlowBuild, workflow *operatorapi.SonataFlow)
*buildv1.BuildConfig {
optimizationPol := buildv1.ImageOptimizationSkipLayers
dockerFile :=
platform.GetCustomizedBuilderDockerfile(o.builderConfigMap.Data[defaultBuilderResourceName],
*o.platform)
+ forcePull :=
kubeutil.GetImageTag(platform.GetFromImageTagDockerfile(dockerFile)) == "latest"
return &buildv1.BuildConfig{
ObjectMeta: metav1.ObjectMeta{Namespace: build.Namespace, Name:
build.Name},
Spec: buildv1.BuildConfigSpec{
@@ -168,6 +169,7 @@ func (o *openshiftBuilderManager)
newDefaultBuildConfig(build *operatorapi.Sonat
ImageOptimizationPolicy:
&optimizationPol,
BuildArgs:
build.Spec.BuildArgs,
Env:
build.Spec.Envs,
+ ForcePull:
forcePull,
},
},
Output: buildv1.BuildOutput{
diff --git a/controllers/builder/openshiftbuilder_test.go
b/controllers/builder/openshiftbuilder_test.go
index bd992c3b..ea8c8b74 100644
--- a/controllers/builder/openshiftbuilder_test.go
+++ b/controllers/builder/openshiftbuilder_test.go
@@ -131,3 +131,36 @@ func Test_openshiftbuilder_externalCMs(t *testing.T) {
assert.Len(t, bc.Spec.Source.ConfigMaps, 1)
}
+
+func Test_openshiftbuilder_forcePull(t *testing.T) {
+ // Setup
+ ns := t.Name()
+ workflow := test.GetBaseSonataFlow(ns)
+ platform := test.GetBasePlatformInReadyPhase(t.Name())
+ config := test.GetSonataFlowBuilderConfig(ns)
+ namespacedName := types.NamespacedName{Namespace: workflow.Namespace,
Name: workflow.Name}
+ client :=
test.NewKogitoClientBuilderWithOpenShift().WithRuntimeObjects(workflow,
platform, config).Build()
+ buildClient := buildfake.NewSimpleClientset().BuildV1()
+ managerContext := buildManagerContext{
+ ctx: context.TODO(),
+ client: client,
+ platform: platform,
+ builderConfigMap: config,
+ }
+
+ buildManager := newOpenShiftBuilderManagerWithClient(managerContext,
buildClient)
+ // End Setup
+
+ // Schedule a build
+ kogitoBuildManager := NewSonataFlowBuildManager(context.TODO(), client)
+ kbuild, err := kogitoBuildManager.GetOrCreateBuild(workflow)
+ assert.NoError(t, err)
+ assert.NotNil(t, kbuild)
+ assert.NoError(t, buildManager.Schedule(kbuild))
+
+ bc := &buildv1.BuildConfig{}
+ assert.NoError(t, client.Get(context.TODO(), namespacedName, bc))
+
+ // verify if we set force pull to BC
+ assert.True(t, bc.Spec.Strategy.DockerStrategy.ForcePull)
+}
diff --git a/controllers/platform/platformutils.go
b/controllers/platform/platformutils.go
index f88863bf..f3978b74 100644
--- a/controllers/platform/platformutils.go
+++ b/controllers/platform/platformutils.go
@@ -161,8 +161,12 @@ func GetRegistryAddress(ctx context.Context, c
client.Client) (*string, error) {
// GetCustomizedBuilderDockerfile gets the Dockerfile as defined in the
default platform ConfigMap, apply any custom requirements and return.
func GetCustomizedBuilderDockerfile(dockerfile string, platform
operatorapi.SonataFlowPlatform) string {
if len(platform.Spec.Build.Config.BaseImage) > 0 {
- res :=
builderDockerfileFromRE.FindAllStringSubmatch(dockerfile, 1)
- dockerfile = strings.Replace(dockerfile,
strings.Trim(res[0][1], " "), platform.Spec.Build.Config.BaseImage, 1)
+ dockerfile = strings.Replace(dockerfile,
GetFromImageTagDockerfile(dockerfile), platform.Spec.Build.Config.BaseImage, 1)
}
return dockerfile
}
+
+func GetFromImageTagDockerfile(dockerfile string) string {
+ res := builderDockerfileFromRE.FindAllStringSubmatch(dockerfile, 1)
+ return strings.Trim(res[0][1], " ")
+}
diff --git a/utils/kubernetes/image.go b/utils/kubernetes/image.go
index d7e0b495..93c317c7 100644
--- a/utils/kubernetes/image.go
+++ b/utils/kubernetes/image.go
@@ -23,6 +23,7 @@ import (
// GetImagePullPolicy gets the default corev1.PullPolicy depending on the
image tag specified.
// It follows the conventions of docker client and OpenShift. If no tag
specified, it assumes latest.
// Returns PullAlways if latest tag, empty otherwise to let the cluster figure
it out.
+// See: https://kubernetes.io/docs/concepts/containers/images/#updating-images
func GetImagePullPolicy(imageTag string) corev1.PullPolicy {
if len(imageTag) == 0 {
return ""
@@ -31,9 +32,20 @@ func GetImagePullPolicy(imageTag string) corev1.PullPolicy {
if idx < 0 {
return corev1.PullAlways
}
- tag := imageTag[idx+1:]
- if tag == "latest" {
+ if GetImageTag(imageTag) == "latest" {
return corev1.PullAlways
}
return ""
}
+
+// GetImageTag gets the tag after `:` in an image tag or empty if not found.
+func GetImageTag(imageTag string) string {
+ if len(imageTag) == 0 {
+ return ""
+ }
+ idx := strings.LastIndex(imageTag, ":")
+ if idx < 0 {
+ return ""
+ }
+ return imageTag[idx+1:]
+}
diff --git a/utils/kubernetes/image_test.go b/utils/kubernetes/image_test.go
index 1ba1d167..e9a4b073 100644
--- a/utils/kubernetes/image_test.go
+++ b/utils/kubernetes/image_test.go
@@ -37,6 +37,7 @@ func TestGetImagePullPolicy(t *testing.T) {
{"Long name with tag",
args{"gcr.io/knative-releases/knative.dev/eventing/cmd/event_display:1.2"}, ""},
{"Empty tag", args{""}, ""},
{"Messy tag", args{":"}, ""},
+ {"Sha tag",
args{"ubuntu@sha256:3235326357dfb65f1781dbc4df3b834546d8bf914e82cce58e6e6b676e23ce8f"},
""},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
diff --git a/workflowproj/go.mod b/workflowproj/go.mod
index 79e952d3..2afe69b0 100644
--- a/workflowproj/go.mod
+++ b/workflowproj/go.mod
@@ -2,6 +2,8 @@ module
github.com/apache/incubator-kie-kogito-serverless-operator/workflowproj
go 1.21
+toolchain go1.21.6
+
// Internal dependencies
replace github.com/apache/incubator-kie-kogito-serverless-operator/api v0.0.0
=> ../api
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]