Skip to content

feat(actuator): inject plain and secret environment variables from component snapshots - #803

Merged
VLukiantsev merged 2 commits into
feat/components-snapshot-discovery-gate-b548436694from
feat/components-snapshot-secrets-volumes-b548436694
Sep 8, 2026
Merged

VLukiantsev merged 2 commits into
feat/components-snapshot-discovery-gate-b548436694from
feat/components-snapshot-secrets-volumes-b548436694

Conversation

@VLukiantsev

@VLukiantsev VLukiantsev commented Sep 7, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Layer 2 of the component snapshot injection stack: resolves plain (status.access.envVars) and secret (status.access.secretEnvVars) environment variables from resolved Component custom resources and injects them across primary and init containers in all JobSet replicatedJobs.

Motivation & Context

Following Layer 1's snapshot discovery and placement gating (PR #802), WorkUnits requiring platform components need their operational configurations and credentials passed through container environment variables.

This is Layer 2 of a 3-PR stack (gh-stack):

  • Layer 1 (feat(actuator): integrate component snapshot discovery and placement gating #802): Annotation discovery, cached CR resolution, conditional placement gate, drift warning annotations, and daemon documentation.
  • Layer 2 (this PR): Component environment variable injection (plain status.access.envVars and secret references status.access.secretEnvVars via corev1.SecretKeyRef).
  • Layer 3: Secret volume mounts injection (status.access.secretVolumeMounts) with RFC 1123 DNS subdomain sanitization and collision deduplication.

Key Changes

  • Access Configuration Parsing: In cmd/actuator/k8s_client/component_injection.go, implemented extractComponentAccess to extract envVars and secretEnvVars maps from the Component CR's status.access.
  • Plain Env Var Injection: buildPlainEnvVars transforms key-value pairs into deterministic, sorted corev1.EnvVar entries.
  • Secret Env Var References: buildSecretEnvVars parses declarations in "<secret_name>:<key>" format and creates corev1.EnvVar entries with ValueFrom.SecretKeyRef. Malformed declarations without valid secret/key delimiters are skipped gracefully.
  • Container Injection & Overriding: injectAccessIntoJobSet injects environment variables into all containers (podSpec.Containers and podSpec.InitContainers) across all replicated jobs, updating existing entries in place.
  • Documentation: Updated cmd/actuator/README.md with environment variable injection details.

Assumptions

  • Secret resources referenced by secretEnvVars are managed by the component operator and exist in the WorkUnit's namespace.
  • Non-restarting JobSets contract (MaxRestarts: 0, restartPolicy: Never/OnFailure) remains strictly enforced.

Verification & Testing

  • Bazel Test Matrix: bazel test //cmd/actuator/... executed and passed 100%:
    • //cmd/actuator:actuator_test (PASSED)
    • //cmd/actuator/k8s_client:k8s_client_test (PASSED, 10/10 shards)
    • //cmd/actuator/k8s_client/preconditions_validator:preconditions_validator_test (PASSED)
    • //cmd/actuator/workunittaskhandler:workunittaskhandler_test (PASSED)
  • Unit & E2E Tests:
    • TestConstructJobSet_ComponentSnapshot_EnvVars_Injection: Verifies injection of both plain and secret env vars across containers.
    • TestConstructJobSet_ComponentSnapshot_EnvVars_UpdateExisting: Verifies updating existing env vars in place.
    • TestConstructJobSet_ComponentSnapshot_AccessExtraction_Error: Verifies error propagation on malformed status.access structures.
    • TestConstructJobSet_ComponentSnapshot_EmptyAccess: Verifies clean no-op handling when status.access is nil or empty.
    • TestExtractStringMap_Types: Tests robust scalar string conversion.
    • TestBuildSecretEnvVars_EdgeCases: Verifies delimiter parsing edge cases.
    • TestCreateWorkUnit_ComponentSnapshotInjection_EnvVars_Success: E2E client verification of JobSet creation and env var injection.
  • Diff Sizing Check: tools/analyze_diff_size.py --base-ref feat/components-snapshot-discovery-gate-b548436694 verified 141 production code lines (< 400), 262 test lines, 403 total code lines (< 1,000), and 6 doc lines (< 1,000).
  • Linters: ./.githooks/pre-commit passed cleanly (buildifier, gofmt, golangci-lint, determinism, addlicense).

TAG=agy
CONV=a22ce4d3-ff57-4515-bf2f-e810b9aec5ce

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request extends the actuator's configuration injection by adding support for secret environment variables and secret volume mounts from component custom resources into JobSet containers. It also includes volume name sanitization, collision deduplication, and updated documentation and tests. The feedback suggests optimizing performance by moving the construction of component environment variables outside the loop in injectAccessIntoJobSet and adding a defensive nil check for podSpec in buildSecretVolumeMounts to prevent potential nil pointer dereferences.

@VLukiantsev

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request enhances the actuator's configuration injection by adding support for secret environment variables and secret volume mounts into JobSet containers, complete with volume name sanitization, deduplication, conflict protection, updated documentation, and unit tests. The review feedback suggests adding a defensive check to ensure volume mount paths are absolute to prevent Kubernetes API server rejection, and pre-allocating slices for volume mounts and environment variables to optimize performance.

@VLukiantsev
VLukiantsev force-pushed the feat/components-snapshot-secrets-volumes-b548436694 branch from 2aced12 to 5d09355 Compare September 7, 2026 14:50
@VLukiantsev

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request expands the access configuration injection in the actuator to support secret environment variables (via secretKeyRef) and secret volume mounts. It introduces robust handling for volume name sanitization, volume deduplication for shared secrets, and conflict protection to avoid overwriting existing mounts. Comprehensive unit tests and documentation updates have been added to verify and describe these new features. There are no review comments to address, and I have no additional feedback to provide.

@VLukiantsev
VLukiantsev force-pushed the feat/components-snapshot-secrets-volumes-b548436694 branch from 5d09355 to 4222803 Compare September 7, 2026 15:07
@VLukiantsev
VLukiantsev force-pushed the feat/components-snapshot-secrets-volumes-b548436694 branch from 4222803 to 758b5f7 Compare September 7, 2026 15:13
@VLukiantsev
VLukiantsev force-pushed the feat/components-snapshot-secrets-volumes-b548436694 branch from 758b5f7 to 5681706 Compare September 7, 2026 15:19
@VLukiantsev
VLukiantsev force-pushed the feat/components-snapshot-secrets-volumes-b548436694 branch from 5681706 to 1a86bc8 Compare September 7, 2026 15:25
@VLukiantsev
VLukiantsev force-pushed the feat/components-snapshot-secrets-volumes-b548436694 branch from 1a86bc8 to 6c2c68c Compare September 7, 2026 15:34
@VLukiantsev

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request expands the configuration injection capabilities of the Actuator daemon. In addition to plain environment variables, it now supports injecting secret environment variables (via valueFrom.secretKeyRef) and mounting Kubernetes Secrets as read-only volumes into all primary and init containers of a JobSet. It includes volume name sanitization to RFC 1123 standards, deduplication of shared secret volumes, and conflict protection for existing mounts. Extensive unit tests and documentation updates have been added to cover these new features. I have no additional feedback to provide as there are no review comments.

@VLukiantsev
VLukiantsev force-pushed the feat/components-snapshot-secrets-volumes-b548436694 branch from 6c2c68c to 03926bb Compare September 7, 2026 16:34
@VLukiantsev VLukiantsev changed the title feat(actuator): inject secret env vars and volume mounts from component snapshots feat(actuator): inject plain and secret environment variables from component snapshots Sep 7, 2026
@VLukiantsev
VLukiantsev force-pushed the feat/components-snapshot-secrets-volumes-b548436694 branch 2 times, most recently from 32aaf7b to 88967dc Compare September 7, 2026 17:08
@VLukiantsev
VLukiantsev requested a review from AntonTyb September 8, 2026 09:17
@VLukiantsev
VLukiantsev marked this pull request as ready for review September 8, 2026 09:17
@VLukiantsev
VLukiantsev force-pushed the feat/components-snapshot-secrets-volumes-b548436694 branch from 88967dc to 304a242 Compare September 8, 2026 09:37
AntonTyb
AntonTyb previously approved these changes Sep 8, 2026

@AntonTyb AntonTyb left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

some logging (at least at debug level) would be nice...

@VLukiantsev
VLukiantsev dismissed AntonTyb’s stale review September 8, 2026 11:07

The merge-base changed after approval.

@VLukiantsev
VLukiantsev force-pushed the feat/components-snapshot-secrets-volumes-b548436694 branch from 304a242 to 8703f41 Compare September 8, 2026 11:07
@VLukiantsev

Copy link
Copy Markdown
Collaborator Author

Added structured debug-level logging in cmd/actuator/k8s_client/component_injection.go:

  • Logs component snapshot list when beginning evaluation ("Evaluating component snapshots for JobSet").
  • Logs injection summary per component upon successful placement and resolution ("Injected component environment variables into JobSet", detailing locked generation, plain env count, and secret env count).
  • Logs namespace fallback when a component is not found in the target namespace and falls back to the default xmc namespace ("Component not found in target namespace, falling back to default components namespace").

Kept logging strictly bounded to $O(\text{components})$ per WorkUnit with zero logs inside inner container or replicated-job loops to prevent log spam.

@VLukiantsev
VLukiantsev force-pushed the feat/components-snapshot-secrets-volumes-b548436694 branch from fefb391 to 0336c17 Compare September 8, 2026 11:21
@VLukiantsev
VLukiantsev requested a review from AntonTyb September 8, 2026 11:42
AntonTyb
AntonTyb previously approved these changes Sep 8, 2026
@VLukiantsev
VLukiantsev dismissed AntonTyb’s stale review September 8, 2026 12:50

The merge-base changed after approval.

@VLukiantsev
VLukiantsev force-pushed the feat/components-snapshot-secrets-volumes-b548436694 branch from 0336c17 to aae359c Compare September 8, 2026 12:52
…mponent snapshots

Extract plain environment variables (status.access.envVars) and secret
environment variables (status.access.secretEnvVars) from resolved Component
custom resources and inject them across primary containers and initContainers
in all JobSet replicatedJobs.

Secret environment variables are resolved into corev1.SecretKeyRef selectors
pointing to the target secret and key.

TAG=agy
CONV=a22ce4d3-ff57-4515-bf2f-e810b9aec5ce
Add structured debug-level logging when evaluating component snapshots,
injecting environment variables, and falling back to the default components
namespace, avoiding excessive log spam by logging once per component.

TAG=agy
CONV=a22ce4d3-ff57-4515-bf2f-e810b9aec5ce
@VLukiantsev
VLukiantsev force-pushed the feat/components-snapshot-secrets-volumes-b548436694 branch from aae359c to e5115e6 Compare September 8, 2026 14:49

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🤖 Incremental PR Approval

Clean rebase detected with zero semantic patch lines changed.

Preserving prior approval by @AntonTyb on commit 0336c17.

@VLukiantsev
VLukiantsev added this pull request to the merge queue Sep 8, 2026
Merged via the queue into main with commit cfeef03 Sep 8, 2026
11 checks passed
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

Successfully merging this pull request may close these issues.

2 participants