-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Allow to extend generated clients with custom verbs #16019
Allow to extend generated clients with custom verbs #16019
Conversation
@sttts @deads2k not ideal but somewhat working...
This need more work, but want to share WIP to get some early feedback... |
pkg/deploy/apis/apps/types.go
Outdated
@@ -123,6 +123,7 @@ const ( | |||
) | |||
|
|||
// +genclient | |||
// +genclient:createInstantiateVerb=subresource=instantiate,input=DeploymentRequest |
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 only works if DeploymentRequest is in the same package (does not work for external types or kapi / etc.) ...
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 only works if DeploymentRequest is in the same package (does not work for external types or kapi / etc.)
One our our use-cases is Scale (in autoscaling) and another is ImageSecrets or some such (in the core API group). Could we provide a full package name or something?
/unassign |
func parseClientExpansions(tags map[string][]string) ([]expansion, error) { | ||
ret := []expansion{} | ||
for name, values := range tags { | ||
if !strings.HasPrefix(name, "genclient:") || !strings.HasSuffix(name, "Verb") { |
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.
"genclient:" is worth a constant
name = strings.TrimPrefix(name, "genclient:") | ||
exp := expansion{} | ||
for _, supportedVerb := range SupportedVerbs { | ||
if strings.HasPrefix(name, supportedVerb) { |
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 looks fuzzy. Can't we be more precise with matching?
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.
@sttts at this point we only matched everything that starts with the supported verb and has *Verb suffix. Everything between is considered as expansion verb name. Dunno if there is a better way other than regexp.
continue | ||
} | ||
exp.VerbName = strings.TrimSuffix(strings.TrimPrefix(name, exp.VerbType), "Verb") | ||
if len(values[0]) > 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.
are we sure there are values?
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.
do I remember right that multiple tag line give you multiple values 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.
yes, if you repeat the same tag (same verb) with different configuration it will give you multiple values... i'm not sure if we want to support it... something like this looks like something we don't want to recommend?
// +genclient:createFooVerb=subresource=foo
// +genclient:createFooVerb=output=Foo
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.
nvmd. this actually works well if I move this into a for _, v := range values {} loop... so people can use this in multi-line if they really want
return ret, validateClientGenTags(values) | ||
} | ||
|
||
func parseClientExpansions(tags map[string][]string) ([]expansion, error) { | ||
ret := []expansion{} |
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.
var ret []expansion
. Then you don't need the if at the bottom.
edf8d47
to
1f01937
Compare
This generates what we need and we can use this to produce updateStatus as well (which is a sub-resource) and also the Scale() for autoscaling... This is missing the fake client (it won't conform the interface right now, but this is also broken with normal expansions, I will try to fix it). |
1f01937
to
e0a027a
Compare
e0a027a
to
a2d4d48
Compare
@sttts syntax updated :) |
a2d4d48
to
89245a7
Compare
89245a7
to
f982838
Compare
obj, err := c.Fake. | ||
$if .namespaced$Invokes($.NewListAction|raw$($.type|allLowercasePlural$Resource, $.type|allLowercasePlural$Kind, c.ns, opts), &$.type|raw$List{}) | ||
$else$Invokes($.NewRootListAction|raw$($.type|allLowercasePlural$Resource, $.type|allLowercasePlural$Kind, opts), &$.type|raw$List{})$end$ | ||
$if .namespaced$Invokes($if .subresource$$.NewListSubresourceAction|raw$$else$$.NewListAction|raw$$end$($.type|allLowercasePlural$Resource, $if .subresource$"$.subresourcePath$",$end$$.type|allLowercasePlural$Kind, c.ns, opts), &$.resultType|raw$List{}) |
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.
@sttts this is hell.
f982838
to
a95673f
Compare
(no need to api review, this is just adding genclient tags, not modifying API) |
/retest |
@Kargakis seems like the @openshift-merge-robot doing crazy things :) |
It actually is doing the right thing: adding the approved label because you removed it and the PR is approved, and adding the needs-api-review label because again you removed it. :) The SQ will not block on needs-api-review. We can improve the path-label munger in the future to add labels only on PR creation which will allow us to remove them afterwards. |
/test extended_conformance_gce |
40a369a
to
c087b7d
Compare
/test cmd seems like server failed to start? |
/test extended_conformance_gce |
/retest |
/lgtm If there are changes in the upstream PR, it shouldn't be hard to backport or wait for the next rebase. |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: mfojtik, sttts The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these OWNERS Files:
You can indicate your approval by writing |
Automatic merge from submit-queue |
We need this in order to generate client calls like
.Instantiate()
or.Secrets()
(for image stream secrets).In upstream, this will allow to generate
UpdateStatus
which is currently "guessed" by checking for the presence of ".Status" field in the resource. It also allows to generate custom.Scale(...)
in autoscaler.Additionally this allows to send requests to sub-resources but also allows to override the input and result types for existing client calls or for extended client calls. The extended client calls are generated to the main client interface.
The final syntax is:
(the input/result types will allow to provide full import path, see the checklist)
TODO
.Scale()
and.UpdateStatus()