Skip to content

fix(app): inject secret labels/annotations and execution env vars int…#7630

Merged
pingsutw merged 2 commits into
flyteorg:mainfrom
falloficaruss:fix/app-env-missing-secret-labels-env-vars
Jul 25, 2026
Merged

fix(app): inject secret labels/annotations and execution env vars int…#7630
pingsutw merged 2 commits into
flyteorg:mainfrom
falloficaruss:fix/app-env-missing-secret-labels-env-vars

Conversation

@falloficaruss

@falloficaruss falloficaruss commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Tracking issue

Closes #7600

Why are the changes needed?

The AppEnvironment path (flyte deploy) produces a Knative Service whose pod template was missing two critical pieces that the TaskAction path already provides:

  1. Secret labels/annotations: The flyte-binary-webhook uses objectSelector.matchLabels{inject-flyte-secrets: "true"} to decide which pods to mutate. Without this label on the revision template, the webhook never processes the pod, so SecurityContext.secrets configured on the app are serialized into the proto but never mounted as env vars or files. The scope labels (organization/project/domain) are also required by the embedded secret manager to resolve which secret to fetch.
  2. Execution env vars: The Flyte SDK's flyte.init_in_cluster() reads FLYTE_INTERNAL_EXECUTION_PROJECT and FLYTE_INTERNAL_EXECUTION_DOMAIN to construct admin API URLs. Without these, Run.get(...) builds malformed URLs like //RUN_ID (404), and with_runcontext(...) calls fail with "require_project_and_domain" errors.

What changes were proposed in this pull request?

In app/internal/k8s/app_client.go:

  1. Secret injection: Added code in buildKService that, when app.Spec.SecurityContext.Secrets is non-empty, injects the following into the Knative revision template's ObjectMeta:
  • Labels: organization: "flyte", project: , domain: , inject-flyte-secrets: "true"
  • Annotations: flyte.secrets/s from secrets.MarshalSecretsToMapStrings()
    This mirrors what executor/pkg/plugin/task_exec_metadata.go:81-95 does for TaskAction pods.
  1. Execution env vars: Added FLYTE_INTERNAL_EXECUTION_PROJECT and FLYTE_INTERNAL_EXECUTION_DOMAIN to the container's env vars, derived from appID.Project and appID.Domain. This mirrors what flyteplugins/.../flytek8s/k8s_resource_adds.go:57-63 (via GetExecutionEnvVars) provides for task pods.

How was this patch tested?

Tests were added in app/internal/k8s/app_client_test.go:

  1. TestDeploy_InjectsExecutionEnvVars — deploys an app and asserts the revision template's container env contains FLYTE_INTERNAL_EXECUTION_PROJECT=proj and FLYTE_INTERNAL_EXECUTION_DOMAIN=dev.
  2. TestDeploy_InjectsSecretLabelsAndAnnotations — deploys an app with SecurityContext.Secrets: [{group: "my_group", key: "my_key", mount_requirement: ENV_VAR}] and asserts the revision template has labels organization: "flyte", project: "proj", domain: "dev", inject-flyte-secrets: "true", and that flyte.secrets/s0 annotation is present.
  3. TestDeploy_NoSecretLabelsOrAnnotationsWhenNoSecrets — deploys an app without a SecurityContext and verifies neither inject-flyte-secrets label nor flyte.secrets/s* annotations appear on the template (negative case).
    All 45 tests in ./app/... pass with -count=1, go build ./app/... compiles clean.

Labels

Please add one or more of the following labels to categorize your PR:

  • fixed

This is important to improve the readability of release notes.

Setup process

Screenshots

Check all the applicable boxes

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

Related PRs

Stack

If you do use git town to manage PR Stacks, the stack relevant to this PR
will show below. Otherwise, you can ignore this section.

Docs link

…o AppEnvironment pod template

Signed-off-by: Abhishek Shinde <norizzabhii@gmail.com>
@github-actions github-actions Bot added the flyte2 label Jul 6, 2026
…o AppEnvironment pod template

Signed-off-by: Abhishek Shinde <norizzabhii@gmail.com>
@pingsutw
pingsutw merged commit 081e22c into flyteorg:main Jul 25, 2026
21 checks passed
@falloficaruss
falloficaruss deleted the fix/app-env-missing-secret-labels-env-vars branch July 25, 2026 03:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] AppEnvironment pod template misses inject-flyte-secrets label/annotations and env vars

2 participants