Dynamic variable use in kustomize yaml

Hi Team,

May I know how to use the dynamic variable in kustomize file?

requesting to get the cluster name and update the value.yaml file. before converting the file as secret in argocd?

Example:-

#cat kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

generatorOptions:
disableNameSuffixHash: true

secretGenerator:

  • name: fluent-data-values
    namespace: fluentd
    files:
    • values.yml

resources:

  • deployment.yaml

=============================
#cat values.yml
namespace: “fluentd”
fluent:
config:
service: |
@SET cluster= k8sclustername # replace this k8sclustername from "kubectl get nodes -o=json| jq '.items[0].metadata.annotations."cluster.x-k8s.io/cluster-name"'"

Hi @kantharajmuruganc

It’s a lab or your personal project ? If it’s a lab can you please give us more info on it. if it’s a personal project please provide us more detail

Regard

Its personal project.

The kustomize file have value.yaml for generate the secret. The dynamic variable need to update in value.yaml file before generate the secret.

“kubectl get nodes -o=json| jq '.items[0].metadata.annotations.”[cluster.x-k8s.io/cluster-name"'"]

===============
secretGenerator:

  • name: fluent-data-values
    namespace: fluentd
    files:
    • values.yml
      ============

#cat values.yml
namespace: “fluentd”
fluent:
config:
service: |
@SET cluster= k8sclustername # replace this k8sclustername from "kubectl get nodes -o=json| jq '.items[0].metadata.annotations."cluster.x-k8s.io/cluster-name"'"