From 9e25c3a6a81b78895bbf9172ffbf2166269617ac Mon Sep 17 00:00:00 2001 From: Teodor Date: Thu, 18 Jul 2024 04:57:10 +0300 Subject: [PATCH] fix: add support for imagePullPolicy for installer daemonsets (#395) Signed-off-by: Teodor --- controllers/ccruntime_controller.go | 4 ++-- controllers/common.go | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/controllers/ccruntime_controller.go b/controllers/ccruntime_controller.go index 8a79cf76..de0f12c1 100644 --- a/controllers/ccruntime_controller.go +++ b/controllers/ccruntime_controller.go @@ -722,7 +722,7 @@ func (r *CcRuntimeReconciler) processDaemonset(operation DaemonOperation) *appsv { Name: "cc-runtime-install-pod", Image: r.ccRuntime.Spec.Config.PayloadImage, - ImagePullPolicy: "Always", + ImagePullPolicy: imagePullPolicyOrDefault(r.ccRuntime.Spec.Config.ImagePullPolicy), Lifecycle: preStopHook, SecurityContext: &corev1.SecurityContext{ // TODO - do we really need to run as root? @@ -917,7 +917,7 @@ func (r *CcRuntimeReconciler) makeHookDaemonset(operation DaemonOperation) *apps { Name: "cc-runtime-" + string(operation) + "-pod", Image: image, - ImagePullPolicy: "Always", + ImagePullPolicy: imagePullPolicyOrDefault(r.ccRuntime.Spec.Config.ImagePullPolicy), SecurityContext: &corev1.SecurityContext{ Privileged: &runPrivileged, RunAsUser: &runAsUser, diff --git a/controllers/common.go b/controllers/common.go index 4fe8e016..22e4ca02 100644 --- a/controllers/common.go +++ b/controllers/common.go @@ -1,5 +1,9 @@ package controllers +import ( + corev1 "k8s.io/api/core/v1" +) + // DaemonOperation represents the operation the daemon is going to perform type DaemonOperation string @@ -26,6 +30,8 @@ const ( UpgradeOperation DaemonOperation = "upgrade" RuntimeConfigFinalizer = "runtimeconfig.confidentialcontainers.org/finalizer" + + DefaultImagePullPolicy = corev1.PullAlways ) func contains(list []string, s string) bool { @@ -36,3 +42,10 @@ func contains(list []string, s string) bool { } return false } + +func imagePullPolicyOrDefault(policy corev1.PullPolicy) corev1.PullPolicy { + if policy == "" { + return DefaultImagePullPolicy + } + return policy +}