Skip to content
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
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
5 changes: 3 additions & 2 deletions migration/examples/cmd/migrate-operators-v0-to-v1/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,12 @@ func printDryRunPreview(opts, resourceOpts migration.Options, info *migration.Mi
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("ClusterObjectSet:", fmt.Sprintf("%s-1 (CollisionProtection: None; adopted by the COD)", opts.ClusterExtensionName))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor/non-blocking: could we make the corresponding change in dryRunRecord too? That function still clears cosName when UseClusterObjectDeployment is true, so convert --dry-run --output=jsonl omits cluster_object_set, even though this path now explicitly creates both the initial COS and the COD. The human preview here correctly lists both.

Keeping cosName as <ce-name>-1 and setting only codName conditionally would make the structured preview match the new staging protocol. Please also cover both fields in COD mode: assertStructuredCheckAndPreview currently accepts either one, so it misses this discrepancy. I reproduced it with a focused test: COS-only includes the initial COS, while COS+COD omits it.

detail("ClusterObjectDeployment:", fmt.Sprintf("%s (wait for rollout completion and availability before creating the ClusterExtension)", opts.ClusterExtensionName))
detail("Template CollisionProtection:", "Prevent")
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))
detail("ClusterObjectSet:", fmt.Sprintf("%s-1 (CollisionProtection: None; wait for completion before creating the ClusterExtension)", opts.ClusterExtensionName))
fmt.Printf("\n Resources that would be placed into ClusterObjectSet %s-1:\n", opts.ClusterExtensionName)
}

Expand All @@ -303,7 +305,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 Down
18 changes: 10 additions & 8 deletions migration/pkg/migration/create_rejection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,29 +41,31 @@ func TestMigrationCreateRejectionRecovery(t *testing.T) {
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:
_, isCOS := obj.(*ocv1.ClusterObjectSet)
_, isCOD := obj.(*ocv1.ClusterObjectDeployment)
if mode == "COS" && isCOS || mode == "COD" && isCOD {
attempted = true
return tc.err
default:
return c.Create(ctx, obj, opts...)
}
return c.Create(ctx, obj, opts...)
},
})
m.Client = failingMigrationClient{Client: m.Client, succeedCOS: true}
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)
wantActive := tc.ambiguous || mode == "COD"
if result.TargetMayBeActive != wantActive {
t.Fatalf("TargetMayBeActive = %v, want %v", result.TargetMayBeActive, wantActive)
}
var restored operatorsv1alpha1.Subscription
getErr := m.Client.Get(ctx, client.ObjectKeyFromObject(sub), &restored)
if tc.ambiguous {
if wantActive {
if !apierrors.IsNotFound(getErr) {
t.Fatalf("ambiguous create restored OLMv0: %v", getErr)
t.Fatalf("potentially active migration 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)
Expand Down
20 changes: 17 additions & 3 deletions migration/pkg/migration/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package migration
import (
"context"
"encoding/json"
"errors"
"fmt"
"regexp"
"slices"
Expand Down Expand Up @@ -98,19 +99,27 @@ func (m *Migrator) createClusterObjectDeployment(ctx context.Context, opts Optio

// 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 collision error
err := wait.PollUntilContextTimeout(ctx, cosWaitPollInterval, cosWaitTimeout, true, func(ctx context.Context) (bool, error) {
var cod ocv1.ClusterObjectDeployment
if err := m.Client.Get(ctx, client.ObjectKeyFromObject(created), &cod); err != nil {
return false, err
}
if cod.UID != created.UID || cod.Generation != created.Generation || cod.DeletionTimestamp != nil {
return false, fmt.Errorf("migration ClusterObjectDeployment %s was replaced, changed or deleted", cod.Name)
}
collision = nil
progress := apimeta.FindStatusCondition(cod.Status.Conditions, ocv1.ClusterObjectDeploymentTypeProgressing)
available := apimeta.FindStatusCondition(cod.Status.Conditions, ocv1.ClusterObjectDeploymentTypeAvailable)
if progress != nil && progress.ObservedGeneration == cod.Generation {
if progress.Status == metav1.ConditionFalse && progress.Reason != ocv1.ClusterObjectDeploymentReasonNewClusterObjectSetProgressed {
return false, fmt.Errorf("ClusterObjectDeployment %s rollout failed (%s): %s", cod.Name, progress.Reason, progress.Message)
failure := fmt.Errorf("ClusterObjectDeployment %s rollout failed (%s): %s", cod.Name, progress.Reason, progress.Message)
if progress.Reason != ocv1.ClusterObjectDeploymentReasonRevisionObjectCollision {
return false, failure
}
// Ownership can briefly collide while sibling revisions hand off.
// Continue observing; only actual completion permits migration.
collision = failure
}
if progress.Status == metav1.ConditionFalse && progress.Reason == ocv1.ClusterObjectDeploymentReasonNewClusterObjectSetProgressed &&
available != nil && available.ObservedGeneration == cod.Generation && available.Status == metav1.ConditionTrue {
Expand All @@ -120,6 +129,10 @@ func (m *Migrator) waitForDeployment(ctx context.Context, created *ocv1.ClusterO
m.progress(ProgressEvent{Step: ProgressStepCreate, Status: ProgressWaiting, Message: fmt.Sprintf("Waiting for ClusterObjectDeployment %s rollout completion and availability", cod.Name)})
return false, nil
})
if errors.Is(err, context.DeadlineExceeded) || errors.Is(err, context.Canceled) {
return errors.Join(err, collision)
}
return err
}

// rollbackDeployment permits the COD API to be absent, but never hides
Expand Down Expand Up @@ -286,6 +299,7 @@ func buildClusterObjectDeployment(opts Options, info *MigrationInfo, phases []*o
LabelBundleName: info.BundleName,
LabelBundleVersion: info.Version,
}
addStagingBackup(annotations, info)
if info.BundleImage != "" {
annotations[LabelBundleReference] = info.BundleImage
}
Expand All @@ -297,7 +311,7 @@ func buildClusterObjectDeployment(opts Options, info *MigrationInfo, phases []*o
WithMetadata(ocv1ac.ClusterObjectDeploymentTemplateMetadata().
WithLabels(map[string]string{LabelOwnerKind: ocv1.ClusterExtensionKind, LabelOwnerName: opts.ClusterExtensionName}).
WithAnnotations(annotations)).WithSpec(
ocv1ac.ClusterObjectDeploymentTemplateSpec().WithPhases(phases...).WithCollisionProtection(ocv1.CollisionProtectionNone))))
ocv1ac.ClusterObjectDeploymentTemplateSpec().WithPhases(phases...).WithCollisionProtection(ocv1.CollisionProtectionPrevent))))
data, err := json.Marshal(configuration)
if err != nil {
return nil, fmt.Errorf("marshal ClusterObjectDeployment: %w", err)
Expand Down
Loading
Loading