I'm looking for a better way to update docker images defined ina HelmRelease using GitOps, as my current method is generating noise.
After introducing Helm to a cluster I'm managing with GitOps, I'm finding some difficulties on how to properly declare new docker image builds to be used in the cluster.
In a deployment I can use a simple Kustomization resource to replace image elements, e.g.:
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: my-namespace
resources:
- namespace.yaml
- my-deployment.yaml
images:
- name: my/image
newName: my/image
newTag: updated-tag
and with every new build I simply modify the file with
kustomize edit set image my/image=my/image:updated-tag
Now with Helm I cannot use the same trick, as I need to update the tag spec.values.image
in a HelmRelease, and Kustomize does not seem to have a shorthand for that. So the option is to create a patch:
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: my-namespace
resources:
- namespace.yaml
- my-helm-release.yaml
patches:
- patch: '[{"op": "replace", "path": "/spec/values/image", "value": "my/image:updated-tag"}]'
target:
kind: HelmRelease
name: my-helm-release
namespace: my-namespace
by using a similar command:
kustomize edit add patch \
--kind HelmRelease \
--name my-helm-release \
--namespace my-namespace --patch "[{\"op\": \"replace\", \"path\": \"/spec/values/image\", \"value\": \"my/image:updated-tag\"}]"
(don't mind much the quoted quotes, bear with me)
The problem comes when running multiple times this command. While the kustomize edit set image
overwrites the previous value, in this later case a new patch
is appended to the list with the more-updated-tag
.
patches:
- patch: '[{"op": "replace", "path": "/spec/values/image", "value": "my/image:updated-tag"}]'
target:
kind: HelmRelease
name: my-helm-release
namespace: my-namespace
- patch: '[{"op": "replace", "path": "/spec/values/image", "value": "my/image:more-updated-tag"}]'
target:
kind: HelmRelease
name: my-helm-release
namespace: my-namespace
How can I avoid this repetition and adding more and more noise to my files?
Thanks!
found a cleaner way to do it with yq.