-
Notifications
You must be signed in to change notification settings - Fork 1.6k
🐛 (helm/v2-alpha): Fixed an issue where the ServiceMonitor resource name did not include the default prefix applied by Kustomize.
#5119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: liam-mackie The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
Welcome @liam-mackie! |
|
Hi @liam-mackie. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. 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 kubernetes-sigs/prow repository. |
|
@Kavinjsir / @varshaprasad96 - is there any possibility of getting this one reviewed/approved to test? I'd love to get this in! |
pkg/plugins/optional/helm/v2alpha/scaffolds/internal/kustomize/helm_templater_test.go
Show resolved
Hide resolved
| fs.BoolVar(&p.force, "force", false, "if true, regenerates all the files") | ||
| fs.StringVar(&p.manifestsFile, "manifests", DefaultManifestsFile, | ||
| "path to the YAML file containing Kubernetes manifests from kustomize output") | ||
| fs.StringVar(&p.kustomizePath, "kustomize-path", DefaultKustomizeFile, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think that we should pass the path here, otherwise we will need a flag for each file.
In this case, we might want to get the config from PROJECT file which has the project name instead of check the kustomize file wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, there's no reference to the entrypoint for Kustomize in the PROJECT file, and there's no way to infer the prefix someone uses in Kustomize outside of the kustomization.yaml itself. Kubebuilder conventions put it in config/default/kustomization.yaml. Originally, I left this as unconfigurable, and simply assumed that the kustomization.yaml would always be in this path.
The best we have to get this programatically is the Makefile, which uses it in the build-installer target:
$(KUSTOMIZE) build config/default > dist/install.yaml
The config/default path is what we'd use, and we'd simply look for a kustomization.yaml in there. I'm not sure if that's any better than simply allowing the desired kustomization file to be passed through though.
Happy to defer to your expertise here!
...plugins/optional/helm/v2alpha/scaffolds/internal/templates/chart-templates/servicemonitor.go
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution 🥇
I tried to give the first round of reviews. I think we need to see if we could use the data from install.yaml and check for more generic options. Please, check my comments , let me know wdyt
|
|
||
| // NewChartConverter creates a new chart converter with all necessary components | ||
| func NewChartConverter(resources *ParsedResources, projectName, outputDir string) *ChartConverter { | ||
| func NewChartConverter(resources *ParsedResources, projectName, namePrefix, outputDir string) *ChartConverter { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The projectName and namePrefix here are the same.
So, why would we need both parameters?
Did I miss something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the tests they're the same, but in the code itself, the prefix could possibly be different. We estimate it here and pass it in, as the templater needs it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @liam-mackie
Really thank you for the amazing work 🥇
I think we are very close.
I have just one comment in the latest review — see: https://github.com/kubernetes-sigs/kubebuilder/pull/5119/files#r2434870465
Also, note that for us to get this one merged, we need the commits squashed. Could you please ensure that you squash all commits so that we have only one commit in this PR? Also, could you please rebase this one with master so that it can pass in the tests?
Lastly, I’ll trigger the tests to check if any fail.
ServiceMonitor resource name did not include the default prefix applied by Kustomize.
182aa72 to
11d1780
Compare
All done! Rebased and squashed - thanks for the help! |
There was a problem hiding this comment.
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 fixes an issue where the ServiceMonitor resource name did not respect custom namePrefix values from Kustomize configuration, causing broken installations when using abbreviated controller names.
Key Changes:
- Added
namePrefixdetection from parsed Kustomize resources to distinguish between default and custom prefixes - Modified
ServiceMonitortemplate to use the detected prefix instead of always usingprojectName - Updated the templating logic to preserve custom names when prefix differs from project name
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
servicemonitor.go |
Changed template fields from ProjectNameMixin to explicit NamePrefix and ServiceName fields |
parser.go |
Added EstimatePrefix method to detect custom name prefixes from Kustomize resources |
helm_templater.go |
Added namePrefix field and logic to skip templating when prefix differs from project name |
helm_templater_test.go |
Added tests for ServiceMonitor name generation with matching and differing prefixes |
chart_writer.go |
Updated to use namePrefix instead of projectName for file naming; reformatted function signatures |
chart_converter.go |
Updated constructor to accept namePrefix parameter |
chart_converter_test.go |
Updated test to pass namePrefix to constructor |
edit_kustomize.go |
Added logic to estimate prefix, find metrics service name, and pass both to ServiceMonitor template |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
pkg/plugins/optional/helm/v2alpha/scaffolds/internal/kustomize/parser.go
Outdated
Show resolved
Hide resolved
pkg/plugins/optional/helm/v2alpha/scaffolds/internal/kustomize/helm_templater_test.go
Outdated
Show resolved
Hide resolved
pkg/plugins/optional/helm/v2alpha/scaffolds/internal/kustomize/helm_templater_test.go
Outdated
Show resolved
Hide resolved
11d1780 to
37219ac
Compare
|
I will need some time to properly evaluate /ok-to-test |
|
@liam-mackie: The following test failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. 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 kubernetes-sigs/prow repository. I understand the commands that are listed here. |
That's a good point - we only see the chart name being used at all in the |
|
Hi @liam-mackie 👋 I think the more surgical we are here, the better. Could we try it out this way? |
Background:
When working with long names, you will often need to use a shortened (or abbreviated) version of the controller name as the
namePrefixin thekustomization.yamlfile. This means a shorter name can be used as the prefix to all the files.When using the
v2alpha/helmplugin, this mostly works. The only resource that doesn't use the name generated by Kustomize is theServiceMonitor. This is problematic, as it will use the name (with the custom prefix), then template the chart name (usually the long name) in front of it. This leads to a broken installation.The fix:
This PR fixes this by attempting to get the
namePrefixfrom the kustomization config path. If thenamePrefixand theprojectNameare different, we do not template the file for the service monitor. This way, customisations are honoured, but existing behaviour is maintained.