diff --git a/cmd/client-gen/generators/fake/fake_client_generator.go b/cmd/client-gen/generators/fake/fake_client_generator.go index 699c7b5f..935efec2 100644 --- a/cmd/client-gen/generators/fake/fake_client_generator.go +++ b/cmd/client-gen/generators/fake/fake_client_generator.go @@ -58,8 +58,8 @@ func TargetForGroup(gv clientgentypes.GroupVersion, typeList []*types.Type, clie OutputFilename: "fake_" + strings.ToLower(c.Namers["private"].Name(t)) + ".go", }, outputPackage: outputPkg, + realClientPackage: realClientPkg, inputPackage: inputPkg, - group: gv.Group.NonEmpty(), version: gv.Version.String(), groupGoName: groupGoName, typeToMatch: t, @@ -74,7 +74,6 @@ func TargetForGroup(gv clientgentypes.GroupVersion, typeList []*types.Type, clie }, outputPackage: outputPkg, realClientPackage: realClientPkg, - group: gv.Group.NonEmpty(), version: gv.Version.String(), groupGoName: groupGoName, types: typeList, diff --git a/cmd/client-gen/generators/fake/generator_fake_for_group.go b/cmd/client-gen/generators/fake/generator_fake_for_group.go index d9c9b8ba..04c586a0 100644 --- a/cmd/client-gen/generators/fake/generator_fake_for_group.go +++ b/cmd/client-gen/generators/fake/generator_fake_for_group.go @@ -34,7 +34,6 @@ type genFakeForGroup struct { generator.GoGenerator outputPackage string // must be a Go import-path realClientPackage string // must be a Go import-path - group string version string groupGoName string // types in this group @@ -78,6 +77,8 @@ func (g *genFakeForGroup) GenerateType(c *generator.Context, t *types.Type, w io "Fake": c.Universe.Type(types.Name{Package: "k8s.io/client-go/testing", Name: "Fake"}), "RESTClientInterface": c.Universe.Type(types.Name{Package: "k8s.io/client-go/rest", Name: "Interface"}), "RESTClient": c.Universe.Type(types.Name{Package: "k8s.io/client-go/rest", Name: "RESTClient"}), + "FakeClient": c.Universe.Type(types.Name{Package: "k8s.io/client-go/gentype", Name: "FakeClient"}), + "NewFakeClient": c.Universe.Function(types.Name{Package: "k8s.io/client-go/gentype", Name: "NewFakeClient"}), } sw.Do(groupClientTemplate, m) @@ -110,13 +111,13 @@ type Fake$.GroupGoName$$.Version$ struct { var getterImplNamespaced = ` func (c *Fake$.GroupGoName$$.Version$) $.type|publicPlural$(namespace string) $.realClientPackage$.$.type|public$Interface { - return &Fake$.type|publicPlural${c, namespace} + return newFake$.type|publicPlural$(c, namespace) } ` var getterImplNonNamespaced = ` func (c *Fake$.GroupGoName$$.Version$) $.type|publicPlural$() $.realClientPackage$.$.type|public$Interface { - return &Fake$.type|publicPlural${c} + return newFake$.type|publicPlural$(c) } ` diff --git a/cmd/client-gen/generators/fake/generator_fake_for_type.go b/cmd/client-gen/generators/fake/generator_fake_for_type.go index 0e071af9..6c141003 100644 --- a/cmd/client-gen/generators/fake/generator_fake_for_type.go +++ b/cmd/client-gen/generators/fake/generator_fake_for_type.go @@ -35,7 +35,7 @@ import ( type genFakeForType struct { generator.GoGenerator outputPackage string // Must be a Go import-path - group string + realClientPackage string // Must be a Go import-path version string groupGoName string inputPackage string @@ -61,37 +61,9 @@ func (g *genFakeForType) Imports(c *generator.Context) (imports []string) { return g.imports.ImportLines() } -// Ideally, we'd like genStatus to return true if there is a subresource path -// registered for "status" in the API server, but we do not have that -// information, so genStatus returns true if the type has a status field. -func genStatus(t *types.Type) bool { - // Default to true if we have a Status member - hasStatus := false - for _, m := range t.Members { - if m.Name == "Status" { - hasStatus = true - break - } - } - - tags := util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...)) - return hasStatus && !tags.NoStatus -} - -// hasObjectMeta returns true if the type has a ObjectMeta field. -func hasObjectMeta(t *types.Type) bool { - for _, m := range t.Members { - if m.Embedded && m.Name == "ObjectMeta" { - return true - } - } - return false -} - // GenerateType makes the body of a file implementing the individual typed client for type t. func (g *genFakeForType) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error { sw := generator.NewSnippetWriter(w, c, "$", "$") - pkg := path.Base(t.Name.Package) tags, err := util.ParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...)) if err != nil { return err @@ -99,32 +71,28 @@ func (g *genFakeForType) GenerateType(c *generator.Context, t *types.Type, w io. const pkgClientGoTesting = "k8s.io/client-go/testing" m := map[string]interface{}{ - "type": t, - "inputType": t, - "resultType": t, - "subresourcePath": "", - "package": pkg, - "Package": namer.IC(pkg), - "namespaced": !tags.NonNamespaced, - "Group": namer.IC(g.group), - "GroupGoName": g.groupGoName, - "Version": namer.IC(g.version), - "version": g.version, - "SchemeGroupVersion": c.Universe.Type(types.Name{Package: t.Name.Package, Name: "SchemeGroupVersion"}), - "CreateOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "CreateOptions"}), - "DeleteOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "DeleteOptions"}), - "GetOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "GetOptions"}), - "ListOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "ListOptions"}), - "PatchOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "PatchOptions"}), - "ApplyOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "ApplyOptions"}), - "UpdateOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "UpdateOptions"}), - "Everything": c.Universe.Function(types.Name{Package: "k8s.io/apimachinery/pkg/labels", Name: "Everything"}), - "PatchType": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/types", Name: "PatchType"}), - "ApplyPatchType": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/types", Name: "ApplyPatchType"}), - "watchInterface": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/watch", Name: "Interface"}), - "jsonMarshal": c.Universe.Type(types.Name{Package: "encoding/json", Name: "Marshal"}), - "fmtErrorf": c.Universe.Type(types.Name{Package: "fmt", Name: "Errorf"}), - "contextContext": c.Universe.Type(types.Name{Package: "context", Name: "Context"}), + "type": t, + "inputType": t, + "resultType": t, + "subresourcePath": "", + "namespaced": !tags.NonNamespaced, + "GroupGoName": g.groupGoName, + "Version": namer.IC(g.version), + "realClientInterface": c.Universe.Type(types.Name{Package: g.realClientPackage, Name: t.Name.Name + "Interface"}), + "SchemeGroupVersion": c.Universe.Type(types.Name{Package: t.Name.Package, Name: "SchemeGroupVersion"}), + "CreateOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "CreateOptions"}), + "DeleteOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "DeleteOptions"}), + "GetOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "GetOptions"}), + "ListOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "ListOptions"}), + "PatchOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "PatchOptions"}), + "ApplyOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "ApplyOptions"}), + "UpdateOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "UpdateOptions"}), + "PatchType": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/types", Name: "PatchType"}), + "ApplyPatchType": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/types", Name: "ApplyPatchType"}), + "watchInterface": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/watch", Name: "Interface"}), + "jsonMarshal": c.Universe.Type(types.Name{Package: "encoding/json", Name: "Marshal"}), + "fmtErrorf": c.Universe.Type(types.Name{Package: "fmt", Name: "Errorf"}), + "contextContext": c.Universe.Type(types.Name{Package: "context", Name: "Context"}), "NewRootListActionWithOptions": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootListActionWithOptions"}), "NewListActionWithOptions": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewListActionWithOptions"}), @@ -132,8 +100,6 @@ func (g *genFakeForType) GenerateType(c *generator.Context, t *types.Type, w io. "NewGetActionWithOptions": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewGetActionWithOptions"}), "NewRootDeleteActionWithOptions": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootDeleteActionWithOptions"}), "NewDeleteActionWithOptions": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewDeleteActionWithOptions"}), - "NewRootDeleteCollectionActionWithOptions": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootDeleteCollectionActionWithOptions"}), - "NewDeleteCollectionActionWithOptions": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewDeleteCollectionActionWithOptions"}), "NewRootUpdateActionWithOptions": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootUpdateActionWithOptions"}), "NewUpdateActionWithOptions": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewUpdateActionWithOptions"}), "NewRootCreateActionWithOptions": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootCreateActionWithOptions"}), @@ -146,11 +112,16 @@ func (g *genFakeForType) GenerateType(c *generator.Context, t *types.Type, w io. "NewGetSubresourceActionWithOptions": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewGetSubresourceActionWithOptions"}), "NewRootGetSubresourceActionWithOptions": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootGetSubresourceActionWithOptions"}), "NewRootUpdateSubresourceActionWithOptions": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootUpdateSubresourceActionWithOptions"}), - "NewRootPatchActionWithOptions": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootPatchActionWithOptions"}), - "NewPatchActionWithOptions": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewPatchActionWithOptions"}), "NewRootPatchSubresourceActionWithOptions": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootPatchSubresourceActionWithOptions"}), "NewPatchSubresourceActionWithOptions": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewPatchSubresourceActionWithOptions"}), - "ExtractFromListOptions": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "ExtractFromListOptions"}), + "FakeClient": c.Universe.Type(types.Name{Package: "k8s.io/client-go/gentype", Name: "FakeClient"}), + "NewFakeClient": c.Universe.Function(types.Name{Package: "k8s.io/client-go/gentype", Name: "NewFakeClient"}), + "FakeClientWithApply": c.Universe.Type(types.Name{Package: "k8s.io/client-go/gentype", Name: "FakeClientWithApply"}), + "NewFakeClientWithApply": c.Universe.Function(types.Name{Package: "k8s.io/client-go/gentype", Name: "NewFakeClientWithApply"}), + "FakeClientWithList": c.Universe.Type(types.Name{Package: "k8s.io/client-go/gentype", Name: "FakeClientWithList"}), + "NewFakeClientWithList": c.Universe.Function(types.Name{Package: "k8s.io/client-go/gentype", Name: "NewFakeClientWithList"}), + "FakeClientWithListAndApply": c.Universe.Type(types.Name{Package: "k8s.io/client-go/gentype", Name: "FakeClientWithListAndApply"}), + "NewFakeClientWithListAndApply": c.Universe.Function(types.Name{Package: "k8s.io/client-go/gentype", Name: "NewFakeClientWithListAndApply"}), } generateApply := len(g.applyConfigurationPackage) > 0 @@ -160,56 +131,23 @@ func (g *genFakeForType) GenerateType(c *generator.Context, t *types.Type, w io. m["inputApplyConfig"] = types.Ref(path.Join(g.applyConfigurationPackage, gvString), t.Name.Name+"ApplyConfiguration") } - if tags.NonNamespaced { - sw.Do(structNonNamespaced, m) - } else { - sw.Do(structNamespaced, m) - } + listableOrAppliable := noList | noApply - if tags.NoVerbs { - return sw.Error() + if !tags.NoVerbs && tags.HasVerb("list") { + listableOrAppliable |= withList } - sw.Do(resource, m) - sw.Do(kind, m) - if tags.HasVerb("get") { - sw.Do(getTemplate, m) - } - if tags.HasVerb("list") { - if hasObjectMeta(t) { - sw.Do(listUsingOptionsTemplate, m) - } else { - sw.Do(listTemplate, m) - } - } - if tags.HasVerb("watch") { - sw.Do(watchTemplate, m) + if !tags.NoVerbs && tags.HasVerb("apply") && generateApply { + listableOrAppliable |= withApply } - if tags.HasVerb("create") { - sw.Do(createTemplate, m) - } - if tags.HasVerb("update") { - sw.Do(updateTemplate, m) - } - if tags.HasVerb("updateStatus") && genStatus(t) { - sw.Do(updateStatusTemplate, m) - } - if tags.HasVerb("delete") { - sw.Do(deleteTemplate, m) - } - if tags.HasVerb("deleteCollection") { - sw.Do(deleteCollectionTemplate, m) - } - if tags.HasVerb("patch") { - sw.Do(patchTemplate, m) - } - if tags.HasVerb("apply") && generateApply { - sw.Do(applyTemplate, m) - } - if tags.HasVerb("applyStatus") && generateApply && genStatus(t) { - sw.Do(applyStatusTemplate, m) + sw.Do(structType[listableOrAppliable], m) + sw.Do(newStruct[listableOrAppliable], m) + + if tags.NoVerbs { + return sw.Error() } + _, typeGVString := util.ParsePathGroupVersion(g.inputPackage) // generate extended client methods @@ -253,7 +191,6 @@ func (g *genFakeForType) GenerateType(c *generator.Context, t *types.Type, w io. } if e.HasVerb("list") { - sw.Do(adjustTemplate(e.VerbName, e.VerbType, listTemplate), m) } @@ -307,77 +244,147 @@ func adjustTemplate(name, verbType, template string) string { return strings.ReplaceAll(template, " "+titler.String(verbType), " "+name) } -// template for the struct that implements the type's interface -var structNamespaced = ` -// Fake$.type|publicPlural$ implements $.type|public$Interface -type Fake$.type|publicPlural$ struct { - Fake *Fake$.GroupGoName$$.Version$ - ns string -} -` +// struct and constructor variants +const ( + // The following values are bits in a bitmask. + // The values which can be set indicate list support and apply support; + // to make the declarations easier to read (like a truth table), corresponding zero-values + // are also declared. + noList = 0 + noApply = 0 + withList = 1 << iota + withApply +) -// template for the struct that implements the type's interface -var structNonNamespaced = ` -// Fake$.type|publicPlural$ implements $.type|public$Interface -type Fake$.type|publicPlural$ struct { - Fake *Fake$.GroupGoName$$.Version$ +// The following string slices are similar to maps, but with combinable keys used as indices. +// Each entry defines whether it supports lists and/or apply; each bit is then toggled: +// * noList, noApply: index 0; +// * withList, noApply: index 1; +// * noList, withApply: index 2; +// * withList, withApply: index 3. +// Go enforces index unicity in these kinds of declarations. + +// struct declarations +var structType = []string{ + noList | noApply: ` + // fake$.type|publicPlural$ implements $.type|public$Interface + type fake$.type|publicPlural$ struct { + *$.FakeClient|raw$[*$.type|raw$] + Fake *Fake$.GroupGoName$$.Version$ + } + `, + withList | noApply: ` + // fake$.type|publicPlural$ implements $.type|public$Interface + type fake$.type|publicPlural$ struct { + *$.FakeClientWithList|raw$[*$.type|raw$, *$.type|raw$List] + Fake *Fake$.GroupGoName$$.Version$ + } + `, + noList | withApply: ` + // fake$.type|publicPlural$ implements $.type|public$Interface + type fake$.type|publicPlural$ struct { + *$.FakeClientWithApply|raw$[*$.type|raw$, *$.inputApplyConfig|raw$] + Fake *Fake$.GroupGoName$$.Version$ + } + `, + withList | withApply: ` + // fake$.type|publicPlural$ implements $.type|public$Interface + type fake$.type|publicPlural$ struct { + *$.FakeClientWithListAndApply|raw$[*$.type|raw$, *$.type|raw$List, *$.inputApplyConfig|raw$] + Fake *Fake$.GroupGoName$$.Version$ + } + `, } -` - -var resource = ` -var $.type|allLowercasePlural$Resource = $.SchemeGroupVersion|raw$.WithResource("$.type|resource$") -` -var kind = ` -var $.type|allLowercasePlural$Kind = $.SchemeGroupVersion|raw$.WithKind("$.type|singularKind$") -` - -var listTemplate = ` -// List takes label and field selectors, and returns the list of $.type|publicPlural$ that match those selectors. -func (c *Fake$.type|publicPlural$) List(ctx $.contextContext|raw$, opts $.ListOptions|raw$) (result *$.type|raw$List, err error) { - emptyResult := &$.type|raw$List{} - obj, err := c.Fake. - $if .namespaced$Invokes($.NewListActionWithOptions|raw$($.type|allLowercasePlural$Resource, $.type|allLowercasePlural$Kind, c.ns, opts), emptyResult) - $else$Invokes($.NewRootListActionWithOptions|raw$($.type|allLowercasePlural$Resource, $.type|allLowercasePlural$Kind, opts), emptyResult)$end$ - if obj == nil { - return emptyResult, err +// Constructors for the struct, in all variants +var newStruct = []string{ + noList | noApply: ` + func newFake$.type|publicPlural$(fake *Fake$.GroupGoName$$.Version$$if .namespaced$, namespace string$end$) $.realClientInterface|raw$ { + return &fake$.type|publicPlural${ + $.NewFakeClient|raw$[*$.type|raw$]( + fake.Fake, + $if .namespaced$namespace$else$""$end$, + $.SchemeGroupVersion|raw$.WithResource("$.type|resource$"), + $.SchemeGroupVersion|raw$.WithKind("$.type|singularKind$"), + func() *$.type|raw$ {return &$.type|raw${}}, + ), + fake, + } } - return obj.(*$.type|raw$List), err + `, + noList | withApply: ` + func newFake$.type|publicPlural$(fake *Fake$.GroupGoName$$.Version$$if .namespaced$, namespace string$end$) $.realClientInterface|raw$ { + return &fake$.type|publicPlural${ + $.NewFakeClientWithApply|raw$[*$.type|raw$, *$.inputApplyConfig|raw$]( + fake.Fake, + $if .namespaced$namespace$else$""$end$, + $.SchemeGroupVersion|raw$.WithResource("$.type|resource$"), + $.SchemeGroupVersion|raw$.WithKind("$.type|singularKind$"), + func() *$.type|raw$ {return &$.type|raw${}}, + ), + fake, + } + } + `, + withList | noApply: ` + func newFake$.type|publicPlural$(fake *Fake$.GroupGoName$$.Version$$if .namespaced$, namespace string$end$) $.realClientInterface|raw$ { + return &fake$.type|publicPlural${ + $.NewFakeClientWithList|raw$[*$.type|raw$, *$.type|raw$List]( + fake.Fake, + $if .namespaced$namespace$else$""$end$, + $.SchemeGroupVersion|raw$.WithResource("$.type|resource$"), + $.SchemeGroupVersion|raw$.WithKind("$.type|singularKind$"), + func() *$.type|raw$ {return &$.type|raw${}}, + func() *$.type|raw$List {return &$.type|raw$List{}}, + func(dst, src *$.type|raw$List) {dst.ListMeta = src.ListMeta}, + func(list *$.type|raw$List) []*$.type|raw$ {return gentype.ToPointerSlice(list.Items)}, + func(list *$.type|raw$List, items []*$.type|raw$) {list.Items = gentype.FromPointerSlice(items)}, + ), + fake, + } + } + `, + withList | withApply: ` + func newFake$.type|publicPlural$(fake *Fake$.GroupGoName$$.Version$$if .namespaced$, namespace string$end$) $.realClientInterface|raw$ { + return &fake$.type|publicPlural${ + $.NewFakeClientWithListAndApply|raw$[*$.type|raw$, *$.type|raw$List, *$.inputApplyConfig|raw$]( + fake.Fake, + $if .namespaced$namespace$else$""$end$, + $.SchemeGroupVersion|raw$.WithResource("$.type|resource$"), + $.SchemeGroupVersion|raw$.WithKind("$.type|singularKind$"), + func() *$.type|raw$ {return &$.type|raw${}}, + func() *$.type|raw$List {return &$.type|raw$List{}}, + func(dst, src *$.type|raw$List) {dst.ListMeta = src.ListMeta}, + func(list *$.type|raw$List) []*$.type|raw$ {return gentype.ToPointerSlice(list.Items)}, + func(list *$.type|raw$List, items []*$.type|raw$) {list.Items = gentype.FromPointerSlice(items)}, + ), + fake, + } + } + `, } -` -var listUsingOptionsTemplate = ` +var listTemplate = ` // List takes label and field selectors, and returns the list of $.type|publicPlural$ that match those selectors. -func (c *Fake$.type|publicPlural$) List(ctx $.contextContext|raw$, opts $.ListOptions|raw$) (result *$.type|raw$List, err error) { +func (c *fake$.type|publicPlural$) List(ctx $.contextContext|raw$, opts $.ListOptions|raw$) (result *$.type|raw$List, err error) { emptyResult := &$.type|raw$List{} obj, err := c.Fake. - $if .namespaced$Invokes($.NewListActionWithOptions|raw$($.type|allLowercasePlural$Resource, $.type|allLowercasePlural$Kind, c.ns, opts), emptyResult) - $else$Invokes($.NewRootListActionWithOptions|raw$($.type|allLowercasePlural$Resource, $.type|allLowercasePlural$Kind, opts), emptyResult)$end$ + $if .namespaced$Invokes($.NewListActionWithOptions|raw$(c.Resource(), c.Kind(), c.Namespace(), opts), emptyResult) + $else$Invokes($.NewRootListActionWithOptions|raw$(c.Resource(), c.Kind(), opts), emptyResult)$end$ if obj == nil { return emptyResult, err } - - label, _, _ := $.ExtractFromListOptions|raw$(opts) - if label == nil { - label = $.Everything|raw$() - } - list := &$.type|raw$List{ListMeta: obj.(*$.type|raw$List).ListMeta} - for _, item := range obj.(*$.type|raw$List).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err + return obj.(*$.type|raw$List), err } ` var getTemplate = ` // Get takes name of the $.type|private$, and returns the corresponding $.resultType|private$ object, and an error if there is any. -func (c *Fake$.type|publicPlural$) Get(ctx $.contextContext|raw$, name string, options $.GetOptions|raw$) (result *$.resultType|raw$, err error) { +func (c *fake$.type|publicPlural$) Get(ctx $.contextContext|raw$, name string, options $.GetOptions|raw$) (result *$.resultType|raw$, err error) { emptyResult := &$.resultType|raw${} obj, err := c.Fake. - $if .namespaced$Invokes($.NewGetActionWithOptions|raw$($.type|allLowercasePlural$Resource, c.ns, name, options), emptyResult) - $else$Invokes($.NewRootGetActionWithOptions|raw$($.type|allLowercasePlural$Resource, name, options), emptyResult)$end$ + $if .namespaced$Invokes($.NewGetActionWithOptions|raw$(c.Resource(), c.Namespace(), name, options), emptyResult) + $else$Invokes($.NewRootGetActionWithOptions|raw$(c.Resource(), name, options), emptyResult)$end$ if obj == nil { return emptyResult, err } @@ -387,11 +394,11 @@ func (c *Fake$.type|publicPlural$) Get(ctx $.contextContext|raw$, name string, o var getSubresourceTemplate = ` // Get takes name of the $.type|private$, and returns the corresponding $.resultType|private$ object, and an error if there is any. -func (c *Fake$.type|publicPlural$) Get(ctx $.contextContext|raw$, $.type|private$Name string, options $.GetOptions|raw$) (result *$.resultType|raw$, err error) { +func (c *fake$.type|publicPlural$) Get(ctx $.contextContext|raw$, $.type|private$Name string, options $.GetOptions|raw$) (result *$.resultType|raw$, err error) { emptyResult := &$.resultType|raw${} obj, err := c.Fake. - $if .namespaced$Invokes($.NewGetSubresourceActionWithOptions|raw$($.type|allLowercasePlural$Resource, c.ns, "$.subresourcePath$", $.type|private$Name, options), emptyResult) - $else$Invokes($.NewRootGetSubresourceActionWithOptions|raw$($.type|allLowercasePlural$Resource, "$.subresourcePath$", $.type|private$Name, options), emptyResult)$end$ + $if .namespaced$Invokes($.NewGetSubresourceActionWithOptions|raw$(c.Resource(), c.Namespace(), "$.subresourcePath$", $.type|private$Name, options), emptyResult) + $else$Invokes($.NewRootGetSubresourceActionWithOptions|raw$(c.Resource(), "$.subresourcePath$", $.type|private$Name, options), emptyResult)$end$ if obj == nil { return emptyResult, err } @@ -401,31 +408,21 @@ func (c *Fake$.type|publicPlural$) Get(ctx $.contextContext|raw$, $.type|private var deleteTemplate = ` // Delete takes name of the $.type|private$ and deletes it. Returns an error if one occurs. -func (c *Fake$.type|publicPlural$) Delete(ctx $.contextContext|raw$, name string, opts $.DeleteOptions|raw$) error { +func (c *fake$.type|publicPlural$) Delete(ctx $.contextContext|raw$, name string, opts $.DeleteOptions|raw$) error { _, err := c.Fake. - $if .namespaced$Invokes($.NewDeleteActionWithOptions|raw$($.type|allLowercasePlural$Resource, c.ns, name, opts), &$.type|raw${}) - $else$Invokes($.NewRootDeleteActionWithOptions|raw$($.type|allLowercasePlural$Resource, name, opts), &$.type|raw${})$end$ + $if .namespaced$Invokes($.NewDeleteActionWithOptions|raw$(c.Resource(), c.Namespace(), name, opts), &$.type|raw${}) + $else$Invokes($.NewRootDeleteActionWithOptions|raw$(c.Resource(), name, opts), &$.type|raw${})$end$ return err } ` -var deleteCollectionTemplate = ` -// DeleteCollection deletes a collection of objects. -func (c *Fake$.type|publicPlural$) DeleteCollection(ctx $.contextContext|raw$, opts $.DeleteOptions|raw$, listOpts $.ListOptions|raw$) error { - $if .namespaced$action := $.NewDeleteCollectionActionWithOptions|raw$($.type|allLowercasePlural$Resource, c.ns, opts, listOpts) - $else$action := $.NewRootDeleteCollectionActionWithOptions|raw$($.type|allLowercasePlural$Resource, opts, listOpts) - $end$ - _, err := c.Fake.Invokes(action, &$.type|raw$List{}) - return err -} -` var createTemplate = ` // Create takes the representation of a $.inputType|private$ and creates it. Returns the server's representation of the $.resultType|private$, and an error, if there is any. -func (c *Fake$.type|publicPlural$) Create(ctx $.contextContext|raw$, $.inputType|private$ *$.inputType|raw$, opts $.CreateOptions|raw$) (result *$.resultType|raw$, err error) { +func (c *fake$.type|publicPlural$) Create(ctx $.contextContext|raw$, $.inputType|private$ *$.inputType|raw$, opts $.CreateOptions|raw$) (result *$.resultType|raw$, err error) { emptyResult := &$.resultType|raw${} obj, err := c.Fake. - $if .namespaced$Invokes($.NewCreateActionWithOptions|raw$($.inputType|allLowercasePlural$Resource, c.ns, $.inputType|private$, opts), emptyResult) - $else$Invokes($.NewRootCreateActionWithOptions|raw$($.inputType|allLowercasePlural$Resource, $.inputType|private$, opts), emptyResult)$end$ + $if .namespaced$Invokes($.NewCreateActionWithOptions|raw$(c.Resource(), c.Namespace(), $.inputType|private$, opts), emptyResult) + $else$Invokes($.NewRootCreateActionWithOptions|raw$(c.Resource(), $.inputType|private$, opts), emptyResult)$end$ if obj == nil { return emptyResult, err } @@ -435,11 +432,11 @@ func (c *Fake$.type|publicPlural$) Create(ctx $.contextContext|raw$, $.inputType var createSubresourceTemplate = ` // Create takes the representation of a $.inputType|private$ and creates it. Returns the server's representation of the $.resultType|private$, and an error, if there is any. -func (c *Fake$.type|publicPlural$) Create(ctx $.contextContext|raw$, $.type|private$Name string, $.inputType|private$ *$.inputType|raw$, opts $.CreateOptions|raw$) (result *$.resultType|raw$, err error) { +func (c *fake$.type|publicPlural$) Create(ctx $.contextContext|raw$, $.type|private$Name string, $.inputType|private$ *$.inputType|raw$, opts $.CreateOptions|raw$) (result *$.resultType|raw$, err error) { emptyResult := &$.resultType|raw${} obj, err := c.Fake. - $if .namespaced$Invokes($.NewCreateSubresourceActionWithOptions|raw$($.type|allLowercasePlural$Resource, $.type|private$Name, "$.subresourcePath$", c.ns, $.inputType|private$, opts), emptyResult) - $else$Invokes($.NewRootCreateSubresourceActionWithOptions|raw$($.type|allLowercasePlural$Resource, $.type|private$Name, "$.subresourcePath$", $.inputType|private$, opts), emptyResult)$end$ + $if .namespaced$Invokes($.NewCreateSubresourceActionWithOptions|raw$(c.Resource(), $.type|private$Name, "$.subresourcePath$", c.Namespace(), $.inputType|private$, opts), emptyResult) + $else$Invokes($.NewRootCreateSubresourceActionWithOptions|raw$(c.Resource(), $.type|private$Name, "$.subresourcePath$", $.inputType|private$, opts), emptyResult)$end$ if obj == nil { return emptyResult, err } @@ -449,11 +446,11 @@ func (c *Fake$.type|publicPlural$) Create(ctx $.contextContext|raw$, $.type|priv var updateTemplate = ` // Update takes the representation of a $.inputType|private$ and updates it. Returns the server's representation of the $.resultType|private$, and an error, if there is any. -func (c *Fake$.type|publicPlural$) Update(ctx $.contextContext|raw$, $.inputType|private$ *$.inputType|raw$, opts $.UpdateOptions|raw$) (result *$.resultType|raw$, err error) { +func (c *fake$.type|publicPlural$) Update(ctx $.contextContext|raw$, $.inputType|private$ *$.inputType|raw$, opts $.UpdateOptions|raw$) (result *$.resultType|raw$, err error) { emptyResult := &$.resultType|raw${} obj, err := c.Fake. - $if .namespaced$Invokes($.NewUpdateActionWithOptions|raw$($.inputType|allLowercasePlural$Resource, c.ns, $.inputType|private$, opts), emptyResult) - $else$Invokes($.NewRootUpdateActionWithOptions|raw$($.inputType|allLowercasePlural$Resource, $.inputType|private$, opts), emptyResult)$end$ + $if .namespaced$Invokes($.NewUpdateActionWithOptions|raw$(c.Resource(), c.Namespace(), $.inputType|private$, opts), emptyResult) + $else$Invokes($.NewRootUpdateActionWithOptions|raw$(c.Resource(), $.inputType|private$, opts), emptyResult)$end$ if obj == nil { return emptyResult, err } @@ -463,11 +460,11 @@ func (c *Fake$.type|publicPlural$) Update(ctx $.contextContext|raw$, $.inputType var updateSubresourceTemplate = ` // Update takes the representation of a $.inputType|private$ and updates it. Returns the server's representation of the $.resultType|private$, and an error, if there is any. -func (c *Fake$.type|publicPlural$) Update(ctx $.contextContext|raw$, $.type|private$Name string, $.inputType|private$ *$.inputType|raw$, opts $.UpdateOptions|raw$) (result *$.resultType|raw$, err error) { +func (c *fake$.type|publicPlural$) Update(ctx $.contextContext|raw$, $.type|private$Name string, $.inputType|private$ *$.inputType|raw$, opts $.UpdateOptions|raw$) (result *$.resultType|raw$, err error) { emptyResult := &$.resultType|raw${} obj, err := c.Fake. - $if .namespaced$Invokes($.NewUpdateSubresourceActionWithOptions|raw$($.type|allLowercasePlural$Resource, "$.subresourcePath$", c.ns, $.inputType|private$, opts), &$.inputType|raw${}) - $else$Invokes($.NewRootUpdateSubresourceActionWithOptions|raw$($.type|allLowercasePlural$Resource, "$.subresourcePath$", $.inputType|private$, opts), emptyResult)$end$ + $if .namespaced$Invokes($.NewUpdateSubresourceActionWithOptions|raw$(c.Resource(), "$.subresourcePath$", c.Namespace(), $.inputType|private$, opts), &$.inputType|raw${}) + $else$Invokes($.NewRootUpdateSubresourceActionWithOptions|raw$(c.Resource(), "$.subresourcePath$", $.inputType|private$, opts), emptyResult)$end$ if obj == nil { return emptyResult, err } @@ -475,37 +472,22 @@ func (c *Fake$.type|publicPlural$) Update(ctx $.contextContext|raw$, $.type|priv } ` -var updateStatusTemplate = ` -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *Fake$.type|publicPlural$) UpdateStatus(ctx $.contextContext|raw$, $.type|private$ *$.type|raw$, opts $.UpdateOptions|raw$) (result *$.type|raw$, err error) { - emptyResult := &$.type|raw${} - obj, err := c.Fake. - $if .namespaced$Invokes($.NewUpdateSubresourceActionWithOptions|raw$($.type|allLowercasePlural$Resource, "status", c.ns, $.type|private$, opts), emptyResult) - $else$Invokes($.NewRootUpdateSubresourceActionWithOptions|raw$($.type|allLowercasePlural$Resource, "status", $.type|private$, opts), emptyResult)$end$ - if obj == nil { - return emptyResult, err - } - return obj.(*$.type|raw$), err -} -` - var watchTemplate = ` // Watch returns a $.watchInterface|raw$ that watches the requested $.type|privatePlural$. -func (c *Fake$.type|publicPlural$) Watch(ctx $.contextContext|raw$, opts $.ListOptions|raw$) ($.watchInterface|raw$, error) { +func (c *fake$.type|publicPlural$) Watch(ctx $.contextContext|raw$, opts $.ListOptions|raw$) ($.watchInterface|raw$, error) { return c.Fake. - $if .namespaced$InvokesWatch($.NewWatchActionWithOptions|raw$($.type|allLowercasePlural$Resource, c.ns, opts)) - $else$InvokesWatch($.NewRootWatchActionWithOptions|raw$($.type|allLowercasePlural$Resource, opts))$end$ + $if .namespaced$InvokesWatch($.NewWatchActionWithOptions|raw$(c.Resource(), c.Namespace(), opts)) + $else$InvokesWatch($.NewRootWatchActionWithOptions|raw$(c.Resource(), opts))$end$ } ` var patchTemplate = ` // Patch applies the patch and returns the patched $.resultType|private$. -func (c *Fake$.type|publicPlural$) Patch(ctx $.contextContext|raw$, name string, pt $.PatchType|raw$, data []byte, opts $.PatchOptions|raw$, subresources ...string) (result *$.resultType|raw$, err error) { +func (c *fake$.type|publicPlural$) Patch(ctx $.contextContext|raw$, name string, pt $.PatchType|raw$, data []byte, opts $.PatchOptions|raw$, subresources ...string) (result *$.resultType|raw$, err error) { emptyResult := &$.resultType|raw${} obj, err := c.Fake. - $if .namespaced$Invokes($.NewPatchSubresourceActionWithOptions|raw$($.type|allLowercasePlural$Resource, c.ns, name, pt, data, opts, subresources... ), emptyResult) - $else$Invokes($.NewRootPatchSubresourceActionWithOptions|raw$($.type|allLowercasePlural$Resource, name, pt, data, opts, subresources...), emptyResult)$end$ + $if .namespaced$Invokes($.NewPatchSubresourceActionWithOptions|raw$(c.Resource(), c.Namespace(), name, pt, data, opts, subresources... ), emptyResult) + $else$Invokes($.NewRootPatchSubresourceActionWithOptions|raw$(c.Resource(), name, pt, data, opts, subresources...), emptyResult)$end$ if obj == nil { return emptyResult, err } @@ -515,33 +497,7 @@ func (c *Fake$.type|publicPlural$) Patch(ctx $.contextContext|raw$, name string, var applyTemplate = ` // Apply takes the given apply declarative configuration, applies it and returns the applied $.resultType|private$. -func (c *Fake$.type|publicPlural$) Apply(ctx $.contextContext|raw$, $.inputType|private$ *$.inputApplyConfig|raw$, opts $.ApplyOptions|raw$) (result *$.resultType|raw$, err error) { - if $.inputType|private$ == nil { - return nil, $.fmtErrorf|raw$("$.inputType|private$ provided to Apply must not be nil") - } - data, err := $.jsonMarshal|raw$($.inputType|private$) - if err != nil { - return nil, err - } - name := $.inputType|private$.Name - if name == nil { - return nil, $.fmtErrorf|raw$("$.inputType|private$.Name must be provided to Apply") - } - emptyResult := &$.resultType|raw${} - obj, err := c.Fake. - $if .namespaced$Invokes($.NewPatchSubresourceActionWithOptions|raw$($.type|allLowercasePlural$Resource, c.ns, *name, $.ApplyPatchType|raw$, data, opts.ToPatchOptions()), emptyResult) - $else$Invokes($.NewRootPatchSubresourceActionWithOptions|raw$($.type|allLowercasePlural$Resource, *name, $.ApplyPatchType|raw$, data, opts.ToPatchOptions()), emptyResult)$end$ - if obj == nil { - return emptyResult, err - } - return obj.(*$.resultType|raw$), err -} -` - -var applyStatusTemplate = ` -// ApplyStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating ApplyStatus(). -func (c *Fake$.type|publicPlural$) ApplyStatus(ctx $.contextContext|raw$, $.inputType|private$ *$.inputApplyConfig|raw$, opts $.ApplyOptions|raw$) (result *$.resultType|raw$, err error) { +func (c *fake$.type|publicPlural$) Apply(ctx $.contextContext|raw$, $.inputType|private$ *$.inputApplyConfig|raw$, opts $.ApplyOptions|raw$) (result *$.resultType|raw$, err error) { if $.inputType|private$ == nil { return nil, $.fmtErrorf|raw$("$.inputType|private$ provided to Apply must not be nil") } @@ -555,8 +511,8 @@ func (c *Fake$.type|publicPlural$) ApplyStatus(ctx $.contextContext|raw$, $.inpu } emptyResult := &$.resultType|raw${} obj, err := c.Fake. - $if .namespaced$Invokes($.NewPatchSubresourceActionWithOptions|raw$($.type|allLowercasePlural$Resource, c.ns, *name, $.ApplyPatchType|raw$, data, opts.ToPatchOptions(), "status"), emptyResult) - $else$Invokes($.NewRootPatchSubresourceActionWithOptions|raw$($.type|allLowercasePlural$Resource, *name, $.ApplyPatchType|raw$, data, opts.ToPatchOptions(), "status"), emptyResult)$end$ + $if .namespaced$Invokes($.NewPatchSubresourceActionWithOptions|raw$(c.Resource(), c.Namespace(), *name, $.ApplyPatchType|raw$, data, opts.ToPatchOptions()), emptyResult) + $else$Invokes($.NewRootPatchSubresourceActionWithOptions|raw$(c.Resource(), *name, $.ApplyPatchType|raw$, data, opts.ToPatchOptions()), emptyResult)$end$ if obj == nil { return emptyResult, err } @@ -567,7 +523,7 @@ func (c *Fake$.type|publicPlural$) ApplyStatus(ctx $.contextContext|raw$, $.inpu var applySubresourceTemplate = ` // Apply takes top resource name and the apply declarative configuration for $.subresourcePath$, // applies it and returns the applied $.resultType|private$, and an error, if there is any. -func (c *Fake$.type|publicPlural$) Apply(ctx $.contextContext|raw$, $.type|private$Name string, $.inputType|private$ *$.inputApplyConfig|raw$, opts $.ApplyOptions|raw$) (result *$.resultType|raw$, err error) { +func (c *fake$.type|publicPlural$) Apply(ctx $.contextContext|raw$, $.type|private$Name string, $.inputType|private$ *$.inputApplyConfig|raw$, opts $.ApplyOptions|raw$) (result *$.resultType|raw$, err error) { if $.inputType|private$ == nil { return nil, $.fmtErrorf|raw$("$.inputType|private$ provided to Apply must not be nil") } @@ -577,8 +533,8 @@ func (c *Fake$.type|publicPlural$) Apply(ctx $.contextContext|raw$, $.type|priva } emptyResult := &$.resultType|raw${} obj, err := c.Fake. - $if .namespaced$Invokes($.NewPatchSubresourceActionWithOptions|raw$($.type|allLowercasePlural$Resource, c.ns, $.type|private$Name, $.ApplyPatchType|raw$, data, opts.ToPatchOptions(), "$.inputType|private$"), emptyResult) - $else$Invokes($.NewRootPatchSubresourceActionWithOptions|raw$($.type|allLowercasePlural$Resource, $.type|private$Name, $.ApplyPatchType|raw$, data, opts.ToPatchOptions(), "$.inputType|private$"), emptyResult)$end$ + $if .namespaced$Invokes($.NewPatchSubresourceActionWithOptions|raw$(c.Resource(), c.Namespace(), $.type|private$Name, $.ApplyPatchType|raw$, data, opts.ToPatchOptions(), "$.inputType|private$"), emptyResult) + $else$Invokes($.NewRootPatchSubresourceActionWithOptions|raw$(c.Resource(), $.type|private$Name, $.ApplyPatchType|raw$, data, opts.ToPatchOptions(), "$.inputType|private$"), emptyResult)$end$ if obj == nil { return emptyResult, err } diff --git a/examples/HyphenGroup/clientset/versioned/typed/example/v1/fake/fake_clustertesttype.go b/examples/HyphenGroup/clientset/versioned/typed/example/v1/fake/fake_clustertesttype.go index a2cbe609..7d875dba 100644 --- a/examples/HyphenGroup/clientset/versioned/typed/example/v1/fake/fake_clustertesttype.go +++ b/examples/HyphenGroup/clientset/versioned/typed/example/v1/fake/fake_clustertesttype.go @@ -20,177 +20,46 @@ package fake import ( context "context" - json "encoding/json" - fmt "fmt" autoscalingv1 "k8s.io/api/autoscaling/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" + gentype "k8s.io/client-go/gentype" testing "k8s.io/client-go/testing" v1 "k8s.io/code-generator/examples/HyphenGroup/apis/example/v1" examplev1 "k8s.io/code-generator/examples/HyphenGroup/applyconfiguration/example/v1" + typedexamplev1 "k8s.io/code-generator/examples/HyphenGroup/clientset/versioned/typed/example/v1" ) -// FakeClusterTestTypes implements ClusterTestTypeInterface -type FakeClusterTestTypes struct { +// fakeClusterTestTypes implements ClusterTestTypeInterface +type fakeClusterTestTypes struct { + *gentype.FakeClientWithListAndApply[*v1.ClusterTestType, *v1.ClusterTestTypeList, *examplev1.ClusterTestTypeApplyConfiguration] Fake *FakeExampleGroupV1 } -var clustertesttypesResource = v1.SchemeGroupVersion.WithResource("clustertesttypes") - -var clustertesttypesKind = v1.SchemeGroupVersion.WithKind("ClusterTestType") - -// Get takes name of the clusterTestType, and returns the corresponding clusterTestType object, and an error if there is any. -func (c *FakeClusterTestTypes) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.ClusterTestType, err error) { - emptyResult := &v1.ClusterTestType{} - obj, err := c.Fake. - Invokes(testing.NewRootGetActionWithOptions(clustertesttypesResource, name, options), emptyResult) - if obj == nil { - return emptyResult, err - } - return obj.(*v1.ClusterTestType), err -} - -// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors. -func (c *FakeClusterTestTypes) List(ctx context.Context, opts metav1.ListOptions) (result *v1.ClusterTestTypeList, err error) { - emptyResult := &v1.ClusterTestTypeList{} - obj, err := c.Fake. - Invokes(testing.NewRootListActionWithOptions(clustertesttypesResource, clustertesttypesKind, opts), emptyResult) - if obj == nil { - return emptyResult, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &v1.ClusterTestTypeList{ListMeta: obj.(*v1.ClusterTestTypeList).ListMeta} - for _, item := range obj.(*v1.ClusterTestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -// Watch returns a watch.Interface that watches the requested clusterTestTypes. -func (c *FakeClusterTestTypes) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewRootWatchActionWithOptions(clustertesttypesResource, opts)) -} - -// Create takes the representation of a clusterTestType and creates it. Returns the server's representation of the clusterTestType, and an error, if there is any. -func (c *FakeClusterTestTypes) Create(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.CreateOptions) (result *v1.ClusterTestType, err error) { - emptyResult := &v1.ClusterTestType{} - obj, err := c.Fake. - Invokes(testing.NewRootCreateActionWithOptions(clustertesttypesResource, clusterTestType, opts), emptyResult) - if obj == nil { - return emptyResult, err - } - return obj.(*v1.ClusterTestType), err -} - -// Update takes the representation of a clusterTestType and updates it. Returns the server's representation of the clusterTestType, and an error, if there is any. -func (c *FakeClusterTestTypes) Update(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.UpdateOptions) (result *v1.ClusterTestType, err error) { - emptyResult := &v1.ClusterTestType{} - obj, err := c.Fake. - Invokes(testing.NewRootUpdateActionWithOptions(clustertesttypesResource, clusterTestType, opts), emptyResult) - if obj == nil { - return emptyResult, err - } - return obj.(*v1.ClusterTestType), err -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *FakeClusterTestTypes) UpdateStatus(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.UpdateOptions) (result *v1.ClusterTestType, err error) { - emptyResult := &v1.ClusterTestType{} - obj, err := c.Fake. - Invokes(testing.NewRootUpdateSubresourceActionWithOptions(clustertesttypesResource, "status", clusterTestType, opts), emptyResult) - if obj == nil { - return emptyResult, err - } - return obj.(*v1.ClusterTestType), err -} - -// Delete takes name of the clusterTestType and deletes it. Returns an error if one occurs. -func (c *FakeClusterTestTypes) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewRootDeleteActionWithOptions(clustertesttypesResource, name, opts), &v1.ClusterTestType{}) - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakeClusterTestTypes) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := testing.NewRootDeleteCollectionActionWithOptions(clustertesttypesResource, opts, listOpts) - - _, err := c.Fake.Invokes(action, &v1.ClusterTestTypeList{}) - return err -} - -// Patch applies the patch and returns the patched clusterTestType. -func (c *FakeClusterTestTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.ClusterTestType, err error) { - emptyResult := &v1.ClusterTestType{} - obj, err := c.Fake. - Invokes(testing.NewRootPatchSubresourceActionWithOptions(clustertesttypesResource, name, pt, data, opts, subresources...), emptyResult) - if obj == nil { - return emptyResult, err - } - return obj.(*v1.ClusterTestType), err -} - -// Apply takes the given apply declarative configuration, applies it and returns the applied clusterTestType. -func (c *FakeClusterTestTypes) Apply(ctx context.Context, clusterTestType *examplev1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *v1.ClusterTestType, err error) { - if clusterTestType == nil { - return nil, fmt.Errorf("clusterTestType provided to Apply must not be nil") - } - data, err := json.Marshal(clusterTestType) - if err != nil { - return nil, err - } - name := clusterTestType.Name - if name == nil { - return nil, fmt.Errorf("clusterTestType.Name must be provided to Apply") - } - emptyResult := &v1.ClusterTestType{} - obj, err := c.Fake. - Invokes(testing.NewRootPatchSubresourceActionWithOptions(clustertesttypesResource, *name, types.ApplyPatchType, data, opts.ToPatchOptions()), emptyResult) - if obj == nil { - return emptyResult, err - } - return obj.(*v1.ClusterTestType), err -} - -// ApplyStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating ApplyStatus(). -func (c *FakeClusterTestTypes) ApplyStatus(ctx context.Context, clusterTestType *examplev1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *v1.ClusterTestType, err error) { - if clusterTestType == nil { - return nil, fmt.Errorf("clusterTestType provided to Apply must not be nil") - } - data, err := json.Marshal(clusterTestType) - if err != nil { - return nil, err - } - name := clusterTestType.Name - if name == nil { - return nil, fmt.Errorf("clusterTestType.Name must be provided to Apply") - } - emptyResult := &v1.ClusterTestType{} - obj, err := c.Fake. - Invokes(testing.NewRootPatchSubresourceActionWithOptions(clustertesttypesResource, *name, types.ApplyPatchType, data, opts.ToPatchOptions(), "status"), emptyResult) - if obj == nil { - return emptyResult, err +func newFakeClusterTestTypes(fake *FakeExampleGroupV1) typedexamplev1.ClusterTestTypeInterface { + return &fakeClusterTestTypes{ + gentype.NewFakeClientWithListAndApply[*v1.ClusterTestType, *v1.ClusterTestTypeList, *examplev1.ClusterTestTypeApplyConfiguration]( + fake.Fake, + "", + v1.SchemeGroupVersion.WithResource("clustertesttypes"), + v1.SchemeGroupVersion.WithKind("ClusterTestType"), + func() *v1.ClusterTestType { return &v1.ClusterTestType{} }, + func() *v1.ClusterTestTypeList { return &v1.ClusterTestTypeList{} }, + func(dst, src *v1.ClusterTestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *v1.ClusterTestTypeList) []*v1.ClusterTestType { return gentype.ToPointerSlice(list.Items) }, + func(list *v1.ClusterTestTypeList, items []*v1.ClusterTestType) { + list.Items = gentype.FromPointerSlice(items) + }, + ), + fake, } - return obj.(*v1.ClusterTestType), err } // GetScale takes name of the clusterTestType, and returns the corresponding scale object, and an error if there is any. -func (c *FakeClusterTestTypes) GetScale(ctx context.Context, clusterTestTypeName string, options metav1.GetOptions) (result *autoscalingv1.Scale, err error) { +func (c *fakeClusterTestTypes) GetScale(ctx context.Context, clusterTestTypeName string, options metav1.GetOptions) (result *autoscalingv1.Scale, err error) { emptyResult := &autoscalingv1.Scale{} obj, err := c.Fake. - Invokes(testing.NewRootGetSubresourceActionWithOptions(clustertesttypesResource, "scale", clusterTestTypeName, options), emptyResult) + Invokes(testing.NewRootGetSubresourceActionWithOptions(c.Resource(), "scale", clusterTestTypeName, options), emptyResult) if obj == nil { return emptyResult, err } @@ -198,10 +67,10 @@ func (c *FakeClusterTestTypes) GetScale(ctx context.Context, clusterTestTypeName } // UpdateScale takes the representation of a scale and updates it. Returns the server's representation of the scale, and an error, if there is any. -func (c *FakeClusterTestTypes) UpdateScale(ctx context.Context, clusterTestTypeName string, scale *autoscalingv1.Scale, opts metav1.UpdateOptions) (result *autoscalingv1.Scale, err error) { +func (c *fakeClusterTestTypes) UpdateScale(ctx context.Context, clusterTestTypeName string, scale *autoscalingv1.Scale, opts metav1.UpdateOptions) (result *autoscalingv1.Scale, err error) { emptyResult := &autoscalingv1.Scale{} obj, err := c.Fake. - Invokes(testing.NewRootUpdateSubresourceActionWithOptions(clustertesttypesResource, "scale", scale, opts), emptyResult) + Invokes(testing.NewRootUpdateSubresourceActionWithOptions(c.Resource(), "scale", scale, opts), emptyResult) if obj == nil { return emptyResult, err } diff --git a/examples/HyphenGroup/clientset/versioned/typed/example/v1/fake/fake_example_client.go b/examples/HyphenGroup/clientset/versioned/typed/example/v1/fake/fake_example_client.go index 1d97ad6a..6afac7c2 100644 --- a/examples/HyphenGroup/clientset/versioned/typed/example/v1/fake/fake_example_client.go +++ b/examples/HyphenGroup/clientset/versioned/typed/example/v1/fake/fake_example_client.go @@ -29,11 +29,11 @@ type FakeExampleGroupV1 struct { } func (c *FakeExampleGroupV1) ClusterTestTypes() v1.ClusterTestTypeInterface { - return &FakeClusterTestTypes{c} + return newFakeClusterTestTypes(c) } func (c *FakeExampleGroupV1) TestTypes(namespace string) v1.TestTypeInterface { - return &FakeTestTypes{c, namespace} + return newFakeTestTypes(c, namespace) } // RESTClient returns a RESTClient that is used to communicate diff --git a/examples/HyphenGroup/clientset/versioned/typed/example/v1/fake/fake_testtype.go b/examples/HyphenGroup/clientset/versioned/typed/example/v1/fake/fake_testtype.go index 39d0cc4a..9188f2f0 100644 --- a/examples/HyphenGroup/clientset/versioned/typed/example/v1/fake/fake_testtype.go +++ b/examples/HyphenGroup/clientset/versioned/typed/example/v1/fake/fake_testtype.go @@ -19,179 +19,31 @@ limitations under the License. package fake import ( - context "context" - json "encoding/json" - fmt "fmt" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - testing "k8s.io/client-go/testing" + gentype "k8s.io/client-go/gentype" v1 "k8s.io/code-generator/examples/HyphenGroup/apis/example/v1" examplev1 "k8s.io/code-generator/examples/HyphenGroup/applyconfiguration/example/v1" + typedexamplev1 "k8s.io/code-generator/examples/HyphenGroup/clientset/versioned/typed/example/v1" ) -// FakeTestTypes implements TestTypeInterface -type FakeTestTypes struct { +// fakeTestTypes implements TestTypeInterface +type fakeTestTypes struct { + *gentype.FakeClientWithListAndApply[*v1.TestType, *v1.TestTypeList, *examplev1.TestTypeApplyConfiguration] Fake *FakeExampleGroupV1 - ns string -} - -var testtypesResource = v1.SchemeGroupVersion.WithResource("testtypes") - -var testtypesKind = v1.SchemeGroupVersion.WithKind("TestType") - -// Get takes name of the testType, and returns the corresponding testType object, and an error if there is any. -func (c *FakeTestTypes) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewGetActionWithOptions(testtypesResource, c.ns, name, options), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// List takes label and field selectors, and returns the list of TestTypes that match those selectors. -func (c *FakeTestTypes) List(ctx context.Context, opts metav1.ListOptions) (result *v1.TestTypeList, err error) { - emptyResult := &v1.TestTypeList{} - obj, err := c.Fake. - Invokes(testing.NewListActionWithOptions(testtypesResource, testtypesKind, c.ns, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &v1.TestTypeList{ListMeta: obj.(*v1.TestTypeList).ListMeta} - for _, item := range obj.(*v1.TestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -// Watch returns a watch.Interface that watches the requested testTypes. -func (c *FakeTestTypes) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewWatchActionWithOptions(testtypesResource, c.ns, opts)) - -} - -// Create takes the representation of a testType and creates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *FakeTestTypes) Create(ctx context.Context, testType *v1.TestType, opts metav1.CreateOptions) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewCreateActionWithOptions(testtypesResource, c.ns, testType, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// Update takes the representation of a testType and updates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *FakeTestTypes) Update(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewUpdateActionWithOptions(testtypesResource, c.ns, testType, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err } -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *FakeTestTypes) UpdateStatus(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewUpdateSubresourceActionWithOptions(testtypesResource, "status", c.ns, testType, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// Delete takes name of the testType and deletes it. Returns an error if one occurs. -func (c *FakeTestTypes) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewDeleteActionWithOptions(testtypesResource, c.ns, name, opts), &v1.TestType{}) - - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakeTestTypes) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := testing.NewDeleteCollectionActionWithOptions(testtypesResource, c.ns, opts, listOpts) - - _, err := c.Fake.Invokes(action, &v1.TestTypeList{}) - return err -} - -// Patch applies the patch and returns the patched testType. -func (c *FakeTestTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceActionWithOptions(testtypesResource, c.ns, name, pt, data, opts, subresources...), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// Apply takes the given apply declarative configuration, applies it and returns the applied testType. -func (c *FakeTestTypes) Apply(ctx context.Context, testType *examplev1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *v1.TestType, err error) { - if testType == nil { - return nil, fmt.Errorf("testType provided to Apply must not be nil") - } - data, err := json.Marshal(testType) - if err != nil { - return nil, err - } - name := testType.Name - if name == nil { - return nil, fmt.Errorf("testType.Name must be provided to Apply") - } - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceActionWithOptions(testtypesResource, c.ns, *name, types.ApplyPatchType, data, opts.ToPatchOptions()), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// ApplyStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating ApplyStatus(). -func (c *FakeTestTypes) ApplyStatus(ctx context.Context, testType *examplev1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *v1.TestType, err error) { - if testType == nil { - return nil, fmt.Errorf("testType provided to Apply must not be nil") - } - data, err := json.Marshal(testType) - if err != nil { - return nil, err - } - name := testType.Name - if name == nil { - return nil, fmt.Errorf("testType.Name must be provided to Apply") - } - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceActionWithOptions(testtypesResource, c.ns, *name, types.ApplyPatchType, data, opts.ToPatchOptions(), "status"), emptyResult) - - if obj == nil { - return emptyResult, err +func newFakeTestTypes(fake *FakeExampleGroupV1, namespace string) typedexamplev1.TestTypeInterface { + return &fakeTestTypes{ + gentype.NewFakeClientWithListAndApply[*v1.TestType, *v1.TestTypeList, *examplev1.TestTypeApplyConfiguration]( + fake.Fake, + namespace, + v1.SchemeGroupVersion.WithResource("testtypes"), + v1.SchemeGroupVersion.WithKind("TestType"), + func() *v1.TestType { return &v1.TestType{} }, + func() *v1.TestTypeList { return &v1.TestTypeList{} }, + func(dst, src *v1.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *v1.TestTypeList) []*v1.TestType { return gentype.ToPointerSlice(list.Items) }, + func(list *v1.TestTypeList, items []*v1.TestType) { list.Items = gentype.FromPointerSlice(items) }, + ), + fake, } - return obj.(*v1.TestType), err } diff --git a/examples/MixedCase/clientset/versioned/typed/example/v1/fake/fake_clustertesttype.go b/examples/MixedCase/clientset/versioned/typed/example/v1/fake/fake_clustertesttype.go index c64103b5..eec15f0b 100644 --- a/examples/MixedCase/clientset/versioned/typed/example/v1/fake/fake_clustertesttype.go +++ b/examples/MixedCase/clientset/versioned/typed/example/v1/fake/fake_clustertesttype.go @@ -20,177 +20,46 @@ package fake import ( context "context" - json "encoding/json" - fmt "fmt" autoscalingv1 "k8s.io/api/autoscaling/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" + gentype "k8s.io/client-go/gentype" testing "k8s.io/client-go/testing" v1 "k8s.io/code-generator/examples/MixedCase/apis/example/v1" examplev1 "k8s.io/code-generator/examples/MixedCase/applyconfiguration/example/v1" + typedexamplev1 "k8s.io/code-generator/examples/MixedCase/clientset/versioned/typed/example/v1" ) -// FakeClusterTestTypes implements ClusterTestTypeInterface -type FakeClusterTestTypes struct { +// fakeClusterTestTypes implements ClusterTestTypeInterface +type fakeClusterTestTypes struct { + *gentype.FakeClientWithListAndApply[*v1.ClusterTestType, *v1.ClusterTestTypeList, *examplev1.ClusterTestTypeApplyConfiguration] Fake *FakeExampleV1 } -var clustertesttypesResource = v1.SchemeGroupVersion.WithResource("clustertesttypes") - -var clustertesttypesKind = v1.SchemeGroupVersion.WithKind("ClusterTestType") - -// Get takes name of the clusterTestType, and returns the corresponding clusterTestType object, and an error if there is any. -func (c *FakeClusterTestTypes) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.ClusterTestType, err error) { - emptyResult := &v1.ClusterTestType{} - obj, err := c.Fake. - Invokes(testing.NewRootGetActionWithOptions(clustertesttypesResource, name, options), emptyResult) - if obj == nil { - return emptyResult, err - } - return obj.(*v1.ClusterTestType), err -} - -// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors. -func (c *FakeClusterTestTypes) List(ctx context.Context, opts metav1.ListOptions) (result *v1.ClusterTestTypeList, err error) { - emptyResult := &v1.ClusterTestTypeList{} - obj, err := c.Fake. - Invokes(testing.NewRootListActionWithOptions(clustertesttypesResource, clustertesttypesKind, opts), emptyResult) - if obj == nil { - return emptyResult, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &v1.ClusterTestTypeList{ListMeta: obj.(*v1.ClusterTestTypeList).ListMeta} - for _, item := range obj.(*v1.ClusterTestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -// Watch returns a watch.Interface that watches the requested clusterTestTypes. -func (c *FakeClusterTestTypes) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewRootWatchActionWithOptions(clustertesttypesResource, opts)) -} - -// Create takes the representation of a clusterTestType and creates it. Returns the server's representation of the clusterTestType, and an error, if there is any. -func (c *FakeClusterTestTypes) Create(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.CreateOptions) (result *v1.ClusterTestType, err error) { - emptyResult := &v1.ClusterTestType{} - obj, err := c.Fake. - Invokes(testing.NewRootCreateActionWithOptions(clustertesttypesResource, clusterTestType, opts), emptyResult) - if obj == nil { - return emptyResult, err - } - return obj.(*v1.ClusterTestType), err -} - -// Update takes the representation of a clusterTestType and updates it. Returns the server's representation of the clusterTestType, and an error, if there is any. -func (c *FakeClusterTestTypes) Update(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.UpdateOptions) (result *v1.ClusterTestType, err error) { - emptyResult := &v1.ClusterTestType{} - obj, err := c.Fake. - Invokes(testing.NewRootUpdateActionWithOptions(clustertesttypesResource, clusterTestType, opts), emptyResult) - if obj == nil { - return emptyResult, err - } - return obj.(*v1.ClusterTestType), err -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *FakeClusterTestTypes) UpdateStatus(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.UpdateOptions) (result *v1.ClusterTestType, err error) { - emptyResult := &v1.ClusterTestType{} - obj, err := c.Fake. - Invokes(testing.NewRootUpdateSubresourceActionWithOptions(clustertesttypesResource, "status", clusterTestType, opts), emptyResult) - if obj == nil { - return emptyResult, err - } - return obj.(*v1.ClusterTestType), err -} - -// Delete takes name of the clusterTestType and deletes it. Returns an error if one occurs. -func (c *FakeClusterTestTypes) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewRootDeleteActionWithOptions(clustertesttypesResource, name, opts), &v1.ClusterTestType{}) - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakeClusterTestTypes) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := testing.NewRootDeleteCollectionActionWithOptions(clustertesttypesResource, opts, listOpts) - - _, err := c.Fake.Invokes(action, &v1.ClusterTestTypeList{}) - return err -} - -// Patch applies the patch and returns the patched clusterTestType. -func (c *FakeClusterTestTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.ClusterTestType, err error) { - emptyResult := &v1.ClusterTestType{} - obj, err := c.Fake. - Invokes(testing.NewRootPatchSubresourceActionWithOptions(clustertesttypesResource, name, pt, data, opts, subresources...), emptyResult) - if obj == nil { - return emptyResult, err - } - return obj.(*v1.ClusterTestType), err -} - -// Apply takes the given apply declarative configuration, applies it and returns the applied clusterTestType. -func (c *FakeClusterTestTypes) Apply(ctx context.Context, clusterTestType *examplev1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *v1.ClusterTestType, err error) { - if clusterTestType == nil { - return nil, fmt.Errorf("clusterTestType provided to Apply must not be nil") - } - data, err := json.Marshal(clusterTestType) - if err != nil { - return nil, err - } - name := clusterTestType.Name - if name == nil { - return nil, fmt.Errorf("clusterTestType.Name must be provided to Apply") - } - emptyResult := &v1.ClusterTestType{} - obj, err := c.Fake. - Invokes(testing.NewRootPatchSubresourceActionWithOptions(clustertesttypesResource, *name, types.ApplyPatchType, data, opts.ToPatchOptions()), emptyResult) - if obj == nil { - return emptyResult, err - } - return obj.(*v1.ClusterTestType), err -} - -// ApplyStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating ApplyStatus(). -func (c *FakeClusterTestTypes) ApplyStatus(ctx context.Context, clusterTestType *examplev1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *v1.ClusterTestType, err error) { - if clusterTestType == nil { - return nil, fmt.Errorf("clusterTestType provided to Apply must not be nil") - } - data, err := json.Marshal(clusterTestType) - if err != nil { - return nil, err - } - name := clusterTestType.Name - if name == nil { - return nil, fmt.Errorf("clusterTestType.Name must be provided to Apply") - } - emptyResult := &v1.ClusterTestType{} - obj, err := c.Fake. - Invokes(testing.NewRootPatchSubresourceActionWithOptions(clustertesttypesResource, *name, types.ApplyPatchType, data, opts.ToPatchOptions(), "status"), emptyResult) - if obj == nil { - return emptyResult, err +func newFakeClusterTestTypes(fake *FakeExampleV1) typedexamplev1.ClusterTestTypeInterface { + return &fakeClusterTestTypes{ + gentype.NewFakeClientWithListAndApply[*v1.ClusterTestType, *v1.ClusterTestTypeList, *examplev1.ClusterTestTypeApplyConfiguration]( + fake.Fake, + "", + v1.SchemeGroupVersion.WithResource("clustertesttypes"), + v1.SchemeGroupVersion.WithKind("ClusterTestType"), + func() *v1.ClusterTestType { return &v1.ClusterTestType{} }, + func() *v1.ClusterTestTypeList { return &v1.ClusterTestTypeList{} }, + func(dst, src *v1.ClusterTestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *v1.ClusterTestTypeList) []*v1.ClusterTestType { return gentype.ToPointerSlice(list.Items) }, + func(list *v1.ClusterTestTypeList, items []*v1.ClusterTestType) { + list.Items = gentype.FromPointerSlice(items) + }, + ), + fake, } - return obj.(*v1.ClusterTestType), err } // GetScale takes name of the clusterTestType, and returns the corresponding scale object, and an error if there is any. -func (c *FakeClusterTestTypes) GetScale(ctx context.Context, clusterTestTypeName string, options metav1.GetOptions) (result *autoscalingv1.Scale, err error) { +func (c *fakeClusterTestTypes) GetScale(ctx context.Context, clusterTestTypeName string, options metav1.GetOptions) (result *autoscalingv1.Scale, err error) { emptyResult := &autoscalingv1.Scale{} obj, err := c.Fake. - Invokes(testing.NewRootGetSubresourceActionWithOptions(clustertesttypesResource, "scale", clusterTestTypeName, options), emptyResult) + Invokes(testing.NewRootGetSubresourceActionWithOptions(c.Resource(), "scale", clusterTestTypeName, options), emptyResult) if obj == nil { return emptyResult, err } @@ -198,10 +67,10 @@ func (c *FakeClusterTestTypes) GetScale(ctx context.Context, clusterTestTypeName } // UpdateScale takes the representation of a scale and updates it. Returns the server's representation of the scale, and an error, if there is any. -func (c *FakeClusterTestTypes) UpdateScale(ctx context.Context, clusterTestTypeName string, scale *autoscalingv1.Scale, opts metav1.UpdateOptions) (result *autoscalingv1.Scale, err error) { +func (c *fakeClusterTestTypes) UpdateScale(ctx context.Context, clusterTestTypeName string, scale *autoscalingv1.Scale, opts metav1.UpdateOptions) (result *autoscalingv1.Scale, err error) { emptyResult := &autoscalingv1.Scale{} obj, err := c.Fake. - Invokes(testing.NewRootUpdateSubresourceActionWithOptions(clustertesttypesResource, "scale", scale, opts), emptyResult) + Invokes(testing.NewRootUpdateSubresourceActionWithOptions(c.Resource(), "scale", scale, opts), emptyResult) if obj == nil { return emptyResult, err } @@ -209,10 +78,10 @@ func (c *FakeClusterTestTypes) UpdateScale(ctx context.Context, clusterTestTypeN } // CreateScale takes the representation of a scale and creates it. Returns the server's representation of the scale, and an error, if there is any. -func (c *FakeClusterTestTypes) CreateScale(ctx context.Context, clusterTestTypeName string, scale *autoscalingv1.Scale, opts metav1.CreateOptions) (result *autoscalingv1.Scale, err error) { +func (c *fakeClusterTestTypes) CreateScale(ctx context.Context, clusterTestTypeName string, scale *autoscalingv1.Scale, opts metav1.CreateOptions) (result *autoscalingv1.Scale, err error) { emptyResult := &autoscalingv1.Scale{} obj, err := c.Fake. - Invokes(testing.NewRootCreateSubresourceActionWithOptions(clustertesttypesResource, clusterTestTypeName, "scale", scale, opts), emptyResult) + Invokes(testing.NewRootCreateSubresourceActionWithOptions(c.Resource(), clusterTestTypeName, "scale", scale, opts), emptyResult) if obj == nil { return emptyResult, err } diff --git a/examples/MixedCase/clientset/versioned/typed/example/v1/fake/fake_example_client.go b/examples/MixedCase/clientset/versioned/typed/example/v1/fake/fake_example_client.go index b545f5b9..e2009382 100644 --- a/examples/MixedCase/clientset/versioned/typed/example/v1/fake/fake_example_client.go +++ b/examples/MixedCase/clientset/versioned/typed/example/v1/fake/fake_example_client.go @@ -29,11 +29,11 @@ type FakeExampleV1 struct { } func (c *FakeExampleV1) ClusterTestTypes() v1.ClusterTestTypeInterface { - return &FakeClusterTestTypes{c} + return newFakeClusterTestTypes(c) } func (c *FakeExampleV1) TestTypes(namespace string) v1.TestTypeInterface { - return &FakeTestTypes{c, namespace} + return newFakeTestTypes(c, namespace) } // RESTClient returns a RESTClient that is used to communicate diff --git a/examples/MixedCase/clientset/versioned/typed/example/v1/fake/fake_testtype.go b/examples/MixedCase/clientset/versioned/typed/example/v1/fake/fake_testtype.go index 8aafcbfb..b57866e2 100644 --- a/examples/MixedCase/clientset/versioned/typed/example/v1/fake/fake_testtype.go +++ b/examples/MixedCase/clientset/versioned/typed/example/v1/fake/fake_testtype.go @@ -19,179 +19,31 @@ limitations under the License. package fake import ( - context "context" - json "encoding/json" - fmt "fmt" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - testing "k8s.io/client-go/testing" + gentype "k8s.io/client-go/gentype" v1 "k8s.io/code-generator/examples/MixedCase/apis/example/v1" examplev1 "k8s.io/code-generator/examples/MixedCase/applyconfiguration/example/v1" + typedexamplev1 "k8s.io/code-generator/examples/MixedCase/clientset/versioned/typed/example/v1" ) -// FakeTestTypes implements TestTypeInterface -type FakeTestTypes struct { +// fakeTestTypes implements TestTypeInterface +type fakeTestTypes struct { + *gentype.FakeClientWithListAndApply[*v1.TestType, *v1.TestTypeList, *examplev1.TestTypeApplyConfiguration] Fake *FakeExampleV1 - ns string -} - -var testtypesResource = v1.SchemeGroupVersion.WithResource("testtypes") - -var testtypesKind = v1.SchemeGroupVersion.WithKind("TestType") - -// Get takes name of the testType, and returns the corresponding testType object, and an error if there is any. -func (c *FakeTestTypes) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewGetActionWithOptions(testtypesResource, c.ns, name, options), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// List takes label and field selectors, and returns the list of TestTypes that match those selectors. -func (c *FakeTestTypes) List(ctx context.Context, opts metav1.ListOptions) (result *v1.TestTypeList, err error) { - emptyResult := &v1.TestTypeList{} - obj, err := c.Fake. - Invokes(testing.NewListActionWithOptions(testtypesResource, testtypesKind, c.ns, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &v1.TestTypeList{ListMeta: obj.(*v1.TestTypeList).ListMeta} - for _, item := range obj.(*v1.TestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -// Watch returns a watch.Interface that watches the requested testTypes. -func (c *FakeTestTypes) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewWatchActionWithOptions(testtypesResource, c.ns, opts)) - -} - -// Create takes the representation of a testType and creates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *FakeTestTypes) Create(ctx context.Context, testType *v1.TestType, opts metav1.CreateOptions) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewCreateActionWithOptions(testtypesResource, c.ns, testType, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// Update takes the representation of a testType and updates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *FakeTestTypes) Update(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewUpdateActionWithOptions(testtypesResource, c.ns, testType, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err } -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *FakeTestTypes) UpdateStatus(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewUpdateSubresourceActionWithOptions(testtypesResource, "status", c.ns, testType, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// Delete takes name of the testType and deletes it. Returns an error if one occurs. -func (c *FakeTestTypes) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewDeleteActionWithOptions(testtypesResource, c.ns, name, opts), &v1.TestType{}) - - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakeTestTypes) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := testing.NewDeleteCollectionActionWithOptions(testtypesResource, c.ns, opts, listOpts) - - _, err := c.Fake.Invokes(action, &v1.TestTypeList{}) - return err -} - -// Patch applies the patch and returns the patched testType. -func (c *FakeTestTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceActionWithOptions(testtypesResource, c.ns, name, pt, data, opts, subresources...), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// Apply takes the given apply declarative configuration, applies it and returns the applied testType. -func (c *FakeTestTypes) Apply(ctx context.Context, testType *examplev1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *v1.TestType, err error) { - if testType == nil { - return nil, fmt.Errorf("testType provided to Apply must not be nil") - } - data, err := json.Marshal(testType) - if err != nil { - return nil, err - } - name := testType.Name - if name == nil { - return nil, fmt.Errorf("testType.Name must be provided to Apply") - } - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceActionWithOptions(testtypesResource, c.ns, *name, types.ApplyPatchType, data, opts.ToPatchOptions()), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// ApplyStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating ApplyStatus(). -func (c *FakeTestTypes) ApplyStatus(ctx context.Context, testType *examplev1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *v1.TestType, err error) { - if testType == nil { - return nil, fmt.Errorf("testType provided to Apply must not be nil") - } - data, err := json.Marshal(testType) - if err != nil { - return nil, err - } - name := testType.Name - if name == nil { - return nil, fmt.Errorf("testType.Name must be provided to Apply") - } - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceActionWithOptions(testtypesResource, c.ns, *name, types.ApplyPatchType, data, opts.ToPatchOptions(), "status"), emptyResult) - - if obj == nil { - return emptyResult, err +func newFakeTestTypes(fake *FakeExampleV1, namespace string) typedexamplev1.TestTypeInterface { + return &fakeTestTypes{ + gentype.NewFakeClientWithListAndApply[*v1.TestType, *v1.TestTypeList, *examplev1.TestTypeApplyConfiguration]( + fake.Fake, + namespace, + v1.SchemeGroupVersion.WithResource("testtypes"), + v1.SchemeGroupVersion.WithKind("TestType"), + func() *v1.TestType { return &v1.TestType{} }, + func() *v1.TestTypeList { return &v1.TestTypeList{} }, + func(dst, src *v1.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *v1.TestTypeList) []*v1.TestType { return gentype.ToPointerSlice(list.Items) }, + func(list *v1.TestTypeList, items []*v1.TestType) { list.Items = gentype.FromPointerSlice(items) }, + ), + fake, } - return obj.(*v1.TestType), err } diff --git a/examples/apiserver/clientset/versioned/typed/core/v1/fake/fake_core_client.go b/examples/apiserver/clientset/versioned/typed/core/v1/fake/fake_core_client.go index 2cdcda78..d7e35208 100644 --- a/examples/apiserver/clientset/versioned/typed/core/v1/fake/fake_core_client.go +++ b/examples/apiserver/clientset/versioned/typed/core/v1/fake/fake_core_client.go @@ -29,7 +29,7 @@ type FakeCoreV1 struct { } func (c *FakeCoreV1) TestTypes(namespace string) v1.TestTypeInterface { - return &FakeTestTypes{c, namespace} + return newFakeTestTypes(c, namespace) } // RESTClient returns a RESTClient that is used to communicate diff --git a/examples/apiserver/clientset/versioned/typed/core/v1/fake/fake_testtype.go b/examples/apiserver/clientset/versioned/typed/core/v1/fake/fake_testtype.go index 5dd2dca0..88d3c42e 100644 --- a/examples/apiserver/clientset/versioned/typed/core/v1/fake/fake_testtype.go +++ b/examples/apiserver/clientset/versioned/typed/core/v1/fake/fake_testtype.go @@ -19,129 +19,30 @@ limitations under the License. package fake import ( - context "context" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - testing "k8s.io/client-go/testing" + gentype "k8s.io/client-go/gentype" v1 "k8s.io/code-generator/examples/apiserver/apis/core/v1" + corev1 "k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/core/v1" ) -// FakeTestTypes implements TestTypeInterface -type FakeTestTypes struct { +// fakeTestTypes implements TestTypeInterface +type fakeTestTypes struct { + *gentype.FakeClientWithList[*v1.TestType, *v1.TestTypeList] Fake *FakeCoreV1 - ns string -} - -var testtypesResource = v1.SchemeGroupVersion.WithResource("testtypes") - -var testtypesKind = v1.SchemeGroupVersion.WithKind("TestType") - -// Get takes name of the testType, and returns the corresponding testType object, and an error if there is any. -func (c *FakeTestTypes) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewGetActionWithOptions(testtypesResource, c.ns, name, options), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// List takes label and field selectors, and returns the list of TestTypes that match those selectors. -func (c *FakeTestTypes) List(ctx context.Context, opts metav1.ListOptions) (result *v1.TestTypeList, err error) { - emptyResult := &v1.TestTypeList{} - obj, err := c.Fake. - Invokes(testing.NewListActionWithOptions(testtypesResource, testtypesKind, c.ns, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &v1.TestTypeList{ListMeta: obj.(*v1.TestTypeList).ListMeta} - for _, item := range obj.(*v1.TestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -// Watch returns a watch.Interface that watches the requested testTypes. -func (c *FakeTestTypes) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewWatchActionWithOptions(testtypesResource, c.ns, opts)) - -} - -// Create takes the representation of a testType and creates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *FakeTestTypes) Create(ctx context.Context, testType *v1.TestType, opts metav1.CreateOptions) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewCreateActionWithOptions(testtypesResource, c.ns, testType, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// Update takes the representation of a testType and updates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *FakeTestTypes) Update(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewUpdateActionWithOptions(testtypesResource, c.ns, testType, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *FakeTestTypes) UpdateStatus(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewUpdateSubresourceActionWithOptions(testtypesResource, "status", c.ns, testType, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// Delete takes name of the testType and deletes it. Returns an error if one occurs. -func (c *FakeTestTypes) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewDeleteActionWithOptions(testtypesResource, c.ns, name, opts), &v1.TestType{}) - - return err } -// DeleteCollection deletes a collection of objects. -func (c *FakeTestTypes) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := testing.NewDeleteCollectionActionWithOptions(testtypesResource, c.ns, opts, listOpts) - - _, err := c.Fake.Invokes(action, &v1.TestTypeList{}) - return err -} - -// Patch applies the patch and returns the patched testType. -func (c *FakeTestTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceActionWithOptions(testtypesResource, c.ns, name, pt, data, opts, subresources...), emptyResult) - - if obj == nil { - return emptyResult, err +func newFakeTestTypes(fake *FakeCoreV1, namespace string) corev1.TestTypeInterface { + return &fakeTestTypes{ + gentype.NewFakeClientWithList[*v1.TestType, *v1.TestTypeList]( + fake.Fake, + namespace, + v1.SchemeGroupVersion.WithResource("testtypes"), + v1.SchemeGroupVersion.WithKind("TestType"), + func() *v1.TestType { return &v1.TestType{} }, + func() *v1.TestTypeList { return &v1.TestTypeList{} }, + func(dst, src *v1.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *v1.TestTypeList) []*v1.TestType { return gentype.ToPointerSlice(list.Items) }, + func(list *v1.TestTypeList, items []*v1.TestType) { list.Items = gentype.FromPointerSlice(items) }, + ), + fake, } - return obj.(*v1.TestType), err } diff --git a/examples/apiserver/clientset/versioned/typed/example/v1/fake/fake_example_client.go b/examples/apiserver/clientset/versioned/typed/example/v1/fake/fake_example_client.go index e13ab6a3..003ff791 100644 --- a/examples/apiserver/clientset/versioned/typed/example/v1/fake/fake_example_client.go +++ b/examples/apiserver/clientset/versioned/typed/example/v1/fake/fake_example_client.go @@ -29,7 +29,7 @@ type FakeExampleV1 struct { } func (c *FakeExampleV1) TestTypes(namespace string) v1.TestTypeInterface { - return &FakeTestTypes{c, namespace} + return newFakeTestTypes(c, namespace) } // RESTClient returns a RESTClient that is used to communicate diff --git a/examples/apiserver/clientset/versioned/typed/example/v1/fake/fake_testtype.go b/examples/apiserver/clientset/versioned/typed/example/v1/fake/fake_testtype.go index 41837225..64318293 100644 --- a/examples/apiserver/clientset/versioned/typed/example/v1/fake/fake_testtype.go +++ b/examples/apiserver/clientset/versioned/typed/example/v1/fake/fake_testtype.go @@ -19,129 +19,30 @@ limitations under the License. package fake import ( - context "context" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - testing "k8s.io/client-go/testing" + gentype "k8s.io/client-go/gentype" v1 "k8s.io/code-generator/examples/apiserver/apis/example/v1" + examplev1 "k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/example/v1" ) -// FakeTestTypes implements TestTypeInterface -type FakeTestTypes struct { +// fakeTestTypes implements TestTypeInterface +type fakeTestTypes struct { + *gentype.FakeClientWithList[*v1.TestType, *v1.TestTypeList] Fake *FakeExampleV1 - ns string -} - -var testtypesResource = v1.SchemeGroupVersion.WithResource("testtypes") - -var testtypesKind = v1.SchemeGroupVersion.WithKind("TestType") - -// Get takes name of the testType, and returns the corresponding testType object, and an error if there is any. -func (c *FakeTestTypes) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewGetActionWithOptions(testtypesResource, c.ns, name, options), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// List takes label and field selectors, and returns the list of TestTypes that match those selectors. -func (c *FakeTestTypes) List(ctx context.Context, opts metav1.ListOptions) (result *v1.TestTypeList, err error) { - emptyResult := &v1.TestTypeList{} - obj, err := c.Fake. - Invokes(testing.NewListActionWithOptions(testtypesResource, testtypesKind, c.ns, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &v1.TestTypeList{ListMeta: obj.(*v1.TestTypeList).ListMeta} - for _, item := range obj.(*v1.TestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -// Watch returns a watch.Interface that watches the requested testTypes. -func (c *FakeTestTypes) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewWatchActionWithOptions(testtypesResource, c.ns, opts)) - -} - -// Create takes the representation of a testType and creates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *FakeTestTypes) Create(ctx context.Context, testType *v1.TestType, opts metav1.CreateOptions) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewCreateActionWithOptions(testtypesResource, c.ns, testType, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// Update takes the representation of a testType and updates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *FakeTestTypes) Update(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewUpdateActionWithOptions(testtypesResource, c.ns, testType, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *FakeTestTypes) UpdateStatus(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewUpdateSubresourceActionWithOptions(testtypesResource, "status", c.ns, testType, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// Delete takes name of the testType and deletes it. Returns an error if one occurs. -func (c *FakeTestTypes) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewDeleteActionWithOptions(testtypesResource, c.ns, name, opts), &v1.TestType{}) - - return err } -// DeleteCollection deletes a collection of objects. -func (c *FakeTestTypes) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := testing.NewDeleteCollectionActionWithOptions(testtypesResource, c.ns, opts, listOpts) - - _, err := c.Fake.Invokes(action, &v1.TestTypeList{}) - return err -} - -// Patch applies the patch and returns the patched testType. -func (c *FakeTestTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceActionWithOptions(testtypesResource, c.ns, name, pt, data, opts, subresources...), emptyResult) - - if obj == nil { - return emptyResult, err +func newFakeTestTypes(fake *FakeExampleV1, namespace string) examplev1.TestTypeInterface { + return &fakeTestTypes{ + gentype.NewFakeClientWithList[*v1.TestType, *v1.TestTypeList]( + fake.Fake, + namespace, + v1.SchemeGroupVersion.WithResource("testtypes"), + v1.SchemeGroupVersion.WithKind("TestType"), + func() *v1.TestType { return &v1.TestType{} }, + func() *v1.TestTypeList { return &v1.TestTypeList{} }, + func(dst, src *v1.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *v1.TestTypeList) []*v1.TestType { return gentype.ToPointerSlice(list.Items) }, + func(list *v1.TestTypeList, items []*v1.TestType) { list.Items = gentype.FromPointerSlice(items) }, + ), + fake, } - return obj.(*v1.TestType), err } diff --git a/examples/apiserver/clientset/versioned/typed/example2/v1/fake/fake_example2_client.go b/examples/apiserver/clientset/versioned/typed/example2/v1/fake/fake_example2_client.go index 6ac144fb..44a41cd6 100644 --- a/examples/apiserver/clientset/versioned/typed/example2/v1/fake/fake_example2_client.go +++ b/examples/apiserver/clientset/versioned/typed/example2/v1/fake/fake_example2_client.go @@ -29,7 +29,7 @@ type FakeSecondExampleV1 struct { } func (c *FakeSecondExampleV1) TestTypes(namespace string) v1.TestTypeInterface { - return &FakeTestTypes{c, namespace} + return newFakeTestTypes(c, namespace) } // RESTClient returns a RESTClient that is used to communicate diff --git a/examples/apiserver/clientset/versioned/typed/example2/v1/fake/fake_testtype.go b/examples/apiserver/clientset/versioned/typed/example2/v1/fake/fake_testtype.go index 33b7ad5a..e02f8070 100644 --- a/examples/apiserver/clientset/versioned/typed/example2/v1/fake/fake_testtype.go +++ b/examples/apiserver/clientset/versioned/typed/example2/v1/fake/fake_testtype.go @@ -19,129 +19,30 @@ limitations under the License. package fake import ( - context "context" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - testing "k8s.io/client-go/testing" + gentype "k8s.io/client-go/gentype" v1 "k8s.io/code-generator/examples/apiserver/apis/example2/v1" + example2v1 "k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/example2/v1" ) -// FakeTestTypes implements TestTypeInterface -type FakeTestTypes struct { +// fakeTestTypes implements TestTypeInterface +type fakeTestTypes struct { + *gentype.FakeClientWithList[*v1.TestType, *v1.TestTypeList] Fake *FakeSecondExampleV1 - ns string -} - -var testtypesResource = v1.SchemeGroupVersion.WithResource("testtypes") - -var testtypesKind = v1.SchemeGroupVersion.WithKind("TestType") - -// Get takes name of the testType, and returns the corresponding testType object, and an error if there is any. -func (c *FakeTestTypes) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewGetActionWithOptions(testtypesResource, c.ns, name, options), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// List takes label and field selectors, and returns the list of TestTypes that match those selectors. -func (c *FakeTestTypes) List(ctx context.Context, opts metav1.ListOptions) (result *v1.TestTypeList, err error) { - emptyResult := &v1.TestTypeList{} - obj, err := c.Fake. - Invokes(testing.NewListActionWithOptions(testtypesResource, testtypesKind, c.ns, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &v1.TestTypeList{ListMeta: obj.(*v1.TestTypeList).ListMeta} - for _, item := range obj.(*v1.TestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -// Watch returns a watch.Interface that watches the requested testTypes. -func (c *FakeTestTypes) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewWatchActionWithOptions(testtypesResource, c.ns, opts)) - -} - -// Create takes the representation of a testType and creates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *FakeTestTypes) Create(ctx context.Context, testType *v1.TestType, opts metav1.CreateOptions) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewCreateActionWithOptions(testtypesResource, c.ns, testType, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// Update takes the representation of a testType and updates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *FakeTestTypes) Update(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewUpdateActionWithOptions(testtypesResource, c.ns, testType, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *FakeTestTypes) UpdateStatus(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewUpdateSubresourceActionWithOptions(testtypesResource, "status", c.ns, testType, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// Delete takes name of the testType and deletes it. Returns an error if one occurs. -func (c *FakeTestTypes) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewDeleteActionWithOptions(testtypesResource, c.ns, name, opts), &v1.TestType{}) - - return err } -// DeleteCollection deletes a collection of objects. -func (c *FakeTestTypes) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := testing.NewDeleteCollectionActionWithOptions(testtypesResource, c.ns, opts, listOpts) - - _, err := c.Fake.Invokes(action, &v1.TestTypeList{}) - return err -} - -// Patch applies the patch and returns the patched testType. -func (c *FakeTestTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceActionWithOptions(testtypesResource, c.ns, name, pt, data, opts, subresources...), emptyResult) - - if obj == nil { - return emptyResult, err +func newFakeTestTypes(fake *FakeSecondExampleV1, namespace string) example2v1.TestTypeInterface { + return &fakeTestTypes{ + gentype.NewFakeClientWithList[*v1.TestType, *v1.TestTypeList]( + fake.Fake, + namespace, + v1.SchemeGroupVersion.WithResource("testtypes"), + v1.SchemeGroupVersion.WithKind("TestType"), + func() *v1.TestType { return &v1.TestType{} }, + func() *v1.TestTypeList { return &v1.TestTypeList{} }, + func(dst, src *v1.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *v1.TestTypeList) []*v1.TestType { return gentype.ToPointerSlice(list.Items) }, + func(list *v1.TestTypeList, items []*v1.TestType) { list.Items = gentype.FromPointerSlice(items) }, + ), + fake, } - return obj.(*v1.TestType), err } diff --git a/examples/apiserver/clientset/versioned/typed/example3.io/v1/fake/fake_example3.io_client.go b/examples/apiserver/clientset/versioned/typed/example3.io/v1/fake/fake_example3.io_client.go index 26510744..221f4aca 100644 --- a/examples/apiserver/clientset/versioned/typed/example3.io/v1/fake/fake_example3.io_client.go +++ b/examples/apiserver/clientset/versioned/typed/example3.io/v1/fake/fake_example3.io_client.go @@ -29,7 +29,7 @@ type FakeThirdExampleV1 struct { } func (c *FakeThirdExampleV1) TestTypes(namespace string) v1.TestTypeInterface { - return &FakeTestTypes{c, namespace} + return newFakeTestTypes(c, namespace) } // RESTClient returns a RESTClient that is used to communicate diff --git a/examples/apiserver/clientset/versioned/typed/example3.io/v1/fake/fake_testtype.go b/examples/apiserver/clientset/versioned/typed/example3.io/v1/fake/fake_testtype.go index 1d1f530f..27531596 100644 --- a/examples/apiserver/clientset/versioned/typed/example3.io/v1/fake/fake_testtype.go +++ b/examples/apiserver/clientset/versioned/typed/example3.io/v1/fake/fake_testtype.go @@ -19,129 +19,30 @@ limitations under the License. package fake import ( - context "context" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - testing "k8s.io/client-go/testing" + gentype "k8s.io/client-go/gentype" v1 "k8s.io/code-generator/examples/apiserver/apis/example3.io/v1" + example3iov1 "k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/example3.io/v1" ) -// FakeTestTypes implements TestTypeInterface -type FakeTestTypes struct { +// fakeTestTypes implements TestTypeInterface +type fakeTestTypes struct { + *gentype.FakeClientWithList[*v1.TestType, *v1.TestTypeList] Fake *FakeThirdExampleV1 - ns string -} - -var testtypesResource = v1.SchemeGroupVersion.WithResource("testtypes") - -var testtypesKind = v1.SchemeGroupVersion.WithKind("TestType") - -// Get takes name of the testType, and returns the corresponding testType object, and an error if there is any. -func (c *FakeTestTypes) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewGetActionWithOptions(testtypesResource, c.ns, name, options), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// List takes label and field selectors, and returns the list of TestTypes that match those selectors. -func (c *FakeTestTypes) List(ctx context.Context, opts metav1.ListOptions) (result *v1.TestTypeList, err error) { - emptyResult := &v1.TestTypeList{} - obj, err := c.Fake. - Invokes(testing.NewListActionWithOptions(testtypesResource, testtypesKind, c.ns, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &v1.TestTypeList{ListMeta: obj.(*v1.TestTypeList).ListMeta} - for _, item := range obj.(*v1.TestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -// Watch returns a watch.Interface that watches the requested testTypes. -func (c *FakeTestTypes) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewWatchActionWithOptions(testtypesResource, c.ns, opts)) - -} - -// Create takes the representation of a testType and creates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *FakeTestTypes) Create(ctx context.Context, testType *v1.TestType, opts metav1.CreateOptions) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewCreateActionWithOptions(testtypesResource, c.ns, testType, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// Update takes the representation of a testType and updates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *FakeTestTypes) Update(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewUpdateActionWithOptions(testtypesResource, c.ns, testType, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *FakeTestTypes) UpdateStatus(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewUpdateSubresourceActionWithOptions(testtypesResource, "status", c.ns, testType, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// Delete takes name of the testType and deletes it. Returns an error if one occurs. -func (c *FakeTestTypes) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewDeleteActionWithOptions(testtypesResource, c.ns, name, opts), &v1.TestType{}) - - return err } -// DeleteCollection deletes a collection of objects. -func (c *FakeTestTypes) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := testing.NewDeleteCollectionActionWithOptions(testtypesResource, c.ns, opts, listOpts) - - _, err := c.Fake.Invokes(action, &v1.TestTypeList{}) - return err -} - -// Patch applies the patch and returns the patched testType. -func (c *FakeTestTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceActionWithOptions(testtypesResource, c.ns, name, pt, data, opts, subresources...), emptyResult) - - if obj == nil { - return emptyResult, err +func newFakeTestTypes(fake *FakeThirdExampleV1, namespace string) example3iov1.TestTypeInterface { + return &fakeTestTypes{ + gentype.NewFakeClientWithList[*v1.TestType, *v1.TestTypeList]( + fake.Fake, + namespace, + v1.SchemeGroupVersion.WithResource("testtypes"), + v1.SchemeGroupVersion.WithKind("TestType"), + func() *v1.TestType { return &v1.TestType{} }, + func() *v1.TestTypeList { return &v1.TestTypeList{} }, + func(dst, src *v1.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *v1.TestTypeList) []*v1.TestType { return gentype.ToPointerSlice(list.Items) }, + func(list *v1.TestTypeList, items []*v1.TestType) { list.Items = gentype.FromPointerSlice(items) }, + ), + fake, } - return obj.(*v1.TestType), err } diff --git a/examples/crd/clientset/versioned/typed/conflicting/v1/fake/fake_conflicting_client.go b/examples/crd/clientset/versioned/typed/conflicting/v1/fake/fake_conflicting_client.go index f3011126..fc99cc7b 100644 --- a/examples/crd/clientset/versioned/typed/conflicting/v1/fake/fake_conflicting_client.go +++ b/examples/crd/clientset/versioned/typed/conflicting/v1/fake/fake_conflicting_client.go @@ -29,7 +29,7 @@ type FakeConflictingExampleV1 struct { } func (c *FakeConflictingExampleV1) TestTypes(namespace string) v1.TestTypeInterface { - return &FakeTestTypes{c, namespace} + return newFakeTestTypes(c, namespace) } // RESTClient returns a RESTClient that is used to communicate diff --git a/examples/crd/clientset/versioned/typed/conflicting/v1/fake/fake_testtype.go b/examples/crd/clientset/versioned/typed/conflicting/v1/fake/fake_testtype.go index 79cb4573..1230aeaa 100644 --- a/examples/crd/clientset/versioned/typed/conflicting/v1/fake/fake_testtype.go +++ b/examples/crd/clientset/versioned/typed/conflicting/v1/fake/fake_testtype.go @@ -19,179 +19,31 @@ limitations under the License. package fake import ( - context "context" - json "encoding/json" - fmt "fmt" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - testing "k8s.io/client-go/testing" + gentype "k8s.io/client-go/gentype" v1 "k8s.io/code-generator/examples/crd/apis/conflicting/v1" conflictingv1 "k8s.io/code-generator/examples/crd/applyconfiguration/conflicting/v1" + typedconflictingv1 "k8s.io/code-generator/examples/crd/clientset/versioned/typed/conflicting/v1" ) -// FakeTestTypes implements TestTypeInterface -type FakeTestTypes struct { +// fakeTestTypes implements TestTypeInterface +type fakeTestTypes struct { + *gentype.FakeClientWithListAndApply[*v1.TestType, *v1.TestTypeList, *conflictingv1.TestTypeApplyConfiguration] Fake *FakeConflictingExampleV1 - ns string -} - -var testtypesResource = v1.SchemeGroupVersion.WithResource("testtypes") - -var testtypesKind = v1.SchemeGroupVersion.WithKind("TestType") - -// Get takes name of the testType, and returns the corresponding testType object, and an error if there is any. -func (c *FakeTestTypes) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewGetActionWithOptions(testtypesResource, c.ns, name, options), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// List takes label and field selectors, and returns the list of TestTypes that match those selectors. -func (c *FakeTestTypes) List(ctx context.Context, opts metav1.ListOptions) (result *v1.TestTypeList, err error) { - emptyResult := &v1.TestTypeList{} - obj, err := c.Fake. - Invokes(testing.NewListActionWithOptions(testtypesResource, testtypesKind, c.ns, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &v1.TestTypeList{ListMeta: obj.(*v1.TestTypeList).ListMeta} - for _, item := range obj.(*v1.TestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -// Watch returns a watch.Interface that watches the requested testTypes. -func (c *FakeTestTypes) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewWatchActionWithOptions(testtypesResource, c.ns, opts)) - -} - -// Create takes the representation of a testType and creates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *FakeTestTypes) Create(ctx context.Context, testType *v1.TestType, opts metav1.CreateOptions) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewCreateActionWithOptions(testtypesResource, c.ns, testType, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// Update takes the representation of a testType and updates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *FakeTestTypes) Update(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewUpdateActionWithOptions(testtypesResource, c.ns, testType, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err } -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *FakeTestTypes) UpdateStatus(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewUpdateSubresourceActionWithOptions(testtypesResource, "status", c.ns, testType, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// Delete takes name of the testType and deletes it. Returns an error if one occurs. -func (c *FakeTestTypes) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewDeleteActionWithOptions(testtypesResource, c.ns, name, opts), &v1.TestType{}) - - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakeTestTypes) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := testing.NewDeleteCollectionActionWithOptions(testtypesResource, c.ns, opts, listOpts) - - _, err := c.Fake.Invokes(action, &v1.TestTypeList{}) - return err -} - -// Patch applies the patch and returns the patched testType. -func (c *FakeTestTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceActionWithOptions(testtypesResource, c.ns, name, pt, data, opts, subresources...), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// Apply takes the given apply declarative configuration, applies it and returns the applied testType. -func (c *FakeTestTypes) Apply(ctx context.Context, testType *conflictingv1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *v1.TestType, err error) { - if testType == nil { - return nil, fmt.Errorf("testType provided to Apply must not be nil") - } - data, err := json.Marshal(testType) - if err != nil { - return nil, err - } - name := testType.Name - if name == nil { - return nil, fmt.Errorf("testType.Name must be provided to Apply") - } - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceActionWithOptions(testtypesResource, c.ns, *name, types.ApplyPatchType, data, opts.ToPatchOptions()), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// ApplyStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating ApplyStatus(). -func (c *FakeTestTypes) ApplyStatus(ctx context.Context, testType *conflictingv1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *v1.TestType, err error) { - if testType == nil { - return nil, fmt.Errorf("testType provided to Apply must not be nil") - } - data, err := json.Marshal(testType) - if err != nil { - return nil, err - } - name := testType.Name - if name == nil { - return nil, fmt.Errorf("testType.Name must be provided to Apply") - } - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceActionWithOptions(testtypesResource, c.ns, *name, types.ApplyPatchType, data, opts.ToPatchOptions(), "status"), emptyResult) - - if obj == nil { - return emptyResult, err +func newFakeTestTypes(fake *FakeConflictingExampleV1, namespace string) typedconflictingv1.TestTypeInterface { + return &fakeTestTypes{ + gentype.NewFakeClientWithListAndApply[*v1.TestType, *v1.TestTypeList, *conflictingv1.TestTypeApplyConfiguration]( + fake.Fake, + namespace, + v1.SchemeGroupVersion.WithResource("testtypes"), + v1.SchemeGroupVersion.WithKind("TestType"), + func() *v1.TestType { return &v1.TestType{} }, + func() *v1.TestTypeList { return &v1.TestTypeList{} }, + func(dst, src *v1.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *v1.TestTypeList) []*v1.TestType { return gentype.ToPointerSlice(list.Items) }, + func(list *v1.TestTypeList, items []*v1.TestType) { list.Items = gentype.FromPointerSlice(items) }, + ), + fake, } - return obj.(*v1.TestType), err } diff --git a/examples/crd/clientset/versioned/typed/example/v1/fake/fake_clustertesttype.go b/examples/crd/clientset/versioned/typed/example/v1/fake/fake_clustertesttype.go index c512d065..7618547f 100644 --- a/examples/crd/clientset/versioned/typed/example/v1/fake/fake_clustertesttype.go +++ b/examples/crd/clientset/versioned/typed/example/v1/fake/fake_clustertesttype.go @@ -20,177 +20,46 @@ package fake import ( context "context" - json "encoding/json" - fmt "fmt" autoscalingv1 "k8s.io/api/autoscaling/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" + gentype "k8s.io/client-go/gentype" testing "k8s.io/client-go/testing" v1 "k8s.io/code-generator/examples/crd/apis/example/v1" examplev1 "k8s.io/code-generator/examples/crd/applyconfiguration/example/v1" + typedexamplev1 "k8s.io/code-generator/examples/crd/clientset/versioned/typed/example/v1" ) -// FakeClusterTestTypes implements ClusterTestTypeInterface -type FakeClusterTestTypes struct { +// fakeClusterTestTypes implements ClusterTestTypeInterface +type fakeClusterTestTypes struct { + *gentype.FakeClientWithListAndApply[*v1.ClusterTestType, *v1.ClusterTestTypeList, *examplev1.ClusterTestTypeApplyConfiguration] Fake *FakeExampleV1 } -var clustertesttypesResource = v1.SchemeGroupVersion.WithResource("clustertesttypes") - -var clustertesttypesKind = v1.SchemeGroupVersion.WithKind("ClusterTestType") - -// Get takes name of the clusterTestType, and returns the corresponding clusterTestType object, and an error if there is any. -func (c *FakeClusterTestTypes) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.ClusterTestType, err error) { - emptyResult := &v1.ClusterTestType{} - obj, err := c.Fake. - Invokes(testing.NewRootGetActionWithOptions(clustertesttypesResource, name, options), emptyResult) - if obj == nil { - return emptyResult, err - } - return obj.(*v1.ClusterTestType), err -} - -// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors. -func (c *FakeClusterTestTypes) List(ctx context.Context, opts metav1.ListOptions) (result *v1.ClusterTestTypeList, err error) { - emptyResult := &v1.ClusterTestTypeList{} - obj, err := c.Fake. - Invokes(testing.NewRootListActionWithOptions(clustertesttypesResource, clustertesttypesKind, opts), emptyResult) - if obj == nil { - return emptyResult, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &v1.ClusterTestTypeList{ListMeta: obj.(*v1.ClusterTestTypeList).ListMeta} - for _, item := range obj.(*v1.ClusterTestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -// Watch returns a watch.Interface that watches the requested clusterTestTypes. -func (c *FakeClusterTestTypes) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewRootWatchActionWithOptions(clustertesttypesResource, opts)) -} - -// Create takes the representation of a clusterTestType and creates it. Returns the server's representation of the clusterTestType, and an error, if there is any. -func (c *FakeClusterTestTypes) Create(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.CreateOptions) (result *v1.ClusterTestType, err error) { - emptyResult := &v1.ClusterTestType{} - obj, err := c.Fake. - Invokes(testing.NewRootCreateActionWithOptions(clustertesttypesResource, clusterTestType, opts), emptyResult) - if obj == nil { - return emptyResult, err - } - return obj.(*v1.ClusterTestType), err -} - -// Update takes the representation of a clusterTestType and updates it. Returns the server's representation of the clusterTestType, and an error, if there is any. -func (c *FakeClusterTestTypes) Update(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.UpdateOptions) (result *v1.ClusterTestType, err error) { - emptyResult := &v1.ClusterTestType{} - obj, err := c.Fake. - Invokes(testing.NewRootUpdateActionWithOptions(clustertesttypesResource, clusterTestType, opts), emptyResult) - if obj == nil { - return emptyResult, err - } - return obj.(*v1.ClusterTestType), err -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *FakeClusterTestTypes) UpdateStatus(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.UpdateOptions) (result *v1.ClusterTestType, err error) { - emptyResult := &v1.ClusterTestType{} - obj, err := c.Fake. - Invokes(testing.NewRootUpdateSubresourceActionWithOptions(clustertesttypesResource, "status", clusterTestType, opts), emptyResult) - if obj == nil { - return emptyResult, err - } - return obj.(*v1.ClusterTestType), err -} - -// Delete takes name of the clusterTestType and deletes it. Returns an error if one occurs. -func (c *FakeClusterTestTypes) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewRootDeleteActionWithOptions(clustertesttypesResource, name, opts), &v1.ClusterTestType{}) - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakeClusterTestTypes) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := testing.NewRootDeleteCollectionActionWithOptions(clustertesttypesResource, opts, listOpts) - - _, err := c.Fake.Invokes(action, &v1.ClusterTestTypeList{}) - return err -} - -// Patch applies the patch and returns the patched clusterTestType. -func (c *FakeClusterTestTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.ClusterTestType, err error) { - emptyResult := &v1.ClusterTestType{} - obj, err := c.Fake. - Invokes(testing.NewRootPatchSubresourceActionWithOptions(clustertesttypesResource, name, pt, data, opts, subresources...), emptyResult) - if obj == nil { - return emptyResult, err - } - return obj.(*v1.ClusterTestType), err -} - -// Apply takes the given apply declarative configuration, applies it and returns the applied clusterTestType. -func (c *FakeClusterTestTypes) Apply(ctx context.Context, clusterTestType *examplev1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *v1.ClusterTestType, err error) { - if clusterTestType == nil { - return nil, fmt.Errorf("clusterTestType provided to Apply must not be nil") - } - data, err := json.Marshal(clusterTestType) - if err != nil { - return nil, err - } - name := clusterTestType.Name - if name == nil { - return nil, fmt.Errorf("clusterTestType.Name must be provided to Apply") - } - emptyResult := &v1.ClusterTestType{} - obj, err := c.Fake. - Invokes(testing.NewRootPatchSubresourceActionWithOptions(clustertesttypesResource, *name, types.ApplyPatchType, data, opts.ToPatchOptions()), emptyResult) - if obj == nil { - return emptyResult, err - } - return obj.(*v1.ClusterTestType), err -} - -// ApplyStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating ApplyStatus(). -func (c *FakeClusterTestTypes) ApplyStatus(ctx context.Context, clusterTestType *examplev1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *v1.ClusterTestType, err error) { - if clusterTestType == nil { - return nil, fmt.Errorf("clusterTestType provided to Apply must not be nil") - } - data, err := json.Marshal(clusterTestType) - if err != nil { - return nil, err - } - name := clusterTestType.Name - if name == nil { - return nil, fmt.Errorf("clusterTestType.Name must be provided to Apply") - } - emptyResult := &v1.ClusterTestType{} - obj, err := c.Fake. - Invokes(testing.NewRootPatchSubresourceActionWithOptions(clustertesttypesResource, *name, types.ApplyPatchType, data, opts.ToPatchOptions(), "status"), emptyResult) - if obj == nil { - return emptyResult, err +func newFakeClusterTestTypes(fake *FakeExampleV1) typedexamplev1.ClusterTestTypeInterface { + return &fakeClusterTestTypes{ + gentype.NewFakeClientWithListAndApply[*v1.ClusterTestType, *v1.ClusterTestTypeList, *examplev1.ClusterTestTypeApplyConfiguration]( + fake.Fake, + "", + v1.SchemeGroupVersion.WithResource("clustertesttypes"), + v1.SchemeGroupVersion.WithKind("ClusterTestType"), + func() *v1.ClusterTestType { return &v1.ClusterTestType{} }, + func() *v1.ClusterTestTypeList { return &v1.ClusterTestTypeList{} }, + func(dst, src *v1.ClusterTestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *v1.ClusterTestTypeList) []*v1.ClusterTestType { return gentype.ToPointerSlice(list.Items) }, + func(list *v1.ClusterTestTypeList, items []*v1.ClusterTestType) { + list.Items = gentype.FromPointerSlice(items) + }, + ), + fake, } - return obj.(*v1.ClusterTestType), err } // GetScale takes name of the clusterTestType, and returns the corresponding scale object, and an error if there is any. -func (c *FakeClusterTestTypes) GetScale(ctx context.Context, clusterTestTypeName string, options metav1.GetOptions) (result *autoscalingv1.Scale, err error) { +func (c *fakeClusterTestTypes) GetScale(ctx context.Context, clusterTestTypeName string, options metav1.GetOptions) (result *autoscalingv1.Scale, err error) { emptyResult := &autoscalingv1.Scale{} obj, err := c.Fake. - Invokes(testing.NewRootGetSubresourceActionWithOptions(clustertesttypesResource, "scale", clusterTestTypeName, options), emptyResult) + Invokes(testing.NewRootGetSubresourceActionWithOptions(c.Resource(), "scale", clusterTestTypeName, options), emptyResult) if obj == nil { return emptyResult, err } @@ -198,10 +67,10 @@ func (c *FakeClusterTestTypes) GetScale(ctx context.Context, clusterTestTypeName } // UpdateScale takes the representation of a scale and updates it. Returns the server's representation of the scale, and an error, if there is any. -func (c *FakeClusterTestTypes) UpdateScale(ctx context.Context, clusterTestTypeName string, scale *autoscalingv1.Scale, opts metav1.UpdateOptions) (result *autoscalingv1.Scale, err error) { +func (c *fakeClusterTestTypes) UpdateScale(ctx context.Context, clusterTestTypeName string, scale *autoscalingv1.Scale, opts metav1.UpdateOptions) (result *autoscalingv1.Scale, err error) { emptyResult := &autoscalingv1.Scale{} obj, err := c.Fake. - Invokes(testing.NewRootUpdateSubresourceActionWithOptions(clustertesttypesResource, "scale", scale, opts), emptyResult) + Invokes(testing.NewRootUpdateSubresourceActionWithOptions(c.Resource(), "scale", scale, opts), emptyResult) if obj == nil { return emptyResult, err } diff --git a/examples/crd/clientset/versioned/typed/example/v1/fake/fake_example_client.go b/examples/crd/clientset/versioned/typed/example/v1/fake/fake_example_client.go index 44bd7f81..c0ffa31f 100644 --- a/examples/crd/clientset/versioned/typed/example/v1/fake/fake_example_client.go +++ b/examples/crd/clientset/versioned/typed/example/v1/fake/fake_example_client.go @@ -29,11 +29,11 @@ type FakeExampleV1 struct { } func (c *FakeExampleV1) ClusterTestTypes() v1.ClusterTestTypeInterface { - return &FakeClusterTestTypes{c} + return newFakeClusterTestTypes(c) } func (c *FakeExampleV1) TestTypes(namespace string) v1.TestTypeInterface { - return &FakeTestTypes{c, namespace} + return newFakeTestTypes(c, namespace) } // RESTClient returns a RESTClient that is used to communicate diff --git a/examples/crd/clientset/versioned/typed/example/v1/fake/fake_testtype.go b/examples/crd/clientset/versioned/typed/example/v1/fake/fake_testtype.go index d96012ad..a07ffdf5 100644 --- a/examples/crd/clientset/versioned/typed/example/v1/fake/fake_testtype.go +++ b/examples/crd/clientset/versioned/typed/example/v1/fake/fake_testtype.go @@ -20,187 +20,43 @@ package fake import ( context "context" - json "encoding/json" - fmt "fmt" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" + gentype "k8s.io/client-go/gentype" testing "k8s.io/client-go/testing" v1 "k8s.io/code-generator/examples/crd/apis/example/v1" examplev1 "k8s.io/code-generator/examples/crd/applyconfiguration/example/v1" + typedexamplev1 "k8s.io/code-generator/examples/crd/clientset/versioned/typed/example/v1" ) -// FakeTestTypes implements TestTypeInterface -type FakeTestTypes struct { +// fakeTestTypes implements TestTypeInterface +type fakeTestTypes struct { + *gentype.FakeClientWithListAndApply[*v1.TestType, *v1.TestTypeList, *examplev1.TestTypeApplyConfiguration] Fake *FakeExampleV1 - ns string } -var testtypesResource = v1.SchemeGroupVersion.WithResource("testtypes") - -var testtypesKind = v1.SchemeGroupVersion.WithKind("TestType") - -// Get takes name of the testType, and returns the corresponding testType object, and an error if there is any. -func (c *FakeTestTypes) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewGetActionWithOptions(testtypesResource, c.ns, name, options), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// List takes label and field selectors, and returns the list of TestTypes that match those selectors. -func (c *FakeTestTypes) List(ctx context.Context, opts metav1.ListOptions) (result *v1.TestTypeList, err error) { - emptyResult := &v1.TestTypeList{} - obj, err := c.Fake. - Invokes(testing.NewListActionWithOptions(testtypesResource, testtypesKind, c.ns, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &v1.TestTypeList{ListMeta: obj.(*v1.TestTypeList).ListMeta} - for _, item := range obj.(*v1.TestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -// Watch returns a watch.Interface that watches the requested testTypes. -func (c *FakeTestTypes) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewWatchActionWithOptions(testtypesResource, c.ns, opts)) - -} - -// Create takes the representation of a testType and creates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *FakeTestTypes) Create(ctx context.Context, testType *v1.TestType, opts metav1.CreateOptions) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewCreateActionWithOptions(testtypesResource, c.ns, testType, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// Update takes the representation of a testType and updates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *FakeTestTypes) Update(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewUpdateActionWithOptions(testtypesResource, c.ns, testType, opts), emptyResult) - - if obj == nil { - return emptyResult, err +func newFakeTestTypes(fake *FakeExampleV1, namespace string) typedexamplev1.TestTypeInterface { + return &fakeTestTypes{ + gentype.NewFakeClientWithListAndApply[*v1.TestType, *v1.TestTypeList, *examplev1.TestTypeApplyConfiguration]( + fake.Fake, + namespace, + v1.SchemeGroupVersion.WithResource("testtypes"), + v1.SchemeGroupVersion.WithKind("TestType"), + func() *v1.TestType { return &v1.TestType{} }, + func() *v1.TestTypeList { return &v1.TestTypeList{} }, + func(dst, src *v1.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *v1.TestTypeList) []*v1.TestType { return gentype.ToPointerSlice(list.Items) }, + func(list *v1.TestTypeList, items []*v1.TestType) { list.Items = gentype.FromPointerSlice(items) }, + ), + fake, } - return obj.(*v1.TestType), err -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *FakeTestTypes) UpdateStatus(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewUpdateSubresourceActionWithOptions(testtypesResource, "status", c.ns, testType, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// Delete takes name of the testType and deletes it. Returns an error if one occurs. -func (c *FakeTestTypes) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewDeleteActionWithOptions(testtypesResource, c.ns, name, opts), &v1.TestType{}) - - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakeTestTypes) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := testing.NewDeleteCollectionActionWithOptions(testtypesResource, c.ns, opts, listOpts) - - _, err := c.Fake.Invokes(action, &v1.TestTypeList{}) - return err -} - -// Patch applies the patch and returns the patched testType. -func (c *FakeTestTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceActionWithOptions(testtypesResource, c.ns, name, pt, data, opts, subresources...), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// Apply takes the given apply declarative configuration, applies it and returns the applied testType. -func (c *FakeTestTypes) Apply(ctx context.Context, testType *examplev1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *v1.TestType, err error) { - if testType == nil { - return nil, fmt.Errorf("testType provided to Apply must not be nil") - } - data, err := json.Marshal(testType) - if err != nil { - return nil, err - } - name := testType.Name - if name == nil { - return nil, fmt.Errorf("testType.Name must be provided to Apply") - } - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceActionWithOptions(testtypesResource, c.ns, *name, types.ApplyPatchType, data, opts.ToPatchOptions()), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// ApplyStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating ApplyStatus(). -func (c *FakeTestTypes) ApplyStatus(ctx context.Context, testType *examplev1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *v1.TestType, err error) { - if testType == nil { - return nil, fmt.Errorf("testType provided to Apply must not be nil") - } - data, err := json.Marshal(testType) - if err != nil { - return nil, err - } - name := testType.Name - if name == nil { - return nil, fmt.Errorf("testType.Name must be provided to Apply") - } - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceActionWithOptions(testtypesResource, c.ns, *name, types.ApplyPatchType, data, opts.ToPatchOptions(), "status"), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err } // GetClusterTestType takes name of the testType, and returns the corresponding testType object, and an error if there is any. -func (c *FakeTestTypes) GetClusterTestType(ctx context.Context, name string, options metav1.GetOptions) (result *v1.TestType, err error) { +func (c *fakeTestTypes) GetClusterTestType(ctx context.Context, name string, options metav1.GetOptions) (result *v1.TestType, err error) { emptyResult := &v1.TestType{} obj, err := c.Fake. - Invokes(testing.NewGetActionWithOptions(testtypesResource, c.ns, name, options), emptyResult) + Invokes(testing.NewGetActionWithOptions(c.Resource(), c.Namespace(), name, options), emptyResult) if obj == nil { return emptyResult, err diff --git a/examples/crd/clientset/versioned/typed/example2/v1/fake/fake_example2_client.go b/examples/crd/clientset/versioned/typed/example2/v1/fake/fake_example2_client.go index c60f7ac9..afa4d893 100644 --- a/examples/crd/clientset/versioned/typed/example2/v1/fake/fake_example2_client.go +++ b/examples/crd/clientset/versioned/typed/example2/v1/fake/fake_example2_client.go @@ -29,7 +29,7 @@ type FakeSecondExampleV1 struct { } func (c *FakeSecondExampleV1) TestTypes(namespace string) v1.TestTypeInterface { - return &FakeTestTypes{c, namespace} + return newFakeTestTypes(c, namespace) } // RESTClient returns a RESTClient that is used to communicate diff --git a/examples/crd/clientset/versioned/typed/example2/v1/fake/fake_testtype.go b/examples/crd/clientset/versioned/typed/example2/v1/fake/fake_testtype.go index 349e732f..b6b05c34 100644 --- a/examples/crd/clientset/versioned/typed/example2/v1/fake/fake_testtype.go +++ b/examples/crd/clientset/versioned/typed/example2/v1/fake/fake_testtype.go @@ -19,179 +19,31 @@ limitations under the License. package fake import ( - context "context" - json "encoding/json" - fmt "fmt" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - testing "k8s.io/client-go/testing" + gentype "k8s.io/client-go/gentype" v1 "k8s.io/code-generator/examples/crd/apis/example2/v1" example2v1 "k8s.io/code-generator/examples/crd/applyconfiguration/example2/v1" + typedexample2v1 "k8s.io/code-generator/examples/crd/clientset/versioned/typed/example2/v1" ) -// FakeTestTypes implements TestTypeInterface -type FakeTestTypes struct { +// fakeTestTypes implements TestTypeInterface +type fakeTestTypes struct { + *gentype.FakeClientWithListAndApply[*v1.TestType, *v1.TestTypeList, *example2v1.TestTypeApplyConfiguration] Fake *FakeSecondExampleV1 - ns string -} - -var testtypesResource = v1.SchemeGroupVersion.WithResource("testtypes") - -var testtypesKind = v1.SchemeGroupVersion.WithKind("TestType") - -// Get takes name of the testType, and returns the corresponding testType object, and an error if there is any. -func (c *FakeTestTypes) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewGetActionWithOptions(testtypesResource, c.ns, name, options), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// List takes label and field selectors, and returns the list of TestTypes that match those selectors. -func (c *FakeTestTypes) List(ctx context.Context, opts metav1.ListOptions) (result *v1.TestTypeList, err error) { - emptyResult := &v1.TestTypeList{} - obj, err := c.Fake. - Invokes(testing.NewListActionWithOptions(testtypesResource, testtypesKind, c.ns, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &v1.TestTypeList{ListMeta: obj.(*v1.TestTypeList).ListMeta} - for _, item := range obj.(*v1.TestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -// Watch returns a watch.Interface that watches the requested testTypes. -func (c *FakeTestTypes) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewWatchActionWithOptions(testtypesResource, c.ns, opts)) - -} - -// Create takes the representation of a testType and creates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *FakeTestTypes) Create(ctx context.Context, testType *v1.TestType, opts metav1.CreateOptions) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewCreateActionWithOptions(testtypesResource, c.ns, testType, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// Update takes the representation of a testType and updates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *FakeTestTypes) Update(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewUpdateActionWithOptions(testtypesResource, c.ns, testType, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err } -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *FakeTestTypes) UpdateStatus(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewUpdateSubresourceActionWithOptions(testtypesResource, "status", c.ns, testType, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// Delete takes name of the testType and deletes it. Returns an error if one occurs. -func (c *FakeTestTypes) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewDeleteActionWithOptions(testtypesResource, c.ns, name, opts), &v1.TestType{}) - - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakeTestTypes) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := testing.NewDeleteCollectionActionWithOptions(testtypesResource, c.ns, opts, listOpts) - - _, err := c.Fake.Invokes(action, &v1.TestTypeList{}) - return err -} - -// Patch applies the patch and returns the patched testType. -func (c *FakeTestTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceActionWithOptions(testtypesResource, c.ns, name, pt, data, opts, subresources...), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// Apply takes the given apply declarative configuration, applies it and returns the applied testType. -func (c *FakeTestTypes) Apply(ctx context.Context, testType *example2v1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *v1.TestType, err error) { - if testType == nil { - return nil, fmt.Errorf("testType provided to Apply must not be nil") - } - data, err := json.Marshal(testType) - if err != nil { - return nil, err - } - name := testType.Name - if name == nil { - return nil, fmt.Errorf("testType.Name must be provided to Apply") - } - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceActionWithOptions(testtypesResource, c.ns, *name, types.ApplyPatchType, data, opts.ToPatchOptions()), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// ApplyStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating ApplyStatus(). -func (c *FakeTestTypes) ApplyStatus(ctx context.Context, testType *example2v1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *v1.TestType, err error) { - if testType == nil { - return nil, fmt.Errorf("testType provided to Apply must not be nil") - } - data, err := json.Marshal(testType) - if err != nil { - return nil, err - } - name := testType.Name - if name == nil { - return nil, fmt.Errorf("testType.Name must be provided to Apply") - } - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceActionWithOptions(testtypesResource, c.ns, *name, types.ApplyPatchType, data, opts.ToPatchOptions(), "status"), emptyResult) - - if obj == nil { - return emptyResult, err +func newFakeTestTypes(fake *FakeSecondExampleV1, namespace string) typedexample2v1.TestTypeInterface { + return &fakeTestTypes{ + gentype.NewFakeClientWithListAndApply[*v1.TestType, *v1.TestTypeList, *example2v1.TestTypeApplyConfiguration]( + fake.Fake, + namespace, + v1.SchemeGroupVersion.WithResource("testtypes"), + v1.SchemeGroupVersion.WithKind("TestType"), + func() *v1.TestType { return &v1.TestType{} }, + func() *v1.TestTypeList { return &v1.TestTypeList{} }, + func(dst, src *v1.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *v1.TestTypeList) []*v1.TestType { return gentype.ToPointerSlice(list.Items) }, + func(list *v1.TestTypeList, items []*v1.TestType) { list.Items = gentype.FromPointerSlice(items) }, + ), + fake, } - return obj.(*v1.TestType), err } diff --git a/examples/crd/clientset/versioned/typed/extensions/v1/fake/fake_extensions_client.go b/examples/crd/clientset/versioned/typed/extensions/v1/fake/fake_extensions_client.go index 2c8de554..5ed70ee1 100644 --- a/examples/crd/clientset/versioned/typed/extensions/v1/fake/fake_extensions_client.go +++ b/examples/crd/clientset/versioned/typed/extensions/v1/fake/fake_extensions_client.go @@ -29,7 +29,7 @@ type FakeExtensionsExampleV1 struct { } func (c *FakeExtensionsExampleV1) TestTypes(namespace string) v1.TestTypeInterface { - return &FakeTestTypes{c, namespace} + return newFakeTestTypes(c, namespace) } // RESTClient returns a RESTClient that is used to communicate diff --git a/examples/crd/clientset/versioned/typed/extensions/v1/fake/fake_testtype.go b/examples/crd/clientset/versioned/typed/extensions/v1/fake/fake_testtype.go index 77dbcf93..0245cbd7 100644 --- a/examples/crd/clientset/versioned/typed/extensions/v1/fake/fake_testtype.go +++ b/examples/crd/clientset/versioned/typed/extensions/v1/fake/fake_testtype.go @@ -24,183 +24,42 @@ import ( fmt "fmt" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" + gentype "k8s.io/client-go/gentype" testing "k8s.io/client-go/testing" v1 "k8s.io/code-generator/examples/crd/apis/extensions/v1" extensionsv1 "k8s.io/code-generator/examples/crd/applyconfiguration/extensions/v1" + typedextensionsv1 "k8s.io/code-generator/examples/crd/clientset/versioned/typed/extensions/v1" ) -// FakeTestTypes implements TestTypeInterface -type FakeTestTypes struct { +// fakeTestTypes implements TestTypeInterface +type fakeTestTypes struct { + *gentype.FakeClientWithListAndApply[*v1.TestType, *v1.TestTypeList, *extensionsv1.TestTypeApplyConfiguration] Fake *FakeExtensionsExampleV1 - ns string } -var testtypesResource = v1.SchemeGroupVersion.WithResource("testtypes") - -var testtypesKind = v1.SchemeGroupVersion.WithKind("TestType") - -// Get takes name of the testType, and returns the corresponding testType object, and an error if there is any. -func (c *FakeTestTypes) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewGetActionWithOptions(testtypesResource, c.ns, name, options), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// List takes label and field selectors, and returns the list of TestTypes that match those selectors. -func (c *FakeTestTypes) List(ctx context.Context, opts metav1.ListOptions) (result *v1.TestTypeList, err error) { - emptyResult := &v1.TestTypeList{} - obj, err := c.Fake. - Invokes(testing.NewListActionWithOptions(testtypesResource, testtypesKind, c.ns, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &v1.TestTypeList{ListMeta: obj.(*v1.TestTypeList).ListMeta} - for _, item := range obj.(*v1.TestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -// Watch returns a watch.Interface that watches the requested testTypes. -func (c *FakeTestTypes) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewWatchActionWithOptions(testtypesResource, c.ns, opts)) - -} - -// Create takes the representation of a testType and creates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *FakeTestTypes) Create(ctx context.Context, testType *v1.TestType, opts metav1.CreateOptions) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewCreateActionWithOptions(testtypesResource, c.ns, testType, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// Update takes the representation of a testType and updates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *FakeTestTypes) Update(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewUpdateActionWithOptions(testtypesResource, c.ns, testType, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *FakeTestTypes) UpdateStatus(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewUpdateSubresourceActionWithOptions(testtypesResource, "status", c.ns, testType, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// Delete takes name of the testType and deletes it. Returns an error if one occurs. -func (c *FakeTestTypes) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewDeleteActionWithOptions(testtypesResource, c.ns, name, opts), &v1.TestType{}) - - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakeTestTypes) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := testing.NewDeleteCollectionActionWithOptions(testtypesResource, c.ns, opts, listOpts) - - _, err := c.Fake.Invokes(action, &v1.TestTypeList{}) - return err -} - -// Patch applies the patch and returns the patched testType. -func (c *FakeTestTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceActionWithOptions(testtypesResource, c.ns, name, pt, data, opts, subresources...), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// Apply takes the given apply declarative configuration, applies it and returns the applied testType. -func (c *FakeTestTypes) Apply(ctx context.Context, testType *extensionsv1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *v1.TestType, err error) { - if testType == nil { - return nil, fmt.Errorf("testType provided to Apply must not be nil") - } - data, err := json.Marshal(testType) - if err != nil { - return nil, err - } - name := testType.Name - if name == nil { - return nil, fmt.Errorf("testType.Name must be provided to Apply") +func newFakeTestTypes(fake *FakeExtensionsExampleV1, namespace string) typedextensionsv1.TestTypeInterface { + return &fakeTestTypes{ + gentype.NewFakeClientWithListAndApply[*v1.TestType, *v1.TestTypeList, *extensionsv1.TestTypeApplyConfiguration]( + fake.Fake, + namespace, + v1.SchemeGroupVersion.WithResource("testtypes"), + v1.SchemeGroupVersion.WithKind("TestType"), + func() *v1.TestType { return &v1.TestType{} }, + func() *v1.TestTypeList { return &v1.TestTypeList{} }, + func(dst, src *v1.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *v1.TestTypeList) []*v1.TestType { return gentype.ToPointerSlice(list.Items) }, + func(list *v1.TestTypeList, items []*v1.TestType) { list.Items = gentype.FromPointerSlice(items) }, + ), + fake, } - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceActionWithOptions(testtypesResource, c.ns, *name, types.ApplyPatchType, data, opts.ToPatchOptions()), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// ApplyStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating ApplyStatus(). -func (c *FakeTestTypes) ApplyStatus(ctx context.Context, testType *extensionsv1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *v1.TestType, err error) { - if testType == nil { - return nil, fmt.Errorf("testType provided to Apply must not be nil") - } - data, err := json.Marshal(testType) - if err != nil { - return nil, err - } - name := testType.Name - if name == nil { - return nil, fmt.Errorf("testType.Name must be provided to Apply") - } - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceActionWithOptions(testtypesResource, c.ns, *name, types.ApplyPatchType, data, opts.ToPatchOptions(), "status"), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err } // GetExtended takes name of the testType, and returns the corresponding testType object, and an error if there is any. -func (c *FakeTestTypes) GetExtended(ctx context.Context, name string, options metav1.GetOptions) (result *v1.TestType, err error) { +func (c *fakeTestTypes) GetExtended(ctx context.Context, name string, options metav1.GetOptions) (result *v1.TestType, err error) { emptyResult := &v1.TestType{} obj, err := c.Fake. - Invokes(testing.NewGetActionWithOptions(testtypesResource, c.ns, name, options), emptyResult) + Invokes(testing.NewGetActionWithOptions(c.Resource(), c.Namespace(), name, options), emptyResult) if obj == nil { return emptyResult, err @@ -209,10 +68,10 @@ func (c *FakeTestTypes) GetExtended(ctx context.Context, name string, options me } // ListExtended takes label and field selectors, and returns the list of TestTypes that match those selectors. -func (c *FakeTestTypes) ListExtended(ctx context.Context, opts metav1.ListOptions) (result *v1.TestTypeList, err error) { +func (c *fakeTestTypes) ListExtended(ctx context.Context, opts metav1.ListOptions) (result *v1.TestTypeList, err error) { emptyResult := &v1.TestTypeList{} obj, err := c.Fake. - Invokes(testing.NewListActionWithOptions(testtypesResource, testtypesKind, c.ns, opts), emptyResult) + Invokes(testing.NewListActionWithOptions(c.Resource(), c.Kind(), c.Namespace(), opts), emptyResult) if obj == nil { return emptyResult, err @@ -221,10 +80,10 @@ func (c *FakeTestTypes) ListExtended(ctx context.Context, opts metav1.ListOption } // CreateExtended takes the representation of a testType and creates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *FakeTestTypes) CreateExtended(ctx context.Context, testType *v1.TestType, opts metav1.CreateOptions) (result *v1.TestType, err error) { +func (c *fakeTestTypes) CreateExtended(ctx context.Context, testType *v1.TestType, opts metav1.CreateOptions) (result *v1.TestType, err error) { emptyResult := &v1.TestType{} obj, err := c.Fake. - Invokes(testing.NewCreateActionWithOptions(testtypesResource, c.ns, testType, opts), emptyResult) + Invokes(testing.NewCreateActionWithOptions(c.Resource(), c.Namespace(), testType, opts), emptyResult) if obj == nil { return emptyResult, err @@ -233,10 +92,10 @@ func (c *FakeTestTypes) CreateExtended(ctx context.Context, testType *v1.TestTyp } // UpdateExtended takes the representation of a testType and updates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *FakeTestTypes) UpdateExtended(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (result *v1.TestType, err error) { +func (c *fakeTestTypes) UpdateExtended(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (result *v1.TestType, err error) { emptyResult := &v1.TestType{} obj, err := c.Fake. - Invokes(testing.NewUpdateActionWithOptions(testtypesResource, c.ns, testType, opts), emptyResult) + Invokes(testing.NewUpdateActionWithOptions(c.Resource(), c.Namespace(), testType, opts), emptyResult) if obj == nil { return emptyResult, err @@ -245,10 +104,10 @@ func (c *FakeTestTypes) UpdateExtended(ctx context.Context, testType *v1.TestTyp } // PatchExtended applies the patch and returns the patched testType. -func (c *FakeTestTypes) PatchExtended(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.TestType, err error) { +func (c *fakeTestTypes) PatchExtended(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.TestType, err error) { emptyResult := &v1.TestType{} obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceActionWithOptions(testtypesResource, c.ns, name, pt, data, opts, subresources...), emptyResult) + Invokes(testing.NewPatchSubresourceActionWithOptions(c.Resource(), c.Namespace(), name, pt, data, opts, subresources...), emptyResult) if obj == nil { return emptyResult, err @@ -257,7 +116,7 @@ func (c *FakeTestTypes) PatchExtended(ctx context.Context, name string, pt types } // ApplyExtended takes the given apply declarative configuration, applies it and returns the applied testType. -func (c *FakeTestTypes) ApplyExtended(ctx context.Context, testType *extensionsv1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *v1.TestType, err error) { +func (c *fakeTestTypes) ApplyExtended(ctx context.Context, testType *extensionsv1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *v1.TestType, err error) { if testType == nil { return nil, fmt.Errorf("testType provided to ApplyExtended must not be nil") } @@ -271,7 +130,7 @@ func (c *FakeTestTypes) ApplyExtended(ctx context.Context, testType *extensionsv } emptyResult := &v1.TestType{} obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceActionWithOptions(testtypesResource, c.ns, *name, types.ApplyPatchType, data, opts.ToPatchOptions()), emptyResult) + Invokes(testing.NewPatchSubresourceActionWithOptions(c.Resource(), c.Namespace(), *name, types.ApplyPatchType, data, opts.ToPatchOptions()), emptyResult) if obj == nil { return emptyResult, err @@ -280,10 +139,10 @@ func (c *FakeTestTypes) ApplyExtended(ctx context.Context, testType *extensionsv } // GetSubresource takes name of the testType, and returns the corresponding testSubresource object, and an error if there is any. -func (c *FakeTestTypes) GetSubresource(ctx context.Context, testTypeName string, options metav1.GetOptions) (result *v1.TestSubresource, err error) { +func (c *fakeTestTypes) GetSubresource(ctx context.Context, testTypeName string, options metav1.GetOptions) (result *v1.TestSubresource, err error) { emptyResult := &v1.TestSubresource{} obj, err := c.Fake. - Invokes(testing.NewGetSubresourceActionWithOptions(testtypesResource, c.ns, "testsubresource", testTypeName, options), emptyResult) + Invokes(testing.NewGetSubresourceActionWithOptions(c.Resource(), c.Namespace(), "testsubresource", testTypeName, options), emptyResult) if obj == nil { return emptyResult, err @@ -292,10 +151,10 @@ func (c *FakeTestTypes) GetSubresource(ctx context.Context, testTypeName string, } // CreateSubresource takes the representation of a testSubresource and creates it. Returns the server's representation of the testSubresource, and an error, if there is any. -func (c *FakeTestTypes) CreateSubresource(ctx context.Context, testTypeName string, testSubresource *v1.TestSubresource, opts metav1.CreateOptions) (result *v1.TestSubresource, err error) { +func (c *fakeTestTypes) CreateSubresource(ctx context.Context, testTypeName string, testSubresource *v1.TestSubresource, opts metav1.CreateOptions) (result *v1.TestSubresource, err error) { emptyResult := &v1.TestSubresource{} obj, err := c.Fake. - Invokes(testing.NewCreateSubresourceActionWithOptions(testtypesResource, testTypeName, "testsubresource", c.ns, testSubresource, opts), emptyResult) + Invokes(testing.NewCreateSubresourceActionWithOptions(c.Resource(), testTypeName, "testsubresource", c.Namespace(), testSubresource, opts), emptyResult) if obj == nil { return emptyResult, err @@ -304,10 +163,10 @@ func (c *FakeTestTypes) CreateSubresource(ctx context.Context, testTypeName stri } // UpdateSubresource takes the representation of a testSubresource and updates it. Returns the server's representation of the testSubresource, and an error, if there is any. -func (c *FakeTestTypes) UpdateSubresource(ctx context.Context, testTypeName string, testSubresource *v1.TestSubresource, opts metav1.UpdateOptions) (result *v1.TestSubresource, err error) { +func (c *fakeTestTypes) UpdateSubresource(ctx context.Context, testTypeName string, testSubresource *v1.TestSubresource, opts metav1.UpdateOptions) (result *v1.TestSubresource, err error) { emptyResult := &v1.TestSubresource{} obj, err := c.Fake. - Invokes(testing.NewUpdateSubresourceActionWithOptions(testtypesResource, "subresource", c.ns, testSubresource, opts), &v1.TestSubresource{}) + Invokes(testing.NewUpdateSubresourceActionWithOptions(c.Resource(), "subresource", c.Namespace(), testSubresource, opts), &v1.TestSubresource{}) if obj == nil { return emptyResult, err @@ -317,7 +176,7 @@ func (c *FakeTestTypes) UpdateSubresource(ctx context.Context, testTypeName stri // ApplySubresource takes top resource name and the apply declarative configuration for subresource, // applies it and returns the applied testSubresource, and an error, if there is any. -func (c *FakeTestTypes) ApplySubresource(ctx context.Context, testTypeName string, testSubresource *extensionsv1.TestSubresourceApplyConfiguration, opts metav1.ApplyOptions) (result *v1.TestSubresource, err error) { +func (c *fakeTestTypes) ApplySubresource(ctx context.Context, testTypeName string, testSubresource *extensionsv1.TestSubresourceApplyConfiguration, opts metav1.ApplyOptions) (result *v1.TestSubresource, err error) { if testSubresource == nil { return nil, fmt.Errorf("testSubresource provided to ApplySubresource must not be nil") } @@ -327,7 +186,7 @@ func (c *FakeTestTypes) ApplySubresource(ctx context.Context, testTypeName strin } emptyResult := &v1.TestSubresource{} obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceActionWithOptions(testtypesResource, c.ns, testTypeName, types.ApplyPatchType, data, opts.ToPatchOptions(), "testSubresource"), emptyResult) + Invokes(testing.NewPatchSubresourceActionWithOptions(c.Resource(), c.Namespace(), testTypeName, types.ApplyPatchType, data, opts.ToPatchOptions(), "testSubresource"), emptyResult) if obj == nil { return emptyResult, err diff --git a/examples/single/clientset/versioned/typed/api/v1/fake/fake_api_client.go b/examples/single/clientset/versioned/typed/api/v1/fake/fake_api_client.go index 905fbe02..e970375a 100644 --- a/examples/single/clientset/versioned/typed/api/v1/fake/fake_api_client.go +++ b/examples/single/clientset/versioned/typed/api/v1/fake/fake_api_client.go @@ -29,11 +29,11 @@ type FakeExampleV1 struct { } func (c *FakeExampleV1) ClusterTestTypes() v1.ClusterTestTypeInterface { - return &FakeClusterTestTypes{c} + return newFakeClusterTestTypes(c) } func (c *FakeExampleV1) TestTypes(namespace string) v1.TestTypeInterface { - return &FakeTestTypes{c, namespace} + return newFakeTestTypes(c, namespace) } // RESTClient returns a RESTClient that is used to communicate diff --git a/examples/single/clientset/versioned/typed/api/v1/fake/fake_clustertesttype.go b/examples/single/clientset/versioned/typed/api/v1/fake/fake_clustertesttype.go index ad9c5e23..c046f8dd 100644 --- a/examples/single/clientset/versioned/typed/api/v1/fake/fake_clustertesttype.go +++ b/examples/single/clientset/versioned/typed/api/v1/fake/fake_clustertesttype.go @@ -20,177 +20,46 @@ package fake import ( context "context" - json "encoding/json" - fmt "fmt" autoscalingv1 "k8s.io/api/autoscaling/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" + gentype "k8s.io/client-go/gentype" testing "k8s.io/client-go/testing" v1 "k8s.io/code-generator/examples/single/api/v1" apiv1 "k8s.io/code-generator/examples/single/applyconfiguration/api/v1" + typedapiv1 "k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1" ) -// FakeClusterTestTypes implements ClusterTestTypeInterface -type FakeClusterTestTypes struct { +// fakeClusterTestTypes implements ClusterTestTypeInterface +type fakeClusterTestTypes struct { + *gentype.FakeClientWithListAndApply[*v1.ClusterTestType, *v1.ClusterTestTypeList, *apiv1.ClusterTestTypeApplyConfiguration] Fake *FakeExampleV1 } -var clustertesttypesResource = v1.SchemeGroupVersion.WithResource("clustertesttypes") - -var clustertesttypesKind = v1.SchemeGroupVersion.WithKind("ClusterTestType") - -// Get takes name of the clusterTestType, and returns the corresponding clusterTestType object, and an error if there is any. -func (c *FakeClusterTestTypes) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.ClusterTestType, err error) { - emptyResult := &v1.ClusterTestType{} - obj, err := c.Fake. - Invokes(testing.NewRootGetActionWithOptions(clustertesttypesResource, name, options), emptyResult) - if obj == nil { - return emptyResult, err - } - return obj.(*v1.ClusterTestType), err -} - -// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors. -func (c *FakeClusterTestTypes) List(ctx context.Context, opts metav1.ListOptions) (result *v1.ClusterTestTypeList, err error) { - emptyResult := &v1.ClusterTestTypeList{} - obj, err := c.Fake. - Invokes(testing.NewRootListActionWithOptions(clustertesttypesResource, clustertesttypesKind, opts), emptyResult) - if obj == nil { - return emptyResult, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &v1.ClusterTestTypeList{ListMeta: obj.(*v1.ClusterTestTypeList).ListMeta} - for _, item := range obj.(*v1.ClusterTestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -// Watch returns a watch.Interface that watches the requested clusterTestTypes. -func (c *FakeClusterTestTypes) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewRootWatchActionWithOptions(clustertesttypesResource, opts)) -} - -// Create takes the representation of a clusterTestType and creates it. Returns the server's representation of the clusterTestType, and an error, if there is any. -func (c *FakeClusterTestTypes) Create(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.CreateOptions) (result *v1.ClusterTestType, err error) { - emptyResult := &v1.ClusterTestType{} - obj, err := c.Fake. - Invokes(testing.NewRootCreateActionWithOptions(clustertesttypesResource, clusterTestType, opts), emptyResult) - if obj == nil { - return emptyResult, err - } - return obj.(*v1.ClusterTestType), err -} - -// Update takes the representation of a clusterTestType and updates it. Returns the server's representation of the clusterTestType, and an error, if there is any. -func (c *FakeClusterTestTypes) Update(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.UpdateOptions) (result *v1.ClusterTestType, err error) { - emptyResult := &v1.ClusterTestType{} - obj, err := c.Fake. - Invokes(testing.NewRootUpdateActionWithOptions(clustertesttypesResource, clusterTestType, opts), emptyResult) - if obj == nil { - return emptyResult, err - } - return obj.(*v1.ClusterTestType), err -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *FakeClusterTestTypes) UpdateStatus(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.UpdateOptions) (result *v1.ClusterTestType, err error) { - emptyResult := &v1.ClusterTestType{} - obj, err := c.Fake. - Invokes(testing.NewRootUpdateSubresourceActionWithOptions(clustertesttypesResource, "status", clusterTestType, opts), emptyResult) - if obj == nil { - return emptyResult, err - } - return obj.(*v1.ClusterTestType), err -} - -// Delete takes name of the clusterTestType and deletes it. Returns an error if one occurs. -func (c *FakeClusterTestTypes) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewRootDeleteActionWithOptions(clustertesttypesResource, name, opts), &v1.ClusterTestType{}) - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakeClusterTestTypes) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := testing.NewRootDeleteCollectionActionWithOptions(clustertesttypesResource, opts, listOpts) - - _, err := c.Fake.Invokes(action, &v1.ClusterTestTypeList{}) - return err -} - -// Patch applies the patch and returns the patched clusterTestType. -func (c *FakeClusterTestTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.ClusterTestType, err error) { - emptyResult := &v1.ClusterTestType{} - obj, err := c.Fake. - Invokes(testing.NewRootPatchSubresourceActionWithOptions(clustertesttypesResource, name, pt, data, opts, subresources...), emptyResult) - if obj == nil { - return emptyResult, err - } - return obj.(*v1.ClusterTestType), err -} - -// Apply takes the given apply declarative configuration, applies it and returns the applied clusterTestType. -func (c *FakeClusterTestTypes) Apply(ctx context.Context, clusterTestType *apiv1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *v1.ClusterTestType, err error) { - if clusterTestType == nil { - return nil, fmt.Errorf("clusterTestType provided to Apply must not be nil") - } - data, err := json.Marshal(clusterTestType) - if err != nil { - return nil, err - } - name := clusterTestType.Name - if name == nil { - return nil, fmt.Errorf("clusterTestType.Name must be provided to Apply") - } - emptyResult := &v1.ClusterTestType{} - obj, err := c.Fake. - Invokes(testing.NewRootPatchSubresourceActionWithOptions(clustertesttypesResource, *name, types.ApplyPatchType, data, opts.ToPatchOptions()), emptyResult) - if obj == nil { - return emptyResult, err - } - return obj.(*v1.ClusterTestType), err -} - -// ApplyStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating ApplyStatus(). -func (c *FakeClusterTestTypes) ApplyStatus(ctx context.Context, clusterTestType *apiv1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *v1.ClusterTestType, err error) { - if clusterTestType == nil { - return nil, fmt.Errorf("clusterTestType provided to Apply must not be nil") - } - data, err := json.Marshal(clusterTestType) - if err != nil { - return nil, err - } - name := clusterTestType.Name - if name == nil { - return nil, fmt.Errorf("clusterTestType.Name must be provided to Apply") - } - emptyResult := &v1.ClusterTestType{} - obj, err := c.Fake. - Invokes(testing.NewRootPatchSubresourceActionWithOptions(clustertesttypesResource, *name, types.ApplyPatchType, data, opts.ToPatchOptions(), "status"), emptyResult) - if obj == nil { - return emptyResult, err +func newFakeClusterTestTypes(fake *FakeExampleV1) typedapiv1.ClusterTestTypeInterface { + return &fakeClusterTestTypes{ + gentype.NewFakeClientWithListAndApply[*v1.ClusterTestType, *v1.ClusterTestTypeList, *apiv1.ClusterTestTypeApplyConfiguration]( + fake.Fake, + "", + v1.SchemeGroupVersion.WithResource("clustertesttypes"), + v1.SchemeGroupVersion.WithKind("ClusterTestType"), + func() *v1.ClusterTestType { return &v1.ClusterTestType{} }, + func() *v1.ClusterTestTypeList { return &v1.ClusterTestTypeList{} }, + func(dst, src *v1.ClusterTestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *v1.ClusterTestTypeList) []*v1.ClusterTestType { return gentype.ToPointerSlice(list.Items) }, + func(list *v1.ClusterTestTypeList, items []*v1.ClusterTestType) { + list.Items = gentype.FromPointerSlice(items) + }, + ), + fake, } - return obj.(*v1.ClusterTestType), err } // GetScale takes name of the clusterTestType, and returns the corresponding scale object, and an error if there is any. -func (c *FakeClusterTestTypes) GetScale(ctx context.Context, clusterTestTypeName string, options metav1.GetOptions) (result *autoscalingv1.Scale, err error) { +func (c *fakeClusterTestTypes) GetScale(ctx context.Context, clusterTestTypeName string, options metav1.GetOptions) (result *autoscalingv1.Scale, err error) { emptyResult := &autoscalingv1.Scale{} obj, err := c.Fake. - Invokes(testing.NewRootGetSubresourceActionWithOptions(clustertesttypesResource, "scale", clusterTestTypeName, options), emptyResult) + Invokes(testing.NewRootGetSubresourceActionWithOptions(c.Resource(), "scale", clusterTestTypeName, options), emptyResult) if obj == nil { return emptyResult, err } @@ -198,10 +67,10 @@ func (c *FakeClusterTestTypes) GetScale(ctx context.Context, clusterTestTypeName } // UpdateScale takes the representation of a scale and updates it. Returns the server's representation of the scale, and an error, if there is any. -func (c *FakeClusterTestTypes) UpdateScale(ctx context.Context, clusterTestTypeName string, scale *autoscalingv1.Scale, opts metav1.UpdateOptions) (result *autoscalingv1.Scale, err error) { +func (c *fakeClusterTestTypes) UpdateScale(ctx context.Context, clusterTestTypeName string, scale *autoscalingv1.Scale, opts metav1.UpdateOptions) (result *autoscalingv1.Scale, err error) { emptyResult := &autoscalingv1.Scale{} obj, err := c.Fake. - Invokes(testing.NewRootUpdateSubresourceActionWithOptions(clustertesttypesResource, "scale", scale, opts), emptyResult) + Invokes(testing.NewRootUpdateSubresourceActionWithOptions(c.Resource(), "scale", scale, opts), emptyResult) if obj == nil { return emptyResult, err } diff --git a/examples/single/clientset/versioned/typed/api/v1/fake/fake_testtype.go b/examples/single/clientset/versioned/typed/api/v1/fake/fake_testtype.go index 2311573d..60bf09f9 100644 --- a/examples/single/clientset/versioned/typed/api/v1/fake/fake_testtype.go +++ b/examples/single/clientset/versioned/typed/api/v1/fake/fake_testtype.go @@ -19,179 +19,31 @@ limitations under the License. package fake import ( - context "context" - json "encoding/json" - fmt "fmt" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - testing "k8s.io/client-go/testing" + gentype "k8s.io/client-go/gentype" v1 "k8s.io/code-generator/examples/single/api/v1" apiv1 "k8s.io/code-generator/examples/single/applyconfiguration/api/v1" + typedapiv1 "k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1" ) -// FakeTestTypes implements TestTypeInterface -type FakeTestTypes struct { +// fakeTestTypes implements TestTypeInterface +type fakeTestTypes struct { + *gentype.FakeClientWithListAndApply[*v1.TestType, *v1.TestTypeList, *apiv1.TestTypeApplyConfiguration] Fake *FakeExampleV1 - ns string -} - -var testtypesResource = v1.SchemeGroupVersion.WithResource("testtypes") - -var testtypesKind = v1.SchemeGroupVersion.WithKind("TestType") - -// Get takes name of the testType, and returns the corresponding testType object, and an error if there is any. -func (c *FakeTestTypes) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewGetActionWithOptions(testtypesResource, c.ns, name, options), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// List takes label and field selectors, and returns the list of TestTypes that match those selectors. -func (c *FakeTestTypes) List(ctx context.Context, opts metav1.ListOptions) (result *v1.TestTypeList, err error) { - emptyResult := &v1.TestTypeList{} - obj, err := c.Fake. - Invokes(testing.NewListActionWithOptions(testtypesResource, testtypesKind, c.ns, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &v1.TestTypeList{ListMeta: obj.(*v1.TestTypeList).ListMeta} - for _, item := range obj.(*v1.TestTypeList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -// Watch returns a watch.Interface that watches the requested testTypes. -func (c *FakeTestTypes) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewWatchActionWithOptions(testtypesResource, c.ns, opts)) - -} - -// Create takes the representation of a testType and creates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *FakeTestTypes) Create(ctx context.Context, testType *v1.TestType, opts metav1.CreateOptions) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewCreateActionWithOptions(testtypesResource, c.ns, testType, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// Update takes the representation of a testType and updates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *FakeTestTypes) Update(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewUpdateActionWithOptions(testtypesResource, c.ns, testType, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err } -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *FakeTestTypes) UpdateStatus(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewUpdateSubresourceActionWithOptions(testtypesResource, "status", c.ns, testType, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// Delete takes name of the testType and deletes it. Returns an error if one occurs. -func (c *FakeTestTypes) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewDeleteActionWithOptions(testtypesResource, c.ns, name, opts), &v1.TestType{}) - - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakeTestTypes) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := testing.NewDeleteCollectionActionWithOptions(testtypesResource, c.ns, opts, listOpts) - - _, err := c.Fake.Invokes(action, &v1.TestTypeList{}) - return err -} - -// Patch applies the patch and returns the patched testType. -func (c *FakeTestTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.TestType, err error) { - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceActionWithOptions(testtypesResource, c.ns, name, pt, data, opts, subresources...), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// Apply takes the given apply declarative configuration, applies it and returns the applied testType. -func (c *FakeTestTypes) Apply(ctx context.Context, testType *apiv1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *v1.TestType, err error) { - if testType == nil { - return nil, fmt.Errorf("testType provided to Apply must not be nil") - } - data, err := json.Marshal(testType) - if err != nil { - return nil, err - } - name := testType.Name - if name == nil { - return nil, fmt.Errorf("testType.Name must be provided to Apply") - } - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceActionWithOptions(testtypesResource, c.ns, *name, types.ApplyPatchType, data, opts.ToPatchOptions()), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1.TestType), err -} - -// ApplyStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating ApplyStatus(). -func (c *FakeTestTypes) ApplyStatus(ctx context.Context, testType *apiv1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *v1.TestType, err error) { - if testType == nil { - return nil, fmt.Errorf("testType provided to Apply must not be nil") - } - data, err := json.Marshal(testType) - if err != nil { - return nil, err - } - name := testType.Name - if name == nil { - return nil, fmt.Errorf("testType.Name must be provided to Apply") - } - emptyResult := &v1.TestType{} - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceActionWithOptions(testtypesResource, c.ns, *name, types.ApplyPatchType, data, opts.ToPatchOptions(), "status"), emptyResult) - - if obj == nil { - return emptyResult, err +func newFakeTestTypes(fake *FakeExampleV1, namespace string) typedapiv1.TestTypeInterface { + return &fakeTestTypes{ + gentype.NewFakeClientWithListAndApply[*v1.TestType, *v1.TestTypeList, *apiv1.TestTypeApplyConfiguration]( + fake.Fake, + namespace, + v1.SchemeGroupVersion.WithResource("testtypes"), + v1.SchemeGroupVersion.WithKind("TestType"), + func() *v1.TestType { return &v1.TestType{} }, + func() *v1.TestTypeList { return &v1.TestTypeList{} }, + func(dst, src *v1.TestTypeList) { dst.ListMeta = src.ListMeta }, + func(list *v1.TestTypeList) []*v1.TestType { return gentype.ToPointerSlice(list.Items) }, + func(list *v1.TestTypeList, items []*v1.TestType) { list.Items = gentype.FromPointerSlice(items) }, + ), + fake, } - return obj.(*v1.TestType), err } diff --git a/go.mod b/go.mod index 6836018d..9b61ae0c 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/google/gofuzz v1.2.0 github.com/spf13/pflag v1.0.5 golang.org/x/text v0.19.0 - k8s.io/apimachinery v0.0.0-20241108022104-96b97de8d6ba + k8s.io/apimachinery v0.0.0-20240920213627-16af2ff33fbf k8s.io/gengo/v2 v2.0.0-20240911193312-2b36238f13e9 k8s.io/klog/v2 v2.130.1 k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f diff --git a/go.sum b/go.sum index ca0b8d73..7bb372c3 100644 --- a/go.sum +++ b/go.sum @@ -124,8 +124,8 @@ gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -k8s.io/apimachinery v0.0.0-20241108022104-96b97de8d6ba h1:ghB5Iygt6Ge8UyIwW7C1kJx4kP7AUTCL9Qg6GCsUUOY= -k8s.io/apimachinery v0.0.0-20241108022104-96b97de8d6ba/go.mod h1:HqhdaJUgQqky29T1V0o2yFkt/pZqLFIDyn9Zi/8rxoY= +k8s.io/apimachinery v0.0.0-20240920213627-16af2ff33fbf h1:ZRwu8YHh3bFbQU4NRvHB6fiovWLBouxY86wIcLd7sBA= +k8s.io/apimachinery v0.0.0-20240920213627-16af2ff33fbf/go.mod h1:HqhdaJUgQqky29T1V0o2yFkt/pZqLFIDyn9Zi/8rxoY= k8s.io/gengo/v2 v2.0.0-20240911193312-2b36238f13e9 h1:si3PfKm8dDYxgfbeA6orqrtLkvvIeH8UqffFJDl0bz4= k8s.io/gengo/v2 v2.0.0-20240911193312-2b36238f13e9/go.mod h1:EJykeLsmFC60UQbYJezXkEsG2FLrt0GPNkU5iK5GWxU= k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=