Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 create migration cr after the cluster manager cr is applied #66

Open
wants to merge 1 commit into
base: backplane-2.3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: migration.k8s.io/v1alpha1
kind: StorageVersionMigration
metadata:
name: managedclustersetbindings.cluster.open-cluster-management.io
name: managedclustersetbindings.v1beta1.cluster.open-cluster-management.io
spec:
resource:
group: cluster.open-cluster-management.io
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: migration.k8s.io/v1alpha1
kind: StorageVersionMigration
metadata:
name: managedclustersets.cluster.open-cluster-management.io
name: managedclustersets.v1beta1.cluster.open-cluster-management.io
spec:
resource:
group: cluster.open-cluster-management.io
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,11 @@ func (n *clusterManagerController) sync(ctx context.Context, controllerContext f

if len(errs) == 0 {
conds = append(conds, metav1.Condition{
Type: clusterManagerApplied,
Status: metav1.ConditionTrue,
Reason: "ClusterManagerApplied",
Message: "Components of cluster manager are applied",
Type: clusterManagerApplied,
Status: metav1.ConditionTrue,
Reason: "ClusterManagerApplied",
Message: "Components of cluster manager are applied",
ObservedGeneration: clusterManager.Generation,
})
} else {
if cond := meta.FindStatusCondition(clusterManager.Status.Conditions, clusterManagerApplied); cond != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,17 @@ func (c *crdMigrationController) sync(ctx context.Context, controllerContext fac
}

// do not apply storage version migrations until other resources are applied
if applied := meta.IsStatusConditionTrue(clusterManager.Status.Conditions, clusterManagerApplied); !applied {
clusterManagerAppliedCondition := meta.FindStatusCondition(clusterManager.Status.Conditions, clusterManagerApplied)
if clusterManagerAppliedCondition == nil || clusterManagerAppliedCondition.Status != metav1.ConditionTrue {
controllerContext.Queue().AddRateLimited(clusterManagerName)
klog.Info("Applied condition false, wait for cluster manager to be applied")
return nil
}
if clusterManagerAppliedCondition.ObservedGeneration != clusterManager.Generation {
controllerContext.Queue().AddRateLimited(clusterManagerName)
klog.InfoS("ObservedGeneration not match,wait for cluster manager to be applied",
"ObservedGeneration", clusterManagerAppliedCondition.ObservedGeneration,
"Generation", clusterManager.Generation)
return nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,17 @@ func TestApplyStorageVersionMigrations(t *testing.T) {
validateActions: func(t *testing.T, actions []clienttesting.Action) {
assertActions(t, actions, "get", "create", "get", "create")
actual := actions[1].(clienttesting.CreateActionImpl).Object
assertStorageVersionMigration(t, "managedclustersets.cluster.open-cluster-management.io", actual)
assertStorageVersionMigration(t, "managedclustersets.v1beta1.cluster.open-cluster-management.io", actual)
actual = actions[3].(clienttesting.CreateActionImpl).Object
assertStorageVersionMigration(t, "managedclustersetbindings.cluster.open-cluster-management.io", actual)
assertStorageVersionMigration(t, "managedclustersetbindings.v1beta1.cluster.open-cluster-management.io", actual)
},
},
{
name: "created and updated",
existingObjects: []runtime.Object{
&migrationv1alpha1.StorageVersionMigration{
ObjectMeta: metav1.ObjectMeta{
Name: "managedclustersetbindings.cluster.open-cluster-management.io",
Name: "managedclustersetbindings.v1beta1.cluster.open-cluster-management.io",
},
},
&migrationv1alpha1.StorageVersionMigration{
Expand All @@ -102,9 +102,9 @@ func TestApplyStorageVersionMigrations(t *testing.T) {
validateActions: func(t *testing.T, actions []clienttesting.Action) {
assertActions(t, actions, "get", "create", "get", "update")
actual := actions[1].(clienttesting.CreateActionImpl).Object
assertStorageVersionMigration(t, "managedclustersets.cluster.open-cluster-management.io", actual)
assertStorageVersionMigration(t, "managedclustersets.v1beta1.cluster.open-cluster-management.io", actual)
actual = actions[3].(clienttesting.UpdateActionImpl).Object
assertStorageVersionMigration(t, "managedclustersetbindings.cluster.open-cluster-management.io", actual)
assertStorageVersionMigration(t, "managedclustersetbindings.v1beta1.cluster.open-cluster-management.io", actual)
},
},
}
Expand All @@ -118,7 +118,8 @@ func TestApplyStorageVersionMigrations(t *testing.T) {
t.Run(c.name, func(t *testing.T) {
fakeMigrationClient := fakemigrationclient.NewSimpleClientset(c.existingObjects...)

err := applyStorageVersionMigrations(context.TODO(), fakeMigrationClient.MigrationV1alpha1(), eventstesting.NewTestingEventRecorder(t))
err := applyStorageVersionMigrations(context.TODO(),
fakeMigrationClient.MigrationV1alpha1(), eventstesting.NewTestingEventRecorder(t))
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
Expand All @@ -129,10 +130,8 @@ func TestApplyStorageVersionMigrations(t *testing.T) {

func TestRemoveStorageVersionMigrations(t *testing.T) {
names := []string{
"managedclustersets.cluster.open-cluster-management.io",
"managedclustersetbindings.cluster.open-cluster-management.io",
"placements.cluster.open-cluster-management.io",
"placementdecisions.cluster.open-cluster-management.io",
"managedclustersets.v1beta1.cluster.open-cluster-management.io",
"managedclustersetbindings.v1beta1.cluster.open-cluster-management.io",
}
cases := []struct {
name string
Expand All @@ -150,6 +149,11 @@ func TestRemoveStorageVersionMigrations(t *testing.T) {
Name: "managedclustersetbindings.cluster.open-cluster-management.io",
},
},
&migrationv1alpha1.StorageVersionMigration{
ObjectMeta: metav1.ObjectMeta{
Name: "managedclustersetbindings.v1beta1.cluster.open-cluster-management.io",
},
},
&migrationv1alpha1.StorageVersionMigration{
ObjectMeta: metav1.ObjectMeta{
Name: "placementdecisions.cluster.open-cluster-management.io",
Expand All @@ -169,11 +173,8 @@ func TestRemoveStorageVersionMigrations(t *testing.T) {

for _, name := range names {
_, err := fakeMigrationClient.MigrationV1alpha1().StorageVersionMigrations().Get(context.TODO(), name, metav1.GetOptions{})
if errors.IsNotFound(err) {
continue
}
if err != nil {
t.Fatalf("unexpected error: %v", err)
if !errors.IsNotFound(err) {
t.Fatalf("expected not found error for %s but got: %v", name, err)
}
}
})
Expand Down Expand Up @@ -215,12 +216,12 @@ func Test_syncStorageVersionMigrationsCondition(t *testing.T) {
existingObjects: []runtime.Object{
&migrationv1alpha1.StorageVersionMigration{
ObjectMeta: metav1.ObjectMeta{
Name: "managedclustersetbindings.cluster.open-cluster-management.io",
Name: "managedclustersetbindings.v1beta1.cluster.open-cluster-management.io",
},
},
&migrationv1alpha1.StorageVersionMigration{
ObjectMeta: metav1.ObjectMeta{
Name: "managedclustersets.cluster.open-cluster-management.io",
Name: "managedclustersets.v1beta1.cluster.open-cluster-management.io",
},
},
},
Expand All @@ -235,7 +236,7 @@ func Test_syncStorageVersionMigrationsCondition(t *testing.T) {
existingObjects: []runtime.Object{
&migrationv1alpha1.StorageVersionMigration{
ObjectMeta: metav1.ObjectMeta{
Name: "managedclustersetbindings.cluster.open-cluster-management.io",
Name: "managedclustersetbindings.v1beta1.cluster.open-cluster-management.io",
},
Status: migrationv1alpha1.StorageVersionMigrationStatus{
Conditions: []migrationv1alpha1.MigrationCondition{
Expand All @@ -248,7 +249,7 @@ func Test_syncStorageVersionMigrationsCondition(t *testing.T) {
},
&migrationv1alpha1.StorageVersionMigration{
ObjectMeta: metav1.ObjectMeta{
Name: "managedclustersets.cluster.open-cluster-management.io",
Name: "managedclustersets.v1beta1.cluster.open-cluster-management.io",
},
Status: migrationv1alpha1.StorageVersionMigrationStatus{
Conditions: []migrationv1alpha1.MigrationCondition{
Expand All @@ -271,7 +272,7 @@ func Test_syncStorageVersionMigrationsCondition(t *testing.T) {
existingObjects: []runtime.Object{
&migrationv1alpha1.StorageVersionMigration{
ObjectMeta: metav1.ObjectMeta{
Name: "managedclustersetbindings.cluster.open-cluster-management.io",
Name: "managedclustersetbindings.v1beta1.cluster.open-cluster-management.io",
},
Status: migrationv1alpha1.StorageVersionMigrationStatus{
Conditions: []migrationv1alpha1.MigrationCondition{
Expand All @@ -284,7 +285,7 @@ func Test_syncStorageVersionMigrationsCondition(t *testing.T) {
},
&migrationv1alpha1.StorageVersionMigration{
ObjectMeta: metav1.ObjectMeta{
Name: "managedclustersets.cluster.open-cluster-management.io",
Name: "managedclustersets.v1beta1.cluster.open-cluster-management.io",
},
Status: migrationv1alpha1.StorageVersionMigrationStatus{
Conditions: []migrationv1alpha1.MigrationCondition{
Expand All @@ -307,7 +308,7 @@ func Test_syncStorageVersionMigrationsCondition(t *testing.T) {
existingObjects: []runtime.Object{
&migrationv1alpha1.StorageVersionMigration{
ObjectMeta: metav1.ObjectMeta{
Name: "managedclustersetbindings.cluster.open-cluster-management.io",
Name: "managedclustersetbindings.v1beta1.cluster.open-cluster-management.io",
},
Status: migrationv1alpha1.StorageVersionMigrationStatus{
Conditions: []migrationv1alpha1.MigrationCondition{
Expand All @@ -320,7 +321,7 @@ func Test_syncStorageVersionMigrationsCondition(t *testing.T) {
},
&migrationv1alpha1.StorageVersionMigration{
ObjectMeta: metav1.ObjectMeta{
Name: "managedclustersets.cluster.open-cluster-management.io",
Name: "managedclustersets.v1beta1.cluster.open-cluster-management.io",
},
Status: migrationv1alpha1.StorageVersionMigrationStatus{
Conditions: []migrationv1alpha1.MigrationCondition{
Expand All @@ -343,7 +344,7 @@ func Test_syncStorageVersionMigrationsCondition(t *testing.T) {
existingObjects: []runtime.Object{
&migrationv1alpha1.StorageVersionMigration{
ObjectMeta: metav1.ObjectMeta{
Name: "managedclustersetbindings.cluster.open-cluster-management.io",
Name: "managedclustersetbindings.v1beta1.cluster.open-cluster-management.io",
},
Status: migrationv1alpha1.StorageVersionMigrationStatus{
Conditions: []migrationv1alpha1.MigrationCondition{
Expand All @@ -356,7 +357,7 @@ func Test_syncStorageVersionMigrationsCondition(t *testing.T) {
},
&migrationv1alpha1.StorageVersionMigration{
ObjectMeta: metav1.ObjectMeta{
Name: "managedclustersets.cluster.open-cluster-management.io",
Name: "managedclustersets.v1beta1.cluster.open-cluster-management.io",
},
Status: migrationv1alpha1.StorageVersionMigrationStatus{
Conditions: []migrationv1alpha1.MigrationCondition{
Expand Down