-
Notifications
You must be signed in to change notification settings - Fork 425
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
[WIP] ✨ Generation of typed apply clients using upstream generator #818
base: main
Are you sure you want to change the base?
[WIP] ✨ Generation of typed apply clients using upstream generator #818
Conversation
Skipping CI for Draft Pull Request. |
18594e4
to
74642c2
Compare
"k8s.io/api/": "k8s.io/client-go/applyconfigurations/", | ||
} | ||
|
||
const importPathSuffix = "applyconfiguration" |
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.
Should this be configurable via a marker?
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.
This is now available to be customized with the marker kubebuilder:ac:output:package
pkg/applyconfigurations/gen.go
Outdated
enableTypeMarker = markers.Must(markers.MakeDefinition("kubebuilder:ac:generate", markers.DescribesType, false)) | ||
) | ||
|
||
var importMapping = map[string]string{ |
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.
Should we allow additional import mappings, I know the upstream applyconfiguration gen does
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 think that makes sense, yeah (But we can do that in a follow-up)
/test all Need to work out how to test this, but want to see what the existing tests do with this so I can fix any failures introduced |
/test all |
filesInMaster := make(map[string][]byte) | ||
masterFileNames := sets.New[string]() | ||
cronJobFS := os.DirFS(".") | ||
masterPath := "applyconfiguration-master" |
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.
Because I can't change the directory to which we are generating the assets currently, this is what I came up with, create a copy that we keep checked in and then diff against that, if there are genuine changes we can update both copies.
Will look at gengo to see if there's a backwards compatible way to allow it to output to different places like OutputRule
does for these generators
/assign @alvaroaleman |
As an option I would love to have the Extract functions, we use them extensively in our operator (for better or for worse). |
pkg/applyconfigurations/gen.go
Outdated
genericArgs, _ := generatorargs.NewDefaults() | ||
genericArgs.InputDirs = []string{root.PkgPath} | ||
genericArgs.OutputPackagePath = filepath.Join(root.PkgPath, importPathSuffix) | ||
genericArgs.GoHeaderFilePath = ctx.HeaderFilePath |
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.
If I see correctly this currently stores the generated files somewhere below GOPATH/src (which isn't where I have the controller-tools repo). Would be probably good to align this to how we can set output dir in other generators.
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 tried to run this in Cluster API with ~ apply paths=./api/...
I end up with files generated in $GOPATH/src/sigs.k8s.io/cluster-api/api/v1beta1/applyconfiguration/api/v1beta1
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.
Not sure if it's good if we store the applyconfigurations in a sub-package of the API types. Might be a simple output:apply:dir would be better and then we can store it below there, e.g.
- output:apply:dir is explicitly set to
$GOPATH/src/sigs.k8s.io/cluster-api/applyconfigurations
- files are then generated in e.g.
$GOPATH/src/sigs.k8s.io/cluster-api/applyconfiguration/api/v1beta1
I think this would follow the same pattern as the ones in client-go. (side note: the API folders are not well structured in Cluster API)
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.
(probably this is covered by #818 (comment) feel free to resolve)
@JoelSpeed Can we get rid of the vendor folder? It's probably on my side but the performance of the file tab is pretty bad with 1700 files. |
@@ -0,0 +1,46 @@ | |||
// Code generated by applyconfiguration-gen. DO NOT EDIT. | |||
|
|||
package internal |
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.
Q: Why this is generated?
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.
applyconfiguration-gen always outputs this. The Parser() item is used in the internal extract implementations. And that schema yaml defines what items can then be parsed I believe.
called like this in extractCrdType
internal.Parser().Type("com.domain.group.api.v1.CrdType")
Second this, I can literally not review this through the GitHub UI |
Sorry about that, must have committed during my experimenting, dropped it now, commit history in need of a good clean though |
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.
For an internal project, I added the +kubebuilder:ac:generate=true
comment both on the package and on my type, running controller-gen
with apply paths=./pkg/api/v1/
succeeds but doesn't generate anything - any idea what I am am doing wrong?
pkg/applyconfigurations/gen.go
Outdated
enableTypeMarker = markers.Must(markers.MakeDefinition("kubebuilder:ac:generate", markers.DescribesType, false)) | ||
) | ||
|
||
var importMapping = map[string]string{ |
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 think that makes sense, yeah (But we can do that in a follow-up)
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.
For an internal project, I added the +kubebuilder:ac:generate=true
comment both on the package and on my type, running controller-gen
with apply paths=./pkg/api/v1/
succeeds but doesn't generate anything - any idea what I am am doing wrong?
Potentially could be: #818 (comment) |
607e978
to
0aa6676
Compare
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: JoelSpeed 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 |
@jakobmoellerdev Reached out to me last week and sent me a patch that we think resolves a number of the comments here. @jakobmoellerdev Anything the reviewers need to know about what you've changed? |
"k8s.io/api/": "k8s.io/client-go/applyconfigurations/", | ||
} | ||
|
||
const importPathSuffix = "applyconfiguration" |
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.
This is now available to be customized with the marker kubebuilder:ac:output:package
// looking into the package and retrieving the first go file it finds, and using that as the output base. | ||
// this is because we cannot rely on gogen calculating the correct output base. | ||
// if we leave this empty, gogen will attempt to use GOPATH to write the files which is not wanted | ||
genericArgs.OutputBase = filepath.Dir(root.GoFiles[0]) |
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 think with some more invest it may be possible to resolve the directory smoother but there we issues with the output package not having correct import paths. For now this will work fine with the generation of the base directory being in the package path. For the request of having a directory outside of the package path this needs adjustment though. Open to any ideas here
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 believe in general it should now work both within and outside GOPATH and should resolve the issue @sbueringer and @alvaroaleman not seeing the generated files in the right folders
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 believe this file was included due to the patch, should be removed from the final version
PR needs rebase. 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/test-infra repository. |
@JoelSpeed Do you have some bandwidth to follow up on this PR? I just added the upstream generator to one of our projects to get some progress towards SSA, and it was NOT a pleasant experience! I would love to see the ability to generate apply clients with controller-gen. |
@erikgb I'm currently waiting on a second round of review from those who previously reviewed. @jakobmoellerdev kindly continued the work and we pushed his updates to my branch, but haven't had a review since then |
New year new bump :) any chance this can get another round of review? I can resolve the merge conflict if necessary @JoelSpeed, please let me know if I should take another look |
The Kubernetes project currently lacks enough contributors to adequately respond to all PRs. This bot triages PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
/remove-lifecycle stale Apologies for the further delay. Really trying to get around to it, just too much going on. |
@sbueringer: The In 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 kubernetes/test-infra repository. |
@sbueringer Bringing this back from the depths of your PR pile! |
Not sure if I actually asked it somewhere :). @JoelSpeed How fundamentally might this PR change with the rebase that is necessary for 1.30? |
Great question. I know there's been a massive rewrite of the gengo stuff, I have some WIP stuff in place for some OpenShift tooling that was affected by that, but in general, it wasn't massive. I would hope this would be similar, but yes, we need to get the deps updated to 1.30 and see tbh |
Was just wondering if it makes sense for me to review the PR before the rebase. I could commit to actually doing the review assuming you find the time for a rebase :) |
@JoelSpeed I take that as you choose to do the rebase or I submit another patch. :) PLMK |
I likely won't have time until next friday to take that on, but if you want to have a go @jakobmoellerdev I can force push whatever you come up with over my branch again if you wanted? |
The Kubernetes project currently lacks enough contributors to adequately respond to all PRs. This bot triages PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
This is still relevant /remove-lifecycle stale |
This integrates the upstream applyconfig generator into controller-tools to allow generation of ApplyConfig style types from custom API types.
The aim here is to provide the pointer style structs that could then be passed to an Apply style method for using server side apply.
Setting this up as a WIP PR for now, current TODO list: