Skip to content
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

🐛 (helm/v1-alpha): not scaffold webhooks conditionals manifests for projects without webhooks #4584

Merged

Conversation

camilamacedo86
Copy link
Member

@camilamacedo86 camilamacedo86 commented Feb 28, 2025

Closes: #4582

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Feb 28, 2025
@k8s-ci-robot
Copy link
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

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 approved Indicates a PR has been approved by an approver from all required OWNERS files. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Feb 28, 2025
@camilamacedo86 camilamacedo86 changed the title 🐛 (helm/v1-alpha): Fix helm-chart scaffold by not scaffolding manifests with webhook conditions when webhooks are not used 🐛 (helm/v1-alpha): not scaffold webhooks conditionals manifests for projects without webhooks Feb 28, 2025
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Feb 28, 2025
@@ -96,7 +97,7 @@ func (s *initScaffolder) Scaffold() error {
DeployImages: len(imagesEnvVars) > 0,
HasWebhooks: hasWebhooks,
},
&templatescertmanager.Certificate{},
&templatescertmanager.Certificate{HasWebhooks: hasWebhooks},
Copy link

Choose a reason for hiding this comment

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

sorry Camila, just wondered whether it is being updated due to scaffalding webhooks conditional issues.

Copy link
Member Author

Choose a reason for hiding this comment

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

we are passing the value HasWebhooks here because then inside of the boilerplate to generate the Certs we just generate those which related to Webhook Sever only when we have Webhooks

@camilamacedo86 camilamacedo86 requested a review from sbin64 March 6, 2025 22:56
Copy link

@sbin64 sbin64 left a comment

Choose a reason for hiding this comment

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

Looks good, but why this has failed. I suspect from here whether intended.

sigs.k8s.io/kubebuilder/v4/pkg/config
  Incompatible changes:
  - Config.HasWebhooks: added

@camilamacedo86
Copy link
Member Author

camilamacedo86 commented Mar 7, 2025

Regards: #4584 (review)
The lib try to help us know about breaking changes in the API
In this case, shows a false alarm. We are adding a new method, not removing.

We can either do not change the API and keep the implementation inside of the plugin.
It might be a better choice, if we see more places that needs it then we can consider in expose the method

@@ -172,6 +172,23 @@ func (c Cfg) HasResource(gvk resource.GVK) bool {
return found
}

// HasWebhooks checks if any stored resource has associated webhooks.
func (c Cfg) HasWebhooks() bool {
Copy link
Member Author

Choose a reason for hiding this comment

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

/hold

Remove from the interface

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 7, 2025
@camilamacedo86
Copy link
Member Author

/hold cancel

It is good to fly now.

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 19, 2025
Copy link
Contributor

@Kavinjsir Kavinjsir left a comment

Choose a reason for hiding this comment

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

Hey @camilamacedo86, everything’s looking great! I just dropped a few tiny concerns.

{{ "{{- if and .Values.certmanager.enable (or .Values.webhook.enable .Values.metrics.enable) }}" }}
{{- else }}
{{ "{{- if and .Values.certmanager.enable .Values.metrics.enable }}" }}
{{- end }}
Copy link
Contributor

@Kavinjsir Kavinjsir Mar 22, 2025

Choose a reason for hiding this comment

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

Nit:
For the following two lines, how would you like we predefine variables as references for code readability?

      {{ "{{- if and .Values.certmanager.enable (or .Values.webhook.enable .Values.metrics.enable) }}" }}
      {{ "{{- if and .Values.certmanager.enable .Values.metrics.enable }}" }}

Such as:

{{- $certmanagerConditionWithHooks := `{{- if and .Values.certmanager.enable (or .Values.webhook.enable .Values.metrics.enable) }}` -}}
{{- $certmanagerConditionNoHooks := `{{- if and .Values.certmanager.enable .Values.metrics.enable }}` -}}

{{- if .HasWebhooks }}
  {{ $certmanagerConditionWithHooks }}
{{- else }}
  {{ $certmanagerConditionNoHooks }}
{{- end }}

Or perhaps, having these values defined in helpers.tpl?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure if that would work well — we'd need to test it out first.
Since we're generating boilerplate to produce a template, it's a bit tricky to ensure consistent outputs.

Also, the certmanagerConditionWithHooks and certmanagerConditionNoHooks shouldn't be in the helpers.tpl. The idea is to only include a Helm template with .Values.webhook.enable when the project actually uses webhooks.

That said, if you'd like, we can definitely explore making changes in a follow-up.
If you see a clear path to improve things, we’ll likely need to update other parts as well to keep everything consistent and aligned with the same approach.

So for now, I think we can move forward with the current fix — but please feel free to open issues, PRs, etc., so we can address improvements more broadly.

mutatingWebhooks, validatingWebhooks, err := s.extractWebhooksFromGeneratedFiles()
if err != nil {
return fmt.Errorf("failed to extract webhooks: %w", err)
}
hasWebhooks := hasWebhooks(s.config) || (len(mutatingWebhooks) > 0 && len(validatingWebhooks) > 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Wondering if it’d be okay to change the name of the boolean variable so it’s not the same as the function hasWebhooks
Or, alternatively, update the function name instead, maybe something like webhooksConfigured.
(Just in case this would help readability.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you.
I changed the func name for hasWebhooksWith which seems the most appropriate.

… with webhook conditions when webhooks are not used
@camilamacedo86
Copy link
Member Author

HI @Kavinjsir

I think we can merge this since it fixes the issues, looks for improvements, etc, in follow-up, wdyt?
Do we have your LGTM? PS. Your recommendation about having variables and functions with different names is addressed now, too.

Thank youvery mucht for your time.

@camilamacedo86
Copy link
Member Author

Since the comments have been addressed and there were no objections to the fix, I'm going ahead and merging this so we can get it into the next release.

That said, we can always iterate and improve on it in a follow-up as needed.

Please feel free to open new PRs if you have suggestions or improvements in mind — always happy to review!

@camilamacedo86 camilamacedo86 added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 26, 2025
@camilamacedo86 camilamacedo86 merged commit d90d095 into kubernetes-sigs:master Mar 26, 2025
24 of 28 checks passed
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: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. 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.

(helm/v1-alpha) Generates invalid chart in operator without webhooks
4 participants