From af287f1b1594c47edd27f2eab3f8090cacf77760 Mon Sep 17 00:00:00 2001 From: Chao Xu Date: Mon, 19 Aug 2019 16:30:10 -0700 Subject: [PATCH 1/3] make StorageVersionMigration cluster-scoped --- manifests/crd.yaml | 2 +- manifests/namespace-rbac.yaml | 8 +++----- pkg/apis/migration/v1alpha1/types.go | 1 + 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/manifests/crd.yaml b/manifests/crd.yaml index 1d5594c75..e5e0f2e2d 100644 --- a/manifests/crd.yaml +++ b/manifests/crd.yaml @@ -9,7 +9,7 @@ spec: listKind: StorageVersionMigrationList plural: storageversionmigrations singular: storageversionmigration - scope: Namespaced + scope: Cluster subresources: status: {} version: v1alpha1 diff --git a/manifests/namespace-rbac.yaml b/manifests/namespace-rbac.yaml index da426b8ea..3f5f8158f 100644 --- a/manifests/namespace-rbac.yaml +++ b/manifests/namespace-rbac.yaml @@ -36,11 +36,10 @@ rules: resources: ["customresourcedefinitions"] verbs: ["create", "delete", "get"] --- -kind: Role +kind: ClusterRole apiVersion: rbac.authorization.k8s.io/v1 metadata: name: storage-version-migration-initializer - namespace: NAMESPACE rules: - apiGroups: ["migration.k8s.io"] resources: ["storageversionmigrations"] @@ -85,16 +84,15 @@ roleRef: name: storage-version-migration-crd-creator apiGroup: rbac.authorization.k8s.io --- -kind: RoleBinding +kind: ClusterRoleBinding apiVersion: rbac.authorization.k8s.io/v1 metadata: name: storage-version-migration-initializer - namespace: NAMESPACE subjects: - kind: ServiceAccount name: default namespace: NAMESPACE roleRef: - kind: Role + kind: ClusterRole name: storage-version-migration-initializer apiGroup: rbac.authorization.k8s.io diff --git a/pkg/apis/migration/v1alpha1/types.go b/pkg/apis/migration/v1alpha1/types.go index 8e9a5cf4b..dde42a5b3 100644 --- a/pkg/apis/migration/v1alpha1/types.go +++ b/pkg/apis/migration/v1alpha1/types.go @@ -23,6 +23,7 @@ import ( // +genclient // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +// +genclient:nonNamespaced // StorageVersionMigration represents a migration of stored data to the latest // storage version. From 348237f85a77845d6fdd007a42192ef9131d007a Mon Sep 17 00:00:00 2001 From: Chao Xu Date: Mon, 19 Aug 2019 16:32:08 -0700 Subject: [PATCH 2/3] generated --- .../v1alpha1/fake/fake_migration_client.go | 4 +- .../fake/fake_storageversionmigration.go | 27 +++++-------- .../migration/v1alpha1/migration_client.go | 4 +- .../v1alpha1/storageversionmigration.go | 15 +------ .../informer/migration/v1alpha1/interface.go | 2 +- .../v1alpha1/storageversionmigration.go | 13 +++---- .../migration/v1alpha1/expansion_generated.go | 4 -- .../v1alpha1/storageversionmigration.go | 39 +++---------------- 8 files changed, 27 insertions(+), 81 deletions(-) diff --git a/pkg/clients/clientset/typed/migration/v1alpha1/fake/fake_migration_client.go b/pkg/clients/clientset/typed/migration/v1alpha1/fake/fake_migration_client.go index 258bd3a78..2fe813c1c 100644 --- a/pkg/clients/clientset/typed/migration/v1alpha1/fake/fake_migration_client.go +++ b/pkg/clients/clientset/typed/migration/v1alpha1/fake/fake_migration_client.go @@ -32,8 +32,8 @@ func (c *FakeMigrationV1alpha1) StorageStates() v1alpha1.StorageStateInterface { return &FakeStorageStates{c} } -func (c *FakeMigrationV1alpha1) StorageVersionMigrations(namespace string) v1alpha1.StorageVersionMigrationInterface { - return &FakeStorageVersionMigrations{c, namespace} +func (c *FakeMigrationV1alpha1) StorageVersionMigrations() v1alpha1.StorageVersionMigrationInterface { + return &FakeStorageVersionMigrations{c} } // RESTClient returns a RESTClient that is used to communicate diff --git a/pkg/clients/clientset/typed/migration/v1alpha1/fake/fake_storageversionmigration.go b/pkg/clients/clientset/typed/migration/v1alpha1/fake/fake_storageversionmigration.go index 70aa5f984..379c91442 100644 --- a/pkg/clients/clientset/typed/migration/v1alpha1/fake/fake_storageversionmigration.go +++ b/pkg/clients/clientset/typed/migration/v1alpha1/fake/fake_storageversionmigration.go @@ -31,7 +31,6 @@ import ( // FakeStorageVersionMigrations implements StorageVersionMigrationInterface type FakeStorageVersionMigrations struct { Fake *FakeMigrationV1alpha1 - ns string } var storageversionmigrationsResource = schema.GroupVersionResource{Group: "migration.k8s.io", Version: "v1alpha1", Resource: "storageversionmigrations"} @@ -41,8 +40,7 @@ var storageversionmigrationsKind = schema.GroupVersionKind{Group: "migration.k8s // Get takes name of the storageVersionMigration, and returns the corresponding storageVersionMigration object, and an error if there is any. func (c *FakeStorageVersionMigrations) Get(name string, options v1.GetOptions) (result *v1alpha1.StorageVersionMigration, err error) { obj, err := c.Fake. - Invokes(testing.NewGetAction(storageversionmigrationsResource, c.ns, name), &v1alpha1.StorageVersionMigration{}) - + Invokes(testing.NewRootGetAction(storageversionmigrationsResource, name), &v1alpha1.StorageVersionMigration{}) if obj == nil { return nil, err } @@ -52,8 +50,7 @@ func (c *FakeStorageVersionMigrations) Get(name string, options v1.GetOptions) ( // List takes label and field selectors, and returns the list of StorageVersionMigrations that match those selectors. func (c *FakeStorageVersionMigrations) List(opts v1.ListOptions) (result *v1alpha1.StorageVersionMigrationList, err error) { obj, err := c.Fake. - Invokes(testing.NewListAction(storageversionmigrationsResource, storageversionmigrationsKind, c.ns, opts), &v1alpha1.StorageVersionMigrationList{}) - + Invokes(testing.NewRootListAction(storageversionmigrationsResource, storageversionmigrationsKind, opts), &v1alpha1.StorageVersionMigrationList{}) if obj == nil { return nil, err } @@ -74,15 +71,13 @@ func (c *FakeStorageVersionMigrations) List(opts v1.ListOptions) (result *v1alph // Watch returns a watch.Interface that watches the requested storageVersionMigrations. func (c *FakeStorageVersionMigrations) Watch(opts v1.ListOptions) (watch.Interface, error) { return c.Fake. - InvokesWatch(testing.NewWatchAction(storageversionmigrationsResource, c.ns, opts)) - + InvokesWatch(testing.NewRootWatchAction(storageversionmigrationsResource, opts)) } // Create takes the representation of a storageVersionMigration and creates it. Returns the server's representation of the storageVersionMigration, and an error, if there is any. func (c *FakeStorageVersionMigrations) Create(storageVersionMigration *v1alpha1.StorageVersionMigration) (result *v1alpha1.StorageVersionMigration, err error) { obj, err := c.Fake. - Invokes(testing.NewCreateAction(storageversionmigrationsResource, c.ns, storageVersionMigration), &v1alpha1.StorageVersionMigration{}) - + Invokes(testing.NewRootCreateAction(storageversionmigrationsResource, storageVersionMigration), &v1alpha1.StorageVersionMigration{}) if obj == nil { return nil, err } @@ -92,8 +87,7 @@ func (c *FakeStorageVersionMigrations) Create(storageVersionMigration *v1alpha1. // Update takes the representation of a storageVersionMigration and updates it. Returns the server's representation of the storageVersionMigration, and an error, if there is any. func (c *FakeStorageVersionMigrations) Update(storageVersionMigration *v1alpha1.StorageVersionMigration) (result *v1alpha1.StorageVersionMigration, err error) { obj, err := c.Fake. - Invokes(testing.NewUpdateAction(storageversionmigrationsResource, c.ns, storageVersionMigration), &v1alpha1.StorageVersionMigration{}) - + Invokes(testing.NewRootUpdateAction(storageversionmigrationsResource, storageVersionMigration), &v1alpha1.StorageVersionMigration{}) if obj == nil { return nil, err } @@ -104,8 +98,7 @@ func (c *FakeStorageVersionMigrations) Update(storageVersionMigration *v1alpha1. // Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). func (c *FakeStorageVersionMigrations) UpdateStatus(storageVersionMigration *v1alpha1.StorageVersionMigration) (*v1alpha1.StorageVersionMigration, error) { obj, err := c.Fake. - Invokes(testing.NewUpdateSubresourceAction(storageversionmigrationsResource, "status", c.ns, storageVersionMigration), &v1alpha1.StorageVersionMigration{}) - + Invokes(testing.NewRootUpdateSubresourceAction(storageversionmigrationsResource, "status", storageVersionMigration), &v1alpha1.StorageVersionMigration{}) if obj == nil { return nil, err } @@ -115,14 +108,13 @@ func (c *FakeStorageVersionMigrations) UpdateStatus(storageVersionMigration *v1a // Delete takes name of the storageVersionMigration and deletes it. Returns an error if one occurs. func (c *FakeStorageVersionMigrations) Delete(name string, options *v1.DeleteOptions) error { _, err := c.Fake. - Invokes(testing.NewDeleteAction(storageversionmigrationsResource, c.ns, name), &v1alpha1.StorageVersionMigration{}) - + Invokes(testing.NewRootDeleteAction(storageversionmigrationsResource, name), &v1alpha1.StorageVersionMigration{}) return err } // DeleteCollection deletes a collection of objects. func (c *FakeStorageVersionMigrations) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { - action := testing.NewDeleteCollectionAction(storageversionmigrationsResource, c.ns, listOptions) + action := testing.NewRootDeleteCollectionAction(storageversionmigrationsResource, listOptions) _, err := c.Fake.Invokes(action, &v1alpha1.StorageVersionMigrationList{}) return err @@ -131,8 +123,7 @@ func (c *FakeStorageVersionMigrations) DeleteCollection(options *v1.DeleteOption // Patch applies the patch and returns the patched storageVersionMigration. func (c *FakeStorageVersionMigrations) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.StorageVersionMigration, err error) { obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(storageversionmigrationsResource, c.ns, name, pt, data, subresources...), &v1alpha1.StorageVersionMigration{}) - + Invokes(testing.NewRootPatchSubresourceAction(storageversionmigrationsResource, name, pt, data, subresources...), &v1alpha1.StorageVersionMigration{}) if obj == nil { return nil, err } diff --git a/pkg/clients/clientset/typed/migration/v1alpha1/migration_client.go b/pkg/clients/clientset/typed/migration/v1alpha1/migration_client.go index 191e26bd3..bec6319c1 100644 --- a/pkg/clients/clientset/typed/migration/v1alpha1/migration_client.go +++ b/pkg/clients/clientset/typed/migration/v1alpha1/migration_client.go @@ -40,8 +40,8 @@ func (c *MigrationV1alpha1Client) StorageStates() StorageStateInterface { return newStorageStates(c) } -func (c *MigrationV1alpha1Client) StorageVersionMigrations(namespace string) StorageVersionMigrationInterface { - return newStorageVersionMigrations(c, namespace) +func (c *MigrationV1alpha1Client) StorageVersionMigrations() StorageVersionMigrationInterface { + return newStorageVersionMigrations(c) } // NewForConfig creates a new MigrationV1alpha1Client for the given config. diff --git a/pkg/clients/clientset/typed/migration/v1alpha1/storageversionmigration.go b/pkg/clients/clientset/typed/migration/v1alpha1/storageversionmigration.go index 5a6c5c30c..013153db0 100644 --- a/pkg/clients/clientset/typed/migration/v1alpha1/storageversionmigration.go +++ b/pkg/clients/clientset/typed/migration/v1alpha1/storageversionmigration.go @@ -32,7 +32,7 @@ import ( // StorageVersionMigrationsGetter has a method to return a StorageVersionMigrationInterface. // A group's client should implement this interface. type StorageVersionMigrationsGetter interface { - StorageVersionMigrations(namespace string) StorageVersionMigrationInterface + StorageVersionMigrations() StorageVersionMigrationInterface } // StorageVersionMigrationInterface has methods to work with StorageVersionMigration resources. @@ -52,14 +52,12 @@ type StorageVersionMigrationInterface interface { // storageVersionMigrations implements StorageVersionMigrationInterface type storageVersionMigrations struct { client rest.Interface - ns string } // newStorageVersionMigrations returns a StorageVersionMigrations -func newStorageVersionMigrations(c *MigrationV1alpha1Client, namespace string) *storageVersionMigrations { +func newStorageVersionMigrations(c *MigrationV1alpha1Client) *storageVersionMigrations { return &storageVersionMigrations{ client: c.RESTClient(), - ns: namespace, } } @@ -67,7 +65,6 @@ func newStorageVersionMigrations(c *MigrationV1alpha1Client, namespace string) * func (c *storageVersionMigrations) Get(name string, options v1.GetOptions) (result *v1alpha1.StorageVersionMigration, err error) { result = &v1alpha1.StorageVersionMigration{} err = c.client.Get(). - Namespace(c.ns). Resource("storageversionmigrations"). Name(name). VersionedParams(&options, scheme.ParameterCodec). @@ -84,7 +81,6 @@ func (c *storageVersionMigrations) List(opts v1.ListOptions) (result *v1alpha1.S } result = &v1alpha1.StorageVersionMigrationList{} err = c.client.Get(). - Namespace(c.ns). Resource("storageversionmigrations"). VersionedParams(&opts, scheme.ParameterCodec). Timeout(timeout). @@ -101,7 +97,6 @@ func (c *storageVersionMigrations) Watch(opts v1.ListOptions) (watch.Interface, } opts.Watch = true return c.client.Get(). - Namespace(c.ns). Resource("storageversionmigrations"). VersionedParams(&opts, scheme.ParameterCodec). Timeout(timeout). @@ -112,7 +107,6 @@ func (c *storageVersionMigrations) Watch(opts v1.ListOptions) (watch.Interface, func (c *storageVersionMigrations) Create(storageVersionMigration *v1alpha1.StorageVersionMigration) (result *v1alpha1.StorageVersionMigration, err error) { result = &v1alpha1.StorageVersionMigration{} err = c.client.Post(). - Namespace(c.ns). Resource("storageversionmigrations"). Body(storageVersionMigration). Do(). @@ -124,7 +118,6 @@ func (c *storageVersionMigrations) Create(storageVersionMigration *v1alpha1.Stor func (c *storageVersionMigrations) Update(storageVersionMigration *v1alpha1.StorageVersionMigration) (result *v1alpha1.StorageVersionMigration, err error) { result = &v1alpha1.StorageVersionMigration{} err = c.client.Put(). - Namespace(c.ns). Resource("storageversionmigrations"). Name(storageVersionMigration.Name). Body(storageVersionMigration). @@ -139,7 +132,6 @@ func (c *storageVersionMigrations) Update(storageVersionMigration *v1alpha1.Stor func (c *storageVersionMigrations) UpdateStatus(storageVersionMigration *v1alpha1.StorageVersionMigration) (result *v1alpha1.StorageVersionMigration, err error) { result = &v1alpha1.StorageVersionMigration{} err = c.client.Put(). - Namespace(c.ns). Resource("storageversionmigrations"). Name(storageVersionMigration.Name). SubResource("status"). @@ -152,7 +144,6 @@ func (c *storageVersionMigrations) UpdateStatus(storageVersionMigration *v1alpha // Delete takes name of the storageVersionMigration and deletes it. Returns an error if one occurs. func (c *storageVersionMigrations) Delete(name string, options *v1.DeleteOptions) error { return c.client.Delete(). - Namespace(c.ns). Resource("storageversionmigrations"). Name(name). Body(options). @@ -167,7 +158,6 @@ func (c *storageVersionMigrations) DeleteCollection(options *v1.DeleteOptions, l timeout = time.Duration(*listOptions.TimeoutSeconds) * time.Second } return c.client.Delete(). - Namespace(c.ns). Resource("storageversionmigrations"). VersionedParams(&listOptions, scheme.ParameterCodec). Timeout(timeout). @@ -180,7 +170,6 @@ func (c *storageVersionMigrations) DeleteCollection(options *v1.DeleteOptions, l func (c *storageVersionMigrations) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.StorageVersionMigration, err error) { result = &v1alpha1.StorageVersionMigration{} err = c.client.Patch(pt). - Namespace(c.ns). Resource("storageversionmigrations"). SubResource(subresources...). Name(name). diff --git a/pkg/clients/informer/migration/v1alpha1/interface.go b/pkg/clients/informer/migration/v1alpha1/interface.go index 0b3c7de23..aaa3ccbbe 100644 --- a/pkg/clients/informer/migration/v1alpha1/interface.go +++ b/pkg/clients/informer/migration/v1alpha1/interface.go @@ -48,5 +48,5 @@ func (v *version) StorageStates() StorageStateInformer { // StorageVersionMigrations returns a StorageVersionMigrationInformer. func (v *version) StorageVersionMigrations() StorageVersionMigrationInformer { - return &storageVersionMigrationInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} + return &storageVersionMigrationInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} } diff --git a/pkg/clients/informer/migration/v1alpha1/storageversionmigration.go b/pkg/clients/informer/migration/v1alpha1/storageversionmigration.go index da9659e97..28e6cb9a7 100644 --- a/pkg/clients/informer/migration/v1alpha1/storageversionmigration.go +++ b/pkg/clients/informer/migration/v1alpha1/storageversionmigration.go @@ -41,33 +41,32 @@ type StorageVersionMigrationInformer interface { type storageVersionMigrationInformer struct { factory internalinterfaces.SharedInformerFactory tweakListOptions internalinterfaces.TweakListOptionsFunc - namespace string } // NewStorageVersionMigrationInformer constructs a new informer for StorageVersionMigration type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewStorageVersionMigrationInformer(client clientset.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { - return NewFilteredStorageVersionMigrationInformer(client, namespace, resyncPeriod, indexers, nil) +func NewStorageVersionMigrationInformer(client clientset.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredStorageVersionMigrationInformer(client, resyncPeriod, indexers, nil) } // NewFilteredStorageVersionMigrationInformer constructs a new informer for StorageVersionMigration type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewFilteredStorageVersionMigrationInformer(client clientset.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { +func NewFilteredStorageVersionMigrationInformer(client clientset.Interface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options v1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.MigrationV1alpha1().StorageVersionMigrations(namespace).List(options) + return client.MigrationV1alpha1().StorageVersionMigrations().List(options) }, WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.MigrationV1alpha1().StorageVersionMigrations(namespace).Watch(options) + return client.MigrationV1alpha1().StorageVersionMigrations().Watch(options) }, }, &migrationv1alpha1.StorageVersionMigration{}, @@ -77,7 +76,7 @@ func NewFilteredStorageVersionMigrationInformer(client clientset.Interface, name } func (f *storageVersionMigrationInformer) defaultInformer(client clientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFilteredStorageVersionMigrationInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) + return NewFilteredStorageVersionMigrationInformer(client, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) } func (f *storageVersionMigrationInformer) Informer() cache.SharedIndexInformer { diff --git a/pkg/clients/lister/migration/v1alpha1/expansion_generated.go b/pkg/clients/lister/migration/v1alpha1/expansion_generated.go index 2a5d1b405..daa75a09c 100644 --- a/pkg/clients/lister/migration/v1alpha1/expansion_generated.go +++ b/pkg/clients/lister/migration/v1alpha1/expansion_generated.go @@ -25,7 +25,3 @@ type StorageStateListerExpansion interface{} // StorageVersionMigrationListerExpansion allows custom methods to be added to // StorageVersionMigrationLister. type StorageVersionMigrationListerExpansion interface{} - -// StorageVersionMigrationNamespaceListerExpansion allows custom methods to be added to -// StorageVersionMigrationNamespaceLister. -type StorageVersionMigrationNamespaceListerExpansion interface{} diff --git a/pkg/clients/lister/migration/v1alpha1/storageversionmigration.go b/pkg/clients/lister/migration/v1alpha1/storageversionmigration.go index 01e588621..9798e4464 100644 --- a/pkg/clients/lister/migration/v1alpha1/storageversionmigration.go +++ b/pkg/clients/lister/migration/v1alpha1/storageversionmigration.go @@ -29,8 +29,8 @@ import ( type StorageVersionMigrationLister interface { // List lists all StorageVersionMigrations in the indexer. List(selector labels.Selector) (ret []*v1alpha1.StorageVersionMigration, err error) - // StorageVersionMigrations returns an object that can list and get StorageVersionMigrations. - StorageVersionMigrations(namespace string) StorageVersionMigrationNamespaceLister + // Get retrieves the StorageVersionMigration from the index for a given name. + Get(name string) (*v1alpha1.StorageVersionMigration, error) StorageVersionMigrationListerExpansion } @@ -52,38 +52,9 @@ func (s *storageVersionMigrationLister) List(selector labels.Selector) (ret []*v return ret, err } -// StorageVersionMigrations returns an object that can list and get StorageVersionMigrations. -func (s *storageVersionMigrationLister) StorageVersionMigrations(namespace string) StorageVersionMigrationNamespaceLister { - return storageVersionMigrationNamespaceLister{indexer: s.indexer, namespace: namespace} -} - -// StorageVersionMigrationNamespaceLister helps list and get StorageVersionMigrations. -type StorageVersionMigrationNamespaceLister interface { - // List lists all StorageVersionMigrations in the indexer for a given namespace. - List(selector labels.Selector) (ret []*v1alpha1.StorageVersionMigration, err error) - // Get retrieves the StorageVersionMigration from the indexer for a given namespace and name. - Get(name string) (*v1alpha1.StorageVersionMigration, error) - StorageVersionMigrationNamespaceListerExpansion -} - -// storageVersionMigrationNamespaceLister implements the StorageVersionMigrationNamespaceLister -// interface. -type storageVersionMigrationNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all StorageVersionMigrations in the indexer for a given namespace. -func (s storageVersionMigrationNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.StorageVersionMigration, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.StorageVersionMigration)) - }) - return ret, err -} - -// Get retrieves the StorageVersionMigration from the indexer for a given namespace and name. -func (s storageVersionMigrationNamespaceLister) Get(name string) (*v1alpha1.StorageVersionMigration, error) { - obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) +// Get retrieves the StorageVersionMigration from the index for a given name. +func (s *storageVersionMigrationLister) Get(name string) (*v1alpha1.StorageVersionMigration, error) { + obj, exists, err := s.indexer.GetByKey(name) if err != nil { return nil, err } From 23668648fd06518125c7c0f5fa5e677073faf229 Mon Sep 17 00:00:00 2001 From: Chao Xu Date: Mon, 19 Aug 2019 16:46:44 -0700 Subject: [PATCH 3/3] Remove other references to namespaces --- pkg/controller/indexer.go | 5 ++--- pkg/controller/kubemigrator.go | 8 ++++---- pkg/initializer/initializer.go | 27 +-------------------------- pkg/trigger/controller.go | 3 --- pkg/trigger/discovery_handler.go | 6 +++--- pkg/trigger/discovery_handler_test.go | 9 ++++----- pkg/trigger/migration_handler.go | 2 +- test/e2e/tests/chaos.go | 2 +- test/e2e/tests/crd-migration.go | 4 +--- 9 files changed, 17 insertions(+), 49 deletions(-) diff --git a/pkg/controller/indexer.go b/pkg/controller/indexer.go index c3eeedcd3..06f6ffb1b 100644 --- a/pkg/controller/indexer.go +++ b/pkg/controller/indexer.go @@ -23,7 +23,6 @@ import ( migration_v1alpha1 "github.com/kubernetes-sigs/kube-storage-version-migrator/pkg/apis/migration/v1alpha1" migrationclient "github.com/kubernetes-sigs/kube-storage-version-migrator/pkg/clients/clientset" migrationinformer "github.com/kubernetes-sigs/kube-storage-version-migrator/pkg/clients/informer/migration/v1alpha1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/tools/cache" ) @@ -52,7 +51,7 @@ func migrationStatusIndexFunc(obj interface{}) ([]string, error) { } func NewStatusIndexedInformer(c migrationclient.Interface) cache.SharedIndexInformer { - return migrationinformer.NewStorageVersionMigrationInformer(c, metav1.NamespaceAll, 0, cache.Indexers{StatusIndex: migrationStatusIndexFunc}) + return migrationinformer.NewStorageVersionMigrationInformer(c, 0, cache.Indexers{StatusIndex: migrationStatusIndexFunc}) } func ToIndex(r migration_v1alpha1.GroupVersionResource) string { @@ -69,5 +68,5 @@ func migrationResourceIndexFunc(obj interface{}) ([]string, error) { } func NewStatusAndResourceIndexedInformer(c migrationclient.Interface) cache.SharedIndexInformer { - return migrationinformer.NewStorageVersionMigrationInformer(c, metav1.NamespaceAll, 0, cache.Indexers{StatusIndex: migrationStatusIndexFunc, ResourceIndex: migrationResourceIndexFunc}) + return migrationinformer.NewStorageVersionMigrationInformer(c, 0, cache.Indexers{StatusIndex: migrationStatusIndexFunc, ResourceIndex: migrationResourceIndexFunc}) } diff --git a/pkg/controller/kubemigrator.go b/pkg/controller/kubemigrator.go index 17b22132a..fe8772b02 100644 --- a/pkg/controller/kubemigrator.go +++ b/pkg/controller/kubemigrator.go @@ -98,7 +98,7 @@ func (km *KubeMigrator) processOne(obj interface{}) error { } // get the fresh object from the apiserver to make sure the object // still exists, and the object is not completed. - m, err := km.migrationClient.MigrationV1alpha1().StorageVersionMigrations(m.Namespace).Get(m.Name, metav1.GetOptions{}) + m, err := km.migrationClient.MigrationV1alpha1().StorageVersionMigrations().Get(m.Name, metav1.GetOptions{}) if err != nil { return err } @@ -110,7 +110,7 @@ func (km *KubeMigrator) processOne(obj interface{}) error { if err != nil { return err } - progressTracker := migrator.NewProgressTracker(km.migrationClient.MigrationV1alpha1().StorageVersionMigrations(m.Namespace), m.Name) + progressTracker := migrator.NewProgressTracker(km.migrationClient.MigrationV1alpha1().StorageVersionMigrations(), m.Name) core := migrator.NewMigrator(resource(m), km.dynamic, progressTracker) // If the storageVersionMigration object is deleted during Run(), Run() // will return an error when it tries to write the continueToken into the @@ -160,12 +160,12 @@ func (km *KubeMigrator) updateStatus(m *migrationv1alpha1.StorageVersionMigratio newConditions = append(newConditions, newCondition) m.Status.Conditions = newConditions - _, err := km.migrationClient.MigrationV1alpha1().StorageVersionMigrations(m.Namespace).UpdateStatus(m) + _, err := km.migrationClient.MigrationV1alpha1().StorageVersionMigrations().UpdateStatus(m) if err == nil { return true, nil } // Always refresh and retry, no matter what kind of error is returned by the apiserver. - updated, err := km.migrationClient.MigrationV1alpha1().StorageVersionMigrations(m.Namespace).Get(m.Name, metav1.GetOptions{}) + updated, err := km.migrationClient.MigrationV1alpha1().StorageVersionMigrations().Get(m.Name, metav1.GetOptions{}) if err == nil { m = updated } diff --git a/pkg/initializer/initializer.go b/pkg/initializer/initializer.go index 9ffbf080d..4b7240a14 100644 --- a/pkg/initializer/initializer.go +++ b/pkg/initializer/initializer.go @@ -17,13 +17,11 @@ limitations under the License. package initializer import ( - "flag" "fmt" "time" migrationv1alpha1 "github.com/kubernetes-sigs/kube-storage-version-migrator/pkg/apis/migration/v1alpha1" "github.com/kubernetes-sigs/kube-storage-version-migrator/pkg/clients/clientset/typed/migration/v1alpha1" - v1 "k8s.io/api/core/v1" apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1" "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/typed/apiextensions/v1beta1" "k8s.io/apimachinery/pkg/api/errors" @@ -54,14 +52,10 @@ func NewInitializer( discovery: d, crdClient: crdClient, namespaceClient: namespaceClient, - migrationClient: migrationGetter.StorageVersionMigrations(*namespaceName), + migrationClient: migrationGetter.StorageVersionMigrations(), } } -var ( - namespaceName = flag.String("namespace", "kube-system", "the namespace the initializer is going to run in. The namespace should be created before running the initializer. The namespace should be the same one where the migrator runs. Default to kube-system.") -) - const ( singularCRDName = "storageversionmigration" pluralCRDName = "storageversionmigrations" @@ -145,30 +139,11 @@ func (init *initializer) initializeCRD() error { return err } -// TODO: remove this function. Users will use provided yaml files to create the -// namespace, and then create the initializer in the namespace. -func (init *initializer) initializeNamespace() error { - _, err := init.namespaceClient.Get(*namespaceName, metav1.GetOptions{}) - if (err != nil && !errors.IsNotFound(err)) || err == nil { - return err - } - _, err = init.namespaceClient.Create(&v1.Namespace{ - ObjectMeta: metav1.ObjectMeta{ - Name: *namespaceName, - }, - }) - return err -} - func (init *initializer) Initialize() error { // TODO: remove deployment code. if err := init.initializeCRD(); err != nil { return err } - // TODO: remove deployment code. - if err := init.initializeNamespace(); err != nil { - return err - } // run discovery resources, err := init.discovery.FindMigratableResources() diff --git a/pkg/trigger/controller.go b/pkg/trigger/controller.go index 958049ed7..0b47cf47b 100644 --- a/pkg/trigger/controller.go +++ b/pkg/trigger/controller.go @@ -17,7 +17,6 @@ limitations under the License. package trigger import ( - "flag" "fmt" "reflect" "time" @@ -39,8 +38,6 @@ var ( Factor: 5.0, Jitter: 0.1, } - - namespaceName = flag.String("namespace", "kube-system", "the namespace the trigger is going to run in. The namespace should be created before running the trigger. The namespace should be the same one where the migrator runs. Default to kube-system.") ) const ( diff --git a/pkg/trigger/discovery_handler.go b/pkg/trigger/discovery_handler.go index b035dd89b..161eacd51 100644 --- a/pkg/trigger/discovery_handler.go +++ b/pkg/trigger/discovery_handler.go @@ -88,9 +88,9 @@ func (mt *MigrationTrigger) cleanMigrations(r metav1.APIResource) error { if !ok { return fmt.Errorf("expected StorageVersionMigration, got %#v", reflect.TypeOf(m)) } - err := mt.client.MigrationV1alpha1().StorageVersionMigrations(mm.Namespace).Delete(mm.Name, nil) + err := mt.client.MigrationV1alpha1().StorageVersionMigrations().Delete(mm.Name, nil) if err != nil { - return fmt.Errorf("unexpected error deleting migration %s/%s, %v", mm.Namespace, mm.Name, err) + return fmt.Errorf("unexpected error deleting migration %s, %v", mm.Name, err) } } return nil @@ -105,7 +105,7 @@ func (mt *MigrationTrigger) launchMigration(resource migrationv1alpha1.GroupVers Resource: resource, }, } - _, err := mt.client.MigrationV1alpha1().StorageVersionMigrations(*namespaceName).Create(m) + _, err := mt.client.MigrationV1alpha1().StorageVersionMigrations().Create(m) return err } diff --git a/pkg/trigger/discovery_handler_test.go b/pkg/trigger/discovery_handler_test.go index d5c66714e..0f3953d86 100644 --- a/pkg/trigger/discovery_handler_test.go +++ b/pkg/trigger/discovery_handler_test.go @@ -80,11 +80,11 @@ func freshStorageStateWithOldHash() *v1alpha1.StorageState { func newMigrationList() *v1alpha1.StorageVersionMigrationList { var migrations []v1alpha1.StorageVersionMigration for i := 0; i < 3; i++ { - migration := newMigration(fmt.Sprintf("migration%d", i), fmt.Sprintf("namespace%d", i), v1alpha1.GroupVersionResource{Version: "v1", Resource: "pods"}) + migration := newMigration(fmt.Sprintf("migration%d", i), v1alpha1.GroupVersionResource{Version: "v1", Resource: "pods"}) migrations = append(migrations, migration) } for i := 3; i < 6; i++ { - migration := newMigration(fmt.Sprintf("migration%d", i), fmt.Sprintf("namespace%d", i), v1alpha1.GroupVersionResource{Group: "apps", Version: "v1", Resource: "statefulsets"}) + migration := newMigration(fmt.Sprintf("migration%d", i), v1alpha1.GroupVersionResource{Group: "apps", Version: "v1", Resource: "statefulsets"}) migrations = append(migrations, migration) } return &v1alpha1.StorageVersionMigrationList{ @@ -96,11 +96,10 @@ func newMigrationList() *v1alpha1.StorageVersionMigrationList { } } -func newMigration(name, namespace string, r v1alpha1.GroupVersionResource) v1alpha1.StorageVersionMigration { +func newMigration(name string, r v1alpha1.GroupVersionResource) v1alpha1.StorageVersionMigration { return v1alpha1.StorageVersionMigration{ ObjectMeta: metav1.ObjectMeta{ - Name: name, - Namespace: namespace, + Name: name, }, Spec: v1alpha1.StorageVersionMigrationSpec{ Resource: r, diff --git a/pkg/trigger/migration_handler.go b/pkg/trigger/migration_handler.go index 8e6fd4b8e..fbdbfe6ee 100644 --- a/pkg/trigger/migration_handler.go +++ b/pkg/trigger/migration_handler.go @@ -86,7 +86,7 @@ func (mt *MigrationTrigger) processQueue(obj interface{}) error { } // historic migrations are cleaned up when the controller observes // storage version changes in the discovery doc. - m, err := mt.client.MigrationV1alpha1().StorageVersionMigrations(item.namespace).Get(item.name, metav1.GetOptions{}) + m, err := mt.client.MigrationV1alpha1().StorageVersionMigrations().Get(item.name, metav1.GetOptions{}) if err == nil { return mt.processMigration(m) } diff --git a/test/e2e/tests/chaos.go b/test/e2e/tests/chaos.go index 1a585eb8f..003bc598c 100644 --- a/test/e2e/tests/chaos.go +++ b/test/e2e/tests/chaos.go @@ -227,7 +227,7 @@ func (t *StorageMigratorChaosTest) Test(done <-chan struct{}) { } By("Migrations should have all completed") - l, err := t.migrationClient.MigrationV1alpha1().StorageVersionMigrations(namespaceName).List(metav1.ListOptions{}) + l, err := t.migrationClient.MigrationV1alpha1().StorageVersionMigrations().List(metav1.ListOptions{}) if err != nil { util.Failf("%v", err) } diff --git a/test/e2e/tests/crd-migration.go b/test/e2e/tests/crd-migration.go index 51265e342..57bcecf7b 100644 --- a/test/e2e/tests/crd-migration.go +++ b/test/e2e/tests/crd-migration.go @@ -18,8 +18,6 @@ import ( ) const ( - // TODO: centralize the namespace definitions. - namespaceName = "kube-system" // The migration trigger controller redo the discovery every discoveryPeriod. discoveryPeriod = 10 * time.Minute ) @@ -173,7 +171,7 @@ var _ = Describe("storage version migrator", func() { } By("Migrations should have all completed") - l, err := client.MigrationV1alpha1().StorageVersionMigrations(namespaceName).List(metav1.ListOptions{}) + l, err := client.MigrationV1alpha1().StorageVersionMigrations().List(metav1.ListOptions{}) if err != nil { util.Failf("%v", err) }