Skip to content

Commit 9dcd961

Browse files
larsoreevenh
authored andcommitted
Add feature flag to enable locally built images.
1 parent 6c3ca31 commit 9dcd961

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

pkg/flags/flags.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ var FeatureFlags *Features
1515
type Features struct {
1616
DisablePodTopologySpreadConstraints bool
1717
EnableProfiling bool
18+
EnableLocallyBuiltImages bool
1819
}
1920

2021
func init() {
2122
FeatureFlags = &Features{
2223
DisablePodTopologySpreadConstraints: getEnvWithFallback("DISABLE_PTSC", false),
2324
EnableProfiling: getEnvWithFallback("ENABLE_PROFILING", false),
25+
EnableLocallyBuiltImages: getEnvWithFallback("ENABLE_LOCAL_IMAGES", false),
2426
}
2527
}
2628

pkg/resourcegenerator/deployment/deployment.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package deployment
33
import (
44
goerrors "errors"
55
"fmt"
6+
"github.com/kartverket/skiperator/pkg/flags"
67
"strings"
78

89
"github.com/kartverket/skiperator/pkg/reconciliation"
@@ -215,13 +216,16 @@ func Generate(r reconciliation.Reconciliation) error {
215216
deployment.Annotations[AnnotationKeyLinkPrefix] = fmt.Sprintf("https://%s", ingresses[0])
216217
}
217218

218-
err = util.ResolveImageTags(r.GetCtx(), ctxLog.GetLogger(), r.GetRestConfig(), &deployment)
219-
if err != nil {
220-
//TODO fix this
221-
// Exclude dummy image used in tests for decreased verbosity
222-
if !strings.Contains(err.Error(), "https://index.docker.io/v2/library/image/manifests/latest") {
223-
ctxLog.Error(err, "could not resolve container image to digest")
224-
return err
219+
// Global feature flag
220+
if !flags.FeatureFlags.EnableLocallyBuiltImages {
221+
err = util.ResolveImageTags(r.GetCtx(), ctxLog.GetLogger(), r.GetRestConfig(), &deployment)
222+
if err != nil {
223+
//TODO fix this
224+
// Exclude dummy image used in tests for decreased verbosity
225+
if !strings.Contains(err.Error(), "https://index.docker.io/v2/library/image/manifests/latest") {
226+
ctxLog.Error(err, "could not resolve container image to digest")
227+
return err
228+
}
225229
}
226230
}
227231

pkg/resourcegenerator/pod/pod.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,17 @@ func CreatePodSpec(containers []corev1.Container, volumes []corev1.Volume, servi
7575
}
7676

7777
func CreateApplicationContainer(application *skiperatorv1alpha1.Application, opts PodOpts) corev1.Container {
78+
imagePullPolicy := func() corev1.PullPolicy {
79+
if flags.FeatureFlags.EnableLocallyBuiltImages {
80+
return corev1.PullNever
81+
}
82+
return corev1.PullAlways
83+
}()
84+
7885
return corev1.Container{
7986
Name: application.Name,
8087
Image: application.Spec.Image,
81-
ImagePullPolicy: corev1.PullAlways,
88+
ImagePullPolicy: imagePullPolicy,
8289
Command: application.Spec.Command,
8390
SecurityContext: &corev1.SecurityContext{
8491
Privileged: util.PointTo(false),

0 commit comments

Comments
 (0)