From 0a135173b463b708d8676ea28f18ba4aa855ba09 Mon Sep 17 00:00:00 2001 From: Ta-Ching Chen Date: Wed, 19 Dec 2018 22:35:28 +0800 Subject: [PATCH] Fix builder & newdeploy not using latest image during CI build (#1033) --- buildermgr/envwatcher.go | 22 +++++------------- charts/fission-all/templates/deployment.yaml | 2 ++ charts/fission-core/templates/deployment.yaml | 2 ++ common.go | 12 ++++++++++ executor/newdeploy/newdeploy.go | 2 +- executor/newdeploy/newdeploymgr.go | 15 +++++++----- executor/poolmgr/gp.go | 23 ++----------------- 7 files changed, 34 insertions(+), 44 deletions(-) diff --git a/buildermgr/envwatcher.go b/buildermgr/envwatcher.go index ee80b867..b5a6f449 100644 --- a/buildermgr/envwatcher.go +++ b/buildermgr/envwatcher.go @@ -80,6 +80,7 @@ type ( kubernetesClient *kubernetes.Clientset fetcherImage string fetcherImagePullPolicy apiv1.PullPolicy + builderImagePullPolicy apiv1.PullPolicy useIstio bool } ) @@ -102,20 +103,8 @@ func makeEnvironmentWatcher(fissionClient *crd.FissionClient, fetcherImage = "fission/fetcher" } - fetcherImagePullPolicy := os.Getenv("FETCHER_IMAGE_PULL_POLICY") - if len(fetcherImagePullPolicy) == 0 { - fetcherImagePullPolicy = "IfNotPresent" - } - - var pullPolicy apiv1.PullPolicy - switch fetcherImagePullPolicy { - case "Always": - pullPolicy = apiv1.PullAlways - case "Never": - pullPolicy = apiv1.PullNever - default: - pullPolicy = apiv1.PullIfNotPresent - } + fetcherImagePullPolicy := fission.GetImagePullPolicy(os.Getenv("FETCHER_IMAGE_PULL_POLICY")) + builderImagePullPolicy := fission.GetImagePullPolicy(os.Getenv("BUILDER_IMAGE_PULL_POLICY")) envWatcher := &environmentWatcher{ cache: make(map[string]*builderInfo), @@ -124,7 +113,8 @@ func makeEnvironmentWatcher(fissionClient *crd.FissionClient, fissionClient: fissionClient, kubernetesClient: kubernetesClient, fetcherImage: fetcherImage, - fetcherImagePullPolicy: pullPolicy, + fetcherImagePullPolicy: fetcherImagePullPolicy, + builderImagePullPolicy: builderImagePullPolicy, useIstio: useIstio, } @@ -547,7 +537,7 @@ func (envw *environmentWatcher) createBuilderDeployment(env *crd.Environment, ns fission.MergeContainerSpecs(&apiv1.Container{ Name: "builder", Image: env.Spec.Builder.Image, - ImagePullPolicy: apiv1.PullIfNotPresent, + ImagePullPolicy: envw.builderImagePullPolicy, TerminationMessagePath: "/dev/termination-log", VolumeMounts: []apiv1.VolumeMount{ { diff --git a/charts/fission-all/templates/deployment.yaml b/charts/fission-all/templates/deployment.yaml index 6e4ce833..f10046ab 100644 --- a/charts/fission-all/templates/deployment.yaml +++ b/charts/fission-all/templates/deployment.yaml @@ -328,6 +328,8 @@ spec: value: "{{ .Values.fetcherImage }}:{{ .Values.fetcherImageTag }}" - name: FETCHER_IMAGE_PULL_POLICY value: "{{ .Values.pullPolicy }}" + - name: BUILDER_IMAGE_PULL_POLICY + value: "{{ .Values.pullPolicy }}" - name: ENABLE_ISTIO value: "{{ .Values.enableIstio }}" serviceAccount: fission-svc diff --git a/charts/fission-core/templates/deployment.yaml b/charts/fission-core/templates/deployment.yaml index 2f90c74c..b20612b0 100644 --- a/charts/fission-core/templates/deployment.yaml +++ b/charts/fission-core/templates/deployment.yaml @@ -309,6 +309,8 @@ spec: value: "{{ .Values.fetcherImage }}:{{ .Values.fetcherImageTag }}" - name: FETCHER_IMAGE_PULL_POLICY value: "{{ .Values.pullPolicy }}" + - name: BUILDER_IMAGE_PULL_POLICY + value: "{{ .Values.pullPolicy }}" - name: ENABLE_ISTIO value: "{{ .Values.enableIstio }}" serviceAccount: fission-svc diff --git a/common.go b/common.go index 78f99906..a487201c 100644 --- a/common.go +++ b/common.go @@ -184,3 +184,15 @@ func RemoveZeroBytes(src []byte) []byte { } return bs } + +// GetImagePullPolicy returns the image pull policy base on the input value. +func GetImagePullPolicy(policy string) apiv1.PullPolicy { + switch policy { + case "Always": + return apiv1.PullAlways + case "Never": + return apiv1.PullNever + default: + return apiv1.PullIfNotPresent + } +} diff --git a/executor/newdeploy/newdeploy.go b/executor/newdeploy/newdeploy.go index 03a1c336..36927df7 100644 --- a/executor/newdeploy/newdeploy.go +++ b/executor/newdeploy/newdeploy.go @@ -249,7 +249,7 @@ func (deploy *NewDeploy) getDeploymentSpec(fn *crd.Function, env *crd.Environmen fission.MergeContainerSpecs(&apiv1.Container{ Name: fn.Metadata.Name, Image: env.Spec.Runtime.Image, - ImagePullPolicy: apiv1.PullIfNotPresent, + ImagePullPolicy: deploy.runtimeImagePullPolicy, TerminationMessagePath: "/dev/termination-log", VolumeMounts: []apiv1.VolumeMount{ { diff --git a/executor/newdeploy/newdeploymgr.go b/executor/newdeploy/newdeploymgr.go index 32216d06..8461a765 100644 --- a/executor/newdeploy/newdeploymgr.go +++ b/executor/newdeploy/newdeploymgr.go @@ -52,6 +52,7 @@ type ( fetcherImg string fetcherImagePullPolicy apiv1.PullPolicy + runtimeImagePullPolicy apiv1.PullPolicy namespace string sharedMountPath string sharedSecretPath string @@ -125,17 +126,19 @@ func MakeNewDeploy( namespace: namespace, fsCache: fsCache, - fetcherImg: fetcherImg, - fetcherImagePullPolicy: apiv1.PullIfNotPresent, - sharedMountPath: "/userfunc", - sharedSecretPath: "/secrets", - sharedCfgMapPath: "/configs", - useIstio: enableIstio, + fetcherImg: fetcherImg, + sharedMountPath: "/userfunc", + sharedSecretPath: "/secrets", + sharedCfgMapPath: "/configs", + useIstio: enableIstio, requestChannel: make(chan *fnRequest), idlePodReapTime: 2 * time.Minute, } + nd.runtimeImagePullPolicy = fission.GetImagePullPolicy(os.Getenv("RUNTIME_IMAGE_PULL_POLICY")) + nd.fetcherImagePullPolicy = fission.GetImagePullPolicy(os.Getenv("FETCHER_IMAGE_PULL_POLICY")) + if nd.crdClient != nil { fnStore, fnController := nd.initFuncController() nd.funcStore = fnStore diff --git a/executor/poolmgr/gp.go b/executor/poolmgr/gp.go index f13140c9..0cb8e4e9 100644 --- a/executor/poolmgr/gp.go +++ b/executor/poolmgr/gp.go @@ -84,17 +84,6 @@ type ( } ) -func getImagePullPolicy(policy string) apiv1.PullPolicy { - switch policy { - case "Always": - return apiv1.PullAlways - case "Never": - return apiv1.PullNever - default: - return apiv1.PullIfNotPresent - } -} - func MakeGenericPool( fissionClient *crd.FissionClient, kubernetesClient *kubernetes.Clientset, @@ -112,14 +101,6 @@ func MakeGenericPool( if len(fetcherImage) == 0 { fetcherImage = "fission/fetcher" } - fetcherImagePullPolicy := os.Getenv("FETCHER_IMAGE_PULL_POLICY") - if len(fetcherImagePullPolicy) == 0 { - fetcherImagePullPolicy = "IfNotPresent" - } - runtimeImagePullPolicy := os.Getenv("RUNTIME_IMAGE_PULL_POLICY") - if len(runtimeImagePullPolicy) == 0 { - runtimeImagePullPolicy = "IfNotPresent" - } // TODO: in general we need to provide the user a way to configure pools. Initial // replicas, autoscaling params, various timeouts, etc. @@ -144,9 +125,9 @@ func MakeGenericPool( sharedCfgMapPath: "/configs", } - gp.runtimeImagePullPolicy = getImagePullPolicy(runtimeImagePullPolicy) + gp.runtimeImagePullPolicy = fission.GetImagePullPolicy(os.Getenv("RUNTIME_IMAGE_PULL_POLICY")) + gp.fetcherImagePullPolicy = fission.GetImagePullPolicy(os.Getenv("FETCHER_IMAGE_PULL_POLICY")) - gp.fetcherImagePullPolicy = getImagePullPolicy(fetcherImagePullPolicy) log.Printf("fetcher image: %v, pull policy: %v", gp.fetcherImage, gp.fetcherImagePullPolicy) // create fetcher SA in this ns, if not already created