Skip to content

WIP 🐛 fix(helm/v2-alpha): Respect --force for default ServiceMonitor file#5726

Open
camilamacedo86 wants to merge 1 commit into
kubernetes-sigs:masterfrom
camilamacedo86:fix-force-servicemonitor
Open

WIP 🐛 fix(helm/v2-alpha): Respect --force for default ServiceMonitor file#5726
camilamacedo86 wants to merge 1 commit into
kubernetes-sigs:masterfrom
camilamacedo86:fix-force-servicemonitor

Conversation

@camilamacedo86

@camilamacedo86 camilamacedo86 commented Jun 4, 2026

Copy link
Copy Markdown
Member

Ensures that ServiceMonitor templates follow the same behavior of Network Policies (introduced
Follow-up to #5708) which either is added when not found, preserving user customizations during chart regeneration instead of overwriting them.

@k8s-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: camilamacedo86

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 4, 2026
@camilamacedo86 camilamacedo86 requested a review from Copilot June 4, 2026 22:03

Copilot AI 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.

Pull request overview

This PR updates the Kubebuilder helm/v2-alpha plugin so the default fallback ServiceMonitor template respects the --force flag (preserving user modifications during chart regeneration unless --force is used), aligning its behavior with the existing NetworkPolicy fallback handling.

Changes:

  • Update the ServiceMonitor fallback template to skip overwriting existing files unless --force is set.
  • Extend integration coverage to validate --force behavior for the fallback ServiceMonitor file.
  • Add unit tests and refresh CLI/docs text describing preserved/regenerated files.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pkg/plugins/optional/helm/v2alpha/scaffolds/test/force_integration_test.go Extends integration tests to ensure the fallback ServiceMonitor file is preserved without --force and overwritten with --force.
pkg/plugins/optional/helm/v2alpha/scaffolds/internal/templates/chart-templates/servicemonitor.go Changes default ServiceMonitor fallback behavior to SkipFile unless Force is true.
pkg/plugins/optional/helm/v2alpha/scaffolds/internal/templates/chart-templates/servicemonitor_test.go Adds unit tests verifying IfExistsAction is set correctly based on Force.
pkg/plugins/optional/helm/v2alpha/edit.go Updates edit command help text to document preserved files and include the fallback ServiceMonitor path.
pkg/plugins/optional/helm/v2alpha/edit_test.go Updates tests to assert the updated help/usage strings mention the fallback ServiceMonitor path.
docs/book/src/plugins/available/helm-v2-alpha.md Updates plugin documentation to reflect preserved files and the fallback ServiceMonitor location.

Comment on lines 114 to 118
├── monitoring/
│ └── servicemonitor.yaml
│ └── servicemonitor.yaml # When kustomize output provides a ServiceMonitor
├── prometheus/
│ └── controller-manager-metrics-monitor.yaml # Default fallback when kustomize output does not
├── network-policy/
Comment on lines +109 to +113
fs.BoolVar(&p.force, "force", false,
"If set, regenerate preserved files except Chart.yaml (values.yaml, NOTES.txt, _helpers.tpl, "+
".helmignore, test-chart.yml, network-policy/allow-metrics-traffic.yaml, "+
"network-policy/allow-webhook-traffic.yaml, "+
"prometheus/controller-manager-metrics-monitor.yaml)")
@camilamacedo86 camilamacedo86 changed the title 🐛 fix(helm/v2-alpha): Respect --force for default ServiceMonitor file WIP 🐛 fix(helm/v2-alpha): Respect --force for default ServiceMonitor file Jun 4, 2026
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 4, 2026
Wire the ServiceMonitor scaffold Force flag to SkipFile/OverwriteFile so
prometheus/controller-manager-metrics-monitor.yaml is preserved without --force.

Co-authored-by: Cursor <cursoragent@cursor.com>
@camilamacedo86 camilamacedo86 force-pushed the fix-force-servicemonitor branch from 9b5b2e1 to 9cc0b51 Compare June 4, 2026 23:15
@linux-foundation-easycla

Copy link
Copy Markdown

CLA Not Signed

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. and removed cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jun 4, 2026
@camilamacedo86 camilamacedo86 reopened this Jun 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants