Feature: Implement Apply codegen. (#2624)

🎁 Now that the K8s client libraries have an Apply method for the dynamic client, plumb it through the client code generation.

/kind feature
This commit is contained in:
Matt Moore 2022-10-31 13:24:13 -07:00 committed by GitHub
parent 6eb8f1845a
commit 2f194914a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3446 additions and 202 deletions

File diff suppressed because it is too large Load Diff

View File

@ -286,6 +286,11 @@ func (g *clientGenerator) GenerateType(c *generator.Context, t *types.Type, w io
"Group": group,
"VersionLower": version,
"Kind": t.Name.Name,
"ptrString": c.Universe.Function(types.Name{
Package: "knative.dev/pkg/ptr",
Name: "String",
}),
}
for _, v := range verbs.List() {
@ -575,13 +580,51 @@ func (w *wrap{{.GroupGoName}}{{.Version}}{{ .Type.Name.Name }}Impl) Patch(ctx {{
`,
"apply": `{{if .generateApply}}
func (w *wrap{{.GroupGoName}}{{.Version}}{{ .Type.Name.Name }}Impl) Apply(ctx {{ .contextContext|raw }}, in *{{ .ApplyType|raw }}, opts {{ .metav1ApplyOptions|raw }}) (result *{{ .ResultType|raw }}, err error) {
panic("NYI")
in.Kind = {{ .ptrString|raw }}("{{ .Kind }}")
{{ if .Group }}
in.APIVersion = {{ .ptrString|raw }}("{{ .Group }}/{{ .VersionLower }}")
{{ else }}
in.APIVersion = {{ .ptrString|raw }}("{{ .VersionLower }}")
{{ end }}
uo := &{{ .unstructuredUnstructured|raw }}{}
if err := convert(in, uo); err != nil {
return nil, err
}
uo, err = w.dyn{{if .Namespaced}}.Namespace(w.namespace){{end}}.Apply(ctx, uo.GetName(), uo, opts)
if err != nil {
return nil, err
}
out := &{{ .ResultType|raw }}{}
if err := convert(uo, out); err != nil {
return nil, err
}
return out, nil
}
{{end}}
`,
"applyStatus": `{{if .generateApply}}
func (w *wrap{{.GroupGoName}}{{.Version}}{{ .Type.Name.Name }}Impl) ApplyStatus(ctx {{ .contextContext|raw }}, in *{{ .ApplyType|raw }}, opts {{ .metav1ApplyOptions|raw }}) (result *{{ .ResultType|raw }}, err error) {
panic("NYI")
in.Kind = {{ .ptrString|raw }}("{{ .Kind }}")
{{ if .Group }}
in.APIVersion = {{ .ptrString|raw }}("{{ .Group }}/{{ .VersionLower }}")
{{ else }}
in.APIVersion = {{ .ptrString|raw }}("{{ .VersionLower }}")
{{ end }}
uo := &{{ .unstructuredUnstructured|raw }}{}
if err := convert(in, uo); err != nil {
return nil, err
}
uo, err = w.dyn{{if .Namespaced}}.Namespace(w.namespace){{end}}.ApplyStatus(ctx, uo.GetName(), uo, opts)
if err != nil {
return nil, err
}
out := &{{ .ResultType|raw }}{}
if err := convert(uo, out); err != nil {
return nil, err
}
return out, nil
}
{{end}}
`,