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

Feature: surface metadata (e.g. sources status) as default substitution variables #887

Open
gberche-orange opened this issue Jun 16, 2023 · 0 comments

Comments

@gberche-orange
Copy link

As a kustomization author,
In order to leverage metadata about current flux context and kustomization in the rendered templates,
I need to get metadata as default substitution variables

This would be similar in intent to the K8S downward api
https://kubernetes.io/docs/concepts/workloads/pods/downward-api/

It is sometimes useful for a container to have information about itself, without being overly coupled to Kubernetes. The downward API allows containers to consume information about themselves or the cluster without using the Kubernetes client or API server.

Example metadata:

Example use-cases:

  • displaying git version into an application

Similar feature in other git ops controllers:

argo cd

https://argo-cd.readthedocs.io/en/stable/user-guide/kustomize/

Kustomize apps have access to the standard build environment which can be used in combination with a config managment plugin to alter the rendered manifests.

https://argo-cd.readthedocs.io/en/stable/user-guide/build-environment/

Kustomize support the following build env vars:

Variable Description
ARGOCD_APP_NAME The name of the application.
ARGOCD_APP_NAMESPACE The destination namespace of the application.
ARGOCD_APP_REVISION The resolved revision, e.g. f913b6cbf58aa5ae5ca1f8a2b149477aebcbd9d8.
ARGOCD_APP_SOURCE_PATH The path of the app within the source repo.
ARGOCD_APP_SOURCE_REPO_URL The source repo URL.
ARGOCD_APP_SOURCE_TARGET_REVISION The target revision from the spec, e.g. master.
KUBE_VERSION The version of Kubernetes.
KUBE_API_VERSIONS The version of the Kubernetes API.
[Kustomize](https://argo-cd.readthedocs.io/en/stable/user-guide/kustomize/) support the following build env vars: Variable Description ARGOCD_APP_NAME The name of the application. ARGOCD_APP_NAMESPACE The destination namespace of the application. ARGOCD_APP_REVISION The resolved revision, e.g. f913b6cbf58aa5ae5ca1f8a2b149477aebcbd9d8. ARGOCD_APP_SOURCE_PATH The path of the app within the source repo. ARGOCD_APP_SOURCE_REPO_URL The source repo URL. ARGOCD_APP_SOURCE_TARGET_REVISION The target revision from the spec, e.g. master. KUBE_VERSION The version of Kubernetes. KUBE_API_VERSIONS The version of the Kubernetes API.
carvel.dev/kapp-controller downwardAPI

carvel-dev/kapp-controller#781
https://hackmd.io/6FQhzRIPR_uceqtTqSIXaA

kapp-controller’s downward API was recently introduced into develop (not yet in any release) and works similar to the k8s downward API: We make available certain information from the metadata of the AppCR to the template step. (see develop branch App CR docs for more).

Here we add two new pieces of information: the current version of kapp-controller and of kubernetes itself, and allow the user to specify a name to bind that data to which can then be used during templating. This would allow users to create conditionals during templating that are sensitive to e.g. the current kubernetes version.

For helm, expose kubernetesVersion: {} and kubernetesAPIs:{} bc those correspond to flags we’ll pass in to the helm template.

Then we’ll have the items still in the downwardsAPIs for the other templaters (and technically helm though wouldn’t expect anyone to ever use)

https://carvel.dev/kapp-controller/docs/v0.39.0/app-spec/

        valuesFrom:
[...]
          # downwardAPI allows passing info about App CR as values into templates (v0.39.0+)
          - downwardAPI:
              items:
              # name specifies the key used when the downwardAPI values are rendered. 
              # nested keys are supported by using a '.'. for e.g. `name: parent.child`. 
              # keys requiring a '.' can escape using '\\.'. for e.g. `name: key\\.with\\.dots`
              - name: namespace
                # fieldPath accepts relaxed jsonpath to select metadata fields from the AppCR (name, namespace, uid, labels, annotations)
                fieldPath: metadata.namespace
              - name: specificAnnotation
                fieldPath: metadata.annotations['specificAnnotation']
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

No branches or pull requests

1 participant