Skip to content

Conversation

@yyewolf
Copy link

@yyewolf yyewolf commented Nov 19, 2025

I'm not sure why this issue has been closed: #3692
But I haven't seen anyone working on this.

I marked the PR as breaking though I am not sure of the semantics, since I renamed GroupVersion to SchemeGroupVersion I feel like this is a breaking change to the generated code, even though it's not a breaking change to the CLI.

I'm also working on modifying the Makefile and E2E tests which is gonna be in another PR.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Nov 19, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: yyewolf
Once this PR has been reviewed and has the lgtm label, please assign kavinjsir for approval. For more information see the Code Review Process.

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Nov 19, 2025
@k8s-ci-robot
Copy link
Contributor

Welcome @yyewolf!

It looks like this is your first PR to kubernetes-sigs/kubebuilder 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/kubebuilder has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 19, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @yyewolf. Thanks for your PR.

I'm waiting for a github.com member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Nov 19, 2025
@yyewolf yyewolf force-pushed the feat/applyconfiguration branch from 525e623 to 6ce9be5 Compare November 19, 2025 19:57
@yyewolf yyewolf force-pushed the feat/applyconfiguration branch from 6ce9be5 to 7166a19 Compare November 19, 2025 19:58
@@ -0,0 +1,59 @@
/*
Copy link
Member

@camilamacedo86 camilamacedo86 Nov 19, 2025

Choose a reason for hiding this comment

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

Thank you for looking into that. 🎉

If it turns out to be a breaking change, we need to find a way to make it backwards compatible. We can’t introduce it right now.

However, if you want to go ahead and implement the changes based on how you think it should work, and then share your findings with us, we can refine it together in a follow-up.

Because of that, I wouldn’t worry about the e2e tests at this stage. Instead, focus on making the changes in a way that, when you run make generate, the testdata samples are regenerated—or at least show how a project would look with the new behavior.

// GroupVersion is group version used to register these objects.
GroupVersion = schema.GroupVersion{Group: "{{ .Resource.QualifiedGroup }}", Version: "{{ .Resource.Version }}"}
// SchemeGroupVersion is group version used to register these objects.
SchemeGroupVersion = schema.GroupVersion{Group: "{{ .Resource.QualifiedGroup }}", Version: "{{ .Resource.Version }}"}
Copy link
Member

@camilamacedo86 camilamacedo86 Nov 19, 2025

Choose a reason for hiding this comment

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

Why would those changes?
We did not change the values. Why would we need to change the exported variable name?

Copy link
Author

Choose a reason for hiding this comment

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

The generated code for applyconfiguration uses this variable name, it's referenced here: https://github.com/kubernetes/code-generator/blob/master/cmd/applyconfiguration-gen/generators/util.go#L129

However in order to make it backward compatible, we can easily go back and do

Suggested change
SchemeGroupVersion = schema.GroupVersion{Group: "{{ .Resource.QualifiedGroup }}", Version: "{{ .Resource.Version }}"}
GroupVersion = schema.GroupVersion{Group: "{{ .Resource.QualifiedGroup }}", Version: "{{ .Resource.Version }}"}
SchemeGroupVersion = GroupVersion

//nolint:lll
const typesTemplate = `{{ .Boilerplate }}
// +kubebuilder:ac:generate=true
Copy link
Member

Choose a reason for hiding this comment

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

I think the feature must be optional.
We should not promote it by default, right?
By default, people should still be working as they do today.

Copy link
Author

Choose a reason for hiding this comment

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

You're right, I'll make it optional

Copy link
Member

Choose a reason for hiding this comment

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

But if you want to add it in a way that we can first see it working, then we can evaluate it.

Do you have a project that uses this configuration? I’ve never tried to use it myself, so looking at an example would be helpful and could give us some ideas on how we might add it.

Copy link
Author

Choose a reason for hiding this comment

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

I don't have a project that uses this configuration, however I ran the generate testdata using it: 537f54e

Copy link
Author

Choose a reason for hiding this comment

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

I added the flag, made it true by default (for now so we can see the generated code) and also generated the code 👍

{{- else if not .Resource.IsRegularPlural }}
// +kubebuilder:resource:path={{ .Resource.Plural }}
{{- else }}
// +kubebuilder:resource
Copy link
Member

Choose a reason for hiding this comment

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

What does this marker do?
Have you an example of a project using the option for we give a look?
Could you share?

Copy link
Author

Choose a reason for hiding this comment

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

@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 Nov 19, 2025
@yyewolf yyewolf changed the title ⚠(feat): add necessary changes to support applyconfiguration gen ✨(feat): add necessary changes to support applyconfiguration gen Nov 19, 2025
@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 19, 2025
Copy link
Member

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

That is great 🎉start.
Thank you for looking on that.

We need ApplyConfigs to be optional. It must NOT be part of the default scaffold.

The idea is:

  • Add a new flag to kubebuilder create api, for example --applyconfiguration.
  • Only when this flag is used, we scaffold the Makefile target and the templates.
  • To do that, we add a new scaffold marker in the Makefile:
    +kubebuilder:scaffold:applyconfiguration
  • All projects will contain this marker by default, but it is only replaced when the API is created with the flag. ( that would be a change in the Makefile template of the init command. All new project would need to have the marker for we wire or not things up )

How scaffold markers work:
https://book.kubebuilder.io/reference/markers/scaffold

When the user runs:
kubebuilder create api --applyconfiguration
we replace the marker with something like:

.PHONY: generate-applyconfigs
generate-applyconfigs: controller-gen
	"$(CONTROLLER_GEN)" \
		applyconfiguration:headerFile="hack/boilerplate.go.txt" \
		paths="./apis/..."

Also, the scaffolds for the APIs specific files need to be conditinal. I mean, by default nothing changes and will only change when we use create api first ( for all that is common base ) and only for the specific API scaffold for all that can be unique to that api

  1. Add the new flag here:
    https://github.com/kubernetes-sigs/kubebuilder/blob/master/pkg/plugins/golang/v4/api.go#L112-L121

  2. Conditionally write the scaffold here (same as webhook logic):
    https://github.com/kubernetes-sigs/kubebuilder/blob/master/pkg/plugins/golang/v4/scaffolds/api.go#L101-L102

Reference for conditional scaffolding (webhooks):
https://github.com/kubernetes-sigs/kubebuilder/blob/master/pkg/plugins/golang/v4/scaffolds/webhook.go#L106-L143

if err := scaffold.Execute(
&api.Types{Force: s.force},
&api.Group{},
&api.Doc{},
Copy link
Member

Choose a reason for hiding this comment

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

We should only generate the new files if the/when the flag is informed

"$(CONTROLLER_GEN)" applyconfiguration:headerFile="hack/boilerplate.go.txt" object:headerFile={{printf "%q" .BoilerplatePath}} paths="./..."
{{- else -}}
"$(CONTROLLER_GEN)" object paths="./..."
"$(CONTROLLER_GEN)" applyconfiguration object paths="./..."
Copy link
Member

Choose a reason for hiding this comment

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

So, here we should not do this change as well.
We should not change the default scaffold to be applyconfiguration

That would mean all would only work with.

So, the first question is:

In a project, can I have both?

Apis created with applyconfiguration and others not?
OR if we use applyconfiguration all APIs will need to generate with it?

"if set, generate the resource without prompting the user")
p.resourceFlag = fs.Lookup("resource")
fs.BoolVar(&p.options.Namespaced, "namespaced", true, "resource is namespaced")
fs.BoolVar(&p.options.GenerateApplyConfiguration, "generate-apply-configuration", true, "if set, generate applyconfiguration code for the resource")
Copy link
Member

Choose a reason for hiding this comment

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

Can it be done per API or the whole project need to be changed to adopted this?
I mean, can I have 3 APIs that uses applyconfiguration and 3 that do not use them in the same project?
Is that possible?

@@ -0,0 +1,47 @@
/*
Copy link
Member

Choose a reason for hiding this comment

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

IN the testdata we should have no changes.
We should have all projects generate as before.
See that we have test/generate.sh

So, we would need to have a new mock using it and then yes we would only have the scaffold change for the specific API created with the flag. If we cannot have for example X APIs using it and X APIs using not then the change/flag cannot be in the API and it need to be in the edit and init commands ( such as we have multi-group option )

@yyewolf yyewolf force-pushed the feat/applyconfiguration branch from bc37134 to c91bfa9 Compare November 20, 2025 15:41
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Nov 20, 2025
@yyewolf yyewolf marked this pull request as draft November 20, 2025 15:44
@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 Nov 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. 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.

[Assessment and POC] - Integrate Server-Side-Apply Support in Kubebuilder via Controller-Tools and Code-Generator Enhancements

3 participants