OCPBUGS-90502: Run nmstatectl format in nmstate-configuration#6209
OCPBUGS-90502: Run nmstatectl format in nmstate-configuration#6209cybertron wants to merge 1 commit into
Conversation
Previously it was very difficult to adopt a day 1 config using nmpolicy constructs into the day 2 operator to allow changes after deployment. This is because nmpolicies rely on having a specific start state for the system, and once the config has been applied that state no longer exists. The operator handles this by saving the start state internally, but since the operator isn't present on day one we need a different approach there. Running the nmstatectl format command allows us to save off a fully formatted version of the nmpolicy config that can be applied on day 2 with no more changes than any other day 1 NMState config. This makes modifications on day 2 substantially easier.
|
Pipeline controller notification For optional jobs, comment This repository is configured in: LGTM mode |
|
@cybertron: This pull request references Jira Issue OCPBUGS-90502, which is valid. The bug has been moved to the POST state. 3 validation(s) were run on this bug
The bug has been updated to refer to the pull request using the external bug tracker. DetailsIn response to this:
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 openshift-eng/jira-lifecycle-plugin repository. |
WalkthroughThe Changesnmstate bootstrap formatted config output
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes 🚥 Pre-merge checks | ✅ 15✅ Passed checks (15 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: cybertron The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
@cybertron: This pull request references Jira Issue OCPBUGS-90502, which is valid. 3 validation(s) were run on this bug
DetailsIn response to this:
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 openshift-eng/jira-lifecycle-plugin repository. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@templates/common/_base/files/nmstate-configuration.yaml`:
- Line 48: The nmstatectl format command is directly redirecting output which
can fail and leave a truncated file, and any failure will stop the entire
bootstrap due to set -e. Refactor the nmstatectl format line to first write the
output to a temporary file (using mktemp), then on successful completion
atomically move that temp file to the final location at "$src_path/formatted"
using mv. Wrap this in a conditional or error handling that logs a message if
the formatting fails but allows the script to continue, since this is just a
day-2 convenience feature and should not block the bootstrap process.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 091b10dd-5e7a-4b1c-8ea3-1786cc8a8dd8
📒 Files selected for processing (1)
templates/common/_base/files/nmstate-configuration.yaml
| cp "$src_path/$config_file" "$src_path/applied" | ||
|
|
||
| # Write a formatted copy of nmpolicy configurations for easier adoption on day 2 | ||
| nmstatectl format "$src_path/$config_file" > "$src_path/formatted" |
There was a problem hiding this comment.
Make formatted-output generation best-effort and atomic.
This command can fail the whole bootstrap due to set -e, and direct > can leave a truncated/empty "$src_path/formatted" on failure. Since this is a day-2 convenience artifact, write to a temp file and atomically move only on success; otherwise log and continue.
Suggested patch
- nmstatectl format "$src_path/$config_file" > "$src_path/formatted"
+ tmp_formatted="$(mktemp "$src_path/formatted.XXXXXX")"
+ if nmstatectl format "$src_path/$config_file" > "$tmp_formatted"; then
+ mv -f "$tmp_formatted" "$src_path/formatted"
+ else
+ rm -f "$tmp_formatted"
+ echo "Warning: failed to generate formatted nmstate config; continuing"
+ fi📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| nmstatectl format "$src_path/$config_file" > "$src_path/formatted" | |
| tmp_formatted="$(mktemp "$src_path/formatted.XXXXXX")" | |
| if nmstatectl format "$src_path/$config_file" > "$tmp_formatted"; then | |
| mv -f "$tmp_formatted" "$src_path/formatted" | |
| else | |
| rm -f "$tmp_formatted" | |
| echo "Warning: failed to generate formatted nmstate config; continuing" | |
| fi |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@templates/common/_base/files/nmstate-configuration.yaml` at line 48, The
nmstatectl format command is directly redirecting output which can fail and
leave a truncated file, and any failure will stop the entire bootstrap due to
set -e. Refactor the nmstatectl format line to first write the output to a
temporary file (using mktemp), then on successful completion atomically move
that temp file to the final location at "$src_path/formatted" using mv. Wrap
this in a conditional or error handling that logs a message if the formatting
fails but allows the script to continue, since this is just a day-2 convenience
feature and should not block the bootstrap process.
|
@cybertron: all tests passed! Full PR test history. Your PR dashboard. DetailsInstructions 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-sigs/prow repository. I understand the commands that are listed here. |
Previously it was very difficult to adopt a day 1 config using nmpolicy constructs into the day 2 operator to allow changes after deployment. This is because nmpolicies rely on having a specific start state for the system, and once the config has been applied that state no longer exists. The operator handles this by saving the start state internally, but since the operator isn't present on day one we need a different approach there.
Running the nmstatectl format command allows us to save off a fully formatted version of the nmpolicy config that can be applied on day 2 with no more changes than any other day 1 NMState config. This makes modifications on day 2 substantially easier.
- What I did
- How to verify it
- Description for the changelog
Summary by CodeRabbit