mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Generify fake clientsets
This adds a generic implementation of a fake clientset, and uses it to replace the template code in generated fake clientsets for the default methods. The templates are preserved as-is (or as close as they can be) for use in extensions, whether for resources or subresources. Fake clientsets with no extensions are reduced to their main getter, their specific struct, and their constructor. All method implementations are provided by the generic implementation. The dedicated struct is preserved to allow extensions and expansions to be defined where necessary. Instead of handling the variants (with/without list, apply) with a complex sequence of if statements, build up an index into an array containing the various declarations. Similarly, instead of calling different action constructors for namespaced and non-namespaced clientsets, assume the current behaviour of non-namespaced action creation (equivalent to creating a namespaced action with an empty namespace) and document that assumption in the action implementation. Signed-off-by: Stephen Kitt <skitt@redhat.com>
This commit is contained in:
parent
c25f5eefe4
commit
b0ce65df9b
297
staging/src/k8s.io/client-go/gentype/fake.go
Normal file
297
staging/src/k8s.io/client-go/gentype/fake.go
Normal file
@ -0,0 +1,297 @@
|
||||
/*
|
||||
Copyright 2024 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package gentype
|
||||
|
||||
import (
|
||||
"context"
|
||||
json "encoding/json"
|
||||
"fmt"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
labels "k8s.io/apimachinery/pkg/labels"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
types "k8s.io/apimachinery/pkg/types"
|
||||
watch "k8s.io/apimachinery/pkg/watch"
|
||||
testing "k8s.io/client-go/testing"
|
||||
)
|
||||
|
||||
// FakeClient represents a fake client
|
||||
type FakeClient[T objectWithMeta] struct {
|
||||
*testing.Fake
|
||||
ns string
|
||||
resource schema.GroupVersionResource
|
||||
kind schema.GroupVersionKind
|
||||
newObject func() T
|
||||
}
|
||||
|
||||
// FakeClientWithList represents a fake client with support for lists.
|
||||
type FakeClientWithList[T objectWithMeta, L runtime.Object] struct {
|
||||
*FakeClient[T]
|
||||
alsoFakeLister[T, L]
|
||||
}
|
||||
|
||||
// FakeClientWithApply represents a fake client with support for apply declarative configurations.
|
||||
type FakeClientWithApply[T objectWithMeta, C namedObject] struct {
|
||||
*FakeClient[T]
|
||||
alsoFakeApplier[T, C]
|
||||
}
|
||||
|
||||
// FakeClientWithListAndApply represents a fake client with support for lists and apply declarative configurations.
|
||||
type FakeClientWithListAndApply[T objectWithMeta, L runtime.Object, C namedObject] struct {
|
||||
*FakeClient[T]
|
||||
alsoFakeLister[T, L]
|
||||
alsoFakeApplier[T, C]
|
||||
}
|
||||
|
||||
// Helper types for composition
|
||||
type alsoFakeLister[T objectWithMeta, L runtime.Object] struct {
|
||||
client *FakeClient[T]
|
||||
newList func() L
|
||||
copyListMeta func(L, L)
|
||||
getItems func(L) []T
|
||||
setItems func(L, []T)
|
||||
}
|
||||
|
||||
type alsoFakeApplier[T objectWithMeta, C namedObject] struct {
|
||||
client *FakeClient[T]
|
||||
}
|
||||
|
||||
// NewFakeClient constructs a fake client, namespaced or not, with no support for lists or apply.
|
||||
// Non-namespaced clients are constructed by passing an empty namespace ("").
|
||||
func NewFakeClient[T objectWithMeta](
|
||||
fake *testing.Fake, namespace string, resource schema.GroupVersionResource, kind schema.GroupVersionKind, emptyObjectCreator func() T,
|
||||
) *FakeClient[T] {
|
||||
return &FakeClient[T]{fake, namespace, resource, kind, emptyObjectCreator}
|
||||
}
|
||||
|
||||
// NewFakeClientWithList constructs a namespaced client with support for lists.
|
||||
func NewFakeClientWithList[T runtime.Object, L runtime.Object](
|
||||
fake *testing.Fake, namespace string, resource schema.GroupVersionResource, kind schema.GroupVersionKind, emptyObjectCreator func() T,
|
||||
emptyListCreator func() L, listMetaCopier func(L, L), itemGetter func(L) []T, itemSetter func(L, []T),
|
||||
) *FakeClientWithList[T, L] {
|
||||
fakeClient := NewFakeClient[T](fake, namespace, resource, kind, emptyObjectCreator)
|
||||
return &FakeClientWithList[T, L]{
|
||||
fakeClient,
|
||||
alsoFakeLister[T, L]{fakeClient, emptyListCreator, listMetaCopier, itemGetter, itemSetter},
|
||||
}
|
||||
}
|
||||
|
||||
// NewFakeClientWithApply constructs a namespaced client with support for apply declarative configurations.
|
||||
func NewFakeClientWithApply[T runtime.Object, C namedObject](
|
||||
fake *testing.Fake, namespace string, resource schema.GroupVersionResource, kind schema.GroupVersionKind, emptyObjectCreator func() T,
|
||||
) *FakeClientWithApply[T, C] {
|
||||
fakeClient := NewFakeClient[T](fake, namespace, resource, kind, emptyObjectCreator)
|
||||
return &FakeClientWithApply[T, C]{
|
||||
fakeClient,
|
||||
alsoFakeApplier[T, C]{fakeClient},
|
||||
}
|
||||
}
|
||||
|
||||
// NewFakeClientWithListAndApply constructs a client with support for lists and applying declarative configurations.
|
||||
func NewFakeClientWithListAndApply[T runtime.Object, L runtime.Object, C namedObject](
|
||||
fake *testing.Fake, namespace string, resource schema.GroupVersionResource, kind schema.GroupVersionKind, emptyObjectCreator func() T,
|
||||
emptyListCreator func() L, listMetaCopier func(L, L), itemGetter func(L) []T, itemSetter func(L, []T),
|
||||
) *FakeClientWithListAndApply[T, L, C] {
|
||||
fakeClient := NewFakeClient[T](fake, namespace, resource, kind, emptyObjectCreator)
|
||||
return &FakeClientWithListAndApply[T, L, C]{
|
||||
fakeClient,
|
||||
alsoFakeLister[T, L]{fakeClient, emptyListCreator, listMetaCopier, itemGetter, itemSetter},
|
||||
alsoFakeApplier[T, C]{fakeClient},
|
||||
}
|
||||
}
|
||||
|
||||
// Get takes name of a resource, and returns the corresponding object, and an error if there is any.
|
||||
func (c *FakeClient[T]) Get(ctx context.Context, name string, options metav1.GetOptions) (T, error) {
|
||||
emptyResult := c.newObject()
|
||||
|
||||
obj, err := c.Fake.
|
||||
Invokes(testing.NewGetActionWithOptions(c.resource, c.ns, name, options), emptyResult)
|
||||
if obj == nil {
|
||||
return emptyResult, err
|
||||
}
|
||||
return obj.(T), err
|
||||
}
|
||||
|
||||
func ToPointerSlice[T any](src []T) []*T {
|
||||
if src == nil {
|
||||
return nil
|
||||
}
|
||||
result := make([]*T, len(src))
|
||||
for i := range src {
|
||||
result[i] = &src[i]
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func FromPointerSlice[T any](src []*T) []T {
|
||||
if src == nil {
|
||||
return nil
|
||||
}
|
||||
result := make([]T, len(src))
|
||||
for i := range src {
|
||||
result[i] = *src[i]
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// List takes label and field selectors, and returns the list of ClusterRoles that match those selectors.
|
||||
func (l *alsoFakeLister[T, L]) List(ctx context.Context, opts metav1.ListOptions) (result L, err error) {
|
||||
emptyResult := l.newList()
|
||||
obj, err := l.client.Fake.
|
||||
Invokes(testing.NewListActionWithOptions(l.client.resource, l.client.kind, l.client.ns, opts), emptyResult)
|
||||
if obj == nil {
|
||||
return emptyResult, err
|
||||
}
|
||||
|
||||
label, _, _ := testing.ExtractFromListOptions(opts)
|
||||
if label == nil {
|
||||
label = labels.Everything()
|
||||
}
|
||||
list := l.newList()
|
||||
l.copyListMeta(list, obj.(L))
|
||||
var items []T
|
||||
for _, item := range l.getItems(obj.(L)) {
|
||||
if label.Matches(labels.Set(item.GetLabels())) {
|
||||
items = append(items, item)
|
||||
}
|
||||
}
|
||||
l.setItems(list, items)
|
||||
return list, err
|
||||
}
|
||||
|
||||
// Watch returns a watch.Interface that watches the requested resources.
|
||||
func (c *FakeClient[T]) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {
|
||||
return c.Fake.
|
||||
InvokesWatch(testing.NewWatchActionWithOptions(c.resource, c.ns, opts))
|
||||
}
|
||||
|
||||
// Create takes the representation of a resource and creates it. Returns the server's representation of the resource, and an error, if there is any.
|
||||
func (c *FakeClient[T]) Create(ctx context.Context, resource T, opts metav1.CreateOptions) (result T, err error) {
|
||||
emptyResult := c.newObject()
|
||||
obj, err := c.Fake.
|
||||
Invokes(testing.NewCreateActionWithOptions(c.resource, c.ns, resource, opts), emptyResult)
|
||||
if obj == nil {
|
||||
return emptyResult, err
|
||||
}
|
||||
return obj.(T), err
|
||||
}
|
||||
|
||||
// Update takes the representation of a resource and updates it. Returns the server's representation of the resource, and an error, if there is any.
|
||||
func (c *FakeClient[T]) Update(ctx context.Context, resource T, opts metav1.UpdateOptions) (result T, err error) {
|
||||
emptyResult := c.newObject()
|
||||
obj, err := c.Fake.
|
||||
Invokes(testing.NewUpdateActionWithOptions(c.resource, c.ns, resource, opts), emptyResult)
|
||||
if obj == nil {
|
||||
return emptyResult, err
|
||||
}
|
||||
return obj.(T), err
|
||||
}
|
||||
|
||||
// UpdateStatus updates the resource's status and returns the updated resource.
|
||||
func (c *FakeClient[T]) UpdateStatus(ctx context.Context, resource T, opts metav1.UpdateOptions) (result T, err error) {
|
||||
emptyResult := c.newObject()
|
||||
obj, err := c.Fake.
|
||||
Invokes(testing.NewUpdateSubresourceActionWithOptions(c.resource, "status", c.ns, resource, opts), emptyResult)
|
||||
|
||||
if obj == nil {
|
||||
return emptyResult, err
|
||||
}
|
||||
return obj.(T), err
|
||||
}
|
||||
|
||||
// Delete deletes the resource matching the given name. Returns an error if one occurs.
|
||||
func (c *FakeClient[T]) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error {
|
||||
_, err := c.Fake.
|
||||
Invokes(testing.NewDeleteActionWithOptions(c.resource, c.ns, name, opts), c.newObject())
|
||||
return err
|
||||
}
|
||||
|
||||
// DeleteCollection deletes a collection of objects.
|
||||
func (l *alsoFakeLister[T, L]) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error {
|
||||
_, err := l.client.Fake.
|
||||
Invokes(testing.NewDeleteCollectionActionWithOptions(l.client.resource, l.client.ns, opts, listOpts), l.newList())
|
||||
return err
|
||||
}
|
||||
|
||||
// Patch applies the patch and returns the patched resource.
|
||||
func (c *FakeClient[T]) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result T, err error) {
|
||||
emptyResult := c.newObject()
|
||||
obj, err := c.Fake.
|
||||
Invokes(testing.NewPatchSubresourceActionWithOptions(c.resource, c.ns, name, pt, data, opts, subresources...), emptyResult)
|
||||
if obj == nil {
|
||||
return emptyResult, err
|
||||
}
|
||||
return obj.(T), err
|
||||
}
|
||||
|
||||
// Apply takes the given apply declarative configuration, applies it and returns the applied resource.
|
||||
func (a *alsoFakeApplier[T, C]) Apply(ctx context.Context, configuration C, opts metav1.ApplyOptions) (result T, err error) {
|
||||
if configuration == *new(C) {
|
||||
return *new(T), fmt.Errorf("configuration provided to Apply must not be nil")
|
||||
}
|
||||
data, err := json.Marshal(configuration)
|
||||
if err != nil {
|
||||
return *new(T), err
|
||||
}
|
||||
name := configuration.GetName()
|
||||
if name == nil {
|
||||
return *new(T), fmt.Errorf("configuration.Name must be provided to Apply")
|
||||
}
|
||||
emptyResult := a.client.newObject()
|
||||
obj, err := a.client.Fake.
|
||||
Invokes(testing.NewPatchSubresourceActionWithOptions(a.client.resource, a.client.ns, *name, types.ApplyPatchType, data, opts.ToPatchOptions()), emptyResult)
|
||||
if obj == nil {
|
||||
return emptyResult, err
|
||||
}
|
||||
return obj.(T), err
|
||||
}
|
||||
|
||||
// ApplyStatus applies the given apply declarative configuration to the resource's status and returns the updated resource.
|
||||
func (a *alsoFakeApplier[T, C]) ApplyStatus(ctx context.Context, configuration C, opts metav1.ApplyOptions) (result T, err error) {
|
||||
if configuration == *new(C) {
|
||||
return *new(T), fmt.Errorf("configuration provided to Apply must not be nil")
|
||||
}
|
||||
data, err := json.Marshal(configuration)
|
||||
if err != nil {
|
||||
return *new(T), err
|
||||
}
|
||||
name := configuration.GetName()
|
||||
if name == nil {
|
||||
return *new(T), fmt.Errorf("configuration.Name must be provided to Apply")
|
||||
}
|
||||
emptyResult := a.client.newObject()
|
||||
obj, err := a.client.Fake.
|
||||
Invokes(testing.NewPatchSubresourceActionWithOptions(a.client.resource, a.client.ns, *name, types.ApplyPatchType, data, opts.ToPatchOptions(), "status"), emptyResult)
|
||||
|
||||
if obj == nil {
|
||||
return emptyResult, err
|
||||
}
|
||||
return obj.(T), err
|
||||
}
|
||||
|
||||
func (c *FakeClient[T]) Namespace() string {
|
||||
return c.ns
|
||||
}
|
||||
|
||||
func (c *FakeClient[T]) Kind() schema.GroupVersionKind {
|
||||
return c.kind
|
||||
}
|
||||
|
||||
func (c *FakeClient[T]) Resource() schema.GroupVersionResource {
|
||||
return c.resource
|
||||
}
|
@ -24,9 +24,9 @@ import (
|
||||
core "k8s.io/client-go/testing"
|
||||
)
|
||||
|
||||
func (c *FakeCertificateSigningRequests) UpdateApproval(ctx context.Context, certificateSigningRequest *certificates.CertificateSigningRequest, opts metav1.UpdateOptions) (result *certificates.CertificateSigningRequest, err error) {
|
||||
func (c *fakeCertificateSigningRequests) UpdateApproval(ctx context.Context, certificateSigningRequest *certificates.CertificateSigningRequest, opts metav1.UpdateOptions) (result *certificates.CertificateSigningRequest, err error) {
|
||||
obj, err := c.Fake.
|
||||
Invokes(core.NewRootUpdateSubresourceAction(certificatesigningrequestsResource, "approval", certificateSigningRequest), &certificates.CertificateSigningRequest{})
|
||||
Invokes(core.NewRootUpdateSubresourceAction(c.Resource(), "approval", certificateSigningRequest), &certificates.CertificateSigningRequest{})
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -25,12 +25,12 @@ import (
|
||||
core "k8s.io/client-go/testing"
|
||||
)
|
||||
|
||||
func (c *FakeEvents) CreateWithEventNamespace(event *v1.Event) (*v1.Event, error) {
|
||||
func (c *fakeEvents) CreateWithEventNamespace(event *v1.Event) (*v1.Event, error) {
|
||||
var action core.CreateActionImpl
|
||||
if c.ns != "" {
|
||||
action = core.NewCreateAction(eventsResource, c.ns, event)
|
||||
if c.Namespace() != "" {
|
||||
action = core.NewCreateAction(c.Resource(), c.Namespace(), event)
|
||||
} else {
|
||||
action = core.NewCreateAction(eventsResource, event.GetNamespace(), event)
|
||||
action = core.NewCreateAction(c.Resource(), event.GetNamespace(), event)
|
||||
}
|
||||
obj, err := c.Fake.Invokes(action, event)
|
||||
if obj == nil {
|
||||
@ -41,12 +41,12 @@ func (c *FakeEvents) CreateWithEventNamespace(event *v1.Event) (*v1.Event, error
|
||||
}
|
||||
|
||||
// Update replaces an existing event. Returns the copy of the event the server returns, or an error.
|
||||
func (c *FakeEvents) UpdateWithEventNamespace(event *v1.Event) (*v1.Event, error) {
|
||||
func (c *fakeEvents) UpdateWithEventNamespace(event *v1.Event) (*v1.Event, error) {
|
||||
var action core.UpdateActionImpl
|
||||
if c.ns != "" {
|
||||
action = core.NewUpdateAction(eventsResource, c.ns, event)
|
||||
if c.Namespace() != "" {
|
||||
action = core.NewUpdateAction(c.Resource(), c.Namespace(), event)
|
||||
} else {
|
||||
action = core.NewUpdateAction(eventsResource, event.GetNamespace(), event)
|
||||
action = core.NewUpdateAction(c.Resource(), event.GetNamespace(), event)
|
||||
}
|
||||
obj, err := c.Fake.Invokes(action, event)
|
||||
if obj == nil {
|
||||
@ -58,14 +58,14 @@ func (c *FakeEvents) UpdateWithEventNamespace(event *v1.Event) (*v1.Event, error
|
||||
|
||||
// PatchWithEventNamespace patches an existing event. Returns the copy of the event the server returns, or an error.
|
||||
// TODO: Should take a PatchType as an argument probably.
|
||||
func (c *FakeEvents) PatchWithEventNamespace(event *v1.Event, data []byte) (*v1.Event, error) {
|
||||
func (c *fakeEvents) PatchWithEventNamespace(event *v1.Event, data []byte) (*v1.Event, error) {
|
||||
// TODO: Should be configurable to support additional patch strategies.
|
||||
pt := types.StrategicMergePatchType
|
||||
var action core.PatchActionImpl
|
||||
if c.ns != "" {
|
||||
action = core.NewPatchAction(eventsResource, c.ns, event.Name, pt, data)
|
||||
if c.Namespace() != "" {
|
||||
action = core.NewPatchAction(c.Resource(), c.Namespace(), event.Name, pt, data)
|
||||
} else {
|
||||
action = core.NewPatchAction(eventsResource, event.GetNamespace(), event.Name, pt, data)
|
||||
action = core.NewPatchAction(c.Resource(), event.GetNamespace(), event.Name, pt, data)
|
||||
}
|
||||
obj, err := c.Fake.Invokes(action, event)
|
||||
if obj == nil {
|
||||
@ -76,12 +76,12 @@ func (c *FakeEvents) PatchWithEventNamespace(event *v1.Event, data []byte) (*v1.
|
||||
}
|
||||
|
||||
// Search returns a list of events matching the specified object.
|
||||
func (c *FakeEvents) Search(scheme *runtime.Scheme, objOrRef runtime.Object) (*v1.EventList, error) {
|
||||
func (c *fakeEvents) Search(scheme *runtime.Scheme, objOrRef runtime.Object) (*v1.EventList, error) {
|
||||
var action core.ListActionImpl
|
||||
if c.ns != "" {
|
||||
action = core.NewListAction(eventsResource, eventsKind, c.ns, metav1.ListOptions{})
|
||||
if c.Namespace() != "" {
|
||||
action = core.NewListAction(c.Resource(), c.Kind(), c.Namespace(), metav1.ListOptions{})
|
||||
} else {
|
||||
action = core.NewListAction(eventsResource, eventsKind, v1.NamespaceDefault, metav1.ListOptions{})
|
||||
action = core.NewListAction(c.Resource(), c.Kind(), v1.NamespaceDefault, metav1.ListOptions{})
|
||||
}
|
||||
obj, err := c.Fake.Invokes(action, &v1.EventList{})
|
||||
if obj == nil {
|
||||
@ -91,10 +91,10 @@ func (c *FakeEvents) Search(scheme *runtime.Scheme, objOrRef runtime.Object) (*v
|
||||
return obj.(*v1.EventList), err
|
||||
}
|
||||
|
||||
func (c *FakeEvents) GetFieldSelector(involvedObjectName, involvedObjectNamespace, involvedObjectKind, involvedObjectUID *string) fields.Selector {
|
||||
func (c *fakeEvents) GetFieldSelector(involvedObjectName, involvedObjectNamespace, involvedObjectKind, involvedObjectUID *string) fields.Selector {
|
||||
action := core.GenericActionImpl{}
|
||||
action.Verb = "get-field-selector"
|
||||
action.Resource = eventsResource
|
||||
action.Resource = c.Resource()
|
||||
|
||||
c.Fake.Invokes(action, nil)
|
||||
return fields.Everything()
|
||||
|
@ -19,15 +19,15 @@ package fake
|
||||
import (
|
||||
"context"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
core "k8s.io/client-go/testing"
|
||||
)
|
||||
|
||||
func (c *FakeNamespaces) Finalize(ctx context.Context, namespace *v1.Namespace, opts metav1.UpdateOptions) (*v1.Namespace, error) {
|
||||
func (c *fakeNamespaces) Finalize(ctx context.Context, namespace *v1.Namespace, opts metav1.UpdateOptions) (*v1.Namespace, error) {
|
||||
action := core.CreateActionImpl{}
|
||||
action.Verb = "create"
|
||||
action.Resource = namespacesResource
|
||||
action.Resource = c.Resource()
|
||||
action.Subresource = "finalize"
|
||||
action.Object = namespace
|
||||
|
||||
|
@ -25,11 +25,11 @@ import (
|
||||
)
|
||||
|
||||
// TODO: Should take a PatchType as an argument probably.
|
||||
func (c *FakeNodes) PatchStatus(_ context.Context, nodeName string, data []byte) (*v1.Node, error) {
|
||||
func (c *fakeNodes) PatchStatus(_ context.Context, nodeName string, data []byte) (*v1.Node, error) {
|
||||
// TODO: Should be configurable to support additional patch strategies.
|
||||
pt := types.StrategicMergePatchType
|
||||
obj, err := c.Fake.Invokes(
|
||||
core.NewRootPatchSubresourceAction(nodesResource, nodeName, pt, data, "status"), &v1.Node{})
|
||||
core.NewRootPatchSubresourceAction(c.Resource(), nodeName, pt, data, "status"), &v1.Node{})
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -33,11 +33,11 @@ import (
|
||||
core "k8s.io/client-go/testing"
|
||||
)
|
||||
|
||||
func (c *FakePods) Bind(ctx context.Context, binding *v1.Binding, opts metav1.CreateOptions) error {
|
||||
func (c *fakePods) Bind(ctx context.Context, binding *v1.Binding, opts metav1.CreateOptions) error {
|
||||
action := core.CreateActionImpl{}
|
||||
action.Verb = "create"
|
||||
action.Namespace = binding.Namespace
|
||||
action.Resource = podsResource
|
||||
action.Resource = c.Resource()
|
||||
action.Subresource = "binding"
|
||||
action.Object = binding
|
||||
|
||||
@ -45,9 +45,9 @@ func (c *FakePods) Bind(ctx context.Context, binding *v1.Binding, opts metav1.Cr
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *FakePods) GetBinding(name string) (result *v1.Binding, err error) {
|
||||
func (c *fakePods) GetBinding(name string) (result *v1.Binding, err error) {
|
||||
obj, err := c.Fake.
|
||||
Invokes(core.NewGetSubresourceAction(podsResource, c.ns, "binding", name), &v1.Binding{})
|
||||
Invokes(core.NewGetSubresourceAction(c.Resource(), c.Namespace(), "binding", name), &v1.Binding{})
|
||||
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
@ -55,11 +55,11 @@ func (c *FakePods) GetBinding(name string) (result *v1.Binding, err error) {
|
||||
return obj.(*v1.Binding), err
|
||||
}
|
||||
|
||||
func (c *FakePods) GetLogs(name string, opts *v1.PodLogOptions) *restclient.Request {
|
||||
func (c *fakePods) GetLogs(name string, opts *v1.PodLogOptions) *restclient.Request {
|
||||
action := core.GenericActionImpl{}
|
||||
action.Verb = "get"
|
||||
action.Namespace = c.ns
|
||||
action.Resource = podsResource
|
||||
action.Namespace = c.Namespace()
|
||||
action.Resource = c.Resource()
|
||||
action.Subresource = "log"
|
||||
action.Value = opts
|
||||
|
||||
@ -73,21 +73,21 @@ func (c *FakePods) GetLogs(name string, opts *v1.PodLogOptions) *restclient.Requ
|
||||
return resp, nil
|
||||
}),
|
||||
NegotiatedSerializer: scheme.Codecs.WithoutConversion(),
|
||||
GroupVersion: podsKind.GroupVersion(),
|
||||
VersionedAPIPath: fmt.Sprintf("/api/v1/namespaces/%s/pods/%s/log", c.ns, name),
|
||||
GroupVersion: c.Kind().GroupVersion(),
|
||||
VersionedAPIPath: fmt.Sprintf("/api/v1/namespaces/%s/pods/%s/log", c.Namespace(), name),
|
||||
}
|
||||
return fakeClient.Request()
|
||||
}
|
||||
|
||||
func (c *FakePods) Evict(ctx context.Context, eviction *policyv1beta1.Eviction) error {
|
||||
func (c *fakePods) Evict(ctx context.Context, eviction *policyv1beta1.Eviction) error {
|
||||
return c.EvictV1beta1(ctx, eviction)
|
||||
}
|
||||
|
||||
func (c *FakePods) EvictV1(ctx context.Context, eviction *policyv1.Eviction) error {
|
||||
func (c *fakePods) EvictV1(ctx context.Context, eviction *policyv1.Eviction) error {
|
||||
action := core.CreateActionImpl{}
|
||||
action.Verb = "create"
|
||||
action.Namespace = c.ns
|
||||
action.Resource = podsResource
|
||||
action.Namespace = c.Namespace()
|
||||
action.Resource = c.Resource()
|
||||
action.Subresource = "eviction"
|
||||
action.Object = eviction
|
||||
|
||||
@ -95,11 +95,11 @@ func (c *FakePods) EvictV1(ctx context.Context, eviction *policyv1.Eviction) err
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *FakePods) EvictV1beta1(ctx context.Context, eviction *policyv1beta1.Eviction) error {
|
||||
func (c *fakePods) EvictV1beta1(ctx context.Context, eviction *policyv1beta1.Eviction) error {
|
||||
action := core.CreateActionImpl{}
|
||||
action.Verb = "create"
|
||||
action.Namespace = c.ns
|
||||
action.Resource = podsResource
|
||||
action.Namespace = c.Namespace()
|
||||
action.Resource = c.Resource()
|
||||
action.Subresource = "eviction"
|
||||
action.Object = eviction
|
||||
|
||||
@ -107,6 +107,6 @@ func (c *FakePods) EvictV1beta1(ctx context.Context, eviction *policyv1beta1.Evi
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *FakePods) ProxyGet(scheme, name, port, path string, params map[string]string) restclient.ResponseWrapper {
|
||||
return c.Fake.InvokesProxy(core.NewProxyGetAction(podsResource, c.ns, scheme, name, port, path, params))
|
||||
func (c *fakePods) ProxyGet(scheme, name, port, path string, params map[string]string) restclient.ResponseWrapper {
|
||||
return c.Fake.InvokesProxy(core.NewProxyGetAction(c.Resource(), c.Namespace(), scheme, name, port, path, params))
|
||||
}
|
||||
|
@ -27,10 +27,7 @@ import (
|
||||
)
|
||||
|
||||
func TestFakePodsGetLogs(t *testing.T) {
|
||||
fp := FakePods{
|
||||
Fake: &FakeCoreV1{Fake: &cgtesting.Fake{}},
|
||||
ns: "default",
|
||||
}
|
||||
fp := newFakePods(&FakeCoreV1{Fake: &cgtesting.Fake{}}, "default")
|
||||
req := fp.GetLogs("foo", &corev1.PodLogOptions{})
|
||||
body, err := req.Stream(context.Background())
|
||||
if err != nil {
|
||||
|
@ -21,6 +21,6 @@ import (
|
||||
core "k8s.io/client-go/testing"
|
||||
)
|
||||
|
||||
func (c *FakeServices) ProxyGet(scheme, name, port, path string, params map[string]string) restclient.ResponseWrapper {
|
||||
return c.Fake.InvokesProxy(core.NewProxyGetAction(servicesResource, c.ns, scheme, name, port, path, params))
|
||||
func (c *fakeServices) ProxyGet(scheme, name, port, path string, params map[string]string) restclient.ResponseWrapper {
|
||||
return c.Fake.InvokesProxy(core.NewProxyGetAction(c.Resource(), c.Namespace(), scheme, name, port, path, params))
|
||||
}
|
||||
|
@ -23,10 +23,10 @@ import (
|
||||
)
|
||||
|
||||
// CreateWithEventNamespace creats a new event. Returns the copy of the event the server returns, or an error.
|
||||
func (c *FakeEvents) CreateWithEventNamespace(event *v1beta1.Event) (*v1beta1.Event, error) {
|
||||
action := core.NewRootCreateAction(eventsResource, event)
|
||||
if c.ns != "" {
|
||||
action = core.NewCreateAction(eventsResource, c.ns, event)
|
||||
func (c *fakeEvents) CreateWithEventNamespace(event *v1beta1.Event) (*v1beta1.Event, error) {
|
||||
action := core.NewRootCreateAction(c.Resource(), event)
|
||||
if c.Namespace() != "" {
|
||||
action = core.NewCreateAction(c.Resource(), c.Namespace(), event)
|
||||
}
|
||||
obj, err := c.Fake.Invokes(action, event)
|
||||
if obj == nil {
|
||||
@ -37,10 +37,10 @@ func (c *FakeEvents) CreateWithEventNamespace(event *v1beta1.Event) (*v1beta1.Ev
|
||||
}
|
||||
|
||||
// UpdateWithEventNamespace replaces an existing event. Returns the copy of the event the server returns, or an error.
|
||||
func (c *FakeEvents) UpdateWithEventNamespace(event *v1beta1.Event) (*v1beta1.Event, error) {
|
||||
action := core.NewRootUpdateAction(eventsResource, event)
|
||||
if c.ns != "" {
|
||||
action = core.NewUpdateAction(eventsResource, c.ns, event)
|
||||
func (c *fakeEvents) UpdateWithEventNamespace(event *v1beta1.Event) (*v1beta1.Event, error) {
|
||||
action := core.NewRootUpdateAction(c.Resource(), event)
|
||||
if c.Namespace() != "" {
|
||||
action = core.NewUpdateAction(c.Resource(), c.Namespace(), event)
|
||||
}
|
||||
obj, err := c.Fake.Invokes(action, event)
|
||||
if obj == nil {
|
||||
@ -51,11 +51,11 @@ func (c *FakeEvents) UpdateWithEventNamespace(event *v1beta1.Event) (*v1beta1.Ev
|
||||
}
|
||||
|
||||
// PatchWithEventNamespace patches an existing event. Returns the copy of the event the server returns, or an error.
|
||||
func (c *FakeEvents) PatchWithEventNamespace(event *v1beta1.Event, data []byte) (*v1beta1.Event, error) {
|
||||
func (c *fakeEvents) PatchWithEventNamespace(event *v1beta1.Event, data []byte) (*v1beta1.Event, error) {
|
||||
pt := types.StrategicMergePatchType
|
||||
action := core.NewRootPatchAction(eventsResource, event.Name, pt, data)
|
||||
if c.ns != "" {
|
||||
action = core.NewPatchAction(eventsResource, c.ns, event.Name, pt, data)
|
||||
action := core.NewRootPatchAction(c.Resource(), event.Name, pt, data)
|
||||
if c.Namespace() != "" {
|
||||
action = core.NewPatchAction(c.Resource(), c.Namespace(), event.Name, pt, data)
|
||||
}
|
||||
obj, err := c.Fake.Invokes(action, event)
|
||||
if obj == nil {
|
||||
|
@ -24,10 +24,10 @@ import (
|
||||
core "k8s.io/client-go/testing"
|
||||
)
|
||||
|
||||
func (c *FakeDeployments) Rollback(ctx context.Context, deploymentRollback *v1beta1.DeploymentRollback, opts metav1.CreateOptions) error {
|
||||
func (c *fakeDeployments) Rollback(ctx context.Context, deploymentRollback *v1beta1.DeploymentRollback, opts metav1.CreateOptions) error {
|
||||
action := core.CreateActionImpl{}
|
||||
action.Verb = "create"
|
||||
action.Resource = deploymentsResource
|
||||
action.Resource = c.Resource()
|
||||
action.Subresource = "rollback"
|
||||
action.Object = deploymentRollback
|
||||
|
||||
|
@ -24,10 +24,10 @@ import (
|
||||
core "k8s.io/client-go/testing"
|
||||
)
|
||||
|
||||
func (c *FakeEvictions) Evict(ctx context.Context, eviction *policy.Eviction) error {
|
||||
func (c *fakeEvictions) Evict(ctx context.Context, eviction *policy.Eviction) error {
|
||||
action := core.CreateActionImpl{}
|
||||
action.Verb = "create"
|
||||
action.Namespace = c.ns
|
||||
action.Namespace = c.Namespace()
|
||||
action.Resource = schema.GroupVersionResource{Group: "", Version: "v1", Resource: "pods"}
|
||||
action.Subresource = "eviction"
|
||||
action.Object = eviction
|
||||
|
@ -24,10 +24,10 @@ import (
|
||||
core "k8s.io/client-go/testing"
|
||||
)
|
||||
|
||||
func (c *FakeEvictions) Evict(ctx context.Context, eviction *policy.Eviction) error {
|
||||
func (c *fakeEvictions) Evict(ctx context.Context, eviction *policy.Eviction) error {
|
||||
action := core.CreateActionImpl{}
|
||||
action.Verb = "create"
|
||||
action.Namespace = c.ns
|
||||
action.Namespace = c.Namespace()
|
||||
action.Resource = schema.GroupVersionResource{Group: "", Version: "v1", Resource: "pods"}
|
||||
action.Subresource = "eviction"
|
||||
action.Object = eviction
|
||||
|
@ -29,6 +29,10 @@ import (
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
)
|
||||
|
||||
// All NewRoot... functions return non-namespaced actions, and are equivalent to
|
||||
// calling the corresponding New... function with an empty namespace.
|
||||
// This is assumed by the fake client generator.
|
||||
|
||||
func NewRootGetAction(resource schema.GroupVersionResource, name string) GetActionImpl {
|
||||
return NewRootGetActionWithOptions(resource, name, metav1.GetOptions{})
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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)
|
||||
}
|
||||
`
|
||||
|
||||
|
@ -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 && tags.HasVerb("list") {
|
||||
listableOrAppliable |= withList
|
||||
}
|
||||
|
||||
if !tags.NoVerbs && tags.HasVerb("apply") && generateApply {
|
||||
listableOrAppliable |= withApply
|
||||
}
|
||||
|
||||
sw.Do(structType[listableOrAppliable], m)
|
||||
sw.Do(newStruct[listableOrAppliable], m)
|
||||
|
||||
if tags.NoVerbs {
|
||||
return sw.Error()
|
||||
}
|
||||
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.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)
|
||||
}
|
||||
_, 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,38 +244,133 @@ 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
|
||||
)
|
||||
|
||||
// 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$
|
||||
}
|
||||
`,
|
||||
}
|
||||
`
|
||||
|
||||
// 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$
|
||||
// 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,
|
||||
}
|
||||
}
|
||||
`,
|
||||
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 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) {
|
||||
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
|
||||
}
|
||||
@ -346,38 +378,13 @@ func (c *Fake$.type|publicPlural$) List(ctx $.contextContext|raw$, opts $.ListOp
|
||||
}
|
||||
`
|
||||
|
||||
var listUsingOptionsTemplate = `
|
||||
// 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
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
`
|
||||
|
||||
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,7 +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) {
|
||||
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")
|
||||
}
|
||||
@ -529,34 +511,8 @@ func (c *Fake$.type|publicPlural$) Apply(ctx $.contextContext|raw$, $.inputType|
|
||||
}
|
||||
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) {
|
||||
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(), "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
|
||||
}
|
||||
|
@ -60,6 +60,7 @@ require (
|
||||
github.com/mailru/easyjson v0.7.7 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
|
||||
github.com/x448/float16 v0.8.4 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0 // indirect
|
||||
@ -75,6 +76,7 @@ require (
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240826202546-f6391c0de4c7 // indirect
|
||||
google.golang.org/grpc v1.65.0 // indirect
|
||||
google.golang.org/protobuf v1.35.1 // indirect
|
||||
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
|
||||
gopkg.in/inf.v0 v0.9.1 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
k8s.io/api v0.0.0 // indirect
|
||||
|
2
staging/src/k8s.io/kubelet/go.sum
generated
2
staging/src/k8s.io/kubelet/go.sum
generated
@ -110,6 +110,7 @@ github.com/onsi/ginkgo/v2 v2.21.0 h1:7rg/4f3rB88pb5obDgNZrNHrQ4e6WpjonchcpuBRnZM
|
||||
github.com/onsi/ginkgo/v2 v2.21.0/go.mod h1:7Du3c42kxCUegi0IImZ1wUQzMBVecgIHjR1C+NkhLQo=
|
||||
github.com/onsi/gomega v1.35.1/go.mod h1:PvZbdDc8J6XJEpDK4HCuRBm8a6Fzp9/DmhC9C7yFlog=
|
||||
github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
|
||||
@ -222,6 +223,7 @@ google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojt
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
gopkg.in/evanphx/json-patch.v4 v4.12.0 h1:n6jtcsulIzXPJaxegRbvFNNrZDjbij7ny3gmSPG+6V4=
|
||||
gopkg.in/evanphx/json-patch.v4 v4.12.0/go.mod h1:p8EYWUEYMpynmqDbY58zCKCFZw8pRWMG4EsWvDvM72M=
|
||||
gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
|
||||
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
|
||||
|
Loading…
Reference in New Issue
Block a user