Repository navigation
Description
In what area(s)?
/area API
/area autoscale
/area build
/area monitoring
/area networking
/area test-and-release
Describe the feature
There are many use-cases for knowing information about a particular revision from within the user container. In Knative today we supply a subset of information through automatically injected environment variables such as K_REVISION, K_SERVICE, and K_CONFIGURATION. However, there are two problems with this:
- This information is incomplete. Other useful information such as the ServiceAccountName and Kubernetes namespace are not present which can be useful for constructing requests to relevant services within the same cluster.
- The prefixed environment variables does not easily allow for local development and portability to run on non-Knative platforms. The meaning of a revision or a namespace may change in my local environment, but having a concept provided to my container may be important. For example, in my log output I may want to provide a prefix as to the version I am running to help with debugging. In a Knative I may want to use the Revision name for this purpose, but doing local development I may want the git hash for this purpose as I do not have a Revision name. It would be nice to be able to take this in as "VERSION" in my application rather than "K_REVISION" everywhere I run this container.
Kubernetes gets around this problem by providing the downward API. The downward API is typically available through files (via projected volume mount) or through environment variables (via fieldRef). The problem with the downward API for Knative is that:
- The downward API does not know about Knative so concepts like Service, Revision, and Configuration are not exposed through it
- Some (but not all) of the fields exposed through the Downward API are outside of the Knative API and it leaks implementation details (which may change). For example, Knative does not expose the Pod object through the API. The naming of Pods and lifecycle of Pods are implementation details of Knative. However, the downward API exposes the Pod name through
metadata.name. Applications that use this field would be relying on a detail that may not be portable through all versions or implementations of Knative, and may inadvertently break.
Some fields that are likely valuable:
- metadata.name - While the Pod name is (1) likely not what a user wants and (2) outside the Knative API, having a unique way to address a running instance of the application is valuable.
- metadata.namespace - Useful for calling the Knative or Kubernetes API for discovery, creation, or modification of resources.
- metadata.labels - However, getting the Revision label is likely the right thing to do here as that is where the user would be requesting this from.
- metadata.annotations - However, getting the Revision annotations is likely the right thing to do here as that is where the user would be requesting this from.
- resourceFieldRef - This is also made available through cgroup mounts today.
- spec.serviceAccountName - Useful for making calls with the service account assigned to you.
There are many ways which we could proceed here and it is not clear which way will cover the most use-cases without breaking the serverless abstraction. This issue is created to gather use-cases and discuss proposals.
Some things we could do here:
- Expand K_* environment variable space to be larger and include more
- Override meaning of
fieldReffrom Kubernetes Pod Spec. Provide additional acceptable values, block non-supported values, and translate this in our controller when creating a deployment. - Create a new
fieldRef-like shape in our API that supports only the fields we want. This would live above the PodSpec as to not override existing behavior.
Activity
dgerd commentedon May 30, 2019
Related to: #3090
vtereso commentedon May 30, 2019
Just to reinforce the need for some of these
likely valuablefields, Knative eventing creates webhooks, which are namespace scoped so this variable needs to beinjectedin some manner.mattmoor commentedon Jun 5, 2019
We should also discuss how this pertains to projected volumes: #4079
dgerd commentedon Jun 19, 2019
labels and annotations can change and will get updated on a volume mounted.
dgerd commentedon Jun 19, 2019
Discussed in the API WG this week. Some of my take aways:
I will flush out a bit further what Introducing a new field or introducing a knative namespace into the existing key space looks like.
knative-housekeeping-robot commentedon Dec 24, 2019
Issues go stale after 90 days of inactivity.
Mark the issue as fresh by adding the comment
/remove-lifecycle stale.Stale issues rot after an additional 30 days of inactivity and eventually close.
If this issue is safe to close now please do so by adding the comment
/close.Send feedback to Knative Productivity Slack channel or file an issue in knative/test-infra.
/lifecycle stale
knative-housekeeping-robot commentedon Jan 23, 2020
Stale issues rot after 30 days of inactivity.
Mark the issue as fresh by adding the comment
/remove-lifecycle rotten.Rotten issues close after an additional 30 days of inactivity.
If this issue is safe to close now please do so by adding the comment
/close.Send feedback to Knative Productivity Slack channel or file an issue in knative/test-infra.
/lifecycle rotten
knative-housekeeping-robot commentedon Feb 23, 2020
Rotten issues close after 30 days of inactivity.
Reopen the issue with
/reopen.Mark the issue as fresh by adding the comment
/remove-lifecycle rotten.Send feedback to Knative Productivity Slack channel or file an issue in knative/test-infra.
/close
17 remaining items
dprotaso commentedon Jul 8, 2020
Going to leave this open & in the icebox for now
Further areas to round out support could include:
metadata.*github-actions commentedon Oct 7, 2020
This issue is stale because it has been open for 90 days with no
activity. It will automatically close after 30 more days of
inactivity. Reopen the issue with
/reopen. Mark the issue asfresh by adding the comment
/remove-lifecycle stale.vagababov commentedon Oct 7, 2020
@JRBANCEL
JR, iirc (which might be wrong), you were working on this right?
JRBANCEL commentedon Oct 7, 2020
Downward API comes in two flavors: Environment Variables and Volume Files. The first one is done. The second one is not and has never been requested and I would consider it to be part of #4417 since it is Volume based.
evankanderson commentedon Mar 22, 2021
It looks like this is stale, and we haven't seen requests for Volume Files at the moment, so I'm going to
/close
this issue, and we can open another issue later if we need more capabilities.
knative-prow-robot commentedon Mar 22, 2021
@evankanderson: Closing this issue.
Details
In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
zchenyu commentedon Sep 13, 2023
/reopen
It would be really nice to support downwardAPI. We have a long list of labels/annotations that we'd like to dynamically read from the pod for metadata/logging purposes. Individually defining environment variables kinda works, but it's very tedious/ugly especially as we add new ones.
knative-prow commentedon Sep 13, 2023
@zchenyu: You can't reopen an issue/PR unless you authored it or you are a collaborator.
Details
In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.