From c0914743b07ef65401f6701d5164b9a48c150f1f Mon Sep 17 00:00:00 2001 From: David Liao Date: Wed, 8 Jul 2020 23:53:52 -0700 Subject: [PATCH] add config to respect image pull policy --- README.md | 4 ++-- api/v1alpha1/runner_types.go | 2 ++ .../bases/actions.summerwind.dev_runnerdeployments.yaml | 4 ++++ .../bases/actions.summerwind.dev_runnerreplicasets.yaml | 4 ++++ config/crd/bases/actions.summerwind.dev_runners.yaml | 4 ++++ controllers/runner_controller.go | 7 ++++++- 6 files changed, 22 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 60d211dd..518ccea9 100644 --- a/README.md +++ b/README.md @@ -250,8 +250,8 @@ spec: operator: Exists repository: mumoshu/actions-runner-controller-ci - ImagePullPolicy: Always image: custom-image/actions-runner:latest + imagePullPolicy: Always resources: limits: cpu: "4.0" @@ -317,7 +317,7 @@ The container image is based on Ubuntu 18.04, but it does not contain all of the * docker * build-essentials -The virtual environments from GitHub contain a lot more software packages (different versions of Java, Node.js, Golang, .NET, etc) which are not provided in the runner image. Most of these have dedicated setup actions which allow the tools to be installed on-demand in a workflow, for example: `actions/setup-java` or `actions/setup-node` +The virtual environments from GitHub contain a lot more software packages (different versions of Java, Node.js, Golang, .NET, etc) which are not provided in the runner image. Most of these have dedicated setup actions which allow the tools to be installed on-demand in a workflow, for example: `actions/setup-java` or `actions/setup-node` If there is a need to include packages in the runner image for which there is no setup action, then this can be achieved by building a custom container image for the runner. The easiest way is to start with the `summerwind/actions-runner` image and installing the extra dependencies directly in the docker image: diff --git a/api/v1alpha1/runner_types.go b/api/v1alpha1/runner_types.go index 285eac51..b6f9ad24 100644 --- a/api/v1alpha1/runner_types.go +++ b/api/v1alpha1/runner_types.go @@ -48,6 +48,8 @@ type RunnerSpec struct { // +optional Image string `json:"image"` // +optional + ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"` + // +optional Env []corev1.EnvVar `json:"env,omitempty"` // +optional diff --git a/config/crd/bases/actions.summerwind.dev_runnerdeployments.yaml b/config/crd/bases/actions.summerwind.dev_runnerdeployments.yaml index 329cc35e..47a6d148 100644 --- a/config/crd/bases/actions.summerwind.dev_runnerdeployments.yaml +++ b/config/crd/bases/actions.summerwind.dev_runnerdeployments.yaml @@ -3019,6 +3019,10 @@ spec: type: array image: type: string + imagePullPolicy: + description: PullPolicy describes a policy for if/when to pull + a container image + type: string imagePullSecrets: items: description: LocalObjectReference contains enough information diff --git a/config/crd/bases/actions.summerwind.dev_runnerreplicasets.yaml b/config/crd/bases/actions.summerwind.dev_runnerreplicasets.yaml index 06216a1e..478ea92a 100644 --- a/config/crd/bases/actions.summerwind.dev_runnerreplicasets.yaml +++ b/config/crd/bases/actions.summerwind.dev_runnerreplicasets.yaml @@ -3006,6 +3006,10 @@ spec: type: array image: type: string + imagePullPolicy: + description: PullPolicy describes a policy for if/when to pull + a container image + type: string imagePullSecrets: items: description: LocalObjectReference contains enough information diff --git a/config/crd/bases/actions.summerwind.dev_runners.yaml b/config/crd/bases/actions.summerwind.dev_runners.yaml index 4450d325..94a50497 100644 --- a/config/crd/bases/actions.summerwind.dev_runners.yaml +++ b/config/crd/bases/actions.summerwind.dev_runners.yaml @@ -2815,6 +2815,10 @@ spec: type: array image: type: string + imagePullPolicy: + description: PullPolicy describes a policy for if/when to pull a container + image + type: string imagePullSecrets: items: description: LocalObjectReference contains enough information to let diff --git a/controllers/runner_controller.go b/controllers/runner_controller.go index 52f9ab3f..8314424a 100644 --- a/controllers/runner_controller.go +++ b/controllers/runner_controller.go @@ -261,6 +261,11 @@ func (r *RunnerReconciler) newPod(runner v1alpha1.Runner) (corev1.Pod, error) { runnerImage = r.RunnerImage } + runnerImagePullPolicy := runner.Spec.ImagePullPolicy + if runnerImagePullPolicy == "" { + runnerImagePullPolicy = corev1.PullAlways + } + env := []corev1.EnvVar{ { Name: "RUNNER_NAME", @@ -298,7 +303,7 @@ func (r *RunnerReconciler) newPod(runner v1alpha1.Runner) (corev1.Pod, error) { { Name: containerName, Image: runnerImage, - ImagePullPolicy: "Always", + ImagePullPolicy: runnerImagePullPolicy, Env: env, EnvFrom: runner.Spec.EnvFrom, VolumeMounts: []corev1.VolumeMount{