Skip to content
Open
2 changes: 1 addition & 1 deletion migration.mk
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ migration/test-e2e-cos-supersession: migration/build ## Verify migration COS is
mkdir -p "$$(dirname "$$coverage_profile")"; \
KUBECONFIG="$(E2E_FIXTURE_KUBECONFIG)" ./hack/e2e/migration/delete-v1.sh "$$package"; \
KUBECONFIG="$(E2E_FIXTURE_KUBECONFIG)" ./hack/e2e/migration/install-fixture-v0.sh "$$package"; \
KUBECONFIG="$(E2E_FIXTURE_KUBECONFIG)" E2E_ARTIFACTS="$(E2E_ARTIFACTS)/cos-supersession" E2E_SUITE=fixture E2E_COS_SUPERSESSION_TEST=true E2E_NAMESPACE=migration-e2e-ecr-secret E2E_SUBSCRIPTION="$$package" go test -count=1 -tags=e2e -covermode=count -coverpkg=./migration/... -coverprofile="$$coverage_profile" ./test/e2e/migration -run '^TestPrecreatedClusterObjectSetSupersession$$' -timeout "$(E2E_TIMEOUT)"; \
KUBECONFIG="$(E2E_FIXTURE_KUBECONFIG)" E2E_ARTIFACTS="$(E2E_ARTIFACTS)/cos-supersession" E2E_SUITE=fixture E2E_COS_SUPERSESSION_TEST=true E2E_NAMESPACE=migration-e2e-ecr-secret E2E_SUBSCRIPTION="$$package" go test -count=1 -tags=e2e -covermode=count -coverpkg=./migration/... -coverprofile="$$coverage_profile" ./test/e2e/migration -run '^Test(PrecreatedClusterObjectSetSupersession|CODProtectedRolloutCollision)$$' -timeout "$(E2E_TIMEOUT)"; \
if [[ "$(E2E_KEEP_RESOURCES)" != true ]]; then \
KUBECONFIG="$(E2E_FIXTURE_KUBECONFIG)" ./hack/e2e/migration/delete-v1.sh "$$package"; \
else \
Expand Down
21 changes: 6 additions & 15 deletions migration/examples/cmd/migrate-operators-v0-to-v1/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,20 +245,17 @@ func runConvertDryRun(cmd *cobra.Command, m *migration.Migrator, opts migration.
return output.dryRunPreview(opts, resourceOpts, info)
}

// dryRunRecord describes planned COD staging and resource changes without mutating the cluster.
func dryRunRecord(opts, resourceOpts migration.Options, info *migration.MigrationInfo) outputRecord {
kindCounts := make(map[string]int)
for _, obj := range info.CollectedObjects {
kindCounts[obj.GetKind()]++
}
cosName, codName := opts.ClusterExtensionName+"-1", ""
if info.UseClusterObjectDeployment {
cosName, codName = "", opts.ClusterExtensionName
}
return outputRecord{
Type: "dry-run", Command: "convert", Target: opts.SubscriptionNamespace + "/" + opts.SubscriptionName,
Data: dryRunData{
Package: info.PackageName, Version: info.Version, Channel: info.Channel,
ClusterObjectSet: cosName, ClusterObjectDeployment: codName, ClusterExtension: opts.ClusterExtensionName,
ClusterObjectDeployment: opts.ClusterExtensionName, ClusterExtension: opts.ClusterExtensionName,
InstallNamespace: resourceOpts.InstallNamespace, SystemNamespace: info.SystemNamespace,
ManualApproval: info.ManualApproval, KindCounts: kindCounts,
CleanupActions: dryRunCleanupPlan(opts, resourceOpts, info), BackupDirectory: opts.BackupDirectory,
Expand All @@ -269,17 +266,13 @@ func dryRunRecord(opts, resourceOpts migration.Options, info *migration.Migratio
// printDryRunPreview summarizes the planned migration without printing collected resource contents.
// Resource kinds are sorted so repeated previews present the same order.
func printDryRunPreview(opts, resourceOpts migration.Options, info *migration.MigrationInfo) error {
success(fmt.Sprintf("ClusterObjectSet API established; using operator-controller namespace %s", info.SystemNamespace))
success(fmt.Sprintf("ClusterObjectDeployment and ClusterObjectSet APIs established; using operator-controller namespace %s", info.SystemNamespace))

success(fmt.Sprintf("Package: %s Version: %s Channel: %s", info.PackageName, info.Version, valueOrDefault(info.Channel, "(default)")))
fmt.Printf("\n Resources that would be created:\n")
if info.UseClusterObjectDeployment {
detail("ClusterObjectDeployment:", fmt.Sprintf("%s (wait for rollout completion and availability before creating the ClusterExtension)", opts.ClusterExtensionName))
fmt.Printf("\n Resources that would be placed into its template and controller-created COS revisions:\n")
} else {
detail("ClusterObjectSet:", fmt.Sprintf("%s-1 (wait for completion before creating the ClusterExtension)", opts.ClusterExtensionName))
fmt.Printf("\n Resources that would be placed into ClusterObjectSet %s-1:\n", opts.ClusterExtensionName)
}
detail("ClusterObjectDeployment:", fmt.Sprintf("%s (wait for rollout completion and availability before creating the ClusterExtension)", opts.ClusterExtensionName))
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
detail("Template CollisionProtection:", "None initially; Prevent before enabling ClusterExtension adoption")
fmt.Printf("\n Resources that would be placed into its template and controller-created COS revisions:\n")

kindCounts := make(map[string]int)
for _, obj := range info.CollectedObjects {
Expand All @@ -303,7 +296,6 @@ func printDryRunPreview(opts, resourceOpts migration.Options, info *migration.Mi
detail("Version:", "(unset — automatic channel-based upgrades)")
}
detail("Channel:", valueOrDefault(info.Channel, "(none set)"))
detail("CollisionProtection:", "None")

fmt.Printf("\n OLMv0 resources that would be deleted or changed:\n")
for _, line := range dryRunCleanupPlan(opts, resourceOpts, info) {
Expand All @@ -326,7 +318,6 @@ type dryRunData struct {
Package string `json:"package"`
Version string `json:"version"`
Channel string `json:"channel,omitempty"`
ClusterObjectSet string `json:"cluster_object_set,omitempty"`
ClusterObjectDeployment string `json:"cluster_object_deployment,omitempty"`
ClusterExtension string `json:"cluster_extension"`
InstallNamespace string `json:"install_namespace"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,14 @@ func TestDryRunPreviewSortsResourceKinds(t *testing.T) {
if result.err != nil {
t.Fatal(result.err)
}
sections := strings.Split(string(result.output), "Resources that would be placed into ClusterObjectSet widget-1:")
for _, preview := range strings.Split(string(result.output), "Resources that would be created:")[1:] {
protection := strings.Index(preview, "Template CollisionProtection:")
extension := strings.Index(preview, "ClusterExtension that would be created:")
if protection < 0 || extension <= protection || strings.Count(preview, "CollisionProtection:") != 1 {
t.Fatalf("collision protection must appear only with the COD template: %s", preview)
}
}
sections := strings.Split(string(result.output), "Resources that would be placed into its template and controller-created COS revisions:")
if len(sections) != 6 {
t.Fatalf("got %d preview sections, want 5", len(sections)-1)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ func TestDryRunRejectsSystemManagedSourceNamespace(t *testing.T) {
Status: apiextensionsv1.ConditionTrue,
}}},
}
c := fake.NewClientBuilder().WithScheme(scheme).WithObjects(sub, csv, catalog, operatorGroup, cosCRD, ceCRD).Build()
codCRD := cosCRD.DeepCopy()
codCRD.Name = "clusterobjectdeployments.olm.operatorframework.io"
c := fake.NewClientBuilder().WithScheme(scheme).WithObjects(sub, csv, catalog, operatorGroup, cosCRD, codCRD, ceCRD).Build()
m := migration.NewMigrator(c, nil)
cmd := &cobra.Command{}
cmd.SetContext(t.Context())
Expand Down
96 changes: 44 additions & 52 deletions migration/pkg/migration/create_rejection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,59 +16,51 @@ import (

// TestMigrationCreateRejectionRecovery distinguishes definitive create rejection from ambiguous outcomes before restoring OLMv0.
func TestMigrationCreateRejectionRecovery(t *testing.T) {
for _, mode := range []string{"COS", "COD"} {
for _, tc := range []struct {
name string
err error
ambiguous bool
}{
{name: "forbidden", err: apierrors.NewForbidden(schema.GroupResource{Group: ocv1.GroupVersion.Group, Resource: "revisions"}, "example", errors.New("create denied"))},
{name: "invalid", err: apierrors.NewInvalid(schema.GroupKind{Group: ocv1.GroupVersion.Group, Kind: mode}, "example", nil)},
{name: "bad request", err: apierrors.NewBadRequest("rejected")},
{name: "unauthorized", err: apierrors.NewUnauthorized("rejected")},
{name: "timeout", err: apierrors.NewTimeoutError("unknown result", 1), ambiguous: true},
{name: "transport failure", err: errors.New("connection reset"), ambiguous: true},
} {
t.Run(mode+"/"+tc.name, func(t *testing.T) {
ctx := context.Background()
m := migrationTestClient(t)
if mode == "COD" {
crd := establishedClusterObjectDeploymentCRD()
if err := m.Client.Create(ctx, crd); err != nil {
t.Fatal(err)
for _, tc := range []struct {
name string
err error
ambiguous bool
}{
{name: "forbidden", err: apierrors.NewForbidden(schema.GroupResource{Group: ocv1.GroupVersion.Group, Resource: "revisions"}, "example", errors.New("create denied"))},
{name: "invalid", err: apierrors.NewInvalid(schema.GroupKind{Group: ocv1.GroupVersion.Group, Kind: ocv1.ClusterObjectDeploymentKind}, "example", nil)},
{name: "bad request", err: apierrors.NewBadRequest("rejected")},
{name: "unauthorized", err: apierrors.NewUnauthorized("rejected")},
{name: "timeout", err: apierrors.NewTimeoutError("unknown result", 1), ambiguous: true},
{name: "transport failure", err: errors.New("connection reset"), ambiguous: true},
} {
t.Run(tc.name, func(t *testing.T) {
ctx := context.Background()
m := migrationTestClient(t, establishedClusterObjectDeploymentCRD())
attempted := false
m.Client = interceptor.NewClient(m.Client.(client.WithWatch), interceptor.Funcs{
Create: func(ctx context.Context, c client.WithWatch, obj client.Object, opts ...client.CreateOption) error {
switch obj.(type) {
case *ocv1.ClusterObjectDeployment:
attempted = true
return tc.err
default:
return c.Create(ctx, obj, opts...)
}
}
attempted := false
m.Client = interceptor.NewClient(m.Client.(client.WithWatch), interceptor.Funcs{
Create: func(ctx context.Context, c client.WithWatch, obj client.Object, opts ...client.CreateOption) error {
switch obj.(type) {
case *ocv1.ClusterObjectSet, *ocv1.ClusterObjectDeployment:
attempted = true
return tc.err
default:
return c.Create(ctx, obj, opts...)
}
},
})
m.Client = reconcilingSubscriptionClient{Client: m.Client}
sub, _ := healthySubscriptionFixtures()
result, err := m.CreateMigrationResources(ctx, Options{ClusterExtensionName: "example", SubscriptionName: sub.Name, SubscriptionNamespace: sub.Namespace}, &MigrationInfo{}, &Backup{Subscription: sub})
if !attempted || !errors.Is(err, tc.err) {
t.Fatalf("expected create rejection %v, got %v (attempted: %v)", tc.err, err, attempted)
}
if result.TargetMayBeActive != tc.ambiguous {
t.Fatalf("TargetMayBeActive = %v, want %v", result.TargetMayBeActive, tc.ambiguous)
}
var restored operatorsv1alpha1.Subscription
getErr := m.Client.Get(ctx, client.ObjectKeyFromObject(sub), &restored)
if tc.ambiguous {
if !apierrors.IsNotFound(getErr) {
t.Fatalf("ambiguous create restored OLMv0: %v", getErr)
}
} else if getErr != nil || restored.Status.State != operatorsv1alpha1.SubscriptionStateAtLatest {
t.Fatalf("definitive rejection did not restore OLMv0: %v, state %s", getErr, restored.Status.State)
}
},
})
}
m.Client = reconcilingSubscriptionClient{Client: m.Client}
sub, _ := healthySubscriptionFixtures()
result, err := m.CreateMigrationResources(ctx, Options{ClusterExtensionName: "example", SubscriptionName: sub.Name, SubscriptionNamespace: sub.Namespace}, &MigrationInfo{}, &Backup{Subscription: sub})
if !attempted || !errors.Is(err, tc.err) {
t.Fatalf("expected create rejection %v, got %v (attempted: %v)", tc.err, err, attempted)
}
if result.TargetMayBeActive != tc.ambiguous {
t.Fatalf("TargetMayBeActive = %v, want %v", result.TargetMayBeActive, tc.ambiguous)
}
var restored operatorsv1alpha1.Subscription
getErr := m.Client.Get(ctx, client.ObjectKeyFromObject(sub), &restored)
if tc.ambiguous {
if !apierrors.IsNotFound(getErr) {
t.Fatalf("ambiguous create restored OLMv0: %v", getErr)
}
} else if getErr != nil || restored.Status.State != operatorsv1alpha1.SubscriptionStateAtLatest {
t.Fatalf("definitive rejection did not restore OLMv0: %v, state %s", getErr, restored.Status.State)
}
})
}
}
Loading
Loading