Generate type fake clients that may opt in to the use of managed fields
This commit is contained in:
@@ -23,6 +23,8 @@ import (
|
||||
"strings"
|
||||
|
||||
openapiv2 "github.com/google/gnostic-models/openapiv2"
|
||||
|
||||
clientgentypes "k8s.io/code-generator/cmd/client-gen/types"
|
||||
"k8s.io/gengo/v2/types"
|
||||
utilproto "k8s.io/kube-openapi/pkg/util/proto"
|
||||
"k8s.io/kube-openapi/pkg/validation/spec"
|
||||
@@ -30,11 +32,7 @@ import (
|
||||
|
||||
type typeModels struct {
|
||||
models utilproto.Models
|
||||
gvkToOpenAPIType map[gvk]string
|
||||
}
|
||||
|
||||
type gvk struct {
|
||||
group, version, kind string
|
||||
gvkToOpenAPIType map[clientgentypes.GroupVersionKind]string
|
||||
}
|
||||
|
||||
func newTypeModels(openAPISchemaFilePath string, pkgTypes map[string]*types.Package) (*typeModels, error) {
|
||||
@@ -56,7 +54,7 @@ func newTypeModels(openAPISchemaFilePath string, pkgTypes map[string]*types.Pack
|
||||
|
||||
// Build a mapping from openAPI type name to GVK.
|
||||
// Find the root types needed by by client-go for apply.
|
||||
gvkToOpenAPIType := map[gvk]string{}
|
||||
gvkToOpenAPIType := map[clientgentypes.GroupVersionKind]string{}
|
||||
rootDefs := map[string]spec.Schema{}
|
||||
for _, p := range pkgTypes {
|
||||
gv := groupVersion(p)
|
||||
@@ -65,11 +63,7 @@ func newTypeModels(openAPISchemaFilePath string, pkgTypes map[string]*types.Pack
|
||||
hasApply := tags.HasVerb("apply") || tags.HasVerb("applyStatus")
|
||||
if tags.GenerateClient && hasApply {
|
||||
openAPIType := friendlyName(typeName(t))
|
||||
gvk := gvk{
|
||||
group: gv.Group.String(),
|
||||
version: gv.Version.String(),
|
||||
kind: t.Name.Name,
|
||||
}
|
||||
gvk := gv.WithKind(clientgentypes.Kind(t.Name.Name))
|
||||
rootDefs[openAPIType] = openAPISchema.Definitions[openAPIType]
|
||||
gvkToOpenAPIType[gvk] = openAPIType
|
||||
}
|
||||
@@ -94,7 +88,7 @@ func newTypeModels(openAPISchemaFilePath string, pkgTypes map[string]*types.Pack
|
||||
|
||||
var emptyModels = &typeModels{
|
||||
models: &utilproto.Definitions{},
|
||||
gvkToOpenAPIType: map[gvk]string{},
|
||||
gvkToOpenAPIType: map[clientgentypes.GroupVersionKind]string{},
|
||||
}
|
||||
|
||||
func toValidatedModels(openAPISchema *spec.Swagger) (utilproto.Models, error) {
|
||||
|
@@ -86,10 +86,14 @@ func GetTargets(context *generator.Context, args *args.Args) []generator.Target
|
||||
klog.V(5).Infof("skipping type %v because does not have ObjectMeta", t)
|
||||
continue
|
||||
}
|
||||
gvk := gv.WithKind(clientgentypes.Kind(t.Name.Name))
|
||||
openAPIName := typeModels.gvkToOpenAPIType[gvk]
|
||||
|
||||
if typePkg, ok := refs[t.Name]; ok {
|
||||
toGenerate = append(toGenerate, applyConfig{
|
||||
Type: t,
|
||||
ApplyConfiguration: types.Ref(typePkg, t.Name.Name+ApplyConfigurationTypeSuffix),
|
||||
OpenAPIName: openAPIName,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -132,7 +136,7 @@ func GetTargets(context *generator.Context, args *args.Args) []generator.Target
|
||||
// generate ForKind() utility function
|
||||
targetList = append(targetList,
|
||||
targetForUtils(args.OutputDir, args.OutputPkg,
|
||||
boilerplate, groupVersions, applyConfigsForGroupVersion, groupGoNames))
|
||||
boilerplate, groupVersions, applyConfigsForGroupVersion, groupGoNames, typeModels))
|
||||
// generate internal embedded schema, required for generated Extract functions
|
||||
targetList = append(targetList,
|
||||
targetForInternal(args.OutputDir, args.OutputPkg,
|
||||
@@ -171,11 +175,7 @@ func targetForApplyConfigurationsPackage(outputDirBase, outputPkgBase, pkgSubdir
|
||||
GeneratorsFunc: func(c *generator.Context) (generators []generator.Generator) {
|
||||
for _, toGenerate := range typesToGenerate {
|
||||
var openAPIType *string
|
||||
gvk := gvk{
|
||||
group: gv.Group.String(),
|
||||
version: gv.Version.String(),
|
||||
kind: toGenerate.Type.Name.Name,
|
||||
}
|
||||
gvk := gv.WithKind(clientgentypes.Kind(toGenerate.Type.Name.Name))
|
||||
if v, ok := models.gvkToOpenAPIType[gvk]; ok {
|
||||
openAPIType = &v
|
||||
}
|
||||
@@ -198,7 +198,8 @@ func targetForApplyConfigurationsPackage(outputDirBase, outputPkgBase, pkgSubdir
|
||||
}
|
||||
}
|
||||
|
||||
func targetForUtils(outputDirBase, outputPkgBase string, boilerplate []byte, groupVersions map[string]clientgentypes.GroupVersions, applyConfigsForGroupVersion map[clientgentypes.GroupVersion][]applyConfig, groupGoNames map[string]string) generator.Target {
|
||||
func targetForUtils(outputDirBase, outputPkgBase string, boilerplate []byte, groupVersions map[string]clientgentypes.GroupVersions,
|
||||
applyConfigsForGroupVersion map[clientgentypes.GroupVersion][]applyConfig, groupGoNames map[string]string, models *typeModels) generator.Target {
|
||||
return &generator.SimpleTarget{
|
||||
PkgName: path.Base(outputPkgBase),
|
||||
PkgPath: outputPkgBase,
|
||||
@@ -214,6 +215,7 @@ func targetForUtils(outputDirBase, outputPkgBase string, boilerplate []byte, gro
|
||||
groupVersions: groupVersions,
|
||||
typesForGroupVersion: applyConfigsForGroupVersion,
|
||||
groupGoNames: groupGoNames,
|
||||
typeModels: models,
|
||||
})
|
||||
return generators
|
||||
},
|
||||
|
@@ -19,15 +19,17 @@ package generators
|
||||
import "k8s.io/gengo/v2/types"
|
||||
|
||||
var (
|
||||
applyConfiguration = types.Ref("k8s.io/apimachinery/pkg/runtime", "ApplyConfiguration")
|
||||
groupVersionKind = types.Ref("k8s.io/apimachinery/pkg/runtime/schema", "GroupVersionKind")
|
||||
typeMeta = types.Ref("k8s.io/apimachinery/pkg/apis/meta/v1", "TypeMeta")
|
||||
objectMeta = types.Ref("k8s.io/apimachinery/pkg/apis/meta/v1", "ObjectMeta")
|
||||
rawExtension = types.Ref("k8s.io/apimachinery/pkg/runtime", "RawExtension")
|
||||
unknown = types.Ref("k8s.io/apimachinery/pkg/runtime", "Unknown")
|
||||
extractInto = types.Ref("k8s.io/apimachinery/pkg/util/managedfields", "ExtractInto")
|
||||
smdNewParser = types.Ref("sigs.k8s.io/structured-merge-diff/v4/typed", "NewParser")
|
||||
smdParser = types.Ref("sigs.k8s.io/structured-merge-diff/v4/typed", "Parser")
|
||||
yamlObject = types.Ref("sigs.k8s.io/structured-merge-diff/v4/typed", "YAMLObject")
|
||||
yamlUnmarshal = types.Ref("gopkg.in/yaml.v2", "Unmarshal")
|
||||
applyConfiguration = types.Ref("k8s.io/apimachinery/pkg/runtime", "ApplyConfiguration")
|
||||
groupVersionKind = types.Ref("k8s.io/apimachinery/pkg/runtime/schema", "GroupVersionKind")
|
||||
typeMeta = types.Ref("k8s.io/apimachinery/pkg/apis/meta/v1", "TypeMeta")
|
||||
objectMeta = types.Ref("k8s.io/apimachinery/pkg/apis/meta/v1", "ObjectMeta")
|
||||
rawExtension = types.Ref("k8s.io/apimachinery/pkg/runtime", "RawExtension")
|
||||
unknown = types.Ref("k8s.io/apimachinery/pkg/runtime", "Unknown")
|
||||
extractInto = types.Ref("k8s.io/apimachinery/pkg/util/managedfields", "ExtractInto")
|
||||
runtimeScheme = types.Ref("k8s.io/apimachinery/pkg/runtime", "Scheme")
|
||||
smdNewParser = types.Ref("sigs.k8s.io/structured-merge-diff/v4/typed", "NewParser")
|
||||
smdParser = types.Ref("sigs.k8s.io/structured-merge-diff/v4/typed", "Parser")
|
||||
testingTypeConverter = types.Ref("k8s.io/client-go/testing", "TypeConverter")
|
||||
yamlObject = types.Ref("sigs.k8s.io/structured-merge-diff/v4/typed", "YAMLObject")
|
||||
yamlUnmarshal = types.Ref("gopkg.in/yaml.v2", "Unmarshal")
|
||||
)
|
||||
|
@@ -18,6 +18,7 @@ package generators
|
||||
|
||||
import (
|
||||
"io"
|
||||
"path"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
@@ -37,6 +38,7 @@ type utilGenerator struct {
|
||||
groupGoNames map[string]string
|
||||
typesForGroupVersion map[clientgentypes.GroupVersion][]applyConfig
|
||||
filtered bool
|
||||
typeModels *typeModels
|
||||
}
|
||||
|
||||
var _ generator.Generator = &utilGenerator{}
|
||||
@@ -92,6 +94,7 @@ func (v versionSort) Swap(i, j int) { v[i], v[j] = v[j], v[i] }
|
||||
type applyConfig struct {
|
||||
Type *types.Type
|
||||
ApplyConfiguration *types.Type
|
||||
OpenAPIName string
|
||||
}
|
||||
|
||||
type applyConfigSort []applyConfig
|
||||
@@ -133,16 +136,26 @@ func (g *utilGenerator) GenerateType(c *generator.Context, _ *types.Type, w io.W
|
||||
sort.Sort(groupSort(groups))
|
||||
|
||||
m := map[string]interface{}{
|
||||
"applyConfiguration": applyConfiguration,
|
||||
"groups": groups,
|
||||
"internalParser": types.Ref(path.Join(g.outputPackage, "internal"), "Parser"),
|
||||
"runtimeScheme": runtimeScheme,
|
||||
"schemeGVs": schemeGVs,
|
||||
"schemaGroupVersionKind": groupVersionKind,
|
||||
"applyConfiguration": applyConfiguration,
|
||||
"testingTypeConverter": testingTypeConverter,
|
||||
}
|
||||
sw.Do(forKindFunc, m)
|
||||
sw.Do(typeConverter, m)
|
||||
|
||||
return sw.Error()
|
||||
}
|
||||
|
||||
var typeConverter = `
|
||||
func NewTypeConverter(scheme *{{.runtimeScheme|raw}}) *{{.testingTypeConverter|raw}} {
|
||||
return &{{.testingTypeConverter|raw}}{Scheme: scheme, TypeResolver: {{.internalParser|raw}}()}
|
||||
}
|
||||
`
|
||||
|
||||
var forKindFunc = `
|
||||
// ForKind returns an apply configuration type for the given GroupVersionKind, or nil if no
|
||||
// apply configuration type exists for the given GroupVersionKind.
|
||||
|
@@ -405,7 +405,7 @@ func GetTargets(context *generator.Context, args *args.Args) []generator.Target
|
||||
targetForScheme(args, clientsetDir, clientsetPkg, groupGoNames, boilerplate))
|
||||
if args.FakeClient {
|
||||
targetList = append(targetList,
|
||||
fake.TargetForClientset(args, clientsetDir, clientsetPkg, groupGoNames, boilerplate))
|
||||
fake.TargetForClientset(args, clientsetDir, clientsetPkg, args.ApplyConfigurationPackage, groupGoNames, boilerplate))
|
||||
}
|
||||
|
||||
// If --clientset-only=true, we don't regenerate the individual typed clients.
|
||||
|
@@ -88,7 +88,7 @@ func TargetForGroup(gv clientgentypes.GroupVersion, typeList []*types.Type, clie
|
||||
}
|
||||
}
|
||||
|
||||
func TargetForClientset(args *args.Args, clientsetDir, clientsetPkg string, groupGoNames map[clientgentypes.GroupVersion]string, boilerplate []byte) generator.Target {
|
||||
func TargetForClientset(args *args.Args, clientsetDir, clientsetPkg string, applyConfigurationPkg string, groupGoNames map[clientgentypes.GroupVersion]string, boilerplate []byte) generator.Target {
|
||||
return &generator.SimpleTarget{
|
||||
// TODO: we'll generate fake clientset for different release in the future.
|
||||
// Package name and path are hard coded for now.
|
||||
@@ -108,11 +108,12 @@ func TargetForClientset(args *args.Args, clientsetDir, clientsetPkg string, grou
|
||||
GoGenerator: generator.GoGenerator{
|
||||
OutputFilename: "clientset_generated.go",
|
||||
},
|
||||
groups: args.Groups,
|
||||
groupGoNames: groupGoNames,
|
||||
fakeClientsetPackage: clientsetPkg,
|
||||
imports: generator.NewImportTracker(),
|
||||
realClientsetPackage: clientsetPkg,
|
||||
groups: args.Groups,
|
||||
groupGoNames: groupGoNames,
|
||||
fakeClientsetPackage: clientsetPkg,
|
||||
imports: generator.NewImportTracker(),
|
||||
realClientsetPackage: clientsetPkg,
|
||||
applyConfigurationPackage: applyConfigurationPkg,
|
||||
},
|
||||
&scheme.GenScheme{
|
||||
GoGenerator: generator.GoGenerator{
|
||||
|
@@ -37,7 +37,8 @@ type genClientset struct {
|
||||
imports namer.ImportTracker
|
||||
clientsetGenerated bool
|
||||
// the import path of the generated real clientset.
|
||||
realClientsetPackage string // must be a Go import-path
|
||||
realClientsetPackage string // must be a Go import-path
|
||||
applyConfigurationPackage string
|
||||
}
|
||||
|
||||
var _ generator.Generator = &genClientset{}
|
||||
@@ -76,12 +77,15 @@ func (g *genClientset) Imports(c *generator.Context) (imports []string) {
|
||||
"fakediscovery \"k8s.io/client-go/discovery/fake\"",
|
||||
"k8s.io/apimachinery/pkg/runtime",
|
||||
"k8s.io/apimachinery/pkg/watch",
|
||||
"k8s.io/apimachinery/pkg/api/meta/testrestmapper",
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (g *genClientset) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
|
||||
generateApply := len(g.applyConfigurationPackage) > 0
|
||||
|
||||
// TODO: We actually don't need any type information to generate the clientset,
|
||||
// perhaps we can adapt the go2ild framework to this kind of usage.
|
||||
sw := generator.NewSnippetWriter(w, c, "$", "$")
|
||||
@@ -89,6 +93,13 @@ func (g *genClientset) GenerateType(c *generator.Context, t *types.Type, w io.Wr
|
||||
allGroups := clientgentypes.ToGroupVersionInfo(g.groups, g.groupGoNames)
|
||||
|
||||
sw.Do(common, nil)
|
||||
|
||||
if generateApply {
|
||||
sw.Do(managedFieldsClientset, map[string]any{
|
||||
"newTypeConverter": types.Ref(g.applyConfigurationPackage, "NewTypeConverter"),
|
||||
})
|
||||
}
|
||||
|
||||
sw.Do(checkImpl, nil)
|
||||
|
||||
for _, group := range allGroups {
|
||||
@@ -107,11 +118,50 @@ func (g *genClientset) GenerateType(c *generator.Context, t *types.Type, w io.Wr
|
||||
}
|
||||
|
||||
// This part of code is version-independent, unchanging.
|
||||
var common = `
|
||||
// NewSimpleClientset returns a clientset that will respond with the provided objects.
|
||||
|
||||
var managedFieldsClientset = `
|
||||
// NewClientset returns a clientset that will respond with the provided objects.
|
||||
// It's backed by a very simple object tracker that processes creates, updates and deletions as-is,
|
||||
// without applying any validations and/or defaults. It shouldn't be considered a replacement
|
||||
// for a real clientset and is mostly useful in simple unit tests.
|
||||
func NewClientset(objects ...runtime.Object) *Clientset {
|
||||
o := testing.NewFieldManagedObjectTracker(
|
||||
scheme,
|
||||
codecs.UniversalDecoder(),
|
||||
$.newTypeConverter|raw$(scheme),
|
||||
)
|
||||
for _, obj := range objects {
|
||||
if err := o.Add(obj); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
cs := &Clientset{tracker: o}
|
||||
cs.discovery = &fakediscovery.FakeDiscovery{Fake: &cs.Fake}
|
||||
cs.AddReactor("*", "*", testing.ObjectReaction(o))
|
||||
cs.AddWatchReactor("*", func(action testing.Action) (handled bool, ret watch.Interface, err error) {
|
||||
gvr := action.GetResource()
|
||||
ns := action.GetNamespace()
|
||||
watch, err := o.Watch(gvr, ns)
|
||||
if err != nil {
|
||||
return false, nil, err
|
||||
}
|
||||
return true, watch, nil
|
||||
})
|
||||
|
||||
return cs
|
||||
}
|
||||
`
|
||||
|
||||
var common = `
|
||||
// NewSimpleClientset returns a clientset that will respond with the provided objects.
|
||||
// It's backed by a very simple object tracker that processes creates, updates and deletions as-is,
|
||||
// without applying any field management, validations and/or defaults. It shouldn't be considered a replacement
|
||||
// for a real clientset and is mostly useful in simple unit tests.
|
||||
//
|
||||
// DEPRECATED: NewClientset replaces this with support for field management, which significantly improves
|
||||
// server side apply testing. NewClientset is only available when apply configurations are generated (e.g.
|
||||
// via --with-applyconfig).
|
||||
func NewSimpleClientset(objects ...runtime.Object) *Clientset {
|
||||
o := testing.NewObjectTracker(scheme, codecs.UniversalDecoder())
|
||||
for _, obj := range objects {
|
||||
|
@@ -23,6 +23,7 @@ import (
|
||||
|
||||
"golang.org/x/text/cases"
|
||||
"golang.org/x/text/language"
|
||||
|
||||
"k8s.io/gengo/v2/generator"
|
||||
"k8s.io/gengo/v2/namer"
|
||||
"k8s.io/gengo/v2/types"
|
||||
@@ -123,33 +124,31 @@ func (g *genFakeForType) GenerateType(c *generator.Context, t *types.Type, w io.
|
||||
"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"}),
|
||||
|
||||
"NewRootListAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootListAction"}),
|
||||
"NewListAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewListAction"}),
|
||||
"NewRootGetAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootGetAction"}),
|
||||
"NewGetAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewGetAction"}),
|
||||
"NewRootDeleteAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootDeleteAction"}),
|
||||
"NewRootDeleteActionWithOptions": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootDeleteActionWithOptions"}),
|
||||
"NewDeleteAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewDeleteAction"}),
|
||||
"NewDeleteActionWithOptions": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewDeleteActionWithOptions"}),
|
||||
"NewRootDeleteCollectionAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootDeleteCollectionAction"}),
|
||||
"NewDeleteCollectionAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewDeleteCollectionAction"}),
|
||||
"NewRootUpdateAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootUpdateAction"}),
|
||||
"NewUpdateAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewUpdateAction"}),
|
||||
"NewRootCreateAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootCreateAction"}),
|
||||
"NewCreateAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewCreateAction"}),
|
||||
"NewRootWatchAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootWatchAction"}),
|
||||
"NewWatchAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewWatchAction"}),
|
||||
"NewCreateSubresourceAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewCreateSubresourceAction"}),
|
||||
"NewRootCreateSubresourceAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootCreateSubresourceAction"}),
|
||||
"NewUpdateSubresourceAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewUpdateSubresourceAction"}),
|
||||
"NewGetSubresourceAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewGetSubresourceAction"}),
|
||||
"NewRootGetSubresourceAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootGetSubresourceAction"}),
|
||||
"NewRootUpdateSubresourceAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootUpdateSubresourceAction"}),
|
||||
"NewRootPatchAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootPatchAction"}),
|
||||
"NewPatchAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewPatchAction"}),
|
||||
"NewRootPatchSubresourceAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootPatchSubresourceAction"}),
|
||||
"NewPatchSubresourceAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewPatchSubresourceAction"}),
|
||||
"ExtractFromListOptions": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "ExtractFromListOptions"}),
|
||||
"NewRootListActionWithOptions": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootListActionWithOptions"}),
|
||||
"NewListActionWithOptions": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewListActionWithOptions"}),
|
||||
"NewRootGetActionWithOptions": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootGetActionWithOptions"}),
|
||||
"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"}),
|
||||
"NewCreateActionWithOptions": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewCreateActionWithOptions"}),
|
||||
"NewRootWatchActionWithOptions": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootWatchActionWithOptions"}),
|
||||
"NewWatchActionWithOptions": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewWatchActionWithOptions"}),
|
||||
"NewCreateSubresourceActionWithOptions": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewCreateSubresourceActionWithOptions"}),
|
||||
"NewRootCreateSubresourceActionWithOptions": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootCreateSubresourceActionWithOptions"}),
|
||||
"NewUpdateSubresourceActionWithOptions": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewUpdateSubresourceActionWithOptions"}),
|
||||
"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"}),
|
||||
}
|
||||
|
||||
generateApply := len(g.applyConfigurationPackage) > 0
|
||||
@@ -336,8 +335,8 @@ var listTemplate = `
|
||||
func (c *Fake$.type|publicPlural$) List(ctx context.Context, opts $.ListOptions|raw$) (result *$.type|raw$List, err error) {
|
||||
emptyResult := &$.type|raw$List{}
|
||||
obj, err := c.Fake.
|
||||
$if .namespaced$Invokes($.NewListAction|raw$($.type|allLowercasePlural$Resource, $.type|allLowercasePlural$Kind, c.ns, opts), emptyResult)
|
||||
$else$Invokes($.NewRootListAction|raw$($.type|allLowercasePlural$Resource, $.type|allLowercasePlural$Kind, opts), emptyResult)$end$
|
||||
$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
|
||||
}
|
||||
@@ -350,8 +349,8 @@ var listUsingOptionsTemplate = `
|
||||
func (c *Fake$.type|publicPlural$) List(ctx context.Context, opts $.ListOptions|raw$) (result *$.type|raw$List, err error) {
|
||||
emptyResult := &$.type|raw$List{}
|
||||
obj, err := c.Fake.
|
||||
$if .namespaced$Invokes($.NewListAction|raw$($.type|allLowercasePlural$Resource, $.type|allLowercasePlural$Kind, c.ns, opts), emptyResult)
|
||||
$else$Invokes($.NewRootListAction|raw$($.type|allLowercasePlural$Resource, $.type|allLowercasePlural$Kind, opts), emptyResult)$end$
|
||||
$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
|
||||
}
|
||||
@@ -375,8 +374,8 @@ var getTemplate = `
|
||||
func (c *Fake$.type|publicPlural$) Get(ctx context.Context, name string, options $.GetOptions|raw$) (result *$.resultType|raw$, err error) {
|
||||
emptyResult := &$.resultType|raw${}
|
||||
obj, err := c.Fake.
|
||||
$if .namespaced$Invokes($.NewGetAction|raw$($.type|allLowercasePlural$Resource, c.ns, name), emptyResult)
|
||||
$else$Invokes($.NewRootGetAction|raw$($.type|allLowercasePlural$Resource, name), emptyResult)$end$
|
||||
$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 obj == nil {
|
||||
return emptyResult, err
|
||||
}
|
||||
@@ -389,8 +388,8 @@ var getSubresourceTemplate = `
|
||||
func (c *Fake$.type|publicPlural$) Get(ctx context.Context, $.type|private$Name string, options $.GetOptions|raw$) (result *$.resultType|raw$, err error) {
|
||||
emptyResult := &$.resultType|raw${}
|
||||
obj, err := c.Fake.
|
||||
$if .namespaced$Invokes($.NewGetSubresourceAction|raw$($.type|allLowercasePlural$Resource, c.ns, "$.subresourcePath$", $.type|private$Name), emptyResult)
|
||||
$else$Invokes($.NewRootGetSubresourceAction|raw$($.type|allLowercasePlural$Resource, "$.subresourcePath$", $.type|private$Name), emptyResult)$end$
|
||||
$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 obj == nil {
|
||||
return emptyResult, err
|
||||
}
|
||||
@@ -411,8 +410,8 @@ func (c *Fake$.type|publicPlural$) Delete(ctx context.Context, name string, opts
|
||||
var deleteCollectionTemplate = `
|
||||
// DeleteCollection deletes a collection of objects.
|
||||
func (c *Fake$.type|publicPlural$) DeleteCollection(ctx context.Context, opts $.DeleteOptions|raw$, listOpts $.ListOptions|raw$) error {
|
||||
$if .namespaced$action := $.NewDeleteCollectionAction|raw$($.type|allLowercasePlural$Resource, c.ns, listOpts)
|
||||
$else$action := $.NewRootDeleteCollectionAction|raw$($.type|allLowercasePlural$Resource, listOpts)
|
||||
$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
|
||||
@@ -423,8 +422,8 @@ var createTemplate = `
|
||||
func (c *Fake$.type|publicPlural$) Create(ctx context.Context, $.inputType|private$ *$.inputType|raw$, opts $.CreateOptions|raw$) (result *$.resultType|raw$, err error) {
|
||||
emptyResult := &$.resultType|raw${}
|
||||
obj, err := c.Fake.
|
||||
$if .namespaced$Invokes($.NewCreateAction|raw$($.inputType|allLowercasePlural$Resource, c.ns, $.inputType|private$), emptyResult)
|
||||
$else$Invokes($.NewRootCreateAction|raw$($.inputType|allLowercasePlural$Resource, $.inputType|private$), emptyResult)$end$
|
||||
$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 obj == nil {
|
||||
return emptyResult, err
|
||||
}
|
||||
@@ -437,8 +436,8 @@ var createSubresourceTemplate = `
|
||||
func (c *Fake$.type|publicPlural$) Create(ctx context.Context, $.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($.NewCreateSubresourceAction|raw$($.type|allLowercasePlural$Resource, $.type|private$Name, "$.subresourcePath$", c.ns, $.inputType|private$), emptyResult)
|
||||
$else$Invokes($.NewRootCreateSubresourceAction|raw$($.type|allLowercasePlural$Resource, $.type|private$Name, "$.subresourcePath$", $.inputType|private$), emptyResult)$end$
|
||||
$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 obj == nil {
|
||||
return emptyResult, err
|
||||
}
|
||||
@@ -451,8 +450,8 @@ var updateTemplate = `
|
||||
func (c *Fake$.type|publicPlural$) Update(ctx context.Context, $.inputType|private$ *$.inputType|raw$, opts $.UpdateOptions|raw$) (result *$.resultType|raw$, err error) {
|
||||
emptyResult := &$.resultType|raw${}
|
||||
obj, err := c.Fake.
|
||||
$if .namespaced$Invokes($.NewUpdateAction|raw$($.inputType|allLowercasePlural$Resource, c.ns, $.inputType|private$), emptyResult)
|
||||
$else$Invokes($.NewRootUpdateAction|raw$($.inputType|allLowercasePlural$Resource, $.inputType|private$), emptyResult)$end$
|
||||
$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 obj == nil {
|
||||
return emptyResult, err
|
||||
}
|
||||
@@ -465,8 +464,8 @@ var updateSubresourceTemplate = `
|
||||
func (c *Fake$.type|publicPlural$) Update(ctx context.Context, $.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($.NewUpdateSubresourceAction|raw$($.type|allLowercasePlural$Resource, "$.subresourcePath$", c.ns, $.inputType|private$), &$.inputType|raw${})
|
||||
$else$Invokes($.NewRootUpdateSubresourceAction|raw$($.type|allLowercasePlural$Resource, "$.subresourcePath$", $.inputType|private$), emptyResult)$end$
|
||||
$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 obj == nil {
|
||||
return emptyResult, err
|
||||
}
|
||||
@@ -480,8 +479,8 @@ var updateStatusTemplate = `
|
||||
func (c *Fake$.type|publicPlural$) UpdateStatus(ctx context.Context, $.type|private$ *$.type|raw$, opts $.UpdateOptions|raw$) (result *$.type|raw$, err error) {
|
||||
emptyResult := &$.type|raw${}
|
||||
obj, err := c.Fake.
|
||||
$if .namespaced$Invokes($.NewUpdateSubresourceAction|raw$($.type|allLowercasePlural$Resource, "status", c.ns, $.type|private$), emptyResult)
|
||||
$else$Invokes($.NewRootUpdateSubresourceAction|raw$($.type|allLowercasePlural$Resource, "status", $.type|private$), emptyResult)$end$
|
||||
$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
|
||||
}
|
||||
@@ -493,8 +492,8 @@ var watchTemplate = `
|
||||
// Watch returns a $.watchInterface|raw$ that watches the requested $.type|privatePlural$.
|
||||
func (c *Fake$.type|publicPlural$) Watch(ctx context.Context, opts $.ListOptions|raw$) ($.watchInterface|raw$, error) {
|
||||
return c.Fake.
|
||||
$if .namespaced$InvokesWatch($.NewWatchAction|raw$($.type|allLowercasePlural$Resource, c.ns, opts))
|
||||
$else$InvokesWatch($.NewRootWatchAction|raw$($.type|allLowercasePlural$Resource, opts))$end$
|
||||
$if .namespaced$InvokesWatch($.NewWatchActionWithOptions|raw$($.type|allLowercasePlural$Resource, c.ns, opts))
|
||||
$else$InvokesWatch($.NewRootWatchActionWithOptions|raw$($.type|allLowercasePlural$Resource, opts))$end$
|
||||
}
|
||||
`
|
||||
|
||||
@@ -503,8 +502,8 @@ var patchTemplate = `
|
||||
func (c *Fake$.type|publicPlural$) Patch(ctx context.Context, 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($.NewPatchSubresourceAction|raw$($.type|allLowercasePlural$Resource, c.ns, name, pt, data, subresources... ), emptyResult)
|
||||
$else$Invokes($.NewRootPatchSubresourceAction|raw$($.type|allLowercasePlural$Resource, name, pt, data, subresources...), emptyResult)$end$
|
||||
$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 obj == nil {
|
||||
return emptyResult, err
|
||||
}
|
||||
@@ -528,8 +527,8 @@ func (c *Fake$.type|publicPlural$) Apply(ctx context.Context, $.inputType|privat
|
||||
}
|
||||
emptyResult := &$.resultType|raw${}
|
||||
obj, err := c.Fake.
|
||||
$if .namespaced$Invokes($.NewPatchSubresourceAction|raw$($.type|allLowercasePlural$Resource, c.ns, *name, $.ApplyPatchType|raw$, data), emptyResult)
|
||||
$else$Invokes($.NewRootPatchSubresourceAction|raw$($.type|allLowercasePlural$Resource, *name, $.ApplyPatchType|raw$, data), emptyResult)$end$
|
||||
$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
|
||||
}
|
||||
@@ -554,8 +553,8 @@ func (c *Fake$.type|publicPlural$) ApplyStatus(ctx context.Context, $.inputType|
|
||||
}
|
||||
emptyResult := &$.resultType|raw${}
|
||||
obj, err := c.Fake.
|
||||
$if .namespaced$Invokes($.NewPatchSubresourceAction|raw$($.type|allLowercasePlural$Resource, c.ns, *name, $.ApplyPatchType|raw$, data, "status"), emptyResult)
|
||||
$else$Invokes($.NewRootPatchSubresourceAction|raw$($.type|allLowercasePlural$Resource, *name, $.ApplyPatchType|raw$, data, "status"), emptyResult)$end$
|
||||
$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 obj == nil {
|
||||
return emptyResult, err
|
||||
}
|
||||
@@ -576,8 +575,8 @@ func (c *Fake$.type|publicPlural$) Apply(ctx context.Context, $.type|private$Nam
|
||||
}
|
||||
emptyResult := &$.resultType|raw${}
|
||||
obj, err := c.Fake.
|
||||
$if .namespaced$Invokes($.NewPatchSubresourceAction|raw$($.type|allLowercasePlural$Resource, c.ns, $.type|private$Name, $.ApplyPatchType|raw$, data, "status"), emptyResult)
|
||||
$else$Invokes($.NewRootPatchSubresourceAction|raw$($.type|allLowercasePlural$Resource, $.type|private$Name, $.ApplyPatchType|raw$, data, "status"), emptyResult)$end$
|
||||
$if .namespaced$Invokes($.NewPatchSubresourceActionWithOptions|raw$($.type|allLowercasePlural$Resource, c.ns, $.type|private$Name, $.ApplyPatchType|raw$, data, opts.ToPatchOptions(), "status"), emptyResult)
|
||||
$else$Invokes($.NewRootPatchSubresourceActionWithOptions|raw$($.type|allLowercasePlural$Resource, $.type|private$Name, $.ApplyPatchType|raw$, data, opts.ToPatchOptions(), "status"), emptyResult)$end$
|
||||
if obj == nil {
|
||||
return emptyResult, err
|
||||
}
|
||||
|
@@ -56,6 +56,8 @@ func (g Group) PackageName() string {
|
||||
return strings.ToLower(parts[0])
|
||||
}
|
||||
|
||||
type Kind string
|
||||
|
||||
type PackageVersion struct {
|
||||
Version
|
||||
// The fully qualified package, e.g. k8s.io/kubernetes/pkg/apis/apps, where the types.go is found.
|
||||
@@ -67,6 +69,12 @@ type GroupVersion struct {
|
||||
Version Version
|
||||
}
|
||||
|
||||
type GroupVersionKind struct {
|
||||
Group Group
|
||||
Version Version
|
||||
Kind Kind
|
||||
}
|
||||
|
||||
func (gv GroupVersion) ToAPIVersion() string {
|
||||
if len(gv.Group) > 0 && gv.Group.NonEmpty() != "core" {
|
||||
return gv.Group.String() + "/" + gv.Version.String()
|
||||
@@ -75,6 +83,10 @@ func (gv GroupVersion) ToAPIVersion() string {
|
||||
}
|
||||
}
|
||||
|
||||
func (gv GroupVersion) WithKind(kind Kind) GroupVersionKind {
|
||||
return GroupVersionKind{Group: gv.Group, Version: gv.Version, Kind: kind}
|
||||
}
|
||||
|
||||
type GroupVersions struct {
|
||||
// The name of the package for this group, e.g. apps.
|
||||
PackageName string
|
||||
|
Reference in New Issue
Block a user