diff --git a/pkg/apis/helm.cattle.io/v1/zz_generated_deepcopy.go b/pkg/apis/helm.cattle.io/v1/zz_generated_deepcopy.go index 8666e4bb..2c4571b8 100644 --- a/pkg/apis/helm.cattle.io/v1/zz_generated_deepcopy.go +++ b/pkg/apis/helm.cattle.io/v1/zz_generated_deepcopy.go @@ -57,7 +57,7 @@ func (in *HelmChart) DeepCopyObject() runtime.Object { func (in *HelmChartList) DeepCopyInto(out *HelmChartList) { *out = *in out.TypeMeta = in.TypeMeta - out.ListMeta = in.ListMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) if in.Items != nil { in, out := &in.Items, &out.Items *out = make([]HelmChart, len(*in)) diff --git a/pkg/apis/helm.cattle.io/v1/zz_generated_register.go b/pkg/apis/helm.cattle.io/v1/zz_generated_register.go index 8d482e4c..0ec8109d 100644 --- a/pkg/apis/helm.cattle.io/v1/zz_generated_register.go +++ b/pkg/apis/helm.cattle.io/v1/zz_generated_register.go @@ -27,6 +27,10 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" ) +var ( + HelmChartResourceName = "helmcharts" +) + // SchemeGroupVersion is group version used to register these objects var SchemeGroupVersion = schema.GroupVersion{Group: helm.GroupName, Version: "v1"} diff --git a/pkg/generated/clientset/versioned/clientset.go b/pkg/generated/clientset/versioned/clientset.go index b081c2bf..a655ad68 100644 --- a/pkg/generated/clientset/versioned/clientset.go +++ b/pkg/generated/clientset/versioned/clientset.go @@ -19,6 +19,8 @@ limitations under the License. package versioned import ( + "fmt" + helmv1 "github.com/rancher/helm-controller/pkg/generated/clientset/versioned/typed/helm.cattle.io/v1" discovery "k8s.io/client-go/discovery" rest "k8s.io/client-go/rest" @@ -51,9 +53,14 @@ func (c *Clientset) Discovery() discovery.DiscoveryInterface { } // NewForConfig creates a new Clientset for the given config. +// If config's RateLimiter is not set and QPS and Burst are acceptable, +// NewForConfig will generate a rate-limiter in configShallowCopy. func NewForConfig(c *rest.Config) (*Clientset, error) { configShallowCopy := *c if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 { + if configShallowCopy.Burst <= 0 { + return nil, fmt.Errorf("Burst is required to be greater than 0 when RateLimiter is not set and QPS is set to greater than 0") + } configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst) } var cs Clientset diff --git a/pkg/generated/clientset/versioned/fake/clientset_generated.go b/pkg/generated/clientset/versioned/fake/clientset_generated.go index 413534ed..5615d177 100644 --- a/pkg/generated/clientset/versioned/fake/clientset_generated.go +++ b/pkg/generated/clientset/versioned/fake/clientset_generated.go @@ -41,7 +41,7 @@ func NewSimpleClientset(objects ...runtime.Object) *Clientset { } } - cs := &Clientset{} + 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) { @@ -63,12 +63,17 @@ func NewSimpleClientset(objects ...runtime.Object) *Clientset { type Clientset struct { testing.Fake discovery *fakediscovery.FakeDiscovery + tracker testing.ObjectTracker } func (c *Clientset) Discovery() discovery.DiscoveryInterface { return c.discovery } +func (c *Clientset) Tracker() testing.ObjectTracker { + return c.tracker +} + var _ clientset.Interface = &Clientset{} // HelmV1 retrieves the HelmV1Client diff --git a/pkg/generated/clientset/versioned/typed/helm.cattle.io/v1/helm.cattle.io_client.go b/pkg/generated/clientset/versioned/typed/helm.cattle.io/v1/helm.cattle.io_client.go index d29d04f4..ecf55d5b 100644 --- a/pkg/generated/clientset/versioned/typed/helm.cattle.io/v1/helm.cattle.io_client.go +++ b/pkg/generated/clientset/versioned/typed/helm.cattle.io/v1/helm.cattle.io_client.go @@ -21,7 +21,6 @@ package v1 import ( v1 "github.com/rancher/helm-controller/pkg/apis/helm.cattle.io/v1" "github.com/rancher/helm-controller/pkg/generated/clientset/versioned/scheme" - serializer "k8s.io/apimachinery/pkg/runtime/serializer" rest "k8s.io/client-go/rest" ) @@ -71,7 +70,7 @@ func setConfigDefaults(config *rest.Config) error { gv := v1.SchemeGroupVersion config.GroupVersion = &gv config.APIPath = "/apis" - config.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: scheme.Codecs} + config.NegotiatedSerializer = scheme.Codecs.WithoutConversion() if config.UserAgent == "" { config.UserAgent = rest.DefaultKubernetesUserAgent() diff --git a/pkg/generated/controllers/helm.cattle.io/factory.go b/pkg/generated/controllers/helm.cattle.io/factory.go index d50b22e9..76d9467a 100644 --- a/pkg/generated/controllers/helm.cattle.io/factory.go +++ b/pkg/generated/controllers/helm.cattle.io/factory.go @@ -84,6 +84,10 @@ func NewFactory(clientset clientset.Interface, informerFactory informers.SharedI } } +func (c *Factory) Controllers() map[schema.GroupVersionKind]*generic.Controller { + return c.controllerManager.Controllers() +} + func (c *Factory) SetThreadiness(gvk schema.GroupVersionKind, threadiness int) { c.threadiness[gvk] = threadiness } diff --git a/pkg/generated/controllers/helm.cattle.io/v1/fakes/zz_generated_helm_chart_mock.go b/pkg/generated/controllers/helm.cattle.io/v1/fakes/zz_generated_helm_chart_mock.go deleted file mode 100644 index 512ce56f..00000000 --- a/pkg/generated/controllers/helm.cattle.io/v1/fakes/zz_generated_helm_chart_mock.go +++ /dev/null @@ -1,1511 +0,0 @@ -// Code generated by moq; DO NOT EDIT. -// github.com/matryer/moq - -package fakes - -import ( - context "context" - sync "sync" - - v1a "github.com/rancher/helm-controller/pkg/apis/helm.cattle.io/v1" - v1 "github.com/rancher/helm-controller/pkg/generated/controllers/helm.cattle.io/v1" - generic "github.com/rancher/wrangler/pkg/generic" - v1b "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" - schema "k8s.io/apimachinery/pkg/runtime/schema" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - cache "k8s.io/client-go/tools/cache" -) - -var ( - lockHelmChartControllerMockAddGenericHandler sync.RWMutex - lockHelmChartControllerMockAddGenericRemoveHandler sync.RWMutex - lockHelmChartControllerMockCache sync.RWMutex - lockHelmChartControllerMockCreate sync.RWMutex - lockHelmChartControllerMockDelete sync.RWMutex - lockHelmChartControllerMockEnqueue sync.RWMutex - lockHelmChartControllerMockGet sync.RWMutex - lockHelmChartControllerMockGroupVersionKind sync.RWMutex - lockHelmChartControllerMockInformer sync.RWMutex - lockHelmChartControllerMockList sync.RWMutex - lockHelmChartControllerMockOnChange sync.RWMutex - lockHelmChartControllerMockOnRemove sync.RWMutex - lockHelmChartControllerMockPatch sync.RWMutex - lockHelmChartControllerMockUpdate sync.RWMutex - lockHelmChartControllerMockUpdateStatus sync.RWMutex - lockHelmChartControllerMockUpdater sync.RWMutex - lockHelmChartControllerMockWatch sync.RWMutex -) - -// Ensure, that HelmChartControllerMock does implement HelmChartController. -// If this is not the case, regenerate this file with moq. -var _ v1.HelmChartController = &HelmChartControllerMock{} - -// HelmChartControllerMock is a mock implementation of HelmChartController. -// -// func TestSomethingThatUsesHelmChartController(t *testing.T) { -// -// // make and configure a mocked HelmChartController -// mockedHelmChartController := &HelmChartControllerMock{ -// AddGenericHandlerFunc: func(ctx context.Context, name string, handler generic.Handler) { -// panic("mock out the AddGenericHandler method") -// }, -// AddGenericRemoveHandlerFunc: func(ctx context.Context, name string, handler generic.Handler) { -// panic("mock out the AddGenericRemoveHandler method") -// }, -// CacheFunc: func() v1.HelmChartCache { -// panic("mock out the Cache method") -// }, -// CreateFunc: func(in1 *v1a.HelmChart) (*v1a.HelmChart, error) { -// panic("mock out the Create method") -// }, -// DeleteFunc: func(namespace string, name string, options *v1b.DeleteOptions) error { -// panic("mock out the Delete method") -// }, -// EnqueueFunc: func(namespace string, name string) { -// panic("mock out the Enqueue method") -// }, -// GetFunc: func(namespace string, name string, options v1b.GetOptions) (*v1a.HelmChart, error) { -// panic("mock out the Get method") -// }, -// GroupVersionKindFunc: func() schema.GroupVersionKind { -// panic("mock out the GroupVersionKind method") -// }, -// InformerFunc: func() cache.SharedIndexInformer { -// panic("mock out the Informer method") -// }, -// ListFunc: func(namespace string, opts v1b.ListOptions) (*v1a.HelmChartList, error) { -// panic("mock out the List method") -// }, -// OnChangeFunc: func(ctx context.Context, name string, sync v1.HelmChartHandler) { -// panic("mock out the OnChange method") -// }, -// OnRemoveFunc: func(ctx context.Context, name string, sync v1.HelmChartHandler) { -// panic("mock out the OnRemove method") -// }, -// PatchFunc: func(namespace string, name string, pt types.PatchType, data []byte, subresources ...string) (*v1a.HelmChart, error) { -// panic("mock out the Patch method") -// }, -// UpdateFunc: func(in1 *v1a.HelmChart) (*v1a.HelmChart, error) { -// panic("mock out the Update method") -// }, -// UpdateStatusFunc: func(in1 *v1a.HelmChart) (*v1a.HelmChart, error) { -// panic("mock out the UpdateStatus method") -// }, -// UpdaterFunc: func() generic.Updater { -// panic("mock out the Updater method") -// }, -// WatchFunc: func(namespace string, opts v1b.ListOptions) (watch.Interface, error) { -// panic("mock out the Watch method") -// }, -// } -// -// // use mockedHelmChartController in code that requires HelmChartController -// // and then make assertions. -// -// } -type HelmChartControllerMock struct { - // AddGenericHandlerFunc mocks the AddGenericHandler method. - AddGenericHandlerFunc func(ctx context.Context, name string, handler generic.Handler) - - // AddGenericRemoveHandlerFunc mocks the AddGenericRemoveHandler method. - AddGenericRemoveHandlerFunc func(ctx context.Context, name string, handler generic.Handler) - - // CacheFunc mocks the Cache method. - CacheFunc func() v1.HelmChartCache - - // CreateFunc mocks the Create method. - CreateFunc func(in1 *v1a.HelmChart) (*v1a.HelmChart, error) - - // DeleteFunc mocks the Delete method. - DeleteFunc func(namespace string, name string, options *v1b.DeleteOptions) error - - // EnqueueFunc mocks the Enqueue method. - EnqueueFunc func(namespace string, name string) - - // GetFunc mocks the Get method. - GetFunc func(namespace string, name string, options v1b.GetOptions) (*v1a.HelmChart, error) - - // GroupVersionKindFunc mocks the GroupVersionKind method. - GroupVersionKindFunc func() schema.GroupVersionKind - - // InformerFunc mocks the Informer method. - InformerFunc func() cache.SharedIndexInformer - - // ListFunc mocks the List method. - ListFunc func(namespace string, opts v1b.ListOptions) (*v1a.HelmChartList, error) - - // OnChangeFunc mocks the OnChange method. - OnChangeFunc func(ctx context.Context, name string, sync v1.HelmChartHandler) - - // OnRemoveFunc mocks the OnRemove method. - OnRemoveFunc func(ctx context.Context, name string, sync v1.HelmChartHandler) - - // PatchFunc mocks the Patch method. - PatchFunc func(namespace string, name string, pt types.PatchType, data []byte, subresources ...string) (*v1a.HelmChart, error) - - // UpdateFunc mocks the Update method. - UpdateFunc func(in1 *v1a.HelmChart) (*v1a.HelmChart, error) - - // UpdateStatusFunc mocks the UpdateStatus method. - UpdateStatusFunc func(in1 *v1a.HelmChart) (*v1a.HelmChart, error) - - // UpdaterFunc mocks the Updater method. - UpdaterFunc func() generic.Updater - - // WatchFunc mocks the Watch method. - WatchFunc func(namespace string, opts v1b.ListOptions) (watch.Interface, error) - - // calls tracks calls to the methods. - calls struct { - // AddGenericHandler holds details about calls to the AddGenericHandler method. - AddGenericHandler []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // Name is the name argument value. - Name string - // Handler is the handler argument value. - Handler generic.Handler - } - // AddGenericRemoveHandler holds details about calls to the AddGenericRemoveHandler method. - AddGenericRemoveHandler []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // Name is the name argument value. - Name string - // Handler is the handler argument value. - Handler generic.Handler - } - // Cache holds details about calls to the Cache method. - Cache []struct { - } - // Create holds details about calls to the Create method. - Create []struct { - // In1 is the in1 argument value. - In1 *v1a.HelmChart - } - // Delete holds details about calls to the Delete method. - Delete []struct { - // Namespace is the namespace argument value. - Namespace string - // Name is the name argument value. - Name string - // Options is the options argument value. - Options *v1b.DeleteOptions - } - // Enqueue holds details about calls to the Enqueue method. - Enqueue []struct { - // Namespace is the namespace argument value. - Namespace string - // Name is the name argument value. - Name string - } - // Get holds details about calls to the Get method. - Get []struct { - // Namespace is the namespace argument value. - Namespace string - // Name is the name argument value. - Name string - // Options is the options argument value. - Options v1b.GetOptions - } - // GroupVersionKind holds details about calls to the GroupVersionKind method. - GroupVersionKind []struct { - } - // Informer holds details about calls to the Informer method. - Informer []struct { - } - // List holds details about calls to the List method. - List []struct { - // Namespace is the namespace argument value. - Namespace string - // Opts is the opts argument value. - Opts v1b.ListOptions - } - // OnChange holds details about calls to the OnChange method. - OnChange []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // Name is the name argument value. - Name string - // Sync is the sync argument value. - Sync v1.HelmChartHandler - } - // OnRemove holds details about calls to the OnRemove method. - OnRemove []struct { - // Ctx is the ctx argument value. - Ctx context.Context - // Name is the name argument value. - Name string - // Sync is the sync argument value. - Sync v1.HelmChartHandler - } - // Patch holds details about calls to the Patch method. - Patch []struct { - // Namespace is the namespace argument value. - Namespace string - // Name is the name argument value. - Name string - // Pt is the pt argument value. - Pt types.PatchType - // Data is the data argument value. - Data []byte - // Subresources is the subresources argument value. - Subresources []string - } - // Update holds details about calls to the Update method. - Update []struct { - // In1 is the in1 argument value. - In1 *v1a.HelmChart - } - // UpdateStatus holds details about calls to the UpdateStatus method. - UpdateStatus []struct { - // In1 is the in1 argument value. - In1 *v1a.HelmChart - } - // Updater holds details about calls to the Updater method. - Updater []struct { - } - // Watch holds details about calls to the Watch method. - Watch []struct { - // Namespace is the namespace argument value. - Namespace string - // Opts is the opts argument value. - Opts v1b.ListOptions - } - } -} - -// AddGenericHandler calls AddGenericHandlerFunc. -func (mock *HelmChartControllerMock) AddGenericHandler(ctx context.Context, name string, handler generic.Handler) { - if mock.AddGenericHandlerFunc == nil { - panic("HelmChartControllerMock.AddGenericHandlerFunc: method is nil but HelmChartController.AddGenericHandler was just called") - } - callInfo := struct { - Ctx context.Context - Name string - Handler generic.Handler - }{ - Ctx: ctx, - Name: name, - Handler: handler, - } - lockHelmChartControllerMockAddGenericHandler.Lock() - mock.calls.AddGenericHandler = append(mock.calls.AddGenericHandler, callInfo) - lockHelmChartControllerMockAddGenericHandler.Unlock() - mock.AddGenericHandlerFunc(ctx, name, handler) -} - -// AddGenericHandlerCalls gets all the calls that were made to AddGenericHandler. -// Check the length with: -// len(mockedHelmChartController.AddGenericHandlerCalls()) -func (mock *HelmChartControllerMock) AddGenericHandlerCalls() []struct { - Ctx context.Context - Name string - Handler generic.Handler -} { - var calls []struct { - Ctx context.Context - Name string - Handler generic.Handler - } - lockHelmChartControllerMockAddGenericHandler.RLock() - calls = mock.calls.AddGenericHandler - lockHelmChartControllerMockAddGenericHandler.RUnlock() - return calls -} - -// AddGenericRemoveHandler calls AddGenericRemoveHandlerFunc. -func (mock *HelmChartControllerMock) AddGenericRemoveHandler(ctx context.Context, name string, handler generic.Handler) { - if mock.AddGenericRemoveHandlerFunc == nil { - panic("HelmChartControllerMock.AddGenericRemoveHandlerFunc: method is nil but HelmChartController.AddGenericRemoveHandler was just called") - } - callInfo := struct { - Ctx context.Context - Name string - Handler generic.Handler - }{ - Ctx: ctx, - Name: name, - Handler: handler, - } - lockHelmChartControllerMockAddGenericRemoveHandler.Lock() - mock.calls.AddGenericRemoveHandler = append(mock.calls.AddGenericRemoveHandler, callInfo) - lockHelmChartControllerMockAddGenericRemoveHandler.Unlock() - mock.AddGenericRemoveHandlerFunc(ctx, name, handler) -} - -// AddGenericRemoveHandlerCalls gets all the calls that were made to AddGenericRemoveHandler. -// Check the length with: -// len(mockedHelmChartController.AddGenericRemoveHandlerCalls()) -func (mock *HelmChartControllerMock) AddGenericRemoveHandlerCalls() []struct { - Ctx context.Context - Name string - Handler generic.Handler -} { - var calls []struct { - Ctx context.Context - Name string - Handler generic.Handler - } - lockHelmChartControllerMockAddGenericRemoveHandler.RLock() - calls = mock.calls.AddGenericRemoveHandler - lockHelmChartControllerMockAddGenericRemoveHandler.RUnlock() - return calls -} - -// Cache calls CacheFunc. -func (mock *HelmChartControllerMock) Cache() v1.HelmChartCache { - if mock.CacheFunc == nil { - panic("HelmChartControllerMock.CacheFunc: method is nil but HelmChartController.Cache was just called") - } - callInfo := struct { - }{} - lockHelmChartControllerMockCache.Lock() - mock.calls.Cache = append(mock.calls.Cache, callInfo) - lockHelmChartControllerMockCache.Unlock() - return mock.CacheFunc() -} - -// CacheCalls gets all the calls that were made to Cache. -// Check the length with: -// len(mockedHelmChartController.CacheCalls()) -func (mock *HelmChartControllerMock) CacheCalls() []struct { -} { - var calls []struct { - } - lockHelmChartControllerMockCache.RLock() - calls = mock.calls.Cache - lockHelmChartControllerMockCache.RUnlock() - return calls -} - -// Create calls CreateFunc. -func (mock *HelmChartControllerMock) Create(in1 *v1a.HelmChart) (*v1a.HelmChart, error) { - if mock.CreateFunc == nil { - panic("HelmChartControllerMock.CreateFunc: method is nil but HelmChartController.Create was just called") - } - callInfo := struct { - In1 *v1a.HelmChart - }{ - In1: in1, - } - lockHelmChartControllerMockCreate.Lock() - mock.calls.Create = append(mock.calls.Create, callInfo) - lockHelmChartControllerMockCreate.Unlock() - return mock.CreateFunc(in1) -} - -// CreateCalls gets all the calls that were made to Create. -// Check the length with: -// len(mockedHelmChartController.CreateCalls()) -func (mock *HelmChartControllerMock) CreateCalls() []struct { - In1 *v1a.HelmChart -} { - var calls []struct { - In1 *v1a.HelmChart - } - lockHelmChartControllerMockCreate.RLock() - calls = mock.calls.Create - lockHelmChartControllerMockCreate.RUnlock() - return calls -} - -// Delete calls DeleteFunc. -func (mock *HelmChartControllerMock) Delete(namespace string, name string, options *v1b.DeleteOptions) error { - if mock.DeleteFunc == nil { - panic("HelmChartControllerMock.DeleteFunc: method is nil but HelmChartController.Delete was just called") - } - callInfo := struct { - Namespace string - Name string - Options *v1b.DeleteOptions - }{ - Namespace: namespace, - Name: name, - Options: options, - } - lockHelmChartControllerMockDelete.Lock() - mock.calls.Delete = append(mock.calls.Delete, callInfo) - lockHelmChartControllerMockDelete.Unlock() - return mock.DeleteFunc(namespace, name, options) -} - -// DeleteCalls gets all the calls that were made to Delete. -// Check the length with: -// len(mockedHelmChartController.DeleteCalls()) -func (mock *HelmChartControllerMock) DeleteCalls() []struct { - Namespace string - Name string - Options *v1b.DeleteOptions -} { - var calls []struct { - Namespace string - Name string - Options *v1b.DeleteOptions - } - lockHelmChartControllerMockDelete.RLock() - calls = mock.calls.Delete - lockHelmChartControllerMockDelete.RUnlock() - return calls -} - -// Enqueue calls EnqueueFunc. -func (mock *HelmChartControllerMock) Enqueue(namespace string, name string) { - if mock.EnqueueFunc == nil { - panic("HelmChartControllerMock.EnqueueFunc: method is nil but HelmChartController.Enqueue was just called") - } - callInfo := struct { - Namespace string - Name string - }{ - Namespace: namespace, - Name: name, - } - lockHelmChartControllerMockEnqueue.Lock() - mock.calls.Enqueue = append(mock.calls.Enqueue, callInfo) - lockHelmChartControllerMockEnqueue.Unlock() - mock.EnqueueFunc(namespace, name) -} - -// EnqueueCalls gets all the calls that were made to Enqueue. -// Check the length with: -// len(mockedHelmChartController.EnqueueCalls()) -func (mock *HelmChartControllerMock) EnqueueCalls() []struct { - Namespace string - Name string -} { - var calls []struct { - Namespace string - Name string - } - lockHelmChartControllerMockEnqueue.RLock() - calls = mock.calls.Enqueue - lockHelmChartControllerMockEnqueue.RUnlock() - return calls -} - -// Get calls GetFunc. -func (mock *HelmChartControllerMock) Get(namespace string, name string, options v1b.GetOptions) (*v1a.HelmChart, error) { - if mock.GetFunc == nil { - panic("HelmChartControllerMock.GetFunc: method is nil but HelmChartController.Get was just called") - } - callInfo := struct { - Namespace string - Name string - Options v1b.GetOptions - }{ - Namespace: namespace, - Name: name, - Options: options, - } - lockHelmChartControllerMockGet.Lock() - mock.calls.Get = append(mock.calls.Get, callInfo) - lockHelmChartControllerMockGet.Unlock() - return mock.GetFunc(namespace, name, options) -} - -// GetCalls gets all the calls that were made to Get. -// Check the length with: -// len(mockedHelmChartController.GetCalls()) -func (mock *HelmChartControllerMock) GetCalls() []struct { - Namespace string - Name string - Options v1b.GetOptions -} { - var calls []struct { - Namespace string - Name string - Options v1b.GetOptions - } - lockHelmChartControllerMockGet.RLock() - calls = mock.calls.Get - lockHelmChartControllerMockGet.RUnlock() - return calls -} - -// GroupVersionKind calls GroupVersionKindFunc. -func (mock *HelmChartControllerMock) GroupVersionKind() schema.GroupVersionKind { - if mock.GroupVersionKindFunc == nil { - panic("HelmChartControllerMock.GroupVersionKindFunc: method is nil but HelmChartController.GroupVersionKind was just called") - } - callInfo := struct { - }{} - lockHelmChartControllerMockGroupVersionKind.Lock() - mock.calls.GroupVersionKind = append(mock.calls.GroupVersionKind, callInfo) - lockHelmChartControllerMockGroupVersionKind.Unlock() - return mock.GroupVersionKindFunc() -} - -// GroupVersionKindCalls gets all the calls that were made to GroupVersionKind. -// Check the length with: -// len(mockedHelmChartController.GroupVersionKindCalls()) -func (mock *HelmChartControllerMock) GroupVersionKindCalls() []struct { -} { - var calls []struct { - } - lockHelmChartControllerMockGroupVersionKind.RLock() - calls = mock.calls.GroupVersionKind - lockHelmChartControllerMockGroupVersionKind.RUnlock() - return calls -} - -// Informer calls InformerFunc. -func (mock *HelmChartControllerMock) Informer() cache.SharedIndexInformer { - if mock.InformerFunc == nil { - panic("HelmChartControllerMock.InformerFunc: method is nil but HelmChartController.Informer was just called") - } - callInfo := struct { - }{} - lockHelmChartControllerMockInformer.Lock() - mock.calls.Informer = append(mock.calls.Informer, callInfo) - lockHelmChartControllerMockInformer.Unlock() - return mock.InformerFunc() -} - -// InformerCalls gets all the calls that were made to Informer. -// Check the length with: -// len(mockedHelmChartController.InformerCalls()) -func (mock *HelmChartControllerMock) InformerCalls() []struct { -} { - var calls []struct { - } - lockHelmChartControllerMockInformer.RLock() - calls = mock.calls.Informer - lockHelmChartControllerMockInformer.RUnlock() - return calls -} - -// List calls ListFunc. -func (mock *HelmChartControllerMock) List(namespace string, opts v1b.ListOptions) (*v1a.HelmChartList, error) { - if mock.ListFunc == nil { - panic("HelmChartControllerMock.ListFunc: method is nil but HelmChartController.List was just called") - } - callInfo := struct { - Namespace string - Opts v1b.ListOptions - }{ - Namespace: namespace, - Opts: opts, - } - lockHelmChartControllerMockList.Lock() - mock.calls.List = append(mock.calls.List, callInfo) - lockHelmChartControllerMockList.Unlock() - return mock.ListFunc(namespace, opts) -} - -// ListCalls gets all the calls that were made to List. -// Check the length with: -// len(mockedHelmChartController.ListCalls()) -func (mock *HelmChartControllerMock) ListCalls() []struct { - Namespace string - Opts v1b.ListOptions -} { - var calls []struct { - Namespace string - Opts v1b.ListOptions - } - lockHelmChartControllerMockList.RLock() - calls = mock.calls.List - lockHelmChartControllerMockList.RUnlock() - return calls -} - -// OnChange calls OnChangeFunc. -func (mock *HelmChartControllerMock) OnChange(ctx context.Context, name string, sync v1.HelmChartHandler) { - if mock.OnChangeFunc == nil { - panic("HelmChartControllerMock.OnChangeFunc: method is nil but HelmChartController.OnChange was just called") - } - callInfo := struct { - Ctx context.Context - Name string - Sync v1.HelmChartHandler - }{ - Ctx: ctx, - Name: name, - Sync: sync, - } - lockHelmChartControllerMockOnChange.Lock() - mock.calls.OnChange = append(mock.calls.OnChange, callInfo) - lockHelmChartControllerMockOnChange.Unlock() - mock.OnChangeFunc(ctx, name, sync) -} - -// OnChangeCalls gets all the calls that were made to OnChange. -// Check the length with: -// len(mockedHelmChartController.OnChangeCalls()) -func (mock *HelmChartControllerMock) OnChangeCalls() []struct { - Ctx context.Context - Name string - Sync v1.HelmChartHandler -} { - var calls []struct { - Ctx context.Context - Name string - Sync v1.HelmChartHandler - } - lockHelmChartControllerMockOnChange.RLock() - calls = mock.calls.OnChange - lockHelmChartControllerMockOnChange.RUnlock() - return calls -} - -// OnRemove calls OnRemoveFunc. -func (mock *HelmChartControllerMock) OnRemove(ctx context.Context, name string, sync v1.HelmChartHandler) { - if mock.OnRemoveFunc == nil { - panic("HelmChartControllerMock.OnRemoveFunc: method is nil but HelmChartController.OnRemove was just called") - } - callInfo := struct { - Ctx context.Context - Name string - Sync v1.HelmChartHandler - }{ - Ctx: ctx, - Name: name, - Sync: sync, - } - lockHelmChartControllerMockOnRemove.Lock() - mock.calls.OnRemove = append(mock.calls.OnRemove, callInfo) - lockHelmChartControllerMockOnRemove.Unlock() - mock.OnRemoveFunc(ctx, name, sync) -} - -// OnRemoveCalls gets all the calls that were made to OnRemove. -// Check the length with: -// len(mockedHelmChartController.OnRemoveCalls()) -func (mock *HelmChartControllerMock) OnRemoveCalls() []struct { - Ctx context.Context - Name string - Sync v1.HelmChartHandler -} { - var calls []struct { - Ctx context.Context - Name string - Sync v1.HelmChartHandler - } - lockHelmChartControllerMockOnRemove.RLock() - calls = mock.calls.OnRemove - lockHelmChartControllerMockOnRemove.RUnlock() - return calls -} - -// Patch calls PatchFunc. -func (mock *HelmChartControllerMock) Patch(namespace string, name string, pt types.PatchType, data []byte, subresources ...string) (*v1a.HelmChart, error) { - if mock.PatchFunc == nil { - panic("HelmChartControllerMock.PatchFunc: method is nil but HelmChartController.Patch was just called") - } - callInfo := struct { - Namespace string - Name string - Pt types.PatchType - Data []byte - Subresources []string - }{ - Namespace: namespace, - Name: name, - Pt: pt, - Data: data, - Subresources: subresources, - } - lockHelmChartControllerMockPatch.Lock() - mock.calls.Patch = append(mock.calls.Patch, callInfo) - lockHelmChartControllerMockPatch.Unlock() - return mock.PatchFunc(namespace, name, pt, data, subresources...) -} - -// PatchCalls gets all the calls that were made to Patch. -// Check the length with: -// len(mockedHelmChartController.PatchCalls()) -func (mock *HelmChartControllerMock) PatchCalls() []struct { - Namespace string - Name string - Pt types.PatchType - Data []byte - Subresources []string -} { - var calls []struct { - Namespace string - Name string - Pt types.PatchType - Data []byte - Subresources []string - } - lockHelmChartControllerMockPatch.RLock() - calls = mock.calls.Patch - lockHelmChartControllerMockPatch.RUnlock() - return calls -} - -// Update calls UpdateFunc. -func (mock *HelmChartControllerMock) Update(in1 *v1a.HelmChart) (*v1a.HelmChart, error) { - if mock.UpdateFunc == nil { - panic("HelmChartControllerMock.UpdateFunc: method is nil but HelmChartController.Update was just called") - } - callInfo := struct { - In1 *v1a.HelmChart - }{ - In1: in1, - } - lockHelmChartControllerMockUpdate.Lock() - mock.calls.Update = append(mock.calls.Update, callInfo) - lockHelmChartControllerMockUpdate.Unlock() - return mock.UpdateFunc(in1) -} - -// UpdateCalls gets all the calls that were made to Update. -// Check the length with: -// len(mockedHelmChartController.UpdateCalls()) -func (mock *HelmChartControllerMock) UpdateCalls() []struct { - In1 *v1a.HelmChart -} { - var calls []struct { - In1 *v1a.HelmChart - } - lockHelmChartControllerMockUpdate.RLock() - calls = mock.calls.Update - lockHelmChartControllerMockUpdate.RUnlock() - return calls -} - -// UpdateStatus calls UpdateStatusFunc. -func (mock *HelmChartControllerMock) UpdateStatus(in1 *v1a.HelmChart) (*v1a.HelmChart, error) { - if mock.UpdateStatusFunc == nil { - panic("HelmChartControllerMock.UpdateStatusFunc: method is nil but HelmChartController.UpdateStatus was just called") - } - callInfo := struct { - In1 *v1a.HelmChart - }{ - In1: in1, - } - lockHelmChartControllerMockUpdateStatus.Lock() - mock.calls.UpdateStatus = append(mock.calls.UpdateStatus, callInfo) - lockHelmChartControllerMockUpdateStatus.Unlock() - return mock.UpdateStatusFunc(in1) -} - -// UpdateStatusCalls gets all the calls that were made to UpdateStatus. -// Check the length with: -// len(mockedHelmChartController.UpdateStatusCalls()) -func (mock *HelmChartControllerMock) UpdateStatusCalls() []struct { - In1 *v1a.HelmChart -} { - var calls []struct { - In1 *v1a.HelmChart - } - lockHelmChartControllerMockUpdateStatus.RLock() - calls = mock.calls.UpdateStatus - lockHelmChartControllerMockUpdateStatus.RUnlock() - return calls -} - -// Updater calls UpdaterFunc. -func (mock *HelmChartControllerMock) Updater() generic.Updater { - if mock.UpdaterFunc == nil { - panic("HelmChartControllerMock.UpdaterFunc: method is nil but HelmChartController.Updater was just called") - } - callInfo := struct { - }{} - lockHelmChartControllerMockUpdater.Lock() - mock.calls.Updater = append(mock.calls.Updater, callInfo) - lockHelmChartControllerMockUpdater.Unlock() - return mock.UpdaterFunc() -} - -// UpdaterCalls gets all the calls that were made to Updater. -// Check the length with: -// len(mockedHelmChartController.UpdaterCalls()) -func (mock *HelmChartControllerMock) UpdaterCalls() []struct { -} { - var calls []struct { - } - lockHelmChartControllerMockUpdater.RLock() - calls = mock.calls.Updater - lockHelmChartControllerMockUpdater.RUnlock() - return calls -} - -// Watch calls WatchFunc. -func (mock *HelmChartControllerMock) Watch(namespace string, opts v1b.ListOptions) (watch.Interface, error) { - if mock.WatchFunc == nil { - panic("HelmChartControllerMock.WatchFunc: method is nil but HelmChartController.Watch was just called") - } - callInfo := struct { - Namespace string - Opts v1b.ListOptions - }{ - Namespace: namespace, - Opts: opts, - } - lockHelmChartControllerMockWatch.Lock() - mock.calls.Watch = append(mock.calls.Watch, callInfo) - lockHelmChartControllerMockWatch.Unlock() - return mock.WatchFunc(namespace, opts) -} - -// WatchCalls gets all the calls that were made to Watch. -// Check the length with: -// len(mockedHelmChartController.WatchCalls()) -func (mock *HelmChartControllerMock) WatchCalls() []struct { - Namespace string - Opts v1b.ListOptions -} { - var calls []struct { - Namespace string - Opts v1b.ListOptions - } - lockHelmChartControllerMockWatch.RLock() - calls = mock.calls.Watch - lockHelmChartControllerMockWatch.RUnlock() - return calls -} - -var ( - lockHelmChartClientMockCreate sync.RWMutex - lockHelmChartClientMockDelete sync.RWMutex - lockHelmChartClientMockGet sync.RWMutex - lockHelmChartClientMockList sync.RWMutex - lockHelmChartClientMockPatch sync.RWMutex - lockHelmChartClientMockUpdate sync.RWMutex - lockHelmChartClientMockUpdateStatus sync.RWMutex - lockHelmChartClientMockWatch sync.RWMutex -) - -// Ensure, that HelmChartClientMock does implement HelmChartClient. -// If this is not the case, regenerate this file with moq. -var _ v1.HelmChartClient = &HelmChartClientMock{} - -// HelmChartClientMock is a mock implementation of HelmChartClient. -// -// func TestSomethingThatUsesHelmChartClient(t *testing.T) { -// -// // make and configure a mocked HelmChartClient -// mockedHelmChartClient := &HelmChartClientMock{ -// CreateFunc: func(in1 *v1a.HelmChart) (*v1a.HelmChart, error) { -// panic("mock out the Create method") -// }, -// DeleteFunc: func(namespace string, name string, options *v1b.DeleteOptions) error { -// panic("mock out the Delete method") -// }, -// GetFunc: func(namespace string, name string, options v1b.GetOptions) (*v1a.HelmChart, error) { -// panic("mock out the Get method") -// }, -// ListFunc: func(namespace string, opts v1b.ListOptions) (*v1a.HelmChartList, error) { -// panic("mock out the List method") -// }, -// PatchFunc: func(namespace string, name string, pt types.PatchType, data []byte, subresources ...string) (*v1a.HelmChart, error) { -// panic("mock out the Patch method") -// }, -// UpdateFunc: func(in1 *v1a.HelmChart) (*v1a.HelmChart, error) { -// panic("mock out the Update method") -// }, -// UpdateStatusFunc: func(in1 *v1a.HelmChart) (*v1a.HelmChart, error) { -// panic("mock out the UpdateStatus method") -// }, -// WatchFunc: func(namespace string, opts v1b.ListOptions) (watch.Interface, error) { -// panic("mock out the Watch method") -// }, -// } -// -// // use mockedHelmChartClient in code that requires HelmChartClient -// // and then make assertions. -// -// } -type HelmChartClientMock struct { - // CreateFunc mocks the Create method. - CreateFunc func(in1 *v1a.HelmChart) (*v1a.HelmChart, error) - - // DeleteFunc mocks the Delete method. - DeleteFunc func(namespace string, name string, options *v1b.DeleteOptions) error - - // GetFunc mocks the Get method. - GetFunc func(namespace string, name string, options v1b.GetOptions) (*v1a.HelmChart, error) - - // ListFunc mocks the List method. - ListFunc func(namespace string, opts v1b.ListOptions) (*v1a.HelmChartList, error) - - // PatchFunc mocks the Patch method. - PatchFunc func(namespace string, name string, pt types.PatchType, data []byte, subresources ...string) (*v1a.HelmChart, error) - - // UpdateFunc mocks the Update method. - UpdateFunc func(in1 *v1a.HelmChart) (*v1a.HelmChart, error) - - // UpdateStatusFunc mocks the UpdateStatus method. - UpdateStatusFunc func(in1 *v1a.HelmChart) (*v1a.HelmChart, error) - - // WatchFunc mocks the Watch method. - WatchFunc func(namespace string, opts v1b.ListOptions) (watch.Interface, error) - - // calls tracks calls to the methods. - calls struct { - // Create holds details about calls to the Create method. - Create []struct { - // In1 is the in1 argument value. - In1 *v1a.HelmChart - } - // Delete holds details about calls to the Delete method. - Delete []struct { - // Namespace is the namespace argument value. - Namespace string - // Name is the name argument value. - Name string - // Options is the options argument value. - Options *v1b.DeleteOptions - } - // Get holds details about calls to the Get method. - Get []struct { - // Namespace is the namespace argument value. - Namespace string - // Name is the name argument value. - Name string - // Options is the options argument value. - Options v1b.GetOptions - } - // List holds details about calls to the List method. - List []struct { - // Namespace is the namespace argument value. - Namespace string - // Opts is the opts argument value. - Opts v1b.ListOptions - } - // Patch holds details about calls to the Patch method. - Patch []struct { - // Namespace is the namespace argument value. - Namespace string - // Name is the name argument value. - Name string - // Pt is the pt argument value. - Pt types.PatchType - // Data is the data argument value. - Data []byte - // Subresources is the subresources argument value. - Subresources []string - } - // Update holds details about calls to the Update method. - Update []struct { - // In1 is the in1 argument value. - In1 *v1a.HelmChart - } - // UpdateStatus holds details about calls to the UpdateStatus method. - UpdateStatus []struct { - // In1 is the in1 argument value. - In1 *v1a.HelmChart - } - // Watch holds details about calls to the Watch method. - Watch []struct { - // Namespace is the namespace argument value. - Namespace string - // Opts is the opts argument value. - Opts v1b.ListOptions - } - } -} - -// Create calls CreateFunc. -func (mock *HelmChartClientMock) Create(in1 *v1a.HelmChart) (*v1a.HelmChart, error) { - if mock.CreateFunc == nil { - panic("HelmChartClientMock.CreateFunc: method is nil but HelmChartClient.Create was just called") - } - callInfo := struct { - In1 *v1a.HelmChart - }{ - In1: in1, - } - lockHelmChartClientMockCreate.Lock() - mock.calls.Create = append(mock.calls.Create, callInfo) - lockHelmChartClientMockCreate.Unlock() - return mock.CreateFunc(in1) -} - -// CreateCalls gets all the calls that were made to Create. -// Check the length with: -// len(mockedHelmChartClient.CreateCalls()) -func (mock *HelmChartClientMock) CreateCalls() []struct { - In1 *v1a.HelmChart -} { - var calls []struct { - In1 *v1a.HelmChart - } - lockHelmChartClientMockCreate.RLock() - calls = mock.calls.Create - lockHelmChartClientMockCreate.RUnlock() - return calls -} - -// Delete calls DeleteFunc. -func (mock *HelmChartClientMock) Delete(namespace string, name string, options *v1b.DeleteOptions) error { - if mock.DeleteFunc == nil { - panic("HelmChartClientMock.DeleteFunc: method is nil but HelmChartClient.Delete was just called") - } - callInfo := struct { - Namespace string - Name string - Options *v1b.DeleteOptions - }{ - Namespace: namespace, - Name: name, - Options: options, - } - lockHelmChartClientMockDelete.Lock() - mock.calls.Delete = append(mock.calls.Delete, callInfo) - lockHelmChartClientMockDelete.Unlock() - return mock.DeleteFunc(namespace, name, options) -} - -// DeleteCalls gets all the calls that were made to Delete. -// Check the length with: -// len(mockedHelmChartClient.DeleteCalls()) -func (mock *HelmChartClientMock) DeleteCalls() []struct { - Namespace string - Name string - Options *v1b.DeleteOptions -} { - var calls []struct { - Namespace string - Name string - Options *v1b.DeleteOptions - } - lockHelmChartClientMockDelete.RLock() - calls = mock.calls.Delete - lockHelmChartClientMockDelete.RUnlock() - return calls -} - -// Get calls GetFunc. -func (mock *HelmChartClientMock) Get(namespace string, name string, options v1b.GetOptions) (*v1a.HelmChart, error) { - if mock.GetFunc == nil { - panic("HelmChartClientMock.GetFunc: method is nil but HelmChartClient.Get was just called") - } - callInfo := struct { - Namespace string - Name string - Options v1b.GetOptions - }{ - Namespace: namespace, - Name: name, - Options: options, - } - lockHelmChartClientMockGet.Lock() - mock.calls.Get = append(mock.calls.Get, callInfo) - lockHelmChartClientMockGet.Unlock() - return mock.GetFunc(namespace, name, options) -} - -// GetCalls gets all the calls that were made to Get. -// Check the length with: -// len(mockedHelmChartClient.GetCalls()) -func (mock *HelmChartClientMock) GetCalls() []struct { - Namespace string - Name string - Options v1b.GetOptions -} { - var calls []struct { - Namespace string - Name string - Options v1b.GetOptions - } - lockHelmChartClientMockGet.RLock() - calls = mock.calls.Get - lockHelmChartClientMockGet.RUnlock() - return calls -} - -// List calls ListFunc. -func (mock *HelmChartClientMock) List(namespace string, opts v1b.ListOptions) (*v1a.HelmChartList, error) { - if mock.ListFunc == nil { - panic("HelmChartClientMock.ListFunc: method is nil but HelmChartClient.List was just called") - } - callInfo := struct { - Namespace string - Opts v1b.ListOptions - }{ - Namespace: namespace, - Opts: opts, - } - lockHelmChartClientMockList.Lock() - mock.calls.List = append(mock.calls.List, callInfo) - lockHelmChartClientMockList.Unlock() - return mock.ListFunc(namespace, opts) -} - -// ListCalls gets all the calls that were made to List. -// Check the length with: -// len(mockedHelmChartClient.ListCalls()) -func (mock *HelmChartClientMock) ListCalls() []struct { - Namespace string - Opts v1b.ListOptions -} { - var calls []struct { - Namespace string - Opts v1b.ListOptions - } - lockHelmChartClientMockList.RLock() - calls = mock.calls.List - lockHelmChartClientMockList.RUnlock() - return calls -} - -// Patch calls PatchFunc. -func (mock *HelmChartClientMock) Patch(namespace string, name string, pt types.PatchType, data []byte, subresources ...string) (*v1a.HelmChart, error) { - if mock.PatchFunc == nil { - panic("HelmChartClientMock.PatchFunc: method is nil but HelmChartClient.Patch was just called") - } - callInfo := struct { - Namespace string - Name string - Pt types.PatchType - Data []byte - Subresources []string - }{ - Namespace: namespace, - Name: name, - Pt: pt, - Data: data, - Subresources: subresources, - } - lockHelmChartClientMockPatch.Lock() - mock.calls.Patch = append(mock.calls.Patch, callInfo) - lockHelmChartClientMockPatch.Unlock() - return mock.PatchFunc(namespace, name, pt, data, subresources...) -} - -// PatchCalls gets all the calls that were made to Patch. -// Check the length with: -// len(mockedHelmChartClient.PatchCalls()) -func (mock *HelmChartClientMock) PatchCalls() []struct { - Namespace string - Name string - Pt types.PatchType - Data []byte - Subresources []string -} { - var calls []struct { - Namespace string - Name string - Pt types.PatchType - Data []byte - Subresources []string - } - lockHelmChartClientMockPatch.RLock() - calls = mock.calls.Patch - lockHelmChartClientMockPatch.RUnlock() - return calls -} - -// Update calls UpdateFunc. -func (mock *HelmChartClientMock) Update(in1 *v1a.HelmChart) (*v1a.HelmChart, error) { - if mock.UpdateFunc == nil { - panic("HelmChartClientMock.UpdateFunc: method is nil but HelmChartClient.Update was just called") - } - callInfo := struct { - In1 *v1a.HelmChart - }{ - In1: in1, - } - lockHelmChartClientMockUpdate.Lock() - mock.calls.Update = append(mock.calls.Update, callInfo) - lockHelmChartClientMockUpdate.Unlock() - return mock.UpdateFunc(in1) -} - -// UpdateCalls gets all the calls that were made to Update. -// Check the length with: -// len(mockedHelmChartClient.UpdateCalls()) -func (mock *HelmChartClientMock) UpdateCalls() []struct { - In1 *v1a.HelmChart -} { - var calls []struct { - In1 *v1a.HelmChart - } - lockHelmChartClientMockUpdate.RLock() - calls = mock.calls.Update - lockHelmChartClientMockUpdate.RUnlock() - return calls -} - -// UpdateStatus calls UpdateStatusFunc. -func (mock *HelmChartClientMock) UpdateStatus(in1 *v1a.HelmChart) (*v1a.HelmChart, error) { - if mock.UpdateStatusFunc == nil { - panic("HelmChartClientMock.UpdateStatusFunc: method is nil but HelmChartClient.UpdateStatus was just called") - } - callInfo := struct { - In1 *v1a.HelmChart - }{ - In1: in1, - } - lockHelmChartClientMockUpdateStatus.Lock() - mock.calls.UpdateStatus = append(mock.calls.UpdateStatus, callInfo) - lockHelmChartClientMockUpdateStatus.Unlock() - return mock.UpdateStatusFunc(in1) -} - -// UpdateStatusCalls gets all the calls that were made to UpdateStatus. -// Check the length with: -// len(mockedHelmChartClient.UpdateStatusCalls()) -func (mock *HelmChartClientMock) UpdateStatusCalls() []struct { - In1 *v1a.HelmChart -} { - var calls []struct { - In1 *v1a.HelmChart - } - lockHelmChartClientMockUpdateStatus.RLock() - calls = mock.calls.UpdateStatus - lockHelmChartClientMockUpdateStatus.RUnlock() - return calls -} - -// Watch calls WatchFunc. -func (mock *HelmChartClientMock) Watch(namespace string, opts v1b.ListOptions) (watch.Interface, error) { - if mock.WatchFunc == nil { - panic("HelmChartClientMock.WatchFunc: method is nil but HelmChartClient.Watch was just called") - } - callInfo := struct { - Namespace string - Opts v1b.ListOptions - }{ - Namespace: namespace, - Opts: opts, - } - lockHelmChartClientMockWatch.Lock() - mock.calls.Watch = append(mock.calls.Watch, callInfo) - lockHelmChartClientMockWatch.Unlock() - return mock.WatchFunc(namespace, opts) -} - -// WatchCalls gets all the calls that were made to Watch. -// Check the length with: -// len(mockedHelmChartClient.WatchCalls()) -func (mock *HelmChartClientMock) WatchCalls() []struct { - Namespace string - Opts v1b.ListOptions -} { - var calls []struct { - Namespace string - Opts v1b.ListOptions - } - lockHelmChartClientMockWatch.RLock() - calls = mock.calls.Watch - lockHelmChartClientMockWatch.RUnlock() - return calls -} - -var ( - lockHelmChartCacheMockAddIndexer sync.RWMutex - lockHelmChartCacheMockGet sync.RWMutex - lockHelmChartCacheMockGetByIndex sync.RWMutex - lockHelmChartCacheMockList sync.RWMutex -) - -// Ensure, that HelmChartCacheMock does implement HelmChartCache. -// If this is not the case, regenerate this file with moq. -var _ v1.HelmChartCache = &HelmChartCacheMock{} - -// HelmChartCacheMock is a mock implementation of HelmChartCache. -// -// func TestSomethingThatUsesHelmChartCache(t *testing.T) { -// -// // make and configure a mocked HelmChartCache -// mockedHelmChartCache := &HelmChartCacheMock{ -// AddIndexerFunc: func(indexName string, indexer v1.HelmChartIndexer) { -// panic("mock out the AddIndexer method") -// }, -// GetFunc: func(namespace string, name string) (*v1a.HelmChart, error) { -// panic("mock out the Get method") -// }, -// GetByIndexFunc: func(indexName string, key string) ([]*v1a.HelmChart, error) { -// panic("mock out the GetByIndex method") -// }, -// ListFunc: func(namespace string, selector labels.Selector) ([]*v1a.HelmChart, error) { -// panic("mock out the List method") -// }, -// } -// -// // use mockedHelmChartCache in code that requires HelmChartCache -// // and then make assertions. -// -// } -type HelmChartCacheMock struct { - // AddIndexerFunc mocks the AddIndexer method. - AddIndexerFunc func(indexName string, indexer v1.HelmChartIndexer) - - // GetFunc mocks the Get method. - GetFunc func(namespace string, name string) (*v1a.HelmChart, error) - - // GetByIndexFunc mocks the GetByIndex method. - GetByIndexFunc func(indexName string, key string) ([]*v1a.HelmChart, error) - - // ListFunc mocks the List method. - ListFunc func(namespace string, selector labels.Selector) ([]*v1a.HelmChart, error) - - // calls tracks calls to the methods. - calls struct { - // AddIndexer holds details about calls to the AddIndexer method. - AddIndexer []struct { - // IndexName is the indexName argument value. - IndexName string - // Indexer is the indexer argument value. - Indexer v1.HelmChartIndexer - } - // Get holds details about calls to the Get method. - Get []struct { - // Namespace is the namespace argument value. - Namespace string - // Name is the name argument value. - Name string - } - // GetByIndex holds details about calls to the GetByIndex method. - GetByIndex []struct { - // IndexName is the indexName argument value. - IndexName string - // Key is the key argument value. - Key string - } - // List holds details about calls to the List method. - List []struct { - // Namespace is the namespace argument value. - Namespace string - // Selector is the selector argument value. - Selector labels.Selector - } - } -} - -// AddIndexer calls AddIndexerFunc. -func (mock *HelmChartCacheMock) AddIndexer(indexName string, indexer v1.HelmChartIndexer) { - if mock.AddIndexerFunc == nil { - panic("HelmChartCacheMock.AddIndexerFunc: method is nil but HelmChartCache.AddIndexer was just called") - } - callInfo := struct { - IndexName string - Indexer v1.HelmChartIndexer - }{ - IndexName: indexName, - Indexer: indexer, - } - lockHelmChartCacheMockAddIndexer.Lock() - mock.calls.AddIndexer = append(mock.calls.AddIndexer, callInfo) - lockHelmChartCacheMockAddIndexer.Unlock() - mock.AddIndexerFunc(indexName, indexer) -} - -// AddIndexerCalls gets all the calls that were made to AddIndexer. -// Check the length with: -// len(mockedHelmChartCache.AddIndexerCalls()) -func (mock *HelmChartCacheMock) AddIndexerCalls() []struct { - IndexName string - Indexer v1.HelmChartIndexer -} { - var calls []struct { - IndexName string - Indexer v1.HelmChartIndexer - } - lockHelmChartCacheMockAddIndexer.RLock() - calls = mock.calls.AddIndexer - lockHelmChartCacheMockAddIndexer.RUnlock() - return calls -} - -// Get calls GetFunc. -func (mock *HelmChartCacheMock) Get(namespace string, name string) (*v1a.HelmChart, error) { - if mock.GetFunc == nil { - panic("HelmChartCacheMock.GetFunc: method is nil but HelmChartCache.Get was just called") - } - callInfo := struct { - Namespace string - Name string - }{ - Namespace: namespace, - Name: name, - } - lockHelmChartCacheMockGet.Lock() - mock.calls.Get = append(mock.calls.Get, callInfo) - lockHelmChartCacheMockGet.Unlock() - return mock.GetFunc(namespace, name) -} - -// GetCalls gets all the calls that were made to Get. -// Check the length with: -// len(mockedHelmChartCache.GetCalls()) -func (mock *HelmChartCacheMock) GetCalls() []struct { - Namespace string - Name string -} { - var calls []struct { - Namespace string - Name string - } - lockHelmChartCacheMockGet.RLock() - calls = mock.calls.Get - lockHelmChartCacheMockGet.RUnlock() - return calls -} - -// GetByIndex calls GetByIndexFunc. -func (mock *HelmChartCacheMock) GetByIndex(indexName string, key string) ([]*v1a.HelmChart, error) { - if mock.GetByIndexFunc == nil { - panic("HelmChartCacheMock.GetByIndexFunc: method is nil but HelmChartCache.GetByIndex was just called") - } - callInfo := struct { - IndexName string - Key string - }{ - IndexName: indexName, - Key: key, - } - lockHelmChartCacheMockGetByIndex.Lock() - mock.calls.GetByIndex = append(mock.calls.GetByIndex, callInfo) - lockHelmChartCacheMockGetByIndex.Unlock() - return mock.GetByIndexFunc(indexName, key) -} - -// GetByIndexCalls gets all the calls that were made to GetByIndex. -// Check the length with: -// len(mockedHelmChartCache.GetByIndexCalls()) -func (mock *HelmChartCacheMock) GetByIndexCalls() []struct { - IndexName string - Key string -} { - var calls []struct { - IndexName string - Key string - } - lockHelmChartCacheMockGetByIndex.RLock() - calls = mock.calls.GetByIndex - lockHelmChartCacheMockGetByIndex.RUnlock() - return calls -} - -// List calls ListFunc. -func (mock *HelmChartCacheMock) List(namespace string, selector labels.Selector) ([]*v1a.HelmChart, error) { - if mock.ListFunc == nil { - panic("HelmChartCacheMock.ListFunc: method is nil but HelmChartCache.List was just called") - } - callInfo := struct { - Namespace string - Selector labels.Selector - }{ - Namespace: namespace, - Selector: selector, - } - lockHelmChartCacheMockList.Lock() - mock.calls.List = append(mock.calls.List, callInfo) - lockHelmChartCacheMockList.Unlock() - return mock.ListFunc(namespace, selector) -} - -// ListCalls gets all the calls that were made to List. -// Check the length with: -// len(mockedHelmChartCache.ListCalls()) -func (mock *HelmChartCacheMock) ListCalls() []struct { - Namespace string - Selector labels.Selector -} { - var calls []struct { - Namespace string - Selector labels.Selector - } - lockHelmChartCacheMockList.RLock() - calls = mock.calls.List - lockHelmChartCacheMockList.RUnlock() - return calls -} diff --git a/pkg/generated/controllers/helm.cattle.io/v1/helmchart.go b/pkg/generated/controllers/helm.cattle.io/v1/helmchart.go index 826222fd..93f26efc 100644 --- a/pkg/generated/controllers/helm.cattle.io/v1/helmchart.go +++ b/pkg/generated/controllers/helm.cattle.io/v1/helmchart.go @@ -20,13 +20,17 @@ package v1 import ( "context" + "time" v1 "github.com/rancher/helm-controller/pkg/apis/helm.cattle.io/v1" clientset "github.com/rancher/helm-controller/pkg/generated/clientset/versioned/typed/helm.cattle.io/v1" informers "github.com/rancher/helm-controller/pkg/generated/informers/externalversions/helm.cattle.io/v1" listers "github.com/rancher/helm-controller/pkg/generated/listers/helm.cattle.io/v1" + "github.com/rancher/wrangler/pkg/apply" + "github.com/rancher/wrangler/pkg/condition" "github.com/rancher/wrangler/pkg/generic" "k8s.io/apimachinery/pkg/api/equality" + "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" @@ -40,20 +44,15 @@ import ( type HelmChartHandler func(string, *v1.HelmChart) (*v1.HelmChart, error) type HelmChartController interface { + generic.ControllerMeta HelmChartClient OnChange(ctx context.Context, name string, sync HelmChartHandler) OnRemove(ctx context.Context, name string, sync HelmChartHandler) Enqueue(namespace, name string) + EnqueueAfter(namespace, name string, duration time.Duration) Cache() HelmChartCache - - Informer() cache.SharedIndexInformer - GroupVersionKind() schema.GroupVersionKind - - AddGenericHandler(ctx context.Context, name string, handler generic.Handler) - AddGenericRemoveHandler(ctx context.Context, name string, handler generic.Handler) - Updater() generic.Updater } type HelmChartClient interface { @@ -118,26 +117,21 @@ func (c *helmChartController) Updater() generic.Updater { } } -func UpdateHelmChartOnChange(updater generic.Updater, handler HelmChartHandler) HelmChartHandler { - return func(key string, obj *v1.HelmChart) (*v1.HelmChart, error) { - if obj == nil { - return handler(key, nil) - } - - copyObj := obj.DeepCopy() - newObj, err := handler(key, copyObj) - if newObj != nil { - copyObj = newObj - } - if obj.ResourceVersion == copyObj.ResourceVersion && !equality.Semantic.DeepEqual(obj, copyObj) { - newObj, err := updater(copyObj) - if newObj != nil && err == nil { - copyObj = newObj.(*v1.HelmChart) - } - } +func UpdateHelmChartDeepCopyOnChange(client HelmChartClient, obj *v1.HelmChart, handler func(obj *v1.HelmChart) (*v1.HelmChart, error)) (*v1.HelmChart, error) { + if obj == nil { + return obj, nil + } - return copyObj, err + copyObj := obj.DeepCopy() + newObj, err := handler(copyObj) + if newObj != nil { + copyObj = newObj + } + if obj.ResourceVersion == copyObj.ResourceVersion && !equality.Semantic.DeepEqual(obj, copyObj) { + return client.Update(copyObj) } + + return copyObj, err } func (c *helmChartController) AddGenericHandler(ctx context.Context, name string, handler generic.Handler) { @@ -162,6 +156,10 @@ func (c *helmChartController) Enqueue(namespace, name string) { c.controllerManager.Enqueue(c.gvk, c.informer.Informer(), namespace, name) } +func (c *helmChartController) EnqueueAfter(namespace, name string, duration time.Duration) { + c.controllerManager.EnqueueAfter(c.gvk, c.informer.Informer(), namespace, name, duration) +} + func (c *helmChartController) Informer() cache.SharedIndexInformer { return c.informer.Informer() } @@ -240,3 +238,103 @@ func (c *helmChartCache) GetByIndex(indexName, key string) (result []*v1.HelmCha } return result, nil } + +type HelmChartStatusHandler func(obj *v1.HelmChart, status v1.HelmChartStatus) (v1.HelmChartStatus, error) + +type HelmChartGeneratingHandler func(obj *v1.HelmChart, status v1.HelmChartStatus) ([]runtime.Object, v1.HelmChartStatus, error) + +func RegisterHelmChartStatusHandler(ctx context.Context, controller HelmChartController, condition condition.Cond, name string, handler HelmChartStatusHandler) { + statusHandler := &helmChartStatusHandler{ + client: controller, + condition: condition, + handler: handler, + } + controller.AddGenericHandler(ctx, name, FromHelmChartHandlerToHandler(statusHandler.sync)) +} + +func RegisterHelmChartGeneratingHandler(ctx context.Context, controller HelmChartController, apply apply.Apply, + condition condition.Cond, name string, handler HelmChartGeneratingHandler, opts *generic.GeneratingHandlerOptions) { + statusHandler := &helmChartGeneratingHandler{ + HelmChartGeneratingHandler: handler, + apply: apply, + name: name, + gvk: controller.GroupVersionKind(), + } + if opts != nil { + statusHandler.opts = *opts + } + RegisterHelmChartStatusHandler(ctx, controller, condition, name, statusHandler.Handle) +} + +type helmChartStatusHandler struct { + client HelmChartClient + condition condition.Cond + handler HelmChartStatusHandler +} + +func (a *helmChartStatusHandler) sync(key string, obj *v1.HelmChart) (*v1.HelmChart, error) { + if obj == nil { + return obj, nil + } + + origStatus := obj.Status + obj = obj.DeepCopy() + newStatus, err := a.handler(obj, obj.Status) + if err != nil { + // Revert to old status on error + newStatus = *origStatus.DeepCopy() + } + + obj.Status = newStatus + if a.condition != "" { + if errors.IsConflict(err) { + a.condition.SetError(obj, "", nil) + } else { + a.condition.SetError(obj, "", err) + } + } + if !equality.Semantic.DeepEqual(origStatus, obj.Status) { + var newErr error + obj, newErr = a.client.UpdateStatus(obj) + if err == nil { + err = newErr + } + } + return obj, err +} + +type helmChartGeneratingHandler struct { + HelmChartGeneratingHandler + apply apply.Apply + opts generic.GeneratingHandlerOptions + gvk schema.GroupVersionKind + name string +} + +func (a *helmChartGeneratingHandler) Handle(obj *v1.HelmChart, status v1.HelmChartStatus) (v1.HelmChartStatus, error) { + objs, newStatus, err := a.HelmChartGeneratingHandler(obj, status) + if err != nil { + return newStatus, err + } + + apply := a.apply + + if !a.opts.DynamicLookup { + apply = apply.WithStrictCaching() + } + + if !a.opts.AllowCrossNamespace && !a.opts.AllowClusterScoped { + apply = apply.WithSetOwnerReference(true, false). + WithDefaultNamespace(obj.GetNamespace()). + WithListerNamespace(obj.GetNamespace()) + } + + if !a.opts.AllowClusterScoped { + apply = apply.WithRestrictClusterScoped() + } + + return newStatus, apply. + WithOwner(obj). + WithSetID(a.name). + ApplyObjects(objs...) +} diff --git a/pkg/helm/controller_test.go b/pkg/helm/controller_test.go index 64428fc8..25df9683 100644 --- a/pkg/helm/controller_test.go +++ b/pkg/helm/controller_test.go @@ -5,38 +5,12 @@ import ( "testing" "time" - "github.com/rancher/helm-controller/pkg/apis/helm.cattle.io/v1" - helmMock "github.com/rancher/helm-controller/pkg/generated/controllers/helm.cattle.io/v1/fakes" - jobsv1 "github.com/rancher/wrangler-api/pkg/generated/controllers/batch/v1" - jobsMock "github.com/rancher/wrangler-api/pkg/generated/controllers/batch/v1/fakes" - "github.com/rancher/wrangler/pkg/apply/fake" + v1 "github.com/rancher/helm-controller/pkg/apis/helm.cattle.io/v1" "github.com/stretchr/testify/assert" - batchv1 "k8s.io/api/batch/v1" v12 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" ) -func TestHelmControllerOnChange(t *testing.T) { - assert := assert.New(t) - controller := NewMockHelmController() - chart := NewChart() - key := chart.Namespace + "/" + chart.Name - helmChart, _ := controller.OnHelmChanged(key, NewChart()) - assert.Equal("helm-install-traefik", helmChart.Status.JobName) -} - -func TestHelmControllerOnRemove(t *testing.T) { - assert := assert.New(t) - controller := NewMockHelmController() - chart := NewChart() - key := chart.Namespace + "/" + chart.Name - deleteTime := v12.NewTime(time.Time{}) - chart.DeletionTimestamp = &deleteTime - helmChart, _ := controller.OnHelmRemove(key, chart) - assert.Equal("traefik", helmChart.Name) - assert.Equal("kube-system", helmChart.Namespace) -} - func TestInstallJob(t *testing.T) { assert := assert.New(t) chart := NewChart() @@ -82,31 +56,3 @@ func NewChart() *v1.HelmChart { }, }) } - -func NewMockHelmController() Controller { - helms := &helmMock.HelmChartControllerMock{ - UpdateFunc: func(in1 *v1.HelmChart) (*v1.HelmChart, error) { - return in1, nil - }, - } - - jobs := &jobsMock.JobControllerMock{ - CacheFunc: func() jobsv1.JobCache { - return &jobsMock.JobCacheMock{ - GetFunc: func(namespace string, name string) (*batchv1.Job, error) { - return &batchv1.Job{ - Status: batchv1.JobStatus{ - Succeeded: 0, - }, - }, nil - }, - } - }, - } - - return Controller{ - helmController: helms, - jobsCache: jobs.Cache(), - apply: &fake.FakeApply{}, - } -}