Skip to content

Instantly share code, notes, and snippets.

@maxmoehl
Last active September 4, 2024 09:24
Show Gist options
  • Save maxmoehl/7fe32619f8503b5d29abfcc0e0f9e7df to your computer and use it in GitHub Desktop.
Save maxmoehl/7fe32619f8503b5d29abfcc0e0f9e7df to your computer and use it in GitHub Desktop.
Add the git commit hash to all resources. Due to a bug in kustomize the script will have to be in your path for this to work. Once the bug is fixed it should be possible to have the script relative to the kustomization file.
#!/usr/bin/env bash
# https://mikefarah.gitbook.io/yq/
yq ".items[].metadata.labels += {\"app.kubernetes.io/version\": \"$(git rev-parse HEAD)\"}" < /dev/stdin
apiVersion: internal
kind: GitCommitLabel
metadata:
name: whatever
annotations:
config.kubernetes.io/function: |
exec:
path: git_commit_label.sh
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
transformers:
- gitCommitLabel.yml
# ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment