mirror of https://github.com/knative/pkg.git
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:
parent
6eb8f1845a
commit
2f194914a4
File diff suppressed because it is too large
Load Diff
|
|
@ -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}}
|
||||
`,
|
||||
|
|
|
|||
Loading…
Reference in New Issue