Skip to content

fix(recipes): merge shared DGD environment variables by name - #15064

Merged
yunzhoul-nv merged 4 commits into
mainfrom
yunzhoul/recipes/7/fix-openapi-schema
Sep 21, 2026
Merged

yunzhoul-nv merged 4 commits into
mainfrom
yunzhoul/recipes/7/fix-openapi-schema

Conversation

@yunzhoul-nv

@yunzhoul-nv yunzhoul-nv commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Overview:

Details:

Where should the reviewer start?

Related Issues

⚠️ This section is required. Choose one path below and delete the other.

🔗 This PR is linked to an issue:

  • Closes #XXXX

🚫 This PR is NOT linked to an issue:

  • Confirmed — no related issue

Summary by CodeRabbit

  • New Features

    • Added support for configuring environment variables on DynamoGraphDeployment resources.
    • Environment variables with matching names are merged and updated without creating duplicates.
  • Bug Fixes

    • Improved generated deployment configuration behavior to preserve environment variable values during customization.
  • Tests

    • Added integration coverage for adding and updating shared environment variables through Kustomize.

Signed-off-by: yunzhoul-nv <232973175+yunzhoul-nv@users.noreply.github.com>
@yunzhoul-nv
yunzhoul-nv requested review from a team as code owners September 18, 2026 17:58
@copy-pr-bot

copy-pr-bot Bot commented Sep 18, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 74bbe779-40d3-479d-be44-02fbb2ab267b

📥 Commits

Reviewing files that changed from the base of the PR and between 1f29d08 and eeff336.

📒 Files selected for processing (4)
  • recipes/kustomize/components/dynamo-openapi/dynamo-openapi.json
  • recipes/templates/kustomize/components/dynamo-openapi/dynamo-openapi.json
  • scripts/generate_kustomize_openapi.py
  • tests/test_generate_kustomize_openapi.py

Included review availability: Your plan provides up to 12 included reviews per hour; 11 remain after this review.


Walkthrough

The generator now marks DynamoGraphDeployment.spec.env as a name-keyed Kubernetes map list. Generated schemas include this metadata. An integration test verifies added and updated environment variables merge without duplicate names.

Changes

DynamoGraphDeployment environment merging

Layer / File(s) Summary
Environment merge schema generation
scripts/generate_kustomize_openapi.py, recipes/kustomize/components/dynamo-openapi/dynamo-openapi.json, recipes/templates/kustomize/components/dynamo-openapi/dynamo-openapi.json
The generator applies map-list metadata to spec.env. Both generated schemas define string-valued entries merged by name.
Kustomize merge validation
tests/test_generate_kustomize_openapi.py
The parameterized integration test generates the schema, runs Kustomize, and checks added and updated environment values without duplicate names. The test skips when Kustomize is unavailable and applies execution timeouts.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to eeff3

No actionable merge risk remains from the reviewed change.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. (2 skipped: 2 … Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description includes the required headings but contains no project details. The Related Issues section also retains the placeholder issue number and leaves both issue paths present. Add the PR overview, implementation details, and files for reviewer focus. Replace or remove the placeholder issue entry, then select and complete exactly one Related Issues path.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the main change: merging shared DynamoGraphDeployment environment variables by name.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. (2 skipped: 2 unsupported.)

  • Fix all pre-merge checks with AI

Comment @coderabbitai help to get the list of available commands.

Comment thread scripts/generate_kustomize_openapi.py Resolved
chw001 added a commit to chw001/dynamo that referenced this pull request Sep 18, 2026
…onent

Depends on ai-dynamo#15064.

The component previously used JSON 6902 patches to work around spec.env
being an atomic list: a strategic merge replaced the whole environment
rather than adding to it, dropping MODEL_NAME and HF_HOME. ai-dynamo#15064 gives
spec.env a merge key of name in the generated Kustomize OpenAPI document,
so the workaround is no longer needed.

Switch to a strategic merge. It is more readable, and more importantly it
addresses components by NAME rather than by list index -- the JSON patch
hardcoded /spec/components/1 and /2, so inserting or reordering a
component in the base would silently have moved the RDMA request onto the
wrong role.

The rendered manifest is unchanged: it still matches the manifest
validated on 8x B200, compared with env and components keyed by name.

Until ai-dynamo#15064 merges, `render --check` reports this manifest as stale,
because the render pipeline regenerates the OpenAPI document from the
generator in the tree. That is a loud failure, not a silent one.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Cheng Wang <chengwa@nvidia.com>
Signed-off-by: yunzhoul-nv <232973175+yunzhoul-nv@users.noreply.github.com>
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Sep 18, 2026

@ynpandey-nv ynpandey-nv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Performance codeowners review.

This is the correct Kustomize-only fix: beta DGD spec.env is an atomic array in the CRD, so SMP was replacing the list. Merge-by-name matches container env and is what recipe overlays need for HF_HOME / UCX_TLS / NCCL_* without dropping MODEL_NAME.

Please add a schema-level unit test on nvidia.com.v1beta1.DynamoGraphDeployment spec.env merge keys (same style as the existing container-env test). The new kustomize build test is useful but skips when kustomize is missing.

Nits: retitle away from fix(docs), fill the PR template, and optionally note that SMP field-merges EnvVar so value + valueFrom can coexist (same as container env; not a reason to drop merge-by-name).

Not blocking on the review-agent valueFrom request.

@dmitry-tokarev-nv dmitry-tokarev-nv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review of fb12e94

Approving. The generated artifact is current and reproducible, the new tests fail on the pre-fix code, and the merge rule does what the docs now say. Two non-blocking items are inline, plus one reply on the review-agent thread.

What I ran, and what it returned

Renderer sigs.k8s.io/kustomize/kustomize/v5@v5.8.1, the same version Recipe Check installs. Merge base 0bc706b, head fb12e94.

Generated artifact:

  • python3 scripts/generate_kustomize_openapi.py --check returns 0 at head.
  • A full regeneration leaves the working tree clean. Both checked-in copies are byte-identical (md5 1af5eb50152a0b24bb48e32e4cc7348a), and --check covers both paths.

Merge rule, base schema against head schema:

case merge base 0bc706b head fb12e94
add UCX_TLS the other two entries are dropped all three kept
update HF_HOME MODEL_NAME is dropped MODEL_NAME kept
existing list is empty patch entry only patch entry only
no env key in the base patch entry only patch entry only
patch is env: [] list cleared base entries kept
$patch: delete on one name literal $patch key left in the output the named entry is removed

Test strength: removing the 15-line v1beta1 block from crd_definitions() makes both new parameter cases fail (2 failed, 2 passed). The unmutated tree gives 4 passed, and the file was restored to md5 8f93584f38fec515ab821ce69770fee1 before and after.

Links and paths added by the diff: ../../CONTRIBUTING.md#contribute-a-variant resolves to recipes/CONTRIBUTING.md line 180, ### Contribute a Variant.

On the request for a schema-level unit test: the Kustomize test does not skip in CI

@ynpandey-nv asked for a schema-level test because the new one skips when kustomize is missing. That skip does not happen on this PR. The Recipe Check job installs sigs.k8s.io/kustomize/kustomize/v5@v5.8.1 with go install and exports KUSTOMIZE_BIN, and the job log for fb12e94 reads:

tests/test_generate_kustomize_openapi.py ....                            [ 10%]
======================== 323 passed in 63.80s (0:01:03) ========================

Four tests, no skips. The ask still helps a developer who has no kustomize on the local machine, but CI coverage is real today.

Push shape and base drift

Two commits, both by the PR author, both with a single parent, no merge commits and no force push.

  • The issue timeline holds two committed events and no head_ref_force_pushed event.
  • compare/0bc706b...fb12e94 gives ahead_by 2, behind_by 2, total_commits 2, and the same seven files as the pull request file list.
  • Local ancestry on a clone that reports is-shallow-repository false gives the same two commits.
  • git patch-id --stable over the non-merge commits: eeff336 is 00e58c8d..., fb12e94 is beb8b94a....

Base drift: I merged cedab72, the current tip of main, into fb12e94. The merge is clean and touches 76 files, none of them under recipes/, scripts/generate_kustomize_openapi.py, tests/test_generate_kustomize_openapi.py, or deploy/operator/config/crd/. On the merged tree, --check still returns 0 and the four tests still pass, so no finding here depends on the drift.

What I dropped after measuring it
  • Entry order changes. The merge puts patch entries first, so A,B,C plus a patch of C,D renders C,D,A,B. No recipe YAML file uses $(VAR) inside an env value, so nothing reads that order.
  • Drift between the two dynamo-openapi.json copies. They are byte-identical and --check covers both.
  • The comment update that landed in only one kustomization.yaml. The recipes/kustomize/components/dynamo-openapi/ copy has six lines and never carried that comment, so nothing went out of step.
  • A gap for v1alpha1. That version has no spec.env at all, so the hard-coded version tuple covers the only place the rule can apply.
  • Losing the ability to clear the list with env: []. $patch: delete works, and it works better at head than at the merge base.
Where verification stopped

I did not apply either rendered manifest to a live API server, so "Kubernetes rejects value together with valueFrom" is read from the core EnvVar rule and not measured here. I did not run the operator test suite. No red checks to triage: every check on fb12e94 is green or skipped, and Recipe Check, the job that runs the new tests, passed.

Comment thread recipes/CONTRIBUTING.md Resolved
Comment thread scripts/generate_kustomize_openapi.py Resolved

@dynamo-review-agent dynamo-review-agent 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.

Previously reported defects still present:

  • Original discussion: The code still indexes source_schema["properties"]["spec"]["properties"]["env"] directly, so a v1beta1 DynamoGraphDeployment CRD schema without spec.env would still raise an uncaught KeyError instead of the script's handled error path.
  • Original discussion: The documentation still omits that, after a JSON 6902 append creates duplicate shared-env names, a later strategic merge patch for that name can silently leave the appended value unchanged.
  • Original discussion: The generated schema still makes beta DGD spec.env a name-keyed strategic-merge list, so same-name patches continue to field-merge EnvVar entries; a value-to-valueFrom patch can retain the old value instead of replacing the EnvVar entry.
  • Original discussion: The new CONTRIBUTING.md text still warns only that JSON 6902 appends can create duplicate env names; it does not warn that, after this schema change, a later strategic merge patch by the same name can be dropped when duplicates already exist.
  • Original discussion: The new direct indexing of spec.properties.env still raises an uncaught KeyError when that field is absent, bypassing the generator's normal handled-error path.
  • Original discussion: The new documentation still omits that duplicate shared-env names can cause a later strategic merge patch for that name to be silently ignored.
  • Original discussion: The new merge-by-name rule still field-merges same-name EnvVar entries. A patch changing an entry from value to valueFrom leaves both fields in the rendered DGD, which Kubernetes rejects.
  • Original discussion: The same-name spec.env strategic merge still combines value and valueFrom, which produces an invalid Kubernetes EnvVar instead of replacing the entry.
  • Original discussion: Verified at head: after JSON 6902 appends a duplicate shared environment name, a later strategic merge patch for that name can be silently dropped by Kustomize. The changed docs acknowledge duplicates but omit this runtime configuration consequence.
  • Original discussion: Verified at head: name-keyed strategic merging of spec.env retains fields from an existing EnvVar. A value-to-valueFrom (or reverse) patch therefore renders both mutually exclusive fields, causing Kubernetes to reject the resulting workload.
  • Original discussion: Verified at head: the new direct indexing of the beta DGD spec.env schema raises an uncaught KeyError when that field is absent, bypassing main()'s existing handled input-error path.
  • Original discussion: Verified unchanged: after a JSON 6902 append creates duplicate spec.env names, a later strategic merge patch can be silently ignored by Kustomize. The new documentation warns about duplicates but not this consequence.
  • Original discussion: Verified unchanged: keyed strategic merge field-merges an existing EnvVar. A same-name patch changing value to valueFrom retains value, rendering an invalid EnvVar with both fields.
  • Original discussion: Verified unchanged: the new direct source_schema["properties"]["spec"]["properties"]["env"] lookup raises an uncaught KeyError if the beta DGD schema lacks spec.env, bypassing the generator's handled error path.
  • Original discussion: crd_definitions() still indexes the beta DGD spec.env schema directly, so a CRD missing that field raises an uncaught KeyError.

@yunzhoul-nv yunzhoul-nv changed the title fix(docs): append the environment variable list rather than replace fix(recipes): merge shared DGD environment variables by name Sep 21, 2026
Signed-off-by: yunzhoul-nv <232973175+yunzhoul-nv@users.noreply.github.com>
@yunzhoul-nv

Copy link
Copy Markdown
Contributor Author

/ok to test 914fc62

@yunzhoul-nv
yunzhoul-nv enabled auto-merge (squash) September 21, 2026 19:01
@yunzhoul-nv
yunzhoul-nv merged commit e0c29ae into main Sep 21, 2026
107 checks passed
@yunzhoul-nv
yunzhoul-nv deleted the yunzhoul/recipes/7/fix-openapi-schema branch September 21, 2026 19:02
chw001 added a commit to chw001/dynamo that referenced this pull request Sep 21, 2026
…onent

The component previously used JSON 6902 patches to work around spec.env
being an atomic list: a strategic merge replaced the whole environment
rather than adding to it, dropping MODEL_NAME and HF_HOME. ai-dynamo#15064 gives
spec.env a merge key of name in the generated Kustomize OpenAPI document,
so the workaround is no longer needed.

Switch to a strategic merge. It is more readable, and more importantly it
addresses components by NAME rather than by list index -- the JSON patch
hardcoded /spec/components/1 and /2, so inserting or reordering a
component in the base would silently have moved the RDMA request onto the
wrong role.

The rendered manifest is unchanged: it still matches the manifest
validated on 8x B200, compared with env and components keyed by name.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Cheng Wang <chengwa@nvidia.com>
chw001 added a commit to chw001/dynamo that referenced this pull request Sep 21, 2026
…onent

The component previously used JSON 6902 patches to work around spec.env
being an atomic list: a strategic merge replaced the whole environment
rather than adding to it, dropping MODEL_NAME and HF_HOME. ai-dynamo#15064 gives
spec.env a merge key of name in the generated Kustomize OpenAPI document,
so the workaround is no longer needed.

Switch to a strategic merge. It is more readable, and more importantly it
addresses components by NAME rather than by list index -- the JSON patch
hardcoded /spec/components/1 and /2, so inserting or reordering a
component in the base would silently have moved the RDMA request onto the
wrong role.

The rendered manifest is unchanged: it still matches the manifest
validated on 8x B200, compared with env and components keyed by name.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Cheng Wang <chengwa@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation fix size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants