Skip to content

Commit

Permalink
Remove other references to namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Chao Xu committed Aug 19, 2019
1 parent 1488360 commit 8545be7
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 49 deletions.
5 changes: 2 additions & 3 deletions pkg/controller/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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 {
Expand All @@ -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})
}
8 changes: 4 additions & 4 deletions pkg/controller/kubemigrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
27 changes: 1 addition & 26 deletions pkg/initializer/initializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 0 additions & 3 deletions pkg/trigger/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package trigger

import (
"flag"
"fmt"
"reflect"
"time"
Expand All @@ -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 (
Expand Down
6 changes: 3 additions & 3 deletions pkg/trigger/discovery_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand Down
9 changes: 4 additions & 5 deletions pkg/trigger/discovery_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pkg/trigger/migration_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/tests/chaos.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 1 addition & 3 deletions test/e2e/tests/crd-migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 8545be7

Please sign in to comment.