Skip to content

Commit d60ffff

Browse files
author
Yannick Roffin
committed
feat(runner-config): ✨ permit to override imagePullPolicy in runnerPod template
1 parent cb032d4 commit d60ffff

File tree

7 files changed

+117
-1
lines changed

7 files changed

+117
-1
lines changed

api/v1alpha2/reference_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ type RunnerPodSpec struct {
163163
// +optional
164164
Image string `json:"image,omitempty"`
165165

166+
// Runner pod ImagePullPolicy to use other than default
167+
// +optional
168+
ImagePullPolicy string `json:"imagePullPolicy,omitempty"`
169+
166170
// List of sources to populate environment variables in the container.
167171
// The keys defined within a source must be a C_IDENTIFIER. All invalid keys
168172
// will be reported as an event when the container is starting. When a key exists in multiple

charts/tofu-controller/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ __Note__: If you need to use the `imagePullSecrets` it would be best to set `ser
8484
| runner.grpc.maxMessageSize | int | `4` | Maximum GRPC message size (Controller) |
8585
| runner.image.repository | string | `"ghcr.io/flux-iac/tf-runner"` | Runner image repository |
8686
| runner.image.tag | string | `.Chart.AppVersion` | Runner image tag |
87+
| runner.imagePullPolicy | string | `IfNotPresent, Always, Never` | Runner image pull policy |
8788
| runner.serviceAccount.allowedNamespaces | list | `["flux-system"]` | List of namespaces that the runner may run within (in addition to namespace of the controller itself) |
8889
| runner.serviceAccount.annotations | object | `{}` | Additional runner service Account annotations |
8990
| runner.serviceAccount.create | bool | `true` | If `true`, create a new runner service account |

charts/tofu-controller/crds/crds.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6743,6 +6743,10 @@ spec:
67436743
image:
67446744
description: Runner pod image to use other than default
67456745
type: string
6746+
imagePullPolicy:
6747+
description: Runner pod ImagePullPolicy to use other than
6748+
default
6749+
type: string
67466750
initContainers:
67476751
description: Set up Init Containers for the Runner
67486752
items:

config/crd/bases/infra.contrib.fluxcd.io_terraforms.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6743,6 +6743,10 @@ spec:
67436743
image:
67446744
description: Runner pod image to use other than default
67456745
type: string
6746+
imagePullPolicy:
6747+
description: Runner pod ImagePullPolicy to use other than
6748+
default
6749+
type: string
67466750
initContainers:
67476751
description: Set up Init Containers for the Runner
67486752
items:

controllers/tc000260_runner_pod_test.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ func Test_000260_runner_pod_test(t *testing.T) {
7373
spec := reconciler.runnerPodSpec(helloWorldTF, "runner.tls-123")
7474
g.Expect(spec.ServiceAccountName).To(Equal(serviceAccountName))
7575
g.Expect(spec.Containers[0].Image).To(Equal(runnerPodImage))
76+
g.Expect(spec.Containers[0].ImagePullPolicy).To(Equal(corev1.PullIfNotPresent))
7677
g.Expect(spec.HostAliases[0].Hostnames).To(Equal([]string{"foo", "bar"}))
7778

7879
podTemplate, err := runnerPodTemplate(helloWorldTF, "runner.tls-123", revision)
@@ -178,6 +179,76 @@ func Test_000260_runner_pod_test_env_vars(t *testing.T) {
178179
}()).To(BeTrue())
179180
}
180181

182+
func Test_000260_runner_pod_a_test_image_pull_policy(t *testing.T) {
183+
Spec("This spec describes a runner pod creation process")
184+
185+
const (
186+
terraformName = "runner-pod-test"
187+
sourceName = "runner-pod-test"
188+
serviceAccountName = "helloworld-tf-runner"
189+
runnerPodImage = "ghcr.io/weaveworks/tf-runner:test"
190+
revision = "v2.6@sha256:c7fd0cc69b924aa5f9a6928477311737e439ca1b9e444855b0377e8a8ec65bb5"
191+
)
192+
193+
var stringMap = map[string]string{
194+
"company.com/abc": "xyz",
195+
"company.com/xyz": "abc",
196+
"tf.weave.works/tls-secret-name": "runner.tls-123",
197+
}
198+
199+
g := NewWithT(t)
200+
201+
It("generate a runner pod template")
202+
By("passing a terraform object, the runner pod template should be accurate")
203+
helloWorldTF := infrav1.Terraform{
204+
ObjectMeta: metav1.ObjectMeta{
205+
Name: terraformName,
206+
Namespace: "flux-system",
207+
},
208+
Spec: infrav1.TerraformSpec{
209+
ApprovePlan: "auto",
210+
Path: "./terraform-hello-world-example",
211+
SourceRef: infrav1.CrossNamespaceSourceReference{
212+
Kind: "GitRepository",
213+
Name: sourceName,
214+
Namespace: "flux-system",
215+
},
216+
ServiceAccountName: serviceAccountName,
217+
RunnerPodTemplate: infrav1.RunnerPodTemplate{
218+
Metadata: infrav1.RunnerPodMetadata{
219+
Labels: stringMap,
220+
Annotations: stringMap,
221+
},
222+
Spec: infrav1.RunnerPodSpec{
223+
Image: runnerPodImage,
224+
ImagePullPolicy: "Always",
225+
},
226+
},
227+
},
228+
}
229+
230+
spec := reconciler.runnerPodSpec(helloWorldTF, "runner.tls-123")
231+
g.Expect(spec.ServiceAccountName).To(Equal(serviceAccountName))
232+
g.Expect(spec.Containers[0].Image).To(Equal(runnerPodImage))
233+
g.Expect(spec.Containers[0].ImagePullPolicy).To(Equal(corev1.PullAlways))
234+
235+
podTemplate, err := runnerPodTemplate(helloWorldTF, "runner.tls-123", revision)
236+
g.Expect(err).ToNot(HaveOccurred())
237+
g.Expect(func() bool {
238+
for k, v := range stringMap {
239+
if v != podTemplate.ObjectMeta.Labels[k] {
240+
return false
241+
}
242+
}
243+
for k, v := range stringMap {
244+
if v != podTemplate.ObjectMeta.Annotations[k] {
245+
return false
246+
}
247+
}
248+
return true
249+
}()).To(BeTrue())
250+
}
251+
181252
func Test_000260_runner_pod_test_env_vars_proxy(t *testing.T) {
182253
Spec("This spec describes a runner pod creation process")
183254

controllers/tf_controller_runner.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ func getRunnerPodImage(image string) string {
3939
return runnerPodImage
4040
}
4141

42+
func getRunnerImagePullPolicy(imagePullPolicy string) v1.PullPolicy {
43+
runnerImagePullPolicy := v1.PullPolicy(imagePullPolicy)
44+
if runnerImagePullPolicy == "" {
45+
runnerImagePullPolicy = v1.PullIfNotPresent
46+
}
47+
return runnerImagePullPolicy
48+
}
49+
4250
func runnerPodTemplate(terraform infrav1.Terraform, secretName string, revision string) (v1.Pod, error) {
4351
podNamespace := terraform.Namespace
4452
podName := fmt.Sprintf("%s-tf-runner", terraform.Name)
@@ -272,7 +280,7 @@ func (r *TerraformReconciler) runnerPodSpec(terraform infrav1.Terraform, tlsSecr
272280
"--grpc-max-message-size", fmt.Sprintf("%d", r.RunnerGRPCMaxMessageSize),
273281
},
274282
Image: getRunnerPodImage(terraform.Spec.RunnerPodTemplate.Spec.Image),
275-
ImagePullPolicy: v1.PullIfNotPresent,
283+
ImagePullPolicy: getRunnerImagePullPolicy(terraform.Spec.RunnerPodTemplate.Spec.ImagePullPolicy),
276284
Ports: []v1.ContainerPort{
277285
{
278286
Name: "grpc",

docs/References/terraform.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,18 @@ string
868868
</tr>
869869
<tr>
870870
<td>
871+
<code>imagePullPolicy</code><br>
872+
<em>
873+
string
874+
</em>
875+
</td>
876+
<td>
877+
<em>(Optional)</em>
878+
<p>Runner pod ImagePullPolicy to use other than default</p>
879+
</td>
880+
</tr>
881+
<tr>
882+
<td>
871883
<code>envFrom</code><br>
872884
<em>
873885
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#envfromsource-v1-core">
@@ -1097,6 +1109,18 @@ string
10971109
</tr>
10981110
<tr>
10991111
<td>
1112+
<code>imagePullPolicy</code><br>
1113+
<em>
1114+
string
1115+
</em>
1116+
</td>
1117+
<td>
1118+
<em>(Optional)</em>
1119+
<p>Runner pod ImagePullPolicy to use other than default</p>
1120+
</td>
1121+
</tr>
1122+
<tr>
1123+
<td>
11001124
<code>envFrom</code><br>
11011125
<em>
11021126
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#envfromsource-v1-core">

0 commit comments

Comments
 (0)