Skip to content

Feature Request: Support Downward API #4190

Closed

Description

@dgerd

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:

  1. 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.
  2. 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:

  1. The downward API does not know about Knative so concepts like Service, Revision, and Configuration are not exposed through it
  2. 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:

  1. Expand K_* environment variable space to be larger and include more
  2. Override meaning of fieldRef from Kubernetes Pod Spec. Provide additional acceptable values, block non-supported values, and translate this in our controller when creating a deployment.
  3. 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

  1. added
    kind/feature
    on May 30, 2019
  2. added
    area/API
    kind/spec
    on May 30, 2019
  3. dgerd commented on May 30, 2019

    @dgerd
    Author

    Related to: #3090

  4. vtereso commented on May 30, 2019

    @vtereso

    Just to reinforce the need for some of these likely valuable fields, Knative eventing creates webhooks, which are namespace scoped so this variable needs to be injected in some manner.

  5. mattmoor commented on Jun 5, 2019

    @mattmoor
    Contributor

    We should also discuss how this pertains to projected volumes: #4079

  6. dgerd commented on Jun 19, 2019

    @dgerd
    Author

    labels and annotations can change and will get updated on a volume mounted.

  7. dgerd commented on Jun 19, 2019

    @dgerd
    Author

    Discussed in the API WG this week. Some of my take aways:

    1. Going to cross out option 1 of expanding the always set env vars to include more Knative values as well as Kubernetes values. It seems less preferable to the other two options.
    2. We should prefer to not override semantics of existing K8s keys in the field.
    3. We have no good volume mount solution today for Knative-specific keys. A flex volume type of thing may be possible, but requires installation across cluster.

    I will flush out a bit further what Introducing a new field or introducing a knative namespace into the existing key space looks like.

  8. added this to the Ice Box milestone on Jun 26, 2019
  9. knative-housekeeping-robot commented on Dec 24, 2019

    @knative-housekeeping-robot

    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

  10. added
    lifecycle/stale
    on Dec 24, 2019
  11. knative-housekeeping-robot commented on Jan 23, 2020

    @knative-housekeeping-robot

    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

  12. added
    lifecycle/rotten
    and removed
    lifecycle/stale
    on Jan 23, 2020
  13. knative-housekeeping-robot commented on Feb 23, 2020

    @knative-housekeeping-robot

    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

  14. 17 remaining items

  15. added this to the Needs Triage milestone on Jul 8, 2020
  16. dprotaso commented on Jul 8, 2020

    @dprotaso
    Member

    Going to leave this open & in the icebox for now

    Further areas to round out support could include:

    1. Support Downward API properties through volumes
    2. Potentially allow some non-leaky properties through without the need for the flag to be turned on - ie. metadata.*
  17. modified the milestones: Needs Triage, Ice Box on Jul 8, 2020
  18. github-actions commented on Oct 7, 2020

    @github-actions

    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 as
    fresh by adding the comment /remove-lifecycle stale.

  19. added
    lifecycle/stale
    on Oct 7, 2020
  20. vagababov commented on Oct 7, 2020

    @vagababov
    Contributor

    @JRBANCEL
    JR, iirc (which might be wrong), you were working on this right?

  21. JRBANCEL commented on Oct 7, 2020

    @JRBANCEL
    Contributor

    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.

  22. removed
    lifecycle/stale
    on Jan 23, 2021
  23. evankanderson commented on Mar 22, 2021

    @evankanderson
    Member

    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.

  24. knative-prow-robot commented on Mar 22, 2021

    @knative-prow-robot
    Contributor

    @evankanderson: Closing this issue.

    Details

    In response to this:

    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.

    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.

  25. removed this from the Ice Box milestone on Oct 6, 2021
  26. zchenyu commented on Sep 13, 2023

    @zchenyu

    /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.

  27. knative-prow commented on Sep 13, 2023

    @knative-prow

    @zchenyu: You can't reopen an issue/PR unless you authored it or you are a collaborator.

    Details

    In response to this:

    /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.

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/APIkind/featurekind/spec

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions