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

Add ability to set extra environmental variables through downward API #1077

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dezmodue
Copy link

@dezmodue dezmodue commented Nov 25, 2024

This PR provides a way to set extra environmental variables through the downward API.
Why?
When managing multiple clusters often the difference between helm values boils down to the authPath which is set to a path including the cluster unique ID.
With the latest release of ArgoCD it is now possible to leverage the argocd.argoproj.io/tracking-id annotation to provide the cluster ID to every deployment.
Leveraging the downward API we can programmatically read the cluster ID from the argocd.argoproj.io/tracking-id annotation and set the authPath for all clusters programmatically without the need for a cluster specific value file.

Example:
Generate the injector deployment:

helm template --show-only templates/injector-deployment.yaml \
--set 'injector.annotations.argocd\.argoproj\.io/tracking-id=cluster-1234' \  
--set "injector.extraEnvironmentVarsFieldPath.CLUSTER_ID=metadata.annotations['argocd.argoproj.io/tracking-id']" \
--set 'injector.authPath=/auth/Kubernetes/$(CLUSTER_ID)' .

This will produce the yaml:

...
  template:
    metadata:
      labels:
        app.kubernetes.io/name: vault-agent-injector
        app.kubernetes.io/instance: release-name
        component: webhook
      annotations:
        argocd.argoproj.io/tracking-id: cluster-1234
...
          env:
            - name: "CLUSTER_ID"
              valueFrom:
                fieldRef:
                  fieldPath: metadata.annotations['argocd.argoproj.io/tracking-id']
...
            - name: AGENT_INJECT_VAULT_AUTH_PATH
              value: /auth/Kubernetes/$(CLUSTER_ID)

The resulting env in the running pod shows:

CLUSTER_ID=cluster-1234
AGENT_INJECT_VAULT_AUTH_PATH=/auth/Kubernetes/cluster-1234

The generated Env variables and configuration is valid for any cluster removing the need for cluster specific values

@dezmodue dezmodue requested a review from a team as a code owner November 25, 2024 21:08
Copy link

hashicorp-cla-app bot commented Nov 25, 2024

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant