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

Feat: Inject user identity as pod label in K8s plugin #4637

Merged
merged 12 commits into from
Jan 8, 2024

Conversation

fg91
Copy link
Member

@fg91 fg91 commented Dec 22, 2023

Why are the changes needed?

@ByronHsu recently implemented middleware to inject the user identity into the flyte workflow's ExecutionSpec: flyteorg/flyteadmin#549

Building on this, we would like to inject the user identity (not credentials, just the information who started the execution) into the task pod as an additional label in order to enable the following user stories:

  • As a platform engineer, I would like to know which user started which Pod.
  • As a platform engineer, I would like attribute compute cost to users (e.g. by activating GKE cost export into big query which associates compute cost with pod labels).
  • As a platform user/ML engineer, I would like my task executions to automatically log training progress under my account in an experiment tracking server.

What changes were proposed in this pull request?

  • I propose to add a new flag to the k8s plugin config, specifying whether the execution identity is injected as a label. The default is false to make this opt in.

  • I propose to inject the additional execution identity label in newTaskExecutionMetadata where we also inject labels and annotations for secrets.

    Because of the following reasons I believe that this is a good place but I'm looking for feedback on this:

    • The TaskExecutionMetadata type returned by this function has the following doc string

      TaskExecutionMetadata provides a layer on top of the core TaskExecutionMetadata with customized annotations and labels for k8s plugins.

      I find this fitting the proposed use case.

    • Injecting the label here means that it is automatically injected not only for normal python tasks but also for plugins like kubeflow distributed training tasks.

How was this patch tested?

  • Added unit tests.
  • Ran propeller with the proposed changes in our staging cluster and ensured that the execution identity is correctly injected for python tasks as well as pytorch tasks.
    • I also tested the case where the client authenticates with a client credentials flow instead of pkce flow as in this case the execution identity is not set in the flyte workflow.

Check all the applicable boxes

  • I updated the documentation accordingly.
  • All new and existing tests passed.
  • All commits are signed-off.

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Dec 22, 2023
@fg91 fg91 requested review from hamersaw and ByronHsu December 22, 2023 15:37
@dosubot dosubot bot added the enhancement New feature or request label Dec 22, 2023
@fg91 fg91 self-assigned this Dec 22, 2023
@fg91 fg91 added enhancement New feature or request and removed enhancement New feature or request labels Dec 22, 2023
Copy link

codecov bot commented Dec 22, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (513c3e1) 58.10% compared to head (988a943) 58.08%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4637      +/-   ##
==========================================
- Coverage   58.10%   58.08%   -0.03%     
==========================================
  Files         626      626              
  Lines       53834    53836       +2     
==========================================
- Hits        31280    31270      -10     
- Misses      20048    20058      +10     
- Partials     2506     2508       +2     
Flag Coverage Δ
unittests 58.08% <100.00%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@fg91
Copy link
Member Author

fg91 commented Dec 22, 2023

For documentation purposes:

One can set the following e.g. in the default flyte pod template in order to use the execution identity as a pod template:

apiVersion: v1
kind: PodTemplate
template:
  spec:
    containers:
    - env:
      - name: EXECUTION_IDENTITY
        valueFrom:
          fieldRef:
            apiVersion: v1
            fieldPath: metadata.labels['execution_identity']

@hamersaw
Copy link
Contributor

hamersaw commented Jan 2, 2024

@fg91 this looks great. I agree, the metadata is the correct place to inject this. My first question here is whether this should be behind a configuration flag? Is there a scenario where we would not want the execution identity available? I'm assuming that if a user has Flyte configured to inject user IDs from middleware, it would be beneficial to include this information in k8s resources, thoughts? cc. @ByronHsu

@fg91
Copy link
Member Author

fg91 commented Jan 4, 2024

My first question here is whether this should be behind a configuration flag? Is there a scenario where we would not want the execution identity available?

I can't come up with such a scenario tbh. I first proposed a configuration flag as the most conservative change because I wasn't sure how others feel about this. I'm happy to remove the flag though @hamersaw! a9652e8 115c23d

I'm assuming that if a user has Flyte configured to inject user IDs from middleware, it would be beneficial to include this information in k8s resources, thoughts? cc. @ByronHsu

Injecting user ids from middleware in flyteadmin is not behind a config flag (see here) so users don't have to opt in.

@fg91 fg91 force-pushed the fg91/feat/inject-user-identity-into-pod branch from 8c9cf96 to 77f2d7a Compare January 4, 2024 12:03
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jan 4, 2024
Copy link
Contributor

@hamersaw hamersaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very useful, can we clean up the unit tests?

@fg91 fg91 force-pushed the fg91/feat/inject-user-identity-into-pod branch from 2a6a3a6 to 4437c4c Compare January 5, 2024 14:56
fg91 added 2 commits January 8, 2024 11:30
Signed-off-by: Fabio Graetz <[email protected]>
@fg91 fg91 requested a review from hamersaw January 8, 2024 11:49
@fg91
Copy link
Member Author

fg91 commented Jan 8, 2024

[...] can we clean up the unit tests?

Done ✅

@hamersaw hamersaw merged commit 6dde005 into master Jan 8, 2024
44 of 45 checks passed
@hamersaw hamersaw deleted the fg91/feat/inject-user-identity-into-pod branch January 8, 2024 17:29
@fg91 fg91 changed the title Feat: Add option in K8s plugin config to inject user identity as pod label Feat: Inject user identity as pod label in K8s plugin Jan 9, 2024
katrogan pushed a commit that referenced this pull request Jan 12, 2024
…label (#4637)

* Add option in K8s plugin config to inject user identity into pod labels

Signed-off-by: Fabio Graetz <[email protected]>

* Inject user identity into TaskExecutionMetadata labels

Signed-off-by: Fabio Graetz <[email protected]>

* Add unit tests

Signed-off-by: Fabio Graetz <[email protected]>

* Remove duplicate labels injection

Signed-off-by: Fabio Graetz <[email protected]>

* Lint

Signed-off-by: Fabio Graetz <[email protected]>

* Revert "Add option in K8s plugin config to inject user identity into pod labels"

This reverts commit c42a4a0.

Signed-off-by: Fabio Graetz <[email protected]>

* Always inject user identity as pod label if known

Signed-off-by: Fabio Graetz <[email protected]>

* Use hyphen instead of underscore in pod label

Signed-off-by: Fabio Graetz <[email protected]>

* Update flytepropeller/pkg/controller/nodes/task/k8s/task_exec_context.go

Signed-off-by: Fabio M. Graetz, Ph.D. <[email protected]>
Signed-off-by: Fabio Graetz <[email protected]>

* Fix tests

Signed-off-by: Fabio Graetz <[email protected]>

* Remove duplicate unit test logic

Signed-off-by: Fabio Graetz <[email protected]>

---------

Signed-off-by: Fabio Graetz <[email protected]>
Signed-off-by: Fabio M. Graetz, Ph.D. <[email protected]>
Co-authored-by: Dan Rammer <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants