Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add imagePullPolicy template #79

Merged
merged 3 commits into from
Mar 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/operator/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ spec:
value: {{ .Values.kubernetesClusterDomain }}
image: {{ .Values.controllerManager.manager.image.repository }}:{{ .Values.controllerManager.manager.image.tag
| default .Chart.AppVersion }}
imagePullPolicy: {{ .Values.controllerManager.manager.imagePullPolicy }}
livenessProbe:
httpGet:
path: /healthz
Expand Down
1 change: 1 addition & 0 deletions examples/operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ controllerManager:
image:
repository: controller
tag: latest
imagePullPolicy: Always
resources:
limits:
cpu: 100m
Expand Down
9 changes: 9 additions & 0 deletions pkg/processor/deployment/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const selectorTempl = `%[1]s
{{- include "%[2]s.selectorLabels" . | nindent 6 }}
%[3]s`

const imagePullPolicyTemplate = "{{ .Values.%[1]s.%[2]s.imagePullPolicy }}"
const envValue = "{{ .Values.%[1]s.%[2]s.%[3]s }}"

// New creates processor for k8s Deployment resource.
Expand Down Expand Up @@ -277,6 +278,14 @@ func processPodContainer(name string, appMeta helmify.AppMetadata, c corev1.Cont
return c, errors.Wrap(err, "unable to set container resources value")
}
}

if c.ImagePullPolicy != "" {
err = unstructured.SetNestedField(*values, string(c.ImagePullPolicy), name, containerName, "imagePullPolicy")
if err != nil {
return c, errors.Wrap(err, "unable to set container imagePullPolicy")
}
c.ImagePullPolicy = corev1.PullPolicy(fmt.Sprintf(imagePullPolicyTemplate, name, containerName))
}
return c, nil
}

Expand Down
1 change: 1 addition & 0 deletions test_data/k8s-operator-kustomize.output
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@ spec:
resourceFieldRef:
resource: limits.cpu
image: controller:latest
imagePullPolicy: Always
livenessProbe:
httpGet:
path: /healthz
Expand Down