diff --git a/migration/pkg/migration/deployment.go b/migration/pkg/migration/deployment.go index d996a53..c0098e3 100644 --- a/migration/pkg/migration/deployment.go +++ b/migration/pkg/migration/deployment.go @@ -61,7 +61,7 @@ func (m *Migrator) prepareClusterObjectDeployment(ctx context.Context, name stri return fmt.Errorf("check ClusterObjectDeployment %s: %w", name, err) } // An existing group must not be taken over merely because its deployment - // is absent. Check legacy labels too, before any OLMv0 objects are deleted. + // is absent. Check conflicting labels and names too, before any OLMv0 objects are deleted. var revisions ocv1.ClusterObjectSetList if err := m.Client.List(ctx, &revisions); err != nil { return fmt.Errorf("check migration revision group: %w", err) @@ -96,6 +96,7 @@ func (m *Migrator) createClusterObjectDeployment(ctx context.Context, opts Optio return m.waitForDeployment(ctx, cod) } +// waitForDeployment waits for the created deployment to complete its current rollout and become available. func (m *Migrator) waitForDeployment(ctx context.Context, created *ocv1.ClusterObjectDeployment) error { return wait.PollUntilContextTimeout(ctx, cosWaitPollInterval, cosWaitTimeout, true, func(ctx context.Context) (bool, error) { var cod ocv1.ClusterObjectDeployment @@ -121,7 +122,7 @@ func (m *Migrator) waitForDeployment(ctx context.Context, created *ocv1.ClusterO }) } -// rollbackDeployment permits the legacy API to be absent, but never hides +// rollbackDeployment permits the COD API to be absent, but never hides // authorization or transport errors. A foreign deployment blocks rollback. func (m *Migrator) rollbackDeployment(ctx context.Context, ce *ocv1.ClusterExtension) (*ocv1.ClusterObjectDeployment, error) { var cod ocv1.ClusterObjectDeployment @@ -215,13 +216,14 @@ func (m *Migrator) rememberRollbackDeployment(ctx context.Context, ce *ocv1.Clus return nil } +// listMigrationRevisions selects migration revisions and rejects conflicting ownership identities. func (m *Migrator) listMigrationRevisions(ctx context.Context, ce *ocv1.ClusterExtension, list *ocv1.ClusterObjectSetList) error { if err := m.Client.List(ctx, list); err != nil { return err } selected := list.Items[:0] for _, revision := range list.Items { - if revision.Spec.Group == ce.Name || revision.Spec.Group == "" && revision.Labels[LabelOwnerName] == ce.Name { + if revision.Spec.Group == ce.Name || revision.Labels[LabelOwnerName] == ce.Name || revision.Name == ce.Name+"-1" { if err := m.validateRollbackRevision(ctx, &revision, ce); err != nil { return err } @@ -232,9 +234,10 @@ func (m *Migrator) listMigrationRevisions(ctx context.Context, ce *ocv1.ClusterE return nil } +// validateRollbackRevision requires the expected revision group and verifies controller ancestry before deletion. func (m *Migrator) validateRollbackRevision(ctx context.Context, revision *ocv1.ClusterObjectSet, ce *ocv1.ClusterExtension) error { name := ce.Name - if revision.Spec.Group != "" && revision.Spec.Group != name { + if revision.Spec.Group != name { return fmt.Errorf("migration ClusterObjectSet %s belongs to another group %q", revision.Name, revision.Spec.Group) } if owner := revision.Labels[LabelOwnerName]; owner != "" && owner != name { @@ -242,12 +245,9 @@ func (m *Migrator) validateRollbackRevision(ctx context.Context, revision *ocv1. } owner := metav1.GetControllerOf(revision) if owner == nil { - // Legacy staging revisions and revisions orphaned during rollback have - // no controller. Require a matching group, label, or legacy initial name. - if revision.Spec.Group == name || revision.Labels[LabelOwnerName] == name || revision.Name == name+"-1" { - return nil - } - return fmt.Errorf("migration ClusterObjectSet %s has no verified migration identity", revision.Name) + // Staging revisions and revisions orphaned during rollback have no + // controller. Their required group was verified above. + return nil } unverified := fmt.Errorf("migration ClusterObjectSet %s is controlled by another or unverified owner", revision.Name) if owner.APIVersion != ocv1.GroupVersion.String() || owner.Name != name || owner.UID == "" { diff --git a/migration/pkg/migration/deployment_test.go b/migration/pkg/migration/deployment_test.go index cee331f..8272402 100644 --- a/migration/pkg/migration/deployment_test.go +++ b/migration/pkg/migration/deployment_test.go @@ -344,6 +344,7 @@ func TestRollbackRejectsForeignRevisionsBeforeStoppingDeployment(t *testing.T) { } } +// TestRollbackRevisionControllerOwnership checks that rollback rejects unrelated or unverified revision controllers. func TestRollbackRevisionControllerOwnership(t *testing.T) { ce := &ocv1.ClusterExtension{ObjectMeta: metav1.ObjectMeta{Name: "example", UID: "extension"}} cod := readyDeployment() @@ -354,7 +355,7 @@ func TestRollbackRevisionControllerOwnership(t *testing.T) { missingCOD bool wantError bool }{ - {name: "orphaned or legacy revision"}, + {name: "orphaned revision"}, {name: "CE controller", owner: metav1.NewControllerRef(ce, ocv1.GroupVersion.WithKind(ocv1.ClusterExtensionKind))}, {name: "COD controller", owner: metav1.NewControllerRef(cod, ocv1.GroupVersion.WithKind(ocv1.ClusterObjectDeploymentKind))}, {name: "missing COD cannot verify UID", owner: metav1.NewControllerRef(cod, ocv1.GroupVersion.WithKind(ocv1.ClusterObjectDeploymentKind)), missingCOD: true, wantError: true}, @@ -377,12 +378,11 @@ func TestRollbackRevisionControllerOwnership(t *testing.T) { } }) } - // The old initial revision may lack both group and label; other unowned - // objects without any migration identity must not be admitted by name alone. + // A matching name cannot substitute for the required group. m := migrationTestClient(t, ce) for _, name := range []string{"example-1", "unrelated"} { - revision := &ocv1.ClusterObjectSet{ObjectMeta: metav1.ObjectMeta{Name: name}} - if err := m.validateRollbackRevision(context.Background(), revision, ce); (err != nil) != (name == "unrelated") { + revision := &ocv1.ClusterObjectSet{ObjectMeta: metav1.ObjectMeta{Name: name, Labels: map[string]string{LabelOwnerName: ce.Name}}} + if err := m.validateRollbackRevision(context.Background(), revision, ce); err == nil { t.Fatalf("validation of %s = %v", name, err) } } diff --git a/migration/pkg/migration/labels.go b/migration/pkg/migration/labels.go index 1fd36db..0b0d896 100644 --- a/migration/pkg/migration/labels.go +++ b/migration/pkg/migration/labels.go @@ -48,7 +48,7 @@ const ( MigratedFromCatalogSourceAnnotation = "olm.operatorframework.io/migrated-from-catalogsource" // cosWaitPollInterval / cosWaitTimeout control how long to wait for a - // ClusterObjectSet to reach Succeeded=True. + // ClusterObjectSet to set status.completedAt. cosWaitPollInterval = 5 * time.Second cosWaitTimeout = 5 * time.Minute diff --git a/migration/pkg/migration/migration.go b/migration/pkg/migration/migration.go index 1c9ceef..0e41f4a 100644 --- a/migration/pkg/migration/migration.go +++ b/migration/pkg/migration/migration.go @@ -28,12 +28,6 @@ const ( clusterObjectSetCRDName = "clusterobjectsets.olm.operatorframework.io" clusterExtensionCRDName = "clusterextensions.olm.operatorframework.io" operatorControllerDeployName = "operator-controller-controller-manager" - - // operator-controller v1.12 uses these COS conditions. The COD-capable API - // replaced them with status.completedAt and ClusterObjectSetTypeReady and - // removed their constants; retain the values for legacy COS-only clusters. - legacyCOSConditionSucceeded = "Succeeded" - legacyCOSConditionAvailable = "Available" ) // annotationPrefixesToStrip are annotation prefixes that should be removed from migrated resources. @@ -769,6 +763,7 @@ func (m *Migrator) createClusterObjectSet(ctx context.Context, opts Options, inf return resources, nil } +// cleanupCreatedClusterObjectSet cleans staged resources using their recorded creation identities. func (m *Migrator) cleanupCreatedClusterObjectSet(ctx context.Context, resources *createdMigrationResources) error { if resources == nil { return nil @@ -789,7 +784,7 @@ func (m *Migrator) cleanupCreatedClusterObjectSet(ctx context.Context, resources return m.cleanupCreatedSecrets(cleanupCtx, resources.secrets) } -// WaitForCOSSucceeded waits for status.completedAt or legacy Succeeded=True. +// WaitForCOSSucceeded waits for the current COS completion timestamp. func (m *Migrator) WaitForCOSSucceeded(ctx context.Context, cosName string) error { return wait.PollUntilContextTimeout(ctx, cosWaitPollInterval, cosWaitTimeout, true, func(ctx context.Context) (bool, error) { var cos ocv1.ClusterObjectSet @@ -802,15 +797,13 @@ func (m *Migrator) WaitForCOSSucceeded(ctx context.Context, cosName string) erro return true, nil } for _, c := range cos.Status.Conditions { - if c.Type == legacyCOSConditionSucceeded && c.Status == metav1.ConditionTrue { - return true, nil - } - if c.Type == legacyCOSConditionSucceeded && c.Reason == ocv1.ReasonBlocked { - return false, fmt.Errorf("ClusterObjectSet %s is blocked: %s", cosName, c.Message) + if c.Type == ocv1.ClusterObjectSetTypeReady && c.Status == metav1.ConditionFalse && + c.ObservedGeneration == cos.Generation && c.Reason == ocv1.ClusterObjectSetReasonInvalidSpecification { + return false, fmt.Errorf("ClusterObjectSet %s has invalid specification: %s", cosName, c.Message) } } - m.progress(ProgressEvent{Step: ProgressStepCreate, Status: ProgressWaiting, Message: fmt.Sprintf("Waiting for ClusterObjectSet %s to reach Succeeded=True...", cosName)}) + m.progress(ProgressEvent{Step: ProgressStepCreate, Status: ProgressWaiting, Message: fmt.Sprintf("Waiting for ClusterObjectSet %s to set status.completedAt...", cosName)}) return false, nil }) } @@ -977,11 +970,11 @@ func (m *Migrator) WaitForClusterObjectSetAvailable(ctx context.Context, cosName return false, err } for _, condition := range cos.Status.Conditions { - if (condition.Type == legacyCOSConditionAvailable || condition.Type == ocv1.ClusterObjectSetTypeReady) && condition.Status == metav1.ConditionTrue { + if condition.Type == ocv1.ClusterObjectSetTypeReady && condition.Status == metav1.ConditionTrue { return true, nil } } - m.progress(ProgressEvent{Step: ProgressStepCreate, Status: ProgressWaiting, Message: fmt.Sprintf("Waiting for migration ClusterObjectSet %s to reach Available=True...", cosName)}) + m.progress(ProgressEvent{Step: ProgressStepCreate, Status: ProgressWaiting, Message: fmt.Sprintf("Waiting for migration ClusterObjectSet %s to reach Ready=True...", cosName)}) return false, nil }) } diff --git a/migration/pkg/migration/namespace.go b/migration/pkg/migration/namespace.go index 0ad307a..83454e5 100644 --- a/migration/pkg/migration/namespace.go +++ b/migration/pkg/migration/namespace.go @@ -296,7 +296,7 @@ func clearServiceAllocations(obj *unstructured.Unstructured) { // DeleteSourceNamespaceResources removes the old copies of objects that were // applied in a different install namespace. It runs only after the target CE -// has reached Installed=True and the migration COS reported Available=True, so +// has reached Installed=True and the migration COS reported Ready=True, so // a failed handoff retains the OLMv0 workload. // It intentionally does not delete the Namespace itself; that requires the // separate AcknowledgeNamespaceDelete opt-in. diff --git a/migration/pkg/migration/revision_status_test.go b/migration/pkg/migration/revision_status_test.go new file mode 100644 index 0000000..a8da707 --- /dev/null +++ b/migration/pkg/migration/revision_status_test.go @@ -0,0 +1,62 @@ +package migration + +import ( + "context" + "errors" + "strings" + "testing" + "time" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + ocv1 "github.com/operator-framework/operator-controller/api/v1" +) + +// TestCOSWaitsRejectLegacyConditions requires current completion and readiness signals instead of legacy status conditions. +func TestCOSWaitsRejectLegacyConditions(t *testing.T) { + cos := &ocv1.ClusterObjectSet{ + ObjectMeta: metav1.ObjectMeta{Name: "example-1"}, + Status: ocv1.ClusterObjectSetStatus{Conditions: []metav1.Condition{ + {Type: "Succeeded", Status: metav1.ConditionTrue}, + {Type: "Available", Status: metav1.ConditionTrue}, + }}, + } + m := migrationTestClient(t, cos) + for name, wait := range map[string]func(context.Context, string) error{ + "completion": m.WaitForCOSSucceeded, + "readiness": m.WaitForClusterObjectSetAvailable, + } { + t.Run(name, func(t *testing.T) { + ctx, cancel := context.WithTimeout(context.Background(), 20*time.Millisecond) + defer cancel() + if err := wait(ctx, cos.Name); !errors.Is(err, context.DeadlineExceeded) { + t.Fatalf("legacy conditions must not satisfy wait: %v", err) + } + }) + } +} + +// TestCOSCompletionInvalidSpecification checks that a current invalid-specification condition fails completion promptly. +func TestCOSCompletionInvalidSpecification(t *testing.T) { + for _, generation := range []int64{1, 2} { + cos := &ocv1.ClusterObjectSet{ + ObjectMeta: metav1.ObjectMeta{Name: "example-1", Generation: 2}, + Status: ocv1.ClusterObjectSetStatus{Conditions: []metav1.Condition{{ + Type: ocv1.ClusterObjectSetTypeReady, Status: metav1.ConditionFalse, + Reason: ocv1.ClusterObjectSetReasonInvalidSpecification, + Message: "invalid reference", ObservedGeneration: generation, + }}}, + } + m := migrationTestClient(t, cos) + ctx, cancel := context.WithTimeout(context.Background(), 20*time.Millisecond) + err := m.WaitForCOSSucceeded(ctx, cos.Name) + cancel() + if generation == cos.Generation { + if err == nil || !strings.Contains(err.Error(), "invalid reference") { + t.Fatalf("expected current failure diagnostic, got %v", err) + } + } else if !errors.Is(err, context.DeadlineExceeded) { + t.Fatalf("stale condition must not terminate wait: %v", err) + } + } +} diff --git a/migration/pkg/migration/rollback_recovery_test.go b/migration/pkg/migration/rollback_recovery_test.go index 27a14f9..69954e6 100644 --- a/migration/pkg/migration/rollback_recovery_test.go +++ b/migration/pkg/migration/rollback_recovery_test.go @@ -43,15 +43,16 @@ func (c *orphanRecordingClient) Delete(ctx context.Context, obj client.Object, o return c.Client.Delete(ctx, obj, opts...) } +// TestRollbackRestoresSubscriptionAndOrphansAllOwnedRevisions checks restoration preserves workloads while removing verified revision management. func TestRollbackRestoresSubscriptionAndOrphansAllOwnedRevisions(t *testing.T) { ctx := context.Background() ce := &ocv1.ClusterExtension{ObjectMeta: metav1.ObjectMeta{Name: "widgets", Annotations: map[string]string{ MigratedFromSubscriptionAnnotation: "source/sub", MigrationSubscriptionBackupAnnotation: `{"name":"widgets","source":"catalog","sourceNamespace":"olm","channel":"stable","installPlanApproval":"Manual","startingCSV":"widgets.v1"}`, }}} - first := &ocv1.ClusterObjectSet{ObjectMeta: metav1.ObjectMeta{Name: "widgets-1", Labels: map[string]string{LabelOwnerName: ce.Name}}} - second := &ocv1.ClusterObjectSet{ObjectMeta: metav1.ObjectMeta{Name: "widgets-2", Labels: map[string]string{LabelOwnerName: ce.Name}}} - unrelated := &ocv1.ClusterObjectSet{ObjectMeta: metav1.ObjectMeta{Name: "other-1", Labels: map[string]string{LabelOwnerName: "other"}}} + first := &ocv1.ClusterObjectSet{ObjectMeta: metav1.ObjectMeta{Name: "widgets-1", Labels: map[string]string{LabelOwnerName: ce.Name}}, Spec: ocv1.ClusterObjectSetSpec{Group: ce.Name}} + second := &ocv1.ClusterObjectSet{ObjectMeta: metav1.ObjectMeta{Name: "widgets-2", Labels: map[string]string{LabelOwnerName: ce.Name}}, Spec: ocv1.ClusterObjectSetSpec{Group: ce.Name}} + unrelated := &ocv1.ClusterObjectSet{ObjectMeta: metav1.ObjectMeta{Name: "other-1", Labels: map[string]string{LabelOwnerName: "other"}}, Spec: ocv1.ClusterObjectSetSpec{Group: "other"}} deployment := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "operator", Namespace: "source"}} og := &operatorsv1.OperatorGroup{ObjectMeta: metav1.ObjectMeta{Name: "shared", Namespace: "source"}} m := migrationTestClient(t, ce, first, second, unrelated, deployment, og, &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: "source"}}) @@ -87,7 +88,8 @@ func TestRollbackRestoresSubscriptionAndOrphansAllOwnedRevisions(t *testing.T) { } } -func TestRollbackLegacyRevisionAndForeignNameCollision(t *testing.T) { +// TestRollbackRevisionGroupAndForeignNameCollision rejects missing group identities and foreign revisions with colliding names. +func TestRollbackRevisionGroupAndForeignNameCollision(t *testing.T) { for _, owner := range []string{"", "other"} { t.Run("owner="+owner, func(t *testing.T) { ctx := context.Background() @@ -95,7 +97,7 @@ func TestRollbackLegacyRevisionAndForeignNameCollision(t *testing.T) { MigratedFromSubscriptionAnnotation: "source/sub", MigrationSubscriptionBackupAnnotation: `{"name":"widgets","source":"catalog","sourceNamespace":"olm"}`, }}} - revision := &ocv1.ClusterObjectSet{ObjectMeta: metav1.ObjectMeta{Name: "widgets-1", Labels: map[string]string{LabelOwnerName: owner}}} + revision := &ocv1.ClusterObjectSet{ObjectMeta: metav1.ObjectMeta{Name: "widgets-1", Labels: map[string]string{LabelOwnerName: owner}}, Spec: ocv1.ClusterObjectSetSpec{Group: ce.Name}} m := migrationTestClient(t, ce, revision, &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: "source"}}) err := m.Rollback(ctx, Options{ClusterExtensionName: ce.Name, AcknowledgeInstalled: true}) if owner == "" { @@ -103,7 +105,7 @@ func TestRollbackLegacyRevisionAndForeignNameCollision(t *testing.T) { t.Fatal(err) } if err := m.Client.Get(ctx, client.ObjectKeyFromObject(revision), &ocv1.ClusterObjectSet{}); !apierrors.IsNotFound(err) { - t.Fatalf("legacy revision was not removed: %v", err) + t.Fatalf("revision was not removed: %v", err) } return } @@ -161,6 +163,7 @@ type recreatingRevisionClient struct { deletes int } +// Delete simulates a controller creating a late revision during rollback deletion. func (c *recreatingRevisionClient) Delete(ctx context.Context, obj client.Object, opts ...client.DeleteOption) error { if _, ok := obj.(*ocv1.ClusterObjectSet); !ok { return c.Client.Delete(ctx, obj, opts...) @@ -172,17 +175,18 @@ func (c *recreatingRevisionClient) Delete(ctx context.Context, obj client.Object if c.deletes == 1 { return c.Create(ctx, &ocv1.ClusterObjectSet{ObjectMeta: metav1.ObjectMeta{ Name: obj.GetName(), UID: types.UID("replacement"), Labels: map[string]string{LabelOwnerName: "widgets"}, - }}) + }, Spec: ocv1.ClusterObjectSetSpec{Group: "widgets"}}) } return nil } +// TestRollbackDeletesRevisionRecreatedDuringDeletion checks that late verified revisions are removed before restoration. func TestRollbackDeletesRevisionRecreatedDuringDeletion(t *testing.T) { ctx := context.Background() ce := &ocv1.ClusterExtension{ObjectMeta: metav1.ObjectMeta{Name: "widgets"}} revision := &ocv1.ClusterObjectSet{ObjectMeta: metav1.ObjectMeta{ Name: "widgets-2", UID: types.UID("original"), Labels: map[string]string{LabelOwnerName: "widgets"}, - }} + }, Spec: ocv1.ClusterObjectSetSpec{Group: "widgets"}} m := migrationTestClient(t, ce, revision) recreator := &recreatingRevisionClient{Client: m.Client} m.Client = recreator @@ -206,14 +210,15 @@ func (c *revisionDeleteFailureClient) Delete(ctx context.Context, obj client.Obj return c.Client.Delete(ctx, obj, opts...) } +// TestRollbackRevisionDeleteFailureKeepsBackupForRetry preserves migration backup data when revision deletion fails. func TestRollbackRevisionDeleteFailureKeepsBackupForRetry(t *testing.T) { ctx := context.Background() ce := &ocv1.ClusterExtension{ObjectMeta: metav1.ObjectMeta{Name: "widgets", Annotations: map[string]string{ MigratedFromSubscriptionAnnotation: "source/sub", MigrationSubscriptionBackupAnnotation: `{"name":"widgets","source":"catalog","sourceNamespace":"olm"}`, }}} - first := &ocv1.ClusterObjectSet{ObjectMeta: metav1.ObjectMeta{Name: "widgets-1", Labels: map[string]string{LabelOwnerName: ce.Name}}} - second := &ocv1.ClusterObjectSet{ObjectMeta: metav1.ObjectMeta{Name: "widgets-2", Labels: map[string]string{LabelOwnerName: ce.Name}}} + first := &ocv1.ClusterObjectSet{ObjectMeta: metav1.ObjectMeta{Name: "widgets-1", Labels: map[string]string{LabelOwnerName: ce.Name}}, Spec: ocv1.ClusterObjectSetSpec{Group: ce.Name}} + second := &ocv1.ClusterObjectSet{ObjectMeta: metav1.ObjectMeta{Name: "widgets-2", Labels: map[string]string{LabelOwnerName: ce.Name}}, Spec: ocv1.ClusterObjectSetSpec{Group: ce.Name}} m := migrationTestClient(t, ce, first, second, &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: "source"}}) m.Client = &revisionDeleteFailureClient{Client: m.Client, failName: second.Name, failOnce: true} if err := m.Rollback(ctx, Options{ClusterExtensionName: ce.Name, AcknowledgeInstalled: true}); err == nil || !strings.Contains(err.Error(), "revision deletion forbidden") { @@ -340,12 +345,13 @@ func TestRecoverFromBackupTimeoutPreservesRecreatedSubscription(t *testing.T) { } } +// TestCleanupConflictPreservesSharedOperatorGroupAndOLMv1Management protects shared groups and active OLMv1 ownership during conflict cleanup. func TestCleanupConflictPreservesSharedOperatorGroupAndOLMv1Management(t *testing.T) { ctx := context.Background() ce := &ocv1.ClusterExtension{ObjectMeta: metav1.ObjectMeta{Name: "widgets", Annotations: map[string]string{ MigratedFromSubscriptionAnnotation: "source/sub", }}, Spec: ocv1.ClusterExtensionSpec{Source: ocv1.SourceConfig{Catalog: &ocv1.CatalogFilter{PackageName: "widgets"}}}} - cos := &ocv1.ClusterObjectSet{ObjectMeta: metav1.ObjectMeta{Name: "widgets-2", Labels: map[string]string{LabelOwnerName: ce.Name}}} + cos := &ocv1.ClusterObjectSet{ObjectMeta: metav1.ObjectMeta{Name: "widgets-2", Labels: map[string]string{LabelOwnerName: ce.Name}}, Spec: ocv1.ClusterObjectSetSpec{Group: ce.Name}} sub := &operatorsv1alpha1.Subscription{ObjectMeta: metav1.ObjectMeta{Name: "sub", Namespace: "source"}, Status: operatorsv1alpha1.SubscriptionStatus{InstalledCSV: "widgets.v1"}} csv := &operatorsv1alpha1.ClusterServiceVersion{ObjectMeta: metav1.ObjectMeta{Name: "widgets.v1", Namespace: "source"}} condition := &operatorsv1.OperatorCondition{ObjectMeta: metav1.ObjectMeta{Name: csv.Name, Namespace: csv.Namespace}} diff --git a/migration/pkg/migration/rollback_release.go b/migration/pkg/migration/rollback_release.go index e3f7ed5..92f1f7b 100644 --- a/migration/pkg/migration/rollback_release.go +++ b/migration/pkg/migration/rollback_release.go @@ -317,27 +317,6 @@ func (m *Migrator) waitForRollbackRevisionsRemoved(ctx context.Context, ce *ocv1 if err := m.listMigrationRevisions(ctx, ce, &revisions); err != nil { return false, err } - migrationName := ce.Name + "-1" - foundMigrationRevision := false - for i := range revisions.Items { - if revisions.Items[i].Name == migrationName { - foundMigrationRevision = true - break - } - } - if !foundMigrationRevision { - var migrationRevision ocv1.ClusterObjectSet - err := m.Client.Get(ctx, client.ObjectKey{Name: migrationName}, &migrationRevision) - if client.IgnoreNotFound(err) != nil { - return false, err - } - if err == nil { - if err := m.validateRollbackRevision(ctx, &migrationRevision, ce); err != nil { - return false, err - } - revisions.Items = append(revisions.Items, migrationRevision) - } - } if len(revisions.Items) == 0 { emptyObservations++ return emptyObservations >= 3, nil @@ -367,7 +346,7 @@ func (m *Migrator) waitForRollbackRevisionsRemoved(ctx context.Context, ce *ocv1 } // releaseRevisionObjects waits for orphan propagation, then removes metadata -// written by the old object controller. The UID and recorded metadata guard +// written by the revisions being removed. The UID and recorded metadata guard // against modifying an object replaced or adopted during rollback. func (m *Migrator) releaseRevisionObjects(ctx context.Context, objects []rollbackObject) error { for _, original := range objects { diff --git a/migration/pkg/migration/unit_test.go b/migration/pkg/migration/unit_test.go index abecc35..f1e5d30 100644 --- a/migration/pkg/migration/unit_test.go +++ b/migration/pkg/migration/unit_test.go @@ -43,7 +43,7 @@ type failingMigrationClient struct { unknownCOSCreate bool failCECreate bool failCEAfterCreate bool - blockCOS bool + invalidCOS bool succeedCOS bool } @@ -65,6 +65,7 @@ func (c canceledScaleClient) Update(ctx context.Context, obj client.Object, opts return c.Client.Update(ctx, obj, opts...) } +// Create injects configured creation failures for migration recovery tests. func (c failingMigrationClient) Create(ctx context.Context, obj client.Object, opts ...client.CreateOption) error { if c.failCOSCreate { if _, ok := obj.(*ocv1.ClusterObjectSet); ok { @@ -91,19 +92,20 @@ func (c failingMigrationClient) Create(ctx context.Context, obj client.Object, o } if c.succeedCOS { if cos, ok := obj.(*ocv1.ClusterObjectSet); ok { + cos.Status.CompletedAt = metav1.Now() cos.Status.Conditions = []metav1.Condition{ - {Type: "Succeeded", Status: metav1.ConditionTrue}, - {Type: "Available", Status: metav1.ConditionTrue}, + {Type: ocv1.ClusterObjectSetTypeReady, Status: metav1.ConditionTrue}, } } } return c.Client.Create(ctx, obj, opts...) } +// Get injects configured read failures for migration recovery tests. func (c failingMigrationClient) Get(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error { - if c.blockCOS { + if c.invalidCOS { if cos, ok := obj.(*ocv1.ClusterObjectSet); ok { - cos.Status.Conditions = []metav1.Condition{{Type: "Succeeded", Status: metav1.ConditionFalse, Reason: "Blocked"}} + cos.Status.Conditions = []metav1.Condition{{Type: ocv1.ClusterObjectSetTypeReady, Status: metav1.ConditionFalse, Reason: ocv1.ClusterObjectSetReasonInvalidSpecification}} return nil } } @@ -1699,11 +1701,12 @@ func TestCreateMigrationResourcesPreservesTrackedCOSAfterClusterExtensionFailure } } +// TestCreateClusterObjectSetCleansSecretsAfterReadinessFailure checks failed staging cleans its owned Secret artifacts. func TestCreateClusterObjectSetCleansSecretsAfterReadinessFailure(t *testing.T) { ctx := context.Background() m := migrationTestClient(t, establishedClusterObjectSetCRD()) baseClient := m.Client - m.Client = failingMigrationClient{Client: baseClient, blockCOS: true} + m.Client = failingMigrationClient{Client: baseClient, invalidCOS: true} object := unstructured.Unstructured{Object: map[string]interface{}{ "apiVersion": "v1", "kind": "ConfigMap", "metadata": map[string]interface{}{"name": "operator-config", "namespace": "ns"}, }} @@ -1778,10 +1781,11 @@ func TestRecoverCreatedMigrationResourcesPreservesActiveTargetResources(t *testi } } +// TestWaitForClusterObjectSetAvailable requires the current Ready condition for workload availability. func TestWaitForClusterObjectSetAvailable(t *testing.T) { ctx := context.Background() cos := &ocv1.ClusterObjectSet{ObjectMeta: metav1.ObjectMeta{Name: "sub-1"}, Status: ocv1.ClusterObjectSetStatus{Conditions: []metav1.Condition{{ - Type: "Available", Status: metav1.ConditionTrue, + Type: ocv1.ClusterObjectSetTypeReady, Status: metav1.ConditionTrue, }}}} m := migrationTestClient(t, cos) if err := m.WaitForClusterObjectSetAvailable(ctx, cos.Name); err != nil { diff --git a/specs/20260821-migration-v0-to-v1/e2e.md b/specs/20260821-migration-v0-to-v1/e2e.md index 2dceb07..a8910c7 100644 --- a/specs/20260821-migration-v0-to-v1/e2e.md +++ b/specs/20260821-migration-v0-to-v1/e2e.md @@ -134,7 +134,7 @@ The currently implemented coverage is described in the Fixtures and CI sections. | Validation IDs | Scenario | Required assertions | |---|---|---| -| V1.1, V1.2, V1.3, V3.1–V3.7 | Baseline fixture migration | `check`, dry-run, COS `Succeeded=True` before CE creation, CE `Installed=True`, field mappings, CE backups/audit, Sub/CSV cleanup. | +| V1.1, V1.2, V1.3, V3.1–V3.7 | Baseline fixture migration | `check`, dry-run, COS `status.completedAt` and `Ready=True` before CE creation, CE `Installed=True`, field mappings, CE backups/audit, Sub/CSV cleanup. | | V4.7 | Cross-namespace fixture migration | Target namespace is created with copied PSA/SCC labels; source Deployments are scaled to zero before target creation; CE and rendered Deployment use the target; collected source Deployment is removed while the source namespace remains. | | V4.7 | Acknowledged live namespace deletion | A real OLMv0 installation is converted with `--acknowledge-namespace-delete`; after CE installation in the target namespace, OLMv0 finalizes the CSV and the source namespace is deleted. | | V4.8 | System-managed namespace fixture migration | Against the experimental controller profile, verify the explicit opt-in omits `spec.namespace`, migration imports the prepared bundle-metadata namespace into its COS, the catalog COS takes ownership, OLMv1 manages the target Deployment there, and source copies are removed. Unit tests verify unsupported CRDs reject the mode before mutation. | diff --git a/specs/20260821-migration-v0-to-v1/plan.md b/specs/20260821-migration-v0-to-v1/plan.md index bd75f9c..901d843 100644 --- a/specs/20260821-migration-v0-to-v1/plan.md +++ b/specs/20260821-migration-v0-to-v1/plan.md @@ -132,7 +132,7 @@ flag is set; CE carries the matching annotation. CSV-associated InstallPlans (R2.6; deduplicate by namespace/name) → collect (primary: `Operator` CR `status.components.refs`; supplementary: `olm.owner` label query, ownerRef query, InstallPlan steps; dedup by GVK+ns+name — see R5) → create COS (wait - `Succeeded=True`) → create CE → cleanup. + `status.completedAt` and `Ready=True`) → create CE → cleanup. `--dry-run` previews without mutation. `--all` prints the four-section summary, then converts each Eligible operator; `--continue-on-error` to keep going. Batch classification uses the requested acknowledgment overrides; `-n` and `--ce-name` are rejected with `--all`. diff --git a/specs/20260821-migration-v0-to-v1/requirements.md b/specs/20260821-migration-v0-to-v1/requirements.md index 8f7a4c1..fa74913 100644 --- a/specs/20260821-migration-v0-to-v1/requirements.md +++ b/specs/20260821-migration-v0-to-v1/requirements.md @@ -168,7 +168,7 @@ COD-generated COS revisions receive this label from object-controller. The two manager values apply to different resources and must not be interchanged. Use the current revision object union (`type: InlineManifest` with `inlineManifest`, or `type: SecretReference` with `secretRef`). COS and COD are experimental APIs; -compatibility with older COS/COD schemas is not supported. Install a controller +compatibility with older COS/COD schemas and COS `Succeeded`/`Available` conditions is not supported. COS completion uses `status.completedAt`, and workload readiness uses `Ready=True`. Install a controller with matching API definitions before migration. Reject existing deployments/revision groups before destructive work. Rollback must stop the deployment with orphan deletion before removing revisions and restoring OLMv0 management. diff --git a/specs/20260821-migration-v0-to-v1/validation.md b/specs/20260821-migration-v0-to-v1/validation.md index 4ac7b4a..71cba89 100644 --- a/specs/20260821-migration-v0-to-v1/validation.md +++ b/specs/20260821-migration-v0-to-v1/validation.md @@ -15,7 +15,7 @@ kind cluster with both OLMv0 and OLMv1 installed. - **V1.2** `convert -n --dry-run` lists every resource that would be migrated (grouped by kind), including CRDs, and reports the detected COS or COD manager with `CollisionProtection: None` on the COS or COD template; makes no cluster changes. - **V1.3** `convert -n ` results in a `ClusterExtension` reaching `Installed=True`; the `Subscription` and `CSV` are deleted; CRDs remain and are adopted by OLMv1. In direct COS mode, the COS sets `status.completedAt` before the CE is created. In COD mode, the COD's current-generation rollout completes and becomes available before the CE is created; the CE then owns the same COD and its catalog revision uses `CollisionProtection: Prevent`. - **V1.4** `rollback --acknowledge-installed` starts CE orphan deletion with a rollback finalizer to stop new revisions, records verified ownership from in-flight replacement revisions before deleting them, waits for orphaned resources to lose COS controller references, removes their OLMv1 revision metadata, restores the `Subscription` from the backup annotation, then removes the CE finalizer. A matching Subscription from a prior attempt permits retry; a conflicting Subscription or failed restoration retains the CE backup. The operator returns to OLMv0 management (`AtLatestKnown`/`UpgradePending`), and a subsequent migration can adopt preserved resources. Without `--acknowledge-installed` on an `Installed=True` CE, rollback refuses and exits non-zero. - In COD mode, verify CE-to-COD and COD-to-COS ownership and stop the COD with orphan deletion before removing its COS revisions, preventing replacement revisions during rollback. Before deletion and during subsequent revision discovery, reject controlled COS revisions unless the controller's API version, kind, name, and UID match the CE or its verified COD. Retain support for unowned legacy or orphaned revisions with matching migration identity. Preserve workloads and retain the CE backup if cleanup or restoration fails. + In COD mode, verify CE-to-COD and COD-to-COS ownership and stop the COD with orphan deletion before removing its COS revisions, preventing replacement revisions during rollback. Before deletion and during subsequent revision discovery, reject controlled COS revisions unless the controller's API version, kind, name, and UID match the CE or its verified COD. Require the current `spec.group` identity even for unowned staging or orphaned revisions; a name or owner label alone cannot authorize deletion. Preserve workloads and retain the CE backup if cleanup or restoration fails. - **V1.5** `cleanup ` on a Conflict state deletes the `Subscription` and OLMv0 artifacts (Operator CR, OperatorCondition, copied CSVs, OperatorGroup if last) and leaves the CE intact. - **V1.6** `check --all` and `convert --all` print sections in order Conflict → Ineligible → AlreadyMigrated → Eligible; Conflicts are never auto-migrated; `convert --all` migrates only the Eligible operators. Batch acknowledgment flags affect classification before selection; `convert --all` rejects `-n` and `--ce-name` rather than ignoring them. - **V1.7** `convert --all` stops on the first failure by default; with `--continue-on-error` it logs the failure and continues, exiting non-zero if any operator failed. diff --git a/test/e2e/migration/e2e_test.go b/test/e2e/migration/e2e_test.go index 048de63..be5cd4f 100644 --- a/test/e2e/migration/e2e_test.go +++ b/test/e2e/migration/e2e_test.go @@ -352,7 +352,7 @@ func TestPrecreatedClusterObjectSetSupersession(t *testing.T) { t.Fatal("migration COS lacks the object-controller adoption label") } if !cosSucceeded(before.Items[0]) { - t.Fatal("pre-existing COS did not reach Succeeded=True before CE creation") + t.Fatal("pre-existing COS did not set status.completedAt before CE creation") } if before.Items[0].Spec.CollisionProtection != ocv1.CollisionProtectionNone { t.Fatalf("migration COS collisionProtection = %q, want %q", before.Items[0].Spec.CollisionProtection, ocv1.CollisionProtectionNone) @@ -423,16 +423,9 @@ func TestPrecreatedClusterObjectSetSupersession(t *testing.T) { } } +// cosSucceeded reports revision completion through completedAt, without legacy condition fallbacks. func cosSucceeded(cos ocv1.ClusterObjectSet) bool { - if !cos.Status.CompletedAt.IsZero() { - return true - } - for _, condition := range cos.Status.Conditions { - if condition.Type == "Succeeded" && condition.Status == metav1.ConditionTrue { - return true - } - } - return false + return !cos.Status.CompletedAt.IsZero() } func newMigrator(t *testing.T) (*migration.Migrator, client.Client, *rest.Config) {