diff --git a/.github/workflows/migration-test.yaml b/.github/workflows/migration-test.yaml index cce092a..0cc2449 100644 --- a/.github/workflows/migration-test.yaml +++ b/.github/workflows/migration-test.yaml @@ -102,24 +102,16 @@ jobs: timeout-minutes: 90 env: E2E_FIXTURE_CLUSTER_NAME: library-olm-cod-e2e - E2E_FIXTURE_KUBECONFIG: ${{ github.workspace }}/operator-controller/.kubeconfig/library-olm-cod-e2e.kubeconfig + E2E_FIXTURE_KUBECONFIG: ${{ github.workspace }}/.kubeconfig/library-olm-cod-e2e.kubeconfig E2E_COVERAGE_DIR: ${{ github.workspace }}/artifacts/e2e/coverage/cod steps: - uses: actions/checkout@v7 with: persist-credentials: false - - uses: actions/checkout@v7 - with: - repository: operator-framework/operator-controller - ref: 77754d81ea0125d3a850e9fa57decf7a7255a409 - path: operator-controller - persist-credentials: false - uses: actions/setup-go@v7 with: go-version-file: go.mod - - name: Build and deploy pinned COD-capable controller - run: make -C operator-controller run-experimental KIND_CLUSTER_NAME=library-olm-cod-e2e K8S_VERSION=1.37 - - name: Install committed OLMv0 fixtures and catalog + - name: Install pinned controller, OLMv0 APIs, and fixture catalog run: make migration/e2e-fixture-setup - name: Verify COD handoff and catalog revision run: make migration/test-e2e-cos-supersession @@ -148,7 +140,9 @@ jobs: with: go-version-file: go.mod - name: Run in-cluster migration Job test - run: make migration/test-e2e-in-cluster-job + run: | + make migration/e2e-fixture-setup + make migration/test-e2e-in-cluster-job - name: Tear down fixture cluster if: always() run: E2E_CLUSTER_NAME=library-olm-fixture-e2e make migration/e2e-teardown diff --git a/go.mod b/go.mod index 6638d62..5729b25 100644 --- a/go.mod +++ b/go.mod @@ -8,16 +8,16 @@ require ( github.com/opencontainers/go-digest v1.0.0 github.com/opencontainers/image-spec v1.1.1 github.com/operator-framework/api v0.46.0 - github.com/operator-framework/operator-controller v1.12.1-0.20261106151730-77754d81ea01 + github.com/operator-framework/operator-controller v1.12.1-0.20261111152305-9dd683afa190 github.com/spf13/cobra v1.10.2 github.com/stretchr/testify v1.12.1 go.podman.io/image/v5 v5.42.0 golang.org/x/sync v0.25.0 helm.sh/helm/v4 v4.3.1 - k8s.io/api v0.37.1 + k8s.io/api v0.37.2 k8s.io/apiextensions-apiserver v0.37.1 - k8s.io/apimachinery v0.37.1 - k8s.io/client-go v0.37.1 + k8s.io/apimachinery v0.37.2 + k8s.io/client-go v0.37.2 k8s.io/utils v0.0.0-20260626114624-be93311217bd oras.land/oras-go/v2 v2.7.0 sigs.k8s.io/controller-runtime v0.25.2 @@ -77,6 +77,7 @@ require ( github.com/google/go-containerregistry v0.22.1 // indirect github.com/google/uuid v1.6.0 // indirect github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674 // indirect + github.com/hashicorp/go-uuid v1.0.3 // indirect github.com/ianlancetaylor/demangle v0.0.0-20240805132620-81f5be970eca // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/json-iterator/go v1.1.12 // indirect @@ -96,13 +97,14 @@ require ( github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/opencontainers/runtime-spec v1.3.0 // indirect + github.com/pandatix/go-abnf v0.5.1 // indirect github.com/peterbourgon/diskv v2.0.1+incompatible // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/proglottis/gpgme v0.1.6 // indirect github.com/prometheus/client_golang v1.25.0 // indirect github.com/prometheus/client_model v0.6.3 // indirect - github.com/prometheus/common v0.72.1 // indirect + github.com/prometheus/common v0.73.0 // indirect github.com/prometheus/procfs v0.22.0 // indirect github.com/santhosh-tekuri/jsonschema/v6 v6.0.3 // indirect github.com/secure-systems-lab/go-securesystemslib v0.11.1 // indirect @@ -136,10 +138,10 @@ require ( google.golang.org/protobuf v1.36.12 // indirect gopkg.in/evanphx/json-patch.v4 v4.13.0 // indirect gopkg.in/inf.v0 v0.9.1 // indirect - k8s.io/cli-runtime v0.37.1 // indirect + k8s.io/cli-runtime v0.37.2 // indirect k8s.io/klog/v2 v2.140.0 // indirect k8s.io/kube-openapi v0.0.0-20260721132016-d427ff9ee9ad // indirect - k8s.io/streaming v0.37.1 // indirect + k8s.io/streaming v0.37.2 // indirect sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730 // indirect sigs.k8s.io/kustomize/api v0.21.1 // indirect sigs.k8s.io/kustomize/kyaml v0.21.2 // indirect diff --git a/go.sum b/go.sum index 4d0e460..73c5e75 100644 --- a/go.sum +++ b/go.sum @@ -206,6 +206,8 @@ github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674 h1:JeSE6pjso5T github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674/go.mod h1:r4w70xmWCQKmi1ONH4KIaBptdivuRPyosB9RmPlGEwA= github.com/grpc-ecosystem/grpc-gateway/v2 v2.29.0 h1:5VipnvEpbqr2gA2VbM+nYVbkIF28c5ZQfqCBQ5g2xfk= github.com/grpc-ecosystem/grpc-gateway/v2 v2.29.0/go.mod h1:Hyl3n6Twe1hvtd9XUXDec4pTvgMSEixRuQKPTMH2bNs= +github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8= +github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/golang-lru v1.0.2 h1:dV3g9Z/unq5DpblPpw+Oqcv4dU/1omnb4Ok8iPY6p1c= github.com/hashicorp/golang-lru/arc/v2 v2.0.5 h1:l2zaLDubNhW4XO3LnliVj0GXO3+/CGNJAg1dcN2Fpfw= github.com/hashicorp/golang-lru/arc/v2 v2.0.5/go.mod h1:ny6zBSQZi2JxIeYcv7kt2sH2PXJtirBN7RDhRpxPkxU= @@ -263,8 +265,10 @@ github.com/opencontainers/runtime-spec v1.3.0 h1:YZupQUdctfhpZy3TM39nN9Ika5CBWT5 github.com/opencontainers/runtime-spec v1.3.0/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0= github.com/operator-framework/api v0.46.0 h1:EitSlfRJZKYDewTK+ntH9L/p+NIKv/L1PgRoaIWH+to= github.com/operator-framework/api v0.46.0/go.mod h1:oFXzh7rHCnMwC6N0B92NEsfQyLGJ7FrceAYemjwoKPI= -github.com/operator-framework/operator-controller v1.12.1-0.20261106151730-77754d81ea01 h1:WD3OW21Z7b1lz6I5CGgDkZ2ljZlmgQ/kt3bStqEGjno= -github.com/operator-framework/operator-controller v1.12.1-0.20261106151730-77754d81ea01/go.mod h1:9H3hReMjs2wU5XRaFj2GT1hJMNzKtNpgQFuAm6/sBgc= +github.com/operator-framework/operator-controller v1.12.1-0.20261111152305-9dd683afa190 h1:Ei8X96MuWB44u6rQLTD3hEjrglf0XLBHh+S58gfrv5U= +github.com/operator-framework/operator-controller v1.12.1-0.20261111152305-9dd683afa190/go.mod h1:v1y3MkrEMhVlaqqlixF0jwIseBxQvOc06hAreXMWLmQ= +github.com/pandatix/go-abnf v0.5.1 h1:iyLvSu2Aq12iE0r4n948Qw21BHDuckLq/8WIXAAF+HI= +github.com/pandatix/go-abnf v0.5.1/go.mod h1:VBmbtpFgQNEaQpyAvmi+Ecd9wAYJKzA3TmiB3L93sVg= github.com/peterbourgon/diskv v2.0.1+incompatible h1:UBdAOUP5p4RWqPBg048CAvpKN+vxiaj6gdUUzhl4XmI= github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= @@ -279,8 +283,8 @@ github.com/prometheus/client_golang v1.25.0/go.mod h1:j2X/4/kaQHLPnmyEU8zjmkndo1 github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.6.3 h1:O0jaTVAYNxTHYInEPFJt5I3+sN8zqBtVMPTB1qyxiEo= github.com/prometheus/client_model v0.6.3/go.mod h1:gpN5P9S7Rr6Yr92PiQ+Ixvhf6JZEkF1dnxsYL2aPBEM= -github.com/prometheus/common v0.72.1 h1:ZAiQed/nk8IIcsdzb2TlJu23NEUDyDLQ9TXTN2WRK6Y= -github.com/prometheus/common v0.72.1/go.mod h1:1IoBY4IRaJnhs2ESjNzjilP1cJ/P8pimGoomq7zRXrA= +github.com/prometheus/common v0.73.0 h1:NGIOmVi8jrgiiPQgXxD6rP0FfxFsuZxnMQkel0qBy/g= +github.com/prometheus/common v0.73.0/go.mod h1:Nt+CsVkf/mj4wDAmtSwq1HTPohHSX6fMr6+/f9B5UqM= github.com/prometheus/otlptranslator v1.0.0 h1:s0LJW/iN9dkIH+EnhiD3BlkkP5QVIUVEoIwkU+A6qos= github.com/prometheus/otlptranslator v1.0.0/go.mod h1:vRYWnXvI6aWGpsdY/mOT/cbeVRBlPWtBNDb7kGR3uKM= github.com/prometheus/procfs v0.22.0 h1:6q9+/JL9IKAPbCmBrv9n5O5Ty3NKnciV5X7YGw0oics= @@ -490,26 +494,26 @@ helm.sh/helm/v4 v4.3.1 h1:UndCoLe9UPmNoL7IvWzaUXveL7T5t/ijoorEmgJdI9g= helm.sh/helm/v4 v4.3.1/go.mod h1:Z663D/wNQG1UsG3X7svSEBPvosFVel4SIw4YIMZwmuY= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -k8s.io/api v0.37.1 h1:l6N77U7tjwB5L056bgrBTJIEdevac/naBZ3iSvDNfpM= -k8s.io/api v0.37.1/go.mod h1:zSlbB1YpJ1YQlFVQy20UYll81UJSJJUMLhkhvg6Z78M= +k8s.io/api v0.37.2 h1:PnxqnUFy93jr2GcpWDkKOm8wfy25kT9wa572MuQS8oc= +k8s.io/api v0.37.2/go.mod h1:+NVRLft99kx+Jg9v34GmHw867Dapim89TSyCsn2hK+M= k8s.io/apiextensions-apiserver v0.37.1 h1:7fIQG8eThDSTVYBWg/DOpI8v5wYfKCo0N8/TDMjj+zY= k8s.io/apiextensions-apiserver v0.37.1/go.mod h1:1Q3ujWwHgnhBoGsdmGORflwK1sDFmuaqH1OsMDWk2Gs= -k8s.io/apimachinery v0.37.1 h1:hGCYyvKHCwtwMitj2vU4vYx0Z16N9GyZk9BBnz0wDAE= -k8s.io/apimachinery v0.37.1/go.mod h1:jF84AyUi/IRIXRot5f+lm6MpxoWI+F1XgjaMmwCdTFw= -k8s.io/apiserver v0.37.1 h1:dUsNwjsvItyVKNpC1N0AhQ0OBSiUJKfWz004vPifOe0= -k8s.io/apiserver v0.37.1/go.mod h1:EWXW6PntGfOC2uD9GGVobnOExgFoX1z0hZo7f7Rs7Ng= -k8s.io/cli-runtime v0.37.1 h1:3mir5bM4XjMJHW3SMRk++3Ylf4YQne0XFFsW+IGT85U= -k8s.io/cli-runtime v0.37.1/go.mod h1:g3VQOm71f//aNbp79g0az9jBRTrvPjAHz7WxVysbZ4M= -k8s.io/client-go v0.37.1 h1:QTv/5ha4jAHtW9qxxVBkQVFBRDb4jHfFopQqqMdc+wM= -k8s.io/client-go v0.37.1/go.mod h1:dnAPtTnCNY38Ho04D2KdY1F4IKausa9UbqaAZKl60SY= -k8s.io/component-base v0.37.1 h1:93DMmlENnK7gNLkL4pMqLO5M/HVf3p3sM4q/GasLveY= -k8s.io/component-base v0.37.1/go.mod h1:bBrdziT4dreQG5lzTaPVxBwsZe1oxphG+ZVdD56dQWQ= +k8s.io/apimachinery v0.37.2 h1:G4t9RGoPDbQML38hz/kQQiltttgd3egg2ODCR8aIc2o= +k8s.io/apimachinery v0.37.2/go.mod h1:qaAvSNvgU2x07wRM95MSHSJTPQ/ob/LeNAGbeDgqQJg= +k8s.io/apiserver v0.37.2 h1:9Jq73PeHAA0RThpW7ou6lBcO2+SxLcPrAgleONSMUNQ= +k8s.io/apiserver v0.37.2/go.mod h1:d0P4WZtt6XMYAo6VN8dDPRnvY3O34quI3pOuxtfgAgM= +k8s.io/cli-runtime v0.37.2 h1:EpE50B2FmXz8SxkYqoS2q0piDk1qe7g9dGZGIW+apws= +k8s.io/cli-runtime v0.37.2/go.mod h1:0IDMrrzVnj1cqBlCll8oGSOb2js6mSy0ALtbh0MsYyc= +k8s.io/client-go v0.37.2 h1:sgFtyRZukGkOrsu+QgS7LYnbFFJ5ut3MchdBNduD//E= +k8s.io/client-go v0.37.2/go.mod h1:bo3LFC8YbCtKFPX21Yj8puMsoJLAv/+SvuOODma0s54= +k8s.io/component-base v0.37.2 h1:Ia9IKTg1yWrUntJU5lVetapkC9pXlLg9L6P3R1IkbcY= +k8s.io/component-base v0.37.2/go.mod h1:qq+ueHZyLfzRJzxyDoyxHWNhF1JPv4zm3hcaddXWDvY= k8s.io/klog/v2 v2.140.0 h1:Tf+J3AH7xnUzZyVVXhTgGhEKnFqye14aadWv7bzXdzc= k8s.io/klog/v2 v2.140.0/go.mod h1:o+/RWfJ6PwpnFn7OyAG3QnO47BFsymfEfrz6XyYSSp0= k8s.io/kube-openapi v0.0.0-20260721132016-d427ff9ee9ad h1:oXImqH8mQNk7PmvzKhmN3ddJoY6OnyM225MXwGHPm0A= k8s.io/kube-openapi v0.0.0-20260721132016-d427ff9ee9ad/go.mod h1:0/mqHCVhlumdJ3BhCfnjSZQE037nAhNodh1/hK0T8/I= -k8s.io/streaming v0.37.1 h1:TpzVfQeFuVndn2g9mFqxy1UcUYPwDzqjUmwR/IzJCWc= -k8s.io/streaming v0.37.1/go.mod h1:APlJR26ZWRcVy5bIEj0QRrKUXROtBHPcxl2NT7EAzPU= +k8s.io/streaming v0.37.2 h1:xmzp9nbqIbjvsRcqrBYa+K5XPQ6Jy/Dm3zZ8mN916AI= +k8s.io/streaming v0.37.2/go.mod h1:APlJR26ZWRcVy5bIEj0QRrKUXROtBHPcxl2NT7EAzPU= k8s.io/utils v0.0.0-20260626114624-be93311217bd h1:Ea7fgQ5we8Y9T0OX5o0dAHzQOBRI07D/dEYRaB9ZZEs= k8s.io/utils v0.0.0-20260626114624-be93311217bd/go.mod h1:xDxuJ0whA3d0I4mf/C4ppKHxXynQ+fxnkmQH0vTHnuk= oras.land/oras-go/v2 v2.7.0 h1:0bXRBBSqYgPSjZRrhJbT71Rb465c+rdlft2xdQPxLtQ= diff --git a/hack/demo/migration/README.md b/hack/demo/migration/README.md index f7927cd..63e412b 100644 --- a/hack/demo/migration/README.md +++ b/hack/demo/migration/README.md @@ -4,11 +4,11 @@ Run these scripts from the repository root. They use a dedicated `library-olm-demo` Kind cluster and only the Kind-generated kubeconfig at `.kubeconfig/library-olm-demo`; they do not use your current Kubernetes context. The setup reuses the E2E version pins (Kind v0.33.0, Kubernetes v1.37.0, -OLMv0 v0.46.0, and experimental operator-controller v1.12.0), builds both CLIs, +OLMv0 v0.46.0, and experimental operator-controller pinned in `migration.mk`), builds both CLIs, and migrates the bootstrap CatalogSource so operator checks can resolve a serving ClusterCatalog. It is safe to rerun without recreating the cluster. -Prerequisites: Go, Docker, `kubectl`, `curl`, and `sha256sum`; the `make` target +Prerequisites: Go, Docker, Git, `envsubst`, Python 3, `kubectl`, `curl`, and `sha256sum`; the `make` target installs the pinned Kind binary through Bingo. Release manifests and container images must be reachable. Allow several minutes for OLM and operator installation. diff --git a/hack/e2e/migration/install-olmv1.sh b/hack/e2e/migration/install-olmv1.sh new file mode 100755 index 0000000..b2656c6 --- /dev/null +++ b/hack/e2e/migration/install-olmv1.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Build the pinned controller: released installers use older experimental APIs. +: "${OLM_V1_COMMIT:?OLM_V1_COMMIT is required}" +: "${E2E_KUBECONFIG:?E2E_KUBECONFIG is required}" +: "${E2E_CLUSTER_NAME:?E2E_CLUSTER_NAME is required}" +: "${KIND:?KIND is required}" +[[ "$OLM_V1_COMMIT" =~ ^[0-9a-f]{40}$ ]] || { echo 'OLM_V1_COMMIT must be a full commit hash' >&2; exit 1; } + +source_dir=$(mktemp -d) +trap 'rm -rf "$source_dir"' EXIT +git -C "$source_dir" init --quiet +git -C "$source_dir" fetch --quiet --depth=1 https://github.com/operator-framework/operator-controller.git "$OLM_V1_COMMIT" +git -C "$source_dir" checkout --quiet --detach FETCH_HEAD + +# Reuse upstream image names, build targets, manifest generation, and installer. +# Loading into the existing cluster avoids upstream's destructive cluster target. +# setup.sh installs the live catalog after controller installation. +export KUBECONFIG +KUBECONFIG=$(realpath "$E2E_KUBECONFIG") +# The generated Helm manifest uses these image names; do not inherit caller +# image overrides (including make command-line variables) into the build. +make -C "$source_dir" -f Makefile -f - migration-install \ + IMAGE_REGISTRY=quay.io/operator-framework IMAGE_TAG=devel \ + OPCON_IMAGE_REPO=quay.io/operator-framework/operator-controller \ + CATD_IMAGE_REPO=quay.io/operator-framework/catalogd \ + OBJECT_CONTROLLER_IMAGE_REPO=quay.io/operator-framework/object-controller \ + OPCON_IMG=quay.io/operator-framework/operator-controller:devel \ + CATD_IMG=quay.io/operator-framework/catalogd:devel \ + OBJECT_CONTROLLER_IMG=quay.io/operator-framework/object-controller:devel \ + KIND="$KIND" MIGRATION_CLUSTER="$E2E_CLUSTER_NAME" <<'MAKE' +SHELL := /bin/bash +.SHELLFLAGS := -eu -o pipefail -c +.PHONY: migration-install +migration-install: docker-build manifests + $(KIND) load docker-image $(OPCON_IMG) $(CATD_IMG) $(OBJECT_CONTROLLER_IMG) --name $(MIGRATION_CLUSTER) + MANIFEST=$(EXPERIMENTAL_MANIFEST) DEFAULT_CATALOG=$(CATALOGS_MANIFEST) INSTALL_DEFAULT_CATALOGS=false envsubst '$$DEFAULT_CATALOG,$$CERT_MGR_VERSION,$$INSTALL_DEFAULT_CATALOGS,$$MANIFEST' < scripts/install.tpl.sh | bash +MAKE diff --git a/hack/e2e/migration/setup.sh b/hack/e2e/migration/setup.sh index 4649333..edeea9e 100755 --- a/hack/e2e/migration/setup.sh +++ b/hack/e2e/migration/setup.sh @@ -1,14 +1,12 @@ #!/usr/bin/env bash set -euo pipefail -# Creates a disposable cluster for the migration E2E suites. Manifest locations are -# required inputs: CI supplies immutable, mirrored copies when it cannot access -# the public release URLs. +# Creates a disposable cluster for the migration E2E suites using pinned OLMv0 +# manifests and the current experimental operator-controller source. : "${E2E_KUBECONFIG:?E2E_KUBECONFIG is required}" : "${OLM_V0_CRDS:?OLM_V0_CRDS is required}" : "${OLM_V0_MANIFEST:?OLM_V0_MANIFEST is required}" -: "${OLM_V1_INSTALL:?OLM_V1_INSTALL is required}" -: "${OLM_V1_INSTALL_SHA256:?OLM_V1_INSTALL_SHA256 is required}" +: "${OLM_V1_COMMIT:?OLM_V1_COMMIT is required}" : "${KIND:?KIND is required}" root_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd) @@ -26,6 +24,20 @@ else fi kubectl --kubeconfig "$E2E_KUBECONFIG" wait --for=condition=Ready nodes --all --timeout=3m +# Setup is for a fresh installation, not upgrades or repair. Refuse existing +# OLM namespaces or APIs so partial installations also require explicit teardown. +existing=$(kubectl --kubeconfig "$E2E_KUBECONFIG" get \ + namespace/olm namespace/olmv1-system \ + crd/clusterserviceversions.operators.coreos.com \ + crd/clusterextensions.olm.operatorframework.io \ + crd/clusterobjectsets.olm.operatorframework.io \ + crd/clusterobjectdeployments.olm.operatorframework.io \ + --ignore-not-found -o name) +if [[ -n "$existing" ]]; then + printf 'OLM resources already exist in kind cluster %s. Run E2E_CLUSTER_NAME=%s make migration/e2e-teardown, then rerun setup.\n' "$cluster_name" "$cluster_name" >&2 + exit 1 +fi + # The v0.46 CRD bundle exceeds Kubernetes' client-side last-applied annotation # limit for the CSV CRD. Server-side apply stores managed fields instead. kubectl --kubeconfig "$E2E_KUBECONFIG" apply --server-side -f "$OLM_V0_CRDS" @@ -35,16 +47,13 @@ if [[ ${E2E_INSTALL_OLMV0:-true} == true ]]; then kubectl --kubeconfig "$E2E_KUBECONFIG" -n olm wait --for=condition=Available deployment/catalog-operator --timeout=5m fi -# ClusterObjectSet is an experimental OLMv1 API and is required by the migration -# code, so use operator-controller's experimental installer rather than standard. -# Download a pinned release installer before executing it, restricting redirects -# to HTTPS and verifying its recorded SHA-256. -if ! kubectl --kubeconfig "$E2E_KUBECONFIG" get crd/clusterextensions.olm.operatorframework.io >/dev/null 2>&1; then - installer=$(mktemp) - trap 'rm -f "$installer"' EXIT - curl --fail --location --proto '=https' --proto-redir '=https' --silent --show-error "$OLM_V1_INSTALL" --output "$installer" - printf '%s %s\n' "$OLM_V1_INSTALL_SHA256" "$installer" | sha256sum --check --status - KUBECONFIG="$E2E_KUBECONFIG" bash "$installer" +# Install the controller matching the current experimental COS/COD definitions. +E2E_CLUSTER_NAME="$cluster_name" "$root_dir/hack/e2e/migration/install-olmv1.sh" +kubectl --kubeconfig "$E2E_KUBECONFIG" wait --for=condition=Established crd/clusterextensions.olm.operatorframework.io crd/clustercatalogs.olm.operatorframework.io crd/clusterobjectsets.olm.operatorframework.io crd/clusterobjectdeployments.olm.operatorframework.io --timeout=5m +kubectl --kubeconfig "$E2E_KUBECONFIG" -n olmv1-system wait --for=condition=Available deployment/operator-controller-controller-manager deployment/catalogd-controller-manager deployment/object-controller-controller-manager --timeout=5m + +# Fixture clusters intentionally use only their committed catalog. +if [[ ${E2E_INSTALL_OLMV0:-true} == true ]]; then + kubectl --kubeconfig "$E2E_KUBECONFIG" apply -f "https://raw.githubusercontent.com/operator-framework/operator-controller/$OLM_V1_COMMIT/manifests/default-catalogs.yaml" + kubectl --kubeconfig "$E2E_KUBECONFIG" wait --for=condition=Serving clustercatalog/operatorhubio --timeout=5m fi -kubectl --kubeconfig "$E2E_KUBECONFIG" wait --for=condition=Established crd/clusterextensions.olm.operatorframework.io crd/clustercatalogs.olm.operatorframework.io --timeout=5m -kubectl --kubeconfig "$E2E_KUBECONFIG" -n olmv1-system wait --for=condition=Available deployment/operator-controller-controller-manager deployment/catalogd-controller-manager --timeout=5m diff --git a/migration.mk b/migration.mk index fdf8eec..2c4bf94 100644 --- a/migration.mk +++ b/migration.mk @@ -17,14 +17,12 @@ E2E_COVERAGE_DIR ?= $(E2E_ARTIFACTS)/coverage E2E_CLUSTER_NAME ?= library-olm-e2e E2E_FIXTURE_CLUSTER_NAME ?= library-olm-fixture-e2e E2E_FIXTURE_KUBECONFIG ?= $(ROOT_DIR)/.kubeconfig/library-olm-fixture-e2e -# Pin controller releases used by the E2E cluster. Override only to test a +# Pin controllers used by the E2E cluster. Override only to test a # compatibility candidate; do not use "latest" in CI. OLM_V0_VERSION ?= v0.46.0 -OLM_V1_VERSION ?= v1.12.0 +OLM_V1_COMMIT ?= 9dd683afa190a67bc6c719abbafa97faa2d68b96 OLM_V0_CRDS ?= https://github.com/operator-framework/operator-lifecycle-manager/releases/download/$(OLM_V0_VERSION)/crds.yaml OLM_V0_MANIFEST ?= https://github.com/operator-framework/operator-lifecycle-manager/releases/download/$(OLM_V0_VERSION)/olm.yaml -OLM_V1_INSTALL ?= https://github.com/operator-framework/operator-controller/releases/download/$(OLM_V1_VERSION)/install-experimental.sh -OLM_V1_INSTALL_SHA256 ?= 5c3c86e6d54b21ae7b0b566145ef703f8230e3f4cf4326541d42015a2a195970 E2E_REAL_OPERATOR_MANIFEST ?= $(ROOT_DIR)/test/e2e/migration/real-operator.yaml E2E_REAL_OPERATOR_NAMESPACE ?= migration-e2e-real E2E_REAL_OPERATOR_SUBSCRIPTION ?= ecr-secret-operator @@ -67,12 +65,12 @@ migration/test-verbose: ## Run migration unit tests with verbose output go test ./migration/... -v -count=1 .PHONY: migration/e2e-setup -migration/e2e-setup: $(KIND) ## Create kind and install pinned OLMv0 and OLMv1 releases - E2E_KUBECONFIG="$(E2E_KUBECONFIG)" E2E_CLUSTER_NAME="$(E2E_CLUSTER_NAME)" KIND="$(KIND)" OLM_V0_CRDS="$(OLM_V0_CRDS)" OLM_V0_MANIFEST="$(OLM_V0_MANIFEST)" OLM_V1_INSTALL="$(OLM_V1_INSTALL)" OLM_V1_INSTALL_SHA256="$(OLM_V1_INSTALL_SHA256)" ./hack/e2e/migration/setup.sh +migration/e2e-setup: $(KIND) ## Create kind and install pinned OLMv0 and experimental OLMv1 + E2E_KUBECONFIG="$(E2E_KUBECONFIG)" E2E_CLUSTER_NAME="$(E2E_CLUSTER_NAME)" KIND="$(KIND)" OLM_V0_CRDS="$(OLM_V0_CRDS)" OLM_V0_MANIFEST="$(OLM_V0_MANIFEST)" OLM_V1_COMMIT="$(OLM_V1_COMMIT)" ./hack/e2e/migration/setup.sh .PHONY: migration/e2e-fixture-setup migration/e2e-fixture-setup: $(KIND) $(CRANE) ## Create fixture kind cluster with OLMv0 APIs but no OLMv0 controllers - E2E_KUBECONFIG="$(E2E_FIXTURE_KUBECONFIG)" E2E_CLUSTER_NAME="$(E2E_FIXTURE_CLUSTER_NAME)" E2E_INSTALL_OLMV0=false KIND="$(KIND)" OLM_V0_CRDS="$(OLM_V0_CRDS)" OLM_V0_MANIFEST="$(OLM_V0_MANIFEST)" OLM_V1_INSTALL="$(OLM_V1_INSTALL)" OLM_V1_INSTALL_SHA256="$(OLM_V1_INSTALL_SHA256)" ./hack/e2e/migration/setup.sh + E2E_KUBECONFIG="$(E2E_FIXTURE_KUBECONFIG)" E2E_CLUSTER_NAME="$(E2E_FIXTURE_CLUSTER_NAME)" E2E_INSTALL_OLMV0=false KIND="$(KIND)" OLM_V0_CRDS="$(OLM_V0_CRDS)" OLM_V0_MANIFEST="$(OLM_V0_MANIFEST)" OLM_V1_COMMIT="$(OLM_V1_COMMIT)" ./hack/e2e/migration/setup.sh KUBECONFIG="$(E2E_FIXTURE_KUBECONFIG)" CRANE="$(CRANE)" ./hack/e2e/migration/build-fixture-catalog.sh .PHONY: migration/e2e-teardown @@ -117,8 +115,8 @@ migration/test-e2e-live-matrix: migration/build ## Install and migrate all three .PHONY: migration/test-e2e-live-namespace-delete migration/test-e2e-live-namespace-delete: migration/build ## Verify acknowledged source-namespace deletion with live OLMv0 @set -euo pipefail; \ - package=ecr-secret-operator; \ - namespace=migration-e2e-ecr-secret; \ + package=redis-operator; \ + namespace=migration-e2e-redis; \ target="$$namespace-target"; \ coverage_dir="$(E2E_COVERAGE_DIR)/live/cross-namespace-delete"; \ artifact_dir="$(E2E_ARTIFACTS)/live/cross-namespace-delete"; \ @@ -141,11 +139,11 @@ migration/test-e2e-live-batch: migration/build $(KIND) ## Verify four-state batc KUBECONFIG="$(E2E_KUBECONFIG)" kubectl delete namespace "$$namespace" --ignore-not-found --wait=true; \ done < test/e2e/migration/operators.tsv; \ coverage_dir="$(E2E_COVERAGE_DIR)/live/batch"; mkdir -p "$$coverage_dir"; \ - for operator in ecr-secret-operator redis-operator; do \ + for operator in redis-operator external-secrets-operator; do \ KUBECONFIG="$(E2E_KUBECONFIG)" ./hack/e2e/migration/install-v0.sh "$$operator"; \ done; \ - KUBECONFIG="$(E2E_KUBECONFIG)" GOCOVERDIR="$$coverage_dir" E2E_ARTIFACTS="$(E2E_ARTIFACTS)/live/batch" E2E_SUITE=real-operator E2E_BATCH_TEST=true E2E_NAMESPACE=migration-e2e-ecr-secret E2E_SUBSCRIPTION=ecr-secret-operator E2E_BATCH_SECOND_OPERATOR=redis-operator E2E_BATCH_SECOND_NAMESPACE=migration-e2e-redis go test -count=1 -tags=e2e ./test/e2e/migration -run '^TestBatchSafety$$' -timeout "$(E2E_TIMEOUT)"; \ - for operator in ecr-secret-operator redis-operator; do \ + KUBECONFIG="$(E2E_KUBECONFIG)" GOCOVERDIR="$$coverage_dir" E2E_ARTIFACTS="$(E2E_ARTIFACTS)/live/batch" E2E_SUITE=real-operator E2E_BATCH_TEST=true E2E_NAMESPACE=migration-e2e-redis E2E_SUBSCRIPTION=redis-operator E2E_BATCH_SECOND_OPERATOR=external-secrets-operator E2E_BATCH_SECOND_NAMESPACE=migration-e2e-external-secrets go test -count=1 -tags=e2e ./test/e2e/migration -run '^TestBatchSafety$$' -timeout "$(E2E_TIMEOUT)"; \ + for operator in redis-operator external-secrets-operator; do \ KUBECONFIG="$(E2E_KUBECONFIG)" ./hack/e2e/migration/delete-v1.sh "$$operator"; \ done @@ -253,13 +251,13 @@ migration/test-e2e-system-managed-namespace: migration/build ## Verify migration KUBECONFIG="$(E2E_FIXTURE_KUBECONFIG)" kubectl delete namespace "$$target" --ignore-not-found --wait=true .PHONY: migration/test-e2e-in-cluster-job -migration/test-e2e-in-cluster-job: migration/e2e-fixture-setup migration/build-e2e-image ## Run migration CLIs in a fixture-cluster Job (no coverage collection) +migration/test-e2e-in-cluster-job: migration/build-e2e-image ## Run migration CLIs in a fixture-cluster Job (no coverage collection) E2E_OPERATOR=ecr-secret-operator E2E_KUBECONFIG="$(E2E_FIXTURE_KUBECONFIG)" $(MAKE) migration/e2e-delete-v1 E2E_OPERATOR=ecr-secret-operator $(MAKE) migration/e2e-install-fixture-v0 KUBECONFIG="$(E2E_FIXTURE_KUBECONFIG)" E2E_SUITE=in-cluster-job E2E_NAMESPACE=migration-e2e-ecr-secret E2E_SUBSCRIPTION=ecr-secret-operator E2E_MIGRATION_IMAGE="$(E2E_MIGRATION_IMAGE)" E2E_ARTIFACTS="$(E2E_ARTIFACTS)/in-cluster-job" go test -count=1 -tags=e2e ./test/e2e/migration -run '^TestMigrationInClusterJob$$' -timeout "$(E2E_TIMEOUT)" .PHONY: migration/test-e2e-cos-supersession -migration/test-e2e-cos-supersession: migration/e2e-fixture-setup migration/build ## Verify migration COS is superseded by the catalog revision +migration/test-e2e-cos-supersession: migration/build ## Verify migration COS is superseded by the catalog revision @set -euo pipefail; \ package=ecr-secret-operator; \ coverage_profile="$(E2E_COVERAGE_DIR)/cos-supersession/cos-supersession-coverage.out"; \ diff --git a/migration/examples/cmd/migrate-operators-v0-to-v1/dryrun_eligibility_test.go b/migration/examples/cmd/migrate-operators-v0-to-v1/dryrun_eligibility_test.go index 2d7dc4e..8b9ea0b 100644 --- a/migration/examples/cmd/migrate-operators-v0-to-v1/dryrun_eligibility_test.go +++ b/migration/examples/cmd/migrate-operators-v0-to-v1/dryrun_eligibility_test.go @@ -71,6 +71,7 @@ func TestDryRunRejectsIncompatibleInputs(t *testing.T) { } } +// TestDryRunRejectsSystemManagedSourceNamespace verifies dry-run refuses a managed namespace that resolves back to the source. func TestDryRunRejectsSystemManagedSourceNamespace(t *testing.T) { scheme := runtime.NewScheme() for _, register := range []func(*runtime.Scheme) error{corev1.AddToScheme, operatorsv1.AddToScheme, operatorsv1alpha1.AddToScheme, ocv1.AddToScheme, apiextensionsv1.AddToScheme} { diff --git a/migration/pkg/migration/create_rejection_test.go b/migration/pkg/migration/create_rejection_test.go index b2cc32b..f9850ad 100644 --- a/migration/pkg/migration/create_rejection_test.go +++ b/migration/pkg/migration/create_rejection_test.go @@ -5,9 +5,7 @@ import ( "errors" "testing" - apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/interceptor" @@ -16,6 +14,7 @@ import ( ocv1 "github.com/operator-framework/operator-controller/api/v1" ) +// 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 { @@ -34,7 +33,7 @@ func TestMigrationCreateRejectionRecovery(t *testing.T) { ctx := context.Background() m := migrationTestClient(t) if mode == "COD" { - crd := &apiextensionsv1.CustomResourceDefinition{ObjectMeta: metav1.ObjectMeta{Name: clusterObjectDeploymentCRDName}, Status: apiextensionsv1.CustomResourceDefinitionStatus{Conditions: []apiextensionsv1.CustomResourceDefinitionCondition{{Type: apiextensionsv1.Established, Status: apiextensionsv1.ConditionTrue}}}} + crd := establishedClusterObjectDeploymentCRD() if err := m.Client.Create(ctx, crd); err != nil { t.Fatal(err) } diff --git a/migration/pkg/migration/deployment.go b/migration/pkg/migration/deployment.go index 9722bfa..d996a53 100644 --- a/migration/pkg/migration/deployment.go +++ b/migration/pkg/migration/deployment.go @@ -38,6 +38,7 @@ func (m *Migrator) hasClusterObjectDeploymentCRD(ctx context.Context) (bool, err return true, nil } +// prepareClusterObjectDeployment rejects incompatible APIs and occupied revision groups before migration. func (m *Migrator) prepareClusterObjectDeployment(ctx context.Context, name string) error { if len(name) > 52 || !deploymentNamePattern.MatchString(name) { return fmt.Errorf("ClusterObjectDeployment name %q must be 1–52 lowercase letters, digits or hyphens, starting with a letter and ending with a letter or digit", name) @@ -74,48 +75,25 @@ func (m *Migrator) prepareClusterObjectDeployment(ctx context.Context, name stri } func (m *Migrator) createClusterObjectDeployment(ctx context.Context, opts Options, info *MigrationInfo, phases []*ocv1ac.ClusterObjectSetPhaseApplyConfiguration, marker string, resources *createdMigrationResources) error { - annotations := map[string]string{ - MigratedFromSubscriptionAnnotation: fmt.Sprintf("%s/%s", opts.SubscriptionNamespace, opts.SubscriptionName), - migrationInvocationAnnotation: marker, - LabelPackageName: info.PackageName, - LabelBundleName: info.BundleName, - LabelBundleVersion: info.Version, - } - if info.BundleImage != "" { - annotations[LabelBundleReference] = info.BundleImage - } - configuration := ocv1ac.ClusterObjectDeployment(opts.ClusterExtensionName). - WithAnnotations(annotations). - WithLabels(map[string]string{LabelOwnerKind: ocv1.ClusterExtensionKind, LabelOwnerName: opts.ClusterExtensionName, controllerManagedByLabel: "operator-controller"}). - WithSpec(ocv1ac.ClusterObjectDeploymentSpec().WithTemplate( - ocv1ac.ClusterObjectDeploymentTemplate(). - WithMetadata(ocv1ac.ClusterObjectDeploymentTemplateMetadata(). - WithLabels(map[string]string{LabelOwnerKind: ocv1.ClusterExtensionKind, LabelOwnerName: opts.ClusterExtensionName}). - WithAnnotations(annotations)).WithSpec( - ocv1ac.ClusterObjectDeploymentTemplateSpec().WithPhases(phases...).WithCollisionProtection(ocv1.CollisionProtectionNone)))) - data, err := json.Marshal(configuration) + cod, err := buildClusterObjectDeployment(opts, info, phases, marker) if err != nil { - return fmt.Errorf("marshal ClusterObjectDeployment: %w", err) - } - var cod ocv1.ClusterObjectDeployment - if err := json.Unmarshal(data, &cod); err != nil { - return fmt.Errorf("decode ClusterObjectDeployment: %w", err) + return err } // Create rather than apply: an existing deployment may already manage // workloads, and its mutable template must never be overwritten here. - if err := m.Client.Create(ctx, &cod); err != nil { + if err := m.Client.Create(ctx, cod); err != nil { if createWasRejected(err) { return fmt.Errorf("create ClusterObjectDeployment: %w", err) } - if !apierrors.IsAlreadyExists(err) && m.resolveCreatedObject(context.WithoutCancel(ctx), &cod, marker) { - resources.cod = &cod + if !apierrors.IsAlreadyExists(err) && m.resolveCreatedObject(context.WithoutCancel(ctx), cod, marker) { + resources.cod = cod } else { resources.ownershipUnknown = true } return fmt.Errorf("create ClusterObjectDeployment: %w", err) } - resources.cod = &cod - return m.waitForDeployment(ctx, &cod) + resources.cod = cod + return m.waitForDeployment(ctx, cod) } func (m *Migrator) waitForDeployment(ctx context.Context, created *ocv1.ClusterObjectDeployment) error { @@ -298,3 +276,35 @@ func (m *Migrator) validateRollbackRevision(ctx context.Context, revision *ocv1. } return unverified } + +// buildClusterObjectDeployment constructs the same candidate for validation and creation. +func buildClusterObjectDeployment(opts Options, info *MigrationInfo, phases []*ocv1ac.ClusterObjectSetPhaseApplyConfiguration, marker string) (*ocv1.ClusterObjectDeployment, error) { + annotations := map[string]string{ + MigratedFromSubscriptionAnnotation: fmt.Sprintf("%s/%s", opts.SubscriptionNamespace, opts.SubscriptionName), + migrationInvocationAnnotation: marker, + LabelPackageName: info.PackageName, + LabelBundleName: info.BundleName, + LabelBundleVersion: info.Version, + } + if info.BundleImage != "" { + annotations[LabelBundleReference] = info.BundleImage + } + configuration := ocv1ac.ClusterObjectDeployment(opts.ClusterExtensionName). + WithAnnotations(annotations). + WithLabels(map[string]string{LabelOwnerKind: ocv1.ClusterExtensionKind, LabelOwnerName: opts.ClusterExtensionName, controllerManagedByLabel: "operator-controller"}). + WithSpec(ocv1ac.ClusterObjectDeploymentSpec().WithTemplate( + ocv1ac.ClusterObjectDeploymentTemplate(). + WithMetadata(ocv1ac.ClusterObjectDeploymentTemplateMetadata(). + WithLabels(map[string]string{LabelOwnerKind: ocv1.ClusterExtensionKind, LabelOwnerName: opts.ClusterExtensionName}). + WithAnnotations(annotations)).WithSpec( + ocv1ac.ClusterObjectDeploymentTemplateSpec().WithPhases(phases...).WithCollisionProtection(ocv1.CollisionProtectionNone)))) + data, err := json.Marshal(configuration) + if err != nil { + return nil, fmt.Errorf("marshal ClusterObjectDeployment: %w", err) + } + var cod ocv1.ClusterObjectDeployment + if err := json.Unmarshal(data, &cod); err != nil { + return nil, fmt.Errorf("decode ClusterObjectDeployment: %w", err) + } + return &cod, nil +} diff --git a/migration/pkg/migration/deployment_test.go b/migration/pkg/migration/deployment_test.go index cdc9bce..cee331f 100644 --- a/migration/pkg/migration/deployment_test.go +++ b/migration/pkg/migration/deployment_test.go @@ -71,8 +71,9 @@ func TestDeploymentReadiness(t *testing.T) { } } +// TestPrepareDeployment covers invalid names, unavailable APIs, and occupied deployment identities. func TestPrepareDeployment(t *testing.T) { - crd := &apiextensionsv1.CustomResourceDefinition{ObjectMeta: metav1.ObjectMeta{Name: clusterObjectDeploymentCRDName}, Status: apiextensionsv1.CustomResourceDefinitionStatus{Conditions: []apiextensionsv1.CustomResourceDefinitionCondition{{Type: apiextensionsv1.Established, Status: apiextensionsv1.ConditionTrue}}}} + crd := establishedClusterObjectDeploymentCRD() ctx := context.Background() if err := migrationTestClient(t).prepareClusterObjectDeployment(ctx, "example"); err == nil { t.Fatal("accepted missing CRD") @@ -152,6 +153,7 @@ func TestDeploymentTerminalRevisionFailures(t *testing.T) { } } +// TestAutomaticDeploymentSelection verifies API discovery selects the manager without unsafe fallback. func TestAutomaticDeploymentSelection(t *testing.T) { for _, tc := range []struct { name string @@ -163,10 +165,10 @@ func TestAutomaticDeploymentSelection(t *testing.T) { {name: "discovery failure does not fall back", failDiscovery: true}, } { t.Run(tc.name, func(t *testing.T) { - cosCRD := &apiextensionsv1.CustomResourceDefinition{ObjectMeta: metav1.ObjectMeta{Name: clusterObjectSetCRDName}, Status: apiextensionsv1.CustomResourceDefinitionStatus{Conditions: []apiextensionsv1.CustomResourceDefinitionCondition{{Type: apiextensionsv1.Established, Status: apiextensionsv1.ConditionTrue}}}} + cosCRD := establishedClusterObjectSetCRD() m := migrationTestClient(t, cosCRD) if tc.present { - codCRD := cosCRD.DeepCopy() + codCRD := establishedClusterObjectDeploymentCRD() codCRD.Name = clusterObjectDeploymentCRDName codCRD.ResourceVersion = "" if !tc.established { @@ -477,6 +479,7 @@ type deploymentDeletionClient struct { stopped bool } +// Delete checks that rollback stops the deployment before removing its revisions. func (c *deploymentDeletionClient) Delete(ctx context.Context, obj client.Object, opts ...client.DeleteOption) error { options := (&client.DeleteOptions{}).ApplyOptions(opts) switch obj.(type) { @@ -492,3 +495,10 @@ func (c *deploymentDeletionClient) Delete(ctx context.Context, obj client.Object } return c.Client.Delete(ctx, obj, opts...) } + +// establishedClusterObjectDeploymentCRD returns an established COD API for fake-client lifecycle tests. +func establishedClusterObjectDeploymentCRD() *apiextensionsv1.CustomResourceDefinition { + crd := establishedClusterObjectSetCRD() + crd.Name = clusterObjectDeploymentCRDName + return crd +} diff --git a/migration/pkg/migration/migration.go b/migration/pkg/migration/migration.go index 8efee2b..1c9ceef 100644 --- a/migration/pkg/migration/migration.go +++ b/migration/pkg/migration/migration.go @@ -22,7 +22,6 @@ import ( operatorsv1 "github.com/operator-framework/api/pkg/operators/v1" operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1" ocv1 "github.com/operator-framework/operator-controller/api/v1" - ocv1ac "github.com/operator-framework/operator-controller/applyconfigurations/api/v1" ) const ( @@ -179,6 +178,10 @@ func (m *Migrator) migrate(ctx context.Context, opts Options, nextStep func(Prog } } + if err := m.validateMigrationRevision(ctx, opts, info); err != nil { + return err + } + nextStep(ProgressStepBackup, "Backing up OLMv0 resources") backup, err := m.BackupResources(ctx, opts, csv, ip) if err != nil { @@ -255,17 +258,15 @@ func (m *Migrator) migrate(ctx context.Context, opts Options, nextStep func(Prog return nil } -// PrepareClusterObjectSet validates that this cluster can accept the OLMv1 -// objects migration creates and resolves where SecretPacker data belongs. It -// must run before PrepareForMigration, which deletes OLMv0 management objects. +// PrepareClusterObjectSet checks target ownership, selects the revision manager, +// and resolves where SecretPacker data belongs. Gather and Migrate validate the +// prepared revision with a server-side dry run. Preparation must run before +// PrepareForMigration, which deletes OLMv0 management objects. func (m *Migrator) PrepareClusterObjectSet(ctx context.Context, opts Options) (Options, error) { opts.ApplyDefaults() if err := m.ensureClusterExtensionAbsent(ctx, opts.ClusterExtensionName); err != nil { return opts, err } - if err := m.ensureClusterObjectSetCRD(ctx); err != nil { - return opts, err - } useCOD, err := m.hasClusterObjectDeploymentCRD(ctx) if err != nil { return opts, err @@ -340,11 +341,17 @@ func (m *Migrator) ensureSystemManagedNamespaceSupport(ctx context.Context) erro return fmt.Errorf("system-managed install namespace requires a ClusterExtension CRD schema that declares optional spec.namespace") } +// ensureClusterObjectSetCRD provides a lightweight API availability diagnostic +// for CheckReadiness. It cannot guarantee a later write will succeed; Gather and +// Migrate validate the prepared revision through a server-side dry run. func (m *Migrator) ensureClusterObjectSetCRD(ctx context.Context) error { var crd apiextensionsv1.CustomResourceDefinition if err := m.Client.Get(ctx, client.ObjectKey{Name: clusterObjectSetCRDName}, &crd); err != nil { return fmt.Errorf("ClusterObjectSet CRD %q is required before migration: %w", clusterObjectSetCRDName, err) } + if crd.DeletionTimestamp != nil { + return fmt.Errorf("ClusterObjectSet CRD %q is being deleted", clusterObjectSetCRDName) + } for _, condition := range crd.Status.Conditions { if condition.Type == apiextensionsv1.Established && condition.Status == apiextensionsv1.ConditionTrue { return nil @@ -656,6 +663,7 @@ func (m *Migrator) CreateMigrationResources(ctx context.Context, opts Options, i return MigrationResourcesResult{}, nil } +// createClusterObjectSet stages resources through the selected manager and records identities for recovery. func (m *Migrator) createClusterObjectSet(ctx context.Context, opts Options, info *MigrationInfo) (*createdMigrationResources, error) { resources := &createdMigrationResources{} useCOD, err := m.hasClusterObjectDeploymentCRD(ctx) @@ -675,29 +683,9 @@ func (m *Migrator) createClusterObjectSet(ctx context.Context, opts Options, inf packingName = opts.ClusterExtensionName } - cosObjects := make([]ocv1ac.ClusterObjectSetObjectApplyConfiguration, 0, len(info.CollectedObjects)) - for _, obj := range info.CollectedObjects { - stripped := stripResource(obj) - cosObjects = append(cosObjects, *ocv1ac.ClusterObjectSetObject(). - WithObject(stripped). - WithCollisionProtection(ocv1.CollisionProtectionNone)) - } - - phases := PhaseSort(cosObjects) - - // Pack inline objects into Secrets to stay within etcd's size limit (R2.4). - // SecretPacker gzip-compresses large objects and splits across multiple Secrets - // when the combined size would exceed 900 KiB per Secret. - // TODO: consider exporting secretPacker so consumers can configure whether to use - // Secret-backed refs or inline objects (useful for small bundles or testing). - packer := &secretPacker{ - RevisionName: packingName, - OwnerName: opts.ClusterExtensionName, - SystemNamespace: opts.SystemNamespace, - } - packed, err := packer.pack(phases) + phases, packed, err := buildMigrationPhases(opts, info, packingName) if err != nil { - return resources, fmt.Errorf("failed to pack COS objects into Secrets: %w", err) + return resources, err } cleanupSecrets := func() error { cleanupCtx, cancel := context.WithTimeout(context.WithoutCancel(ctx), 30*time.Second) @@ -739,18 +727,6 @@ func (m *Migrator) createClusterObjectSet(ctx context.Context, opts Options, inf resources.secrets = append(resources.secrets, *secret) } - // Replace inline objects with Secret refs in the phases. - for pos, ref := range packed.Refs { - phaseIdx, objIdx := pos[0], pos[1] - localRef := ref - phases[phaseIdx].Objects[objIdx].Object = nil - phases[phaseIdx].Objects[objIdx].Ref = &ocv1ac.ObjectSourceRefApplyConfiguration{ - Name: &localRef.Name, - Namespace: &localRef.Namespace, - Key: &localRef.Key, - } - } - if opts.UseClusterObjectDeployment { err := m.createClusterObjectDeployment(ctx, opts, info, phases, invocationMarker, resources) if err != nil && resources.cod == nil { @@ -759,40 +735,9 @@ func (m *Migrator) createClusterObjectSet(ctx context.Context, opts Options, inf return resources, err } - cosSpec := ocv1ac.ClusterObjectSetSpec(). - WithGroup(opts.ClusterExtensionName). - WithRevision(1). - WithCollisionProtection(ocv1.CollisionProtectionNone). - WithLifecycleState(ocv1.ClusterObjectSetLifecycleStateActive). - WithPhases(phases...) - - cosAnnotations := map[string]string{ - MigratedFromSubscriptionAnnotation: fmt.Sprintf("%s/%s", opts.SubscriptionNamespace, opts.SubscriptionName), - LabelPackageName: info.PackageName, - LabelBundleName: info.BundleName, - LabelBundleVersion: info.Version, - migrationInvocationAnnotation: invocationMarker, - } - if info.BundleImage != "" { - cosAnnotations[LabelBundleReference] = info.BundleImage - } - - cos := ocv1ac.ClusterObjectSet(cosName). - WithSpec(cosSpec). - WithLabels(map[string]string{ - LabelOwnerKind: ocv1.ClusterExtensionKind, - LabelOwnerName: opts.ClusterExtensionName, - controllerManagedByLabel: "object-controller", - }). - WithAnnotations(cosAnnotations) - - cosData, err := json.Marshal(cos) + cosObj, err := buildClusterObjectSet(opts, info, phases, invocationMarker) if err != nil { - return resources, failWithSecretCleanup(fmt.Errorf("failed to marshal COS: %w", err)) - } - cosObj := &ocv1.ClusterObjectSet{} - if err := json.Unmarshal(cosData, cosObj); err != nil { - return resources, failWithSecretCleanup(fmt.Errorf("failed to decode COS: %w", err)) + return resources, failWithSecretCleanup(err) } // A migration owns only a newly created revision. Applying an existing COS diff --git a/migration/pkg/migration/phase.go b/migration/pkg/migration/phase.go index 76bd869..3bc17e7 100644 --- a/migration/pkg/migration/phase.go +++ b/migration/pkg/migration/phase.go @@ -131,22 +131,23 @@ func determinePhase(gk schema.GroupKind) Phase { return phase } +// compareObjects orders inline manifests by resource identity within a migration phase. func compareObjects(a, b ocv1ac.ClusterObjectSetObjectApplyConfiguration) int { var aGVK, bGVK schema.GroupVersionKind - if a.Object != nil { - aGVK = a.Object.GroupVersionKind() + if a.Type != nil && *a.Type == ocv1.ObjectTypeInlineManifest && a.InlineManifest != nil { + aGVK = a.InlineManifest.GroupVersionKind() } - if b.Object != nil { - bGVK = b.Object.GroupVersionKind() + if b.Type != nil && *b.Type == ocv1.ObjectTypeInlineManifest && b.InlineManifest != nil { + bGVK = b.InlineManifest.GroupVersionKind() } var aNs, bNs, aName, bName string - if a.Object != nil { - aNs = a.Object.GetNamespace() - aName = a.Object.GetName() + if a.Type != nil && *a.Type == ocv1.ObjectTypeInlineManifest && a.InlineManifest != nil { + aNs = a.InlineManifest.GetNamespace() + aName = a.InlineManifest.GetName() } - if b.Object != nil { - bNs = b.Object.GetNamespace() - bName = b.Object.GetName() + if b.Type != nil && *b.Type == ocv1.ObjectTypeInlineManifest && b.InlineManifest != nil { + bNs = b.InlineManifest.GetNamespace() + bName = b.InlineManifest.GetName() } return cmp.Or( cmp.Compare(aGVK.Group, bGVK.Group), @@ -164,8 +165,8 @@ func PhaseSort(unsortedObjs []ocv1ac.ClusterObjectSetObjectApplyConfiguration) [ for _, obj := range unsortedObjs { var gk schema.GroupKind - if obj.Object != nil { - gk = obj.Object.GroupVersionKind().GroupKind() + if obj.Type != nil && *obj.Type == ocv1.ObjectTypeInlineManifest && obj.InlineManifest != nil { + gk = obj.InlineManifest.GroupVersionKind().GroupKind() } phase := determinePhase(gk) phaseMap[phase] = append(phaseMap[phase], obj) diff --git a/migration/pkg/migration/revision_schema.go b/migration/pkg/migration/revision_schema.go new file mode 100644 index 0000000..fee0ced --- /dev/null +++ b/migration/pkg/migration/revision_schema.go @@ -0,0 +1,126 @@ +package migration + +import ( + "context" + "encoding/json" + "fmt" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/uuid" + "sigs.k8s.io/controller-runtime/pkg/client" + + ocv1 "github.com/operator-framework/operator-controller/api/v1" + ocv1ac "github.com/operator-framework/operator-controller/applyconfigurations/api/v1" +) + +// validateMigrationRevision asks the API server to validate the proposed staging +// object without persisting it. Strict field validation rejects obsolete schemas +// instead of silently pruning revision entries. This does not execute controllers +// or validate the contents of the referenced Secrets as Kubernetes resources. +func (m *Migrator) validateMigrationRevision(ctx context.Context, opts Options, info *MigrationInfo) error { + packingName := opts.ClusterExtensionName + "-1" + if opts.UseClusterObjectDeployment { + packingName = opts.ClusterExtensionName + } + phases, _, err := buildMigrationPhases(opts, info, packingName) + if err != nil { + return err + } + marker := string(uuid.NewUUID()) + var candidate client.Object + if opts.UseClusterObjectDeployment { + candidate, err = buildClusterObjectDeployment(opts, info, phases, marker) + } else { + candidate, err = buildClusterObjectSet(opts, info, phases, marker) + } + if err != nil { + return err + } + if err := m.Client.Create(ctx, candidate, client.DryRunAll, client.FieldValidation(metav1.FieldValidationStrict)); err != nil { + return fmt.Errorf("validate migration revision with server-side dry run: %w", err) + } + return nil +} + +// buildMigrationPhases prepares packed references without writing Secrets. +func buildMigrationPhases(opts Options, info *MigrationInfo, packingName string) ([]*ocv1ac.ClusterObjectSetPhaseApplyConfiguration, *packResult, error) { + cosObjects := make([]ocv1ac.ClusterObjectSetObjectApplyConfiguration, 0, len(info.CollectedObjects)) + for _, obj := range info.CollectedObjects { + stripped := stripResource(obj) + cosObjects = append(cosObjects, *ocv1ac.ClusterObjectSetObject(). + WithType(ocv1.ObjectTypeInlineManifest).WithInlineManifest(stripped). + WithCollisionProtection(ocv1.CollisionProtectionNone)) + } + + phases := PhaseSort(cosObjects) + + // Pack inline objects into Secrets to stay within etcd's size limit (R2.4). + // SecretPacker gzip-compresses large objects and splits across multiple Secrets + // when the combined size would exceed 900 KiB per Secret. + // TODO: consider exporting secretPacker so consumers can configure whether to use + // Secret-backed refs or inline objects (useful for small bundles or testing). + packer := &secretPacker{ + RevisionName: packingName, + OwnerName: opts.ClusterExtensionName, + SystemNamespace: opts.SystemNamespace, + } + packed, err := packer.pack(phases) + if err != nil { + return nil, nil, fmt.Errorf("failed to pack COS objects into Secrets: %w", err) + } + // Replace inline objects with Secret refs in the phases. + for pos, ref := range packed.Refs { + phaseIdx, objIdx := pos[0], pos[1] + localRef := ref + phases[phaseIdx].Objects[objIdx].InlineManifest = nil + phases[phaseIdx].Objects[objIdx].WithType(ocv1.ObjectTypeSecretReference) + phases[phaseIdx].Objects[objIdx].SecretRef = &ocv1ac.SecretSourceRefApplyConfiguration{ + Name: &localRef.Name, + Namespace: &localRef.Namespace, + Key: &localRef.Key, + } + } + + return phases, packed, nil +} + +// buildClusterObjectSet constructs the same candidate for validation and creation. +func buildClusterObjectSet(opts Options, info *MigrationInfo, phases []*ocv1ac.ClusterObjectSetPhaseApplyConfiguration, marker string) (*ocv1.ClusterObjectSet, error) { + cosSpec := ocv1ac.ClusterObjectSetSpec(). + WithGroup(opts.ClusterExtensionName). + WithRevision(1). + WithCollisionProtection(ocv1.CollisionProtectionNone). + WithLifecycleState(ocv1.ClusterObjectSetLifecycleStateActive). + WithPhases(phases...) + + cosAnnotations := map[string]string{ + MigratedFromSubscriptionAnnotation: fmt.Sprintf("%s/%s", opts.SubscriptionNamespace, opts.SubscriptionName), + LabelPackageName: info.PackageName, + LabelBundleName: info.BundleName, + LabelBundleVersion: info.Version, + migrationInvocationAnnotation: marker, + } + if info.BundleImage != "" { + cosAnnotations[LabelBundleReference] = info.BundleImage + } + + cos := ocv1ac.ClusterObjectSet(opts.ClusterExtensionName + "-1"). + WithSpec(cosSpec). + WithLabels(map[string]string{ + LabelOwnerKind: ocv1.ClusterExtensionKind, + LabelOwnerName: opts.ClusterExtensionName, + controllerManagedByLabel: "object-controller", + }). + WithAnnotations(cosAnnotations) + + cosData, err := json.Marshal(cos) + if err != nil { + return nil, fmt.Errorf("failed to marshal COS: %w", err) + } + cosObj := &ocv1.ClusterObjectSet{} + if err := json.Unmarshal(cosData, cosObj); err != nil { + return nil, fmt.Errorf("failed to decode COS: %w", err) + } + + return cosObj, nil +} diff --git a/migration/pkg/migration/revision_schema_test.go b/migration/pkg/migration/revision_schema_test.go new file mode 100644 index 0000000..4fd5634 --- /dev/null +++ b/migration/pkg/migration/revision_schema_test.go @@ -0,0 +1,83 @@ +package migration + +import ( + "context" + "errors" + "reflect" + "testing" + + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/client/interceptor" + + ocv1 "github.com/operator-framework/operator-controller/api/v1" +) + +// TestRevisionServerDryRun checks the real candidate and strict non-persisting +// request options, and preserves server validation and authorization failures. +func TestRevisionServerDryRun(t *testing.T) { + rejection := errors.New("API server rejected candidate") + for _, deployment := range []bool{false, true} { + for _, serverErr := range []error{nil, rejection} { + name := "COS" + if deployment { + name = "COD" + } + if serverErr != nil { + name += "/rejected" + } + t.Run(name, func(t *testing.T) { + m := migrationTestClient(t) + calls := 0 + m.Client = interceptor.NewClient(m.Client.(client.WithWatch), interceptor.Funcs{ + Create: func(ctx context.Context, c client.WithWatch, obj client.Object, options ...client.CreateOption) error { + calls++ + opts := (&client.CreateOptions{}).ApplyOptions(options) + if !reflect.DeepEqual(opts.DryRun, []string{metav1.DryRunAll}) || opts.FieldValidation != metav1.FieldValidationStrict { + t.Fatalf("unsafe create options: %+v", opts) + } + var phases []ocv1.ClusterObjectSetPhase + switch candidate := obj.(type) { + case *ocv1.ClusterObjectSet: + if deployment || candidate.Name != "example-1" { + t.Fatalf("unexpected COS: %+v", candidate) + } + phases = candidate.Spec.Phases + case *ocv1.ClusterObjectDeployment: + if !deployment || candidate.Name != "example" { + t.Fatalf("unexpected COD: %+v", candidate) + } + phases = candidate.Spec.Template.Spec.Phases + default: + t.Fatalf("unexpected write of %T", obj) + } + if len(phases) != 1 || len(phases[0].Objects) != 1 { + t.Fatalf("phases = %+v", phases) + } + object := phases[0].Objects[0] + if object.Type != ocv1.ObjectTypeSecretReference || object.SecretRef.Namespace != "controller" || object.SecretRef.Key == "" { + t.Fatalf("unpacked candidate: %+v", object) + } + return serverErr + }, + Delete: func(context.Context, client.WithWatch, client.Object, ...client.DeleteOption) error { + t.Fatal("dry run deleted an object") + return nil + }, + }) + opts := Options{ClusterExtensionName: "example", SystemNamespace: "controller", UseClusterObjectDeployment: deployment} + info := &MigrationInfo{CollectedObjects: []unstructured.Unstructured{{Object: map[string]interface{}{"apiVersion": "v1", "kind": "ConfigMap", "metadata": map[string]interface{}{"name": "config", "namespace": "operators"}, "data": map[string]interface{}{"key": "value"}}}}} + err := m.validateMigrationRevision(t.Context(), opts, info) + if !errors.Is(err, serverErr) || calls != 1 { + t.Fatalf("calls=%d, error=%v", calls, err) + } + var secrets corev1.SecretList + if err := m.Client.List(t.Context(), &secrets); err != nil || len(secrets.Items) != 0 { + t.Fatalf("dry run persisted Secrets: %v, %+v", err, secrets.Items) + } + }) + } + } +} diff --git a/migration/pkg/migration/rollback_recovery_test.go b/migration/pkg/migration/rollback_recovery_test.go index 899cab6..27a14f9 100644 --- a/migration/pkg/migration/rollback_recovery_test.go +++ b/migration/pkg/migration/rollback_recovery_test.go @@ -14,6 +14,7 @@ import ( apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" @@ -464,6 +465,7 @@ func (c conflictCleanupFailureClient) Delete(ctx context.Context, object client. return c.Client.Delete(ctx, object, opts...) } +// TestCleanupConflictReportsCSVAndArtifactFailures checks that cleanup errors retain their resource context. func TestCleanupConflictReportsCSVAndArtifactFailures(t *testing.T) { for _, scenario := range []string{"list", "delete CSV", "delete condition"} { t.Run(scenario, func(t *testing.T) { @@ -486,3 +488,142 @@ func TestCleanupConflictReportsCSVAndArtifactFailures(t *testing.T) { }) } } + +// TestRollbackSnapshotAllowsVerifiedSiblingHandoff permits verified adoption races while rejecting foreign owners and replaced resources. +func TestRollbackSnapshotAllowsVerifiedSiblingHandoff(t *testing.T) { + foreignOwner := *metav1.NewControllerRef(&corev1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Name: "foreign", UID: "foreign"}}, corev1.SchemeGroupVersion.WithKind("ConfigMap")) + for _, scenario := range []struct { + name string + siblingGroup string + siblingHasObject bool + revision string + managedBy string + uid types.UID + owners []metav1.OwnerReference + wantError bool + }{ + {name: "sibling handoff", siblingGroup: "example", siblingHasObject: true, revision: "3", managedBy: "olm.operatorframework.io", uid: "resource"}, + {name: "unlisted revision", siblingGroup: "example", siblingHasObject: true, revision: "4", managedBy: "olm.operatorframework.io", uid: "resource", wantError: true}, + {name: "foreign controller", siblingGroup: "example", siblingHasObject: true, revision: "3", managedBy: "olm.operatorframework.io", uid: "resource", owners: []metav1.OwnerReference{foreignOwner}, wantError: true}, + {name: "changed label", siblingGroup: "example", siblingHasObject: true, revision: "3", managedBy: "foreign", uid: "resource", wantError: true}, + {name: "replaced object", siblingGroup: "example", siblingHasObject: true, revision: "3", managedBy: "olm.operatorframework.io", uid: "replacement", wantError: true}, + {name: "sibling omits object", siblingGroup: "example", siblingHasObject: false, revision: "3", managedBy: "olm.operatorframework.io", uid: "resource", wantError: true}, + {name: "different group", siblingGroup: "other", siblingHasObject: true, revision: "3", managedBy: "olm.operatorframework.io", uid: "resource", wantError: true}, + } { + t.Run(scenario.name, func(t *testing.T) { + ctx := context.Background() + manifest := unstructured.Unstructured{Object: map[string]interface{}{"apiVersion": "v1", "kind": "ConfigMap", "metadata": map[string]interface{}{"name": "config", "namespace": "source"}}} + first := ocv1.ClusterObjectSet{ObjectMeta: metav1.ObjectMeta{Name: "example-2", UID: "revision-2"}, Spec: ocv1.ClusterObjectSetSpec{Group: "example", Revision: 2, Phases: []ocv1.ClusterObjectSetPhase{{Name: "deploy", Objects: []ocv1.ClusterObjectSetObject{{Type: ocv1.ObjectTypeInlineManifest, InlineManifest: manifest}}}}}} + second := *first.DeepCopy() + second.Name = "example-3" + second.UID = "revision-3" + second.Spec.Revision = 3 + second.Spec.Group = scenario.siblingGroup + if !scenario.siblingHasObject { + second.Spec.Phases = nil + } + live := &corev1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Name: "config", Namespace: "source", UID: "resource", OwnerReferences: []metav1.OwnerReference{*metav1.NewControllerRef(&first, ocv1.GroupVersion.WithKind(ocv1.ClusterObjectSetKind))}, Annotations: map[string]string{boxcutterRevisionAnnotation: "2"}, Labels: map[string]string{boxcutterManagedByLabel: "olm.operatorframework.io"}}} + m := migrationTestClient(t, live) + snapshot, err := m.snapshotRevisionObjects(ctx, []ocv1.ClusterObjectSet{first, second}) + if err != nil { + t.Fatal(err) + } + if len(snapshot) != 1 { + t.Fatalf("snapshot = %+v", snapshot) + } + // Permitted sibling identities must survive a persisted-snapshot merge. + old := snapshot[0] + old.AdditionalOwners = nil + mergedSnapshot, _, mergeErr := mergeRollbackObjects([]rollbackObject{old}, snapshot) + if mergeErr != nil || !reflect.DeepEqual(mergedSnapshot, snapshot) { + t.Fatalf("lost sibling identities: %+v, %v", mergedSnapshot, mergeErr) + } + // Adoption completes after the snapshot; GC then removes the verified owner. + live.OwnerReferences = scenario.owners + live.Annotations[boxcutterRevisionAnnotation] = scenario.revision + live.Labels[boxcutterManagedByLabel] = scenario.managedBy + live.UID = scenario.uid + if err := m.Client.Update(ctx, live); err != nil { + t.Fatal(err) + } + err = m.releaseRevisionObjects(ctx, snapshot) + if scenario.wantError { + if err == nil { + t.Fatal("released unverified object") + } + return + } + if err != nil { + t.Fatal(err) + } + if err = m.Client.Get(ctx, client.ObjectKeyFromObject(live), live); err != nil { + t.Fatal(err) + } + if live.Annotations[boxcutterRevisionAnnotation] != "" || live.UID != "resource" { + t.Fatalf("release lost identity or retained metadata: %+v", live) + } + // The permitted transition must also survive snapshot merges on retry. + merged, _, err := mergeRollbackObjects(snapshot, []rollbackObject{{Identity: snapshot[0].Identity, UID: "resource", OwnerUID: "revision-3", Revision: "3", ManagedBy: "olm.operatorframework.io"}}) + if err != nil || len(merged[0].AdditionalOwners) != 1 { + t.Fatalf("merge = %+v, %v", merged, err) + } + }) + } +} + +// TestRollbackSnapshotOrdering is independent of revision list and manifest order. +func TestRollbackSnapshotOrdering(t *testing.T) { + objects := make([]ocv1.ClusterObjectSetObject, 0, 2) + for _, name := range []string{"z-config", "a-config"} { + objects = append(objects, ocv1.ClusterObjectSetObject{ + Type: ocv1.ObjectTypeInlineManifest, + InlineManifest: unstructured.Unstructured{Object: map[string]interface{}{ + "apiVersion": "v1", "kind": "ConfigMap", + "metadata": map[string]interface{}{"name": name, "namespace": "source"}, + }}, + }) + } + first := ocv1.ClusterObjectSet{ + ObjectMeta: metav1.ObjectMeta{Name: "example-1", UID: "revision-1"}, + Spec: ocv1.ClusterObjectSetSpec{Group: "example", Revision: 1, + Phases: []ocv1.ClusterObjectSetPhase{{Name: "deploy", Objects: objects}}}, + } + second, tenth := *first.DeepCopy(), *first.DeepCopy() + second.Name, second.UID, second.Spec.Revision = "example-2", "revision-2", 2 + tenth.Name, tenth.UID, tenth.Spec.Revision = "example-10", "revision-10", 10 + live := make([]runtime.Object, 0, len(objects)) + for _, object := range objects { + live = append(live, &corev1.ConfigMap{ObjectMeta: metav1.ObjectMeta{ + Name: object.InlineManifest.GetName(), Namespace: "source", UID: types.UID(object.InlineManifest.GetName()), + OwnerReferences: []metav1.OwnerReference{*metav1.NewControllerRef(&first, ocv1.GroupVersion.WithKind(ocv1.ClusterObjectSetKind))}, + Annotations: map[string]string{boxcutterRevisionAnnotation: "1"}, + Labels: map[string]string{boxcutterManagedByLabel: "olm.operatorframework.io"}, + }}) + } + m := migrationTestClient(t, live...) + var expected []rollbackObject + for _, order := range [][]ocv1.ClusterObjectSet{ + {tenth, first, second}, {second, tenth, first}, {first, second, tenth}, + } { + before := slices.Clone(order) + got, err := m.snapshotRevisionObjects(t.Context(), order) + if err != nil { + t.Fatal(err) + } + if !reflect.DeepEqual(order, before) { + t.Fatal("snapshot reordered caller's revisions") + } + if len(got) != 2 || got[0].Identity.GetName() != "a-config" || got[1].Identity.GetName() != "z-config" { + t.Fatalf("unexpected resource order: %+v", got) + } + for _, object := range got { + if len(object.AdditionalOwners) != 2 || object.AdditionalOwners[0].Revision != "2" || object.AdditionalOwners[1].Revision != "10" { + t.Fatalf("unexpected sibling order: %+v", object.AdditionalOwners) + } + } + if expected != nil && !reflect.DeepEqual(got, expected) { + t.Fatalf("snapshot depends on revision input order: got %+v, want %+v", got, expected) + } + expected = got + } +} diff --git a/migration/pkg/migration/rollback_release.go b/migration/pkg/migration/rollback_release.go index a822fec..e3f7ed5 100644 --- a/migration/pkg/migration/rollback_release.go +++ b/migration/pkg/migration/rollback_release.go @@ -2,11 +2,14 @@ package migration import ( "bytes" + "cmp" "compress/gzip" "context" "encoding/json" "fmt" "io" + "slices" + "strconv" "time" corev1 "k8s.io/api/core/v1" @@ -121,13 +124,14 @@ type rollbackOwnership struct { Managed string `json:"managed"` } +// ownerships returns the original owner and any verified sibling ownership alternatives. func (object rollbackObject) ownerships() []rollbackOwnership { owners := []rollbackOwnership{{OwnerUID: object.OwnerUID, Revision: object.Revision, ManagedBy: object.ManagedBy, Managed: object.Managed}} return append(owners, object.AdditionalOwners...) } // mergeRollbackObjects retains the original resource UID and accepts another -// owner only when a listed revision was observed controlling that same object. +// owner only when it was verified while snapshotting that same object. func mergeRollbackObjects(saved, observed []rollbackObject) ([]rollbackObject, bool, error) { merged := append([]rollbackObject(nil), saved...) index := make(map[string]int, len(merged)) @@ -147,21 +151,22 @@ func mergeRollbackObjects(saved, observed []rollbackObject) ([]rollbackObject, b if merged[i].UID != candidate.UID { return nil, false, fmt.Errorf("resource %s was replaced during rollback", key) } - ownership := candidate.ownerships()[0] - found := false - for _, prior := range merged[i].ownerships() { - if prior.OwnerUID != ownership.OwnerUID { - continue + for _, ownership := range candidate.ownerships() { + found := false + for _, prior := range merged[i].ownerships() { + if prior.OwnerUID != ownership.OwnerUID { + continue + } + if prior != ownership { + return nil, false, fmt.Errorf("ownership metadata on %s changed during rollback", key) + } + found = true + break } - if prior != ownership { - return nil, false, fmt.Errorf("ownership metadata on %s changed during rollback", key) + if !found { + merged[i].AdditionalOwners = append(merged[i].AdditionalOwners, ownership) + changed = true } - found = true - break - } - if !found { - merged[i].AdditionalOwners = append(merged[i].AdditionalOwners, ownership) - changed = true } } return merged, changed, nil @@ -170,16 +175,22 @@ func mergeRollbackObjects(saved, observed []rollbackObject) ([]rollbackObject, b // snapshotRevisionObjects records only resources currently controlled by a // revision being removed. It runs before deletion, while ownership is provable. func (m *Migrator) snapshotRevisionObjects(ctx context.Context, revisions []ocv1.ClusterObjectSet) ([]rollbackObject, error) { - var objects []rollbackObject - seen := map[string]bool{} + type revisionEntry struct { + manifest unstructured.Unstructured + revision *ocv1.ClusterObjectSet + } + entries := map[string][]revisionEntry{} for i := range revisions { revision := &revisions[i] for _, phase := range revision.Spec.Phases { for _, entry := range phase.Objects { - manifest := entry.Object - if entry.Ref.Name != "" { + if entry.Type != ocv1.ObjectTypeInlineManifest && entry.Type != ocv1.ObjectTypeSecretReference { + return nil, fmt.Errorf("ClusterObjectSet %s has unsupported object type %q", revision.Name, entry.Type) + } + manifest := entry.InlineManifest + if entry.Type == ocv1.ObjectTypeSecretReference { var err error - manifest, err = m.rollbackReferencedObject(ctx, entry.Ref) + manifest, err = m.rollbackReferencedObject(ctx, entry.SecretRef) if err != nil { return nil, fmt.Errorf("ClusterObjectSet %s phase %s: %w", revision.Name, phase.Name, err) } @@ -188,42 +199,74 @@ func (m *Migrator) snapshotRevisionObjects(ctx context.Context, revisions []ocv1 return nil, fmt.Errorf("ClusterObjectSet %s phase %s has an incomplete object identity", revision.Name, phase.Name) } key := resourceKey(manifest) - if seen[key] { - continue - } - live := &unstructured.Unstructured{} - live.SetGroupVersionKind(manifest.GroupVersionKind()) - if err := m.Client.Get(ctx, client.ObjectKeyFromObject(&manifest), live); err != nil { - if apierrors.IsNotFound(err) { - continue - } - return nil, fmt.Errorf("getting %s for rollback: %w", key, err) - } - owner := metav1.GetControllerOf(live) - if owner == nil || owner.UID != revision.UID || owner.Kind != "ClusterObjectSet" { - continue - } - if live.GetAnnotations()[boxcutterRevisionAnnotation] == "" { - continue - } - seen[key] = true - identity := unstructured.Unstructured{} - identity.SetGroupVersionKind(live.GroupVersionKind()) - identity.SetName(live.GetName()) - identity.SetNamespace(live.GetNamespace()) - objects = append(objects, rollbackObject{ - Identity: identity, UID: live.GetUID(), OwnerUID: owner.UID, - Revision: live.GetAnnotations()[boxcutterRevisionAnnotation], - ManagedBy: live.GetLabels()[boxcutterManagedByLabel], - Managed: live.GetLabels()[boxcutterManagedLabel], + entries[key] = append(entries[key], revisionEntry{manifest: manifest, revision: revision}) + } + } + } + var objects []rollbackObject + for key, candidates := range entries { + manifest := candidates[0].manifest + live := &unstructured.Unstructured{} + live.SetGroupVersionKind(manifest.GroupVersionKind()) + if err := m.Client.Get(ctx, client.ObjectKeyFromObject(&manifest), live); err != nil { + if apierrors.IsNotFound(err) { + continue + } + return nil, fmt.Errorf("getting %s for rollback: %w", key, err) + } + owner := metav1.GetControllerOf(live) + if owner == nil || owner.Kind != ocv1.ClusterObjectSetKind || owner.APIVersion != ocv1.GroupVersion.String() { + continue + } + var controlling *ocv1.ClusterObjectSet + for _, candidate := range candidates { + if owner.UID == candidate.revision.UID && owner.Name == candidate.revision.Name { + controlling = candidate.revision + break + } + } + if controlling == nil || live.GetAnnotations()[boxcutterRevisionAnnotation] == "" { + continue + } + identity := unstructured.Unstructured{} + identity.SetGroupVersionKind(live.GroupVersionKind()) + identity.SetName(live.GetName()) + identity.SetNamespace(live.GetNamespace()) + object := rollbackObject{ + Identity: identity, UID: live.GetUID(), OwnerUID: owner.UID, + Revision: live.GetAnnotations()[boxcutterRevisionAnnotation], + ManagedBy: live.GetLabels()[boxcutterManagedByLabel], Managed: live.GetLabels()[boxcutterManagedLabel], + } + // A newer, verified sibling can adopt this same object after our read but + // before orphan deletion. Record only siblings that actually contain the + // object, preserving the resource UID and exact management-label checks. + for _, candidate := range candidates { + revision := candidate.revision + if revision.UID != "" && revision.Spec.Group == controlling.Spec.Group && revision.Spec.Revision > controlling.Spec.Revision { + object.AdditionalOwners = append(object.AdditionalOwners, rollbackOwnership{ + OwnerUID: revision.UID, Revision: strconv.FormatInt(revision.Spec.Revision, 10), + ManagedBy: object.ManagedBy, Managed: object.Managed, }) } } + // These revisions were formatted from int64 values above, so parsing + // cannot fail. Order the completed ownership list before storing it. + slices.SortFunc(object.AdditionalOwners, func(a, b rollbackOwnership) int { + aRevision, _ := strconv.ParseInt(a.Revision, 10, 64) + bRevision, _ := strconv.ParseInt(b.Revision, 10, 64) + return cmp.Or(cmp.Compare(aRevision, bRevision), cmp.Compare(a.OwnerUID, b.OwnerUID)) + }) + objects = append(objects, object) } + // Map iteration must not affect the order of the completed snapshot. + slices.SortFunc(objects, func(a, b rollbackObject) int { + return cmp.Compare(resourceKey(a.Identity), resourceKey(b.Identity)) + }) return objects, nil } -func (m *Migrator) rollbackReferencedObject(ctx context.Context, ref ocv1.ObjectSourceRef) (unstructured.Unstructured, error) { +// rollbackReferencedObject loads and decodes a Secret-backed manifest for rollback snapshots. +func (m *Migrator) rollbackReferencedObject(ctx context.Context, ref ocv1.SecretSourceRef) (unstructured.Unstructured, error) { var secret corev1.Secret if err := m.Client.Get(ctx, client.ObjectKey{Name: ref.Name, Namespace: ref.Namespace}, &secret); err != nil { return unstructured.Unstructured{}, fmt.Errorf("getting object Secret %s/%s: %w", ref.Namespace, ref.Name, err) @@ -364,7 +407,7 @@ func (m *Migrator) releaseRevisionObjects(ctx context.Context, objects []rollbac } } if !knownMetadata { - return false, fmt.Errorf("ownership metadata on %s changed during rollback", key) + return false, fmt.Errorf("ownership metadata on %s changed during rollback (revision=%q, managed-by=%q, managed=%q)", key, currentRevision, currentManagedBy, currentManaged) } if currentRevision == "" && currentManagedBy == "" && currentManaged == "" { return true, nil diff --git a/migration/pkg/migration/scan.go b/migration/pkg/migration/scan.go index 5d44622..2de36db 100644 --- a/migration/pkg/migration/scan.go +++ b/migration/pkg/migration/scan.go @@ -753,6 +753,9 @@ func (m *Migrator) Gather(ctx context.Context, opts Options) (*MigrationInfo, er if err != nil { return nil, err } + if err := m.validateMigrationRevision(ctx, prepared, info); err != nil { + return nil, err + } info.SystemNamespace = prepared.SystemNamespace info.UseClusterObjectDeployment = prepared.UseClusterObjectDeployment return info, nil diff --git a/migration/pkg/migration/secretpacker.go b/migration/pkg/migration/secretpacker.go index 958be16..f403995 100644 --- a/migration/pkg/migration/secretpacker.go +++ b/migration/pkg/migration/secretpacker.go @@ -48,16 +48,16 @@ type secretPacker struct { type packResult struct { // Secrets to be created before the COS. Secrets []corev1.Secret - // Refs maps (phaseIndex, objectIndex) to the ObjectSourceRef that replaces the inline object. - Refs map[[2]int]ocv1.ObjectSourceRef + // Refs maps (phaseIndex, objectIndex) to the SecretSourceRef that replaces the inline object. + Refs map[[2]int]ocv1.SecretSourceRef } // pack takes COS phases with inline objects and produces: // 1. A set of immutable Secrets containing the serialized objects. -// 2. A mapping from (phaseIdx, objIdx) to the corresponding ObjectSourceRef. +// 2. A mapping from (phaseIdx, objIdx) to the corresponding SecretSourceRef. func (p *secretPacker) pack(phases []*ocv1ac.ClusterObjectSetPhaseApplyConfiguration) (*packResult, error) { result := &packResult{ - Refs: make(map[[2]int]ocv1.ObjectSourceRef), + Refs: make(map[[2]int]ocv1.SecretSourceRef), } type pendingRef struct { @@ -77,7 +77,7 @@ func (p *secretPacker) pack(phases []*ocv1ac.ClusterObjectSetPhaseApplyConfigura } secret := p.newSecret(currentData) for _, pr := range currentPending { - result.Refs[pr.pos] = ocv1.ObjectSourceRef{ + result.Refs[pr.pos] = ocv1.SecretSourceRef{ Name: secret.Name, Namespace: p.SystemNamespace, Key: pr.key, @@ -91,11 +91,23 @@ func (p *secretPacker) pack(phases []*ocv1ac.ClusterObjectSetPhaseApplyConfigura for phaseIdx, phase := range phases { for objIdx, obj := range phase.Objects { - if obj.Object == nil { - continue // already a ref + // The generated apply configuration uses *ObjectType to represent an + // unset field; the API object's Type field is a non-pointer ObjectType. + if obj.Type == nil { + return nil, fmt.Errorf("object in phase %d index %d has no type", phaseIdx, objIdx) + } + switch *obj.Type { + case ocv1.ObjectTypeSecretReference: + continue + case ocv1.ObjectTypeInlineManifest: + if obj.InlineManifest == nil { + return nil, fmt.Errorf("inline object in phase %d index %d has no manifest", phaseIdx, objIdx) + } + default: + return nil, fmt.Errorf("object in phase %d index %d has unsupported type %q", phaseIdx, objIdx, *obj.Type) } - data, err := json.Marshal(obj.Object) + data, err := json.Marshal(obj.InlineManifest) if err != nil { return nil, fmt.Errorf("serializing object in phase %d index %d: %w", phaseIdx, objIdx, err) } diff --git a/migration/pkg/migration/secretpacker_validation_test.go b/migration/pkg/migration/secretpacker_validation_test.go index 99ce280..39563b4 100644 --- a/migration/pkg/migration/secretpacker_validation_test.go +++ b/migration/pkg/migration/secretpacker_validation_test.go @@ -10,16 +10,18 @@ import ( "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + ocv1 "github.com/operator-framework/operator-controller/api/v1" ocv1ac "github.com/operator-framework/operator-controller/applyconfigurations/api/v1" ) +// largeConfigMap builds an inline ConfigMap with configurable payload size. func largeConfigMap(name, payload string) *ocv1ac.ClusterObjectSetObjectApplyConfiguration { object := unstructured.Unstructured{Object: map[string]interface{}{ "apiVersion": "v1", "kind": "ConfigMap", "metadata": map[string]interface{}{"name": name}, "data": map[string]interface{}{"payload": payload}, }} - return ocv1ac.ClusterObjectSetObject().WithObject(object) + return ocv1ac.ClusterObjectSetObject().WithType(ocv1.ObjectTypeInlineManifest).WithInlineManifest(object) } func TestSecretPackerSplitsLargeBundleAcrossSecrets(t *testing.T) { @@ -53,6 +55,7 @@ func TestSecretPackerSplitsLargeBundleAcrossSecrets(t *testing.T) { } } +// TestSecretPackerCompressesOversizedObject checks compression preserves a manifest that exceeds the uncompressed size limit. func TestSecretPackerCompressesOversizedObject(t *testing.T) { payload := strings.Repeat("x", gzipThreshold+1) phase := ocv1ac.ClusterObjectSetPhase().WithObjects(largeConfigMap("large", payload)) @@ -83,3 +86,47 @@ func TestSecretPackerCompressesOversizedObject(t *testing.T) { t.Fatalf("restored payload length = %d, found = %t, error = %v", len(data), found, err) } } + +// TestSecretPackerUsesObjectType verifies discriminator dispatch preserves existing references and rejects malformed inline entries. +func TestSecretPackerUsesObjectType(t *testing.T) { + for _, kind := range []string{"inline", "reference", "missing type", "missing manifest", "unknown"} { + t.Run(kind, func(t *testing.T) { + object := largeConfigMap("config", "payload") + switch kind { + case "reference": + object.WithType(ocv1.ObjectTypeSecretReference).WithSecretRef(ocv1ac.SecretSourceRef().WithName("stored").WithNamespace("controller").WithKey("manifest")) + object.InlineManifest = nil + case "missing type": + object.Type = nil + case "missing manifest": + object.InlineManifest = nil + case "unknown": + object.WithType(ocv1.ObjectType("Unknown")) + } + phases := []*ocv1ac.ClusterObjectSetPhaseApplyConfiguration{ocv1ac.ClusterObjectSetPhase().WithObjects(object)} + before, err := json.Marshal(phases) + if err != nil { + t.Fatal(err) + } + packed, err := (&secretPacker{RevisionName: "example", OwnerName: "example", SystemNamespace: "controller"}).pack(phases) + if kind != "inline" && kind != "reference" { + if err == nil { + t.Fatal("accepted malformed union") + } + return + } + if err != nil { + t.Fatal(err) + } + if (len(packed.Refs) > 0) != (kind == "inline") { + t.Fatalf("wrong union member packed: %+v", packed) + } + if kind == "reference" { + after, marshalErr := json.Marshal(phases) + if marshalErr != nil || string(before) != string(after) || len(packed.Secrets) != 0 { + t.Fatalf("existing reference was changed or repacked: phases=%s secrets=%d error=%v", after, len(packed.Secrets), marshalErr) + } + } + }) + } +} diff --git a/migration/pkg/migration/unit_test.go b/migration/pkg/migration/unit_test.go index 203f56c..abecc35 100644 --- a/migration/pkg/migration/unit_test.go +++ b/migration/pkg/migration/unit_test.go @@ -149,6 +149,7 @@ func healthySubscriptionFixtures() (*operatorsv1alpha1.Subscription, *operatorsv return sub, csv } +// establishedClusterObjectSetCRD returns an established COS API for fake-client lifecycle tests. func establishedClusterObjectSetCRD() *apiextensionsv1.CustomResourceDefinition { return &apiextensionsv1.CustomResourceDefinition{ ObjectMeta: metav1.ObjectMeta{Name: clusterObjectSetCRDName}, @@ -386,19 +387,20 @@ func TestCompatibilityPureChecks(t *testing.T) { } } +// TestPhaseSortAndResourceKeys checks deterministic resource ordering and identity keys. func TestPhaseSortAndResourceKeys(t *testing.T) { object := func(group, kind, namespace, name string) ocv1ac.ClusterObjectSetObjectApplyConfiguration { u := unstructured.Unstructured{} u.SetGroupVersionKind(schema.GroupVersionKind{Group: group, Version: "v1", Kind: kind}) u.SetNamespace(namespace) u.SetName(name) - return *ocv1ac.ClusterObjectSetObject().WithObject(u) + return *ocv1ac.ClusterObjectSetObject().WithType(ocv1.ObjectTypeInlineManifest).WithInlineManifest(u) } phases := PhaseSort([]ocv1ac.ClusterObjectSetObjectApplyConfiguration{object("apps", "Deployment", "z", "b"), object("", "Secret", "z", "a"), object("apiextensions.k8s.io", "CustomResourceDefinition", "", "widgets.example.io"), object("apps", "Deployment", "a", "a")}) if len(phases) != 3 || *phases[0].Name != string(PhaseConfiguration) || *phases[1].Name != string(PhaseCRDs) || *phases[2].Name != string(PhaseDeploy) { t.Fatalf("unexpected phases %#v", phases) } - if *phases[2].CollisionProtection != ocv1.CollisionProtectionNone || phases[2].Objects[0].Object.GetNamespace() != "a" { + if *phases[2].CollisionProtection != ocv1.CollisionProtectionNone || phases[2].Objects[0].InlineManifest.GetNamespace() != "a" { t.Fatalf("deployment phase not sorted with migration collision protection: %#v", phases[2]) } a := unstructured.Unstructured{} @@ -412,9 +414,10 @@ func TestPhaseSortAndResourceKeys(t *testing.T) { } } +// TestSecretPacker verifies packed manifests can be recovered through their generated Secret references. func TestSecretPacker(t *testing.T) { obj := unstructured.Unstructured{Object: map[string]interface{}{"apiVersion": "v1", "kind": "ConfigMap", "metadata": map[string]interface{}{"name": "one"}, "data": map[string]interface{}{"x": "y"}}} - phases := []*ocv1ac.ClusterObjectSetPhaseApplyConfiguration{ocv1ac.ClusterObjectSetPhase().WithObjects(ocv1ac.ClusterObjectSetObject().WithObject(obj), ocv1ac.ClusterObjectSetObject().WithObject(obj))} + phases := []*ocv1ac.ClusterObjectSetPhaseApplyConfiguration{ocv1ac.ClusterObjectSetPhase().WithObjects(ocv1ac.ClusterObjectSetObject().WithType(ocv1.ObjectTypeInlineManifest).WithInlineManifest(obj), ocv1ac.ClusterObjectSetObject().WithType(ocv1.ObjectTypeInlineManifest).WithInlineManifest(obj))} result, err := (&secretPacker{RevisionName: "rev", OwnerName: "ce", SystemNamespace: "system"}).pack(phases) if err != nil || len(result.Secrets) != 1 || len(result.Secrets[0].Data) != 1 || len(result.Refs) != 2 { t.Fatalf("pack result=%#v err=%v", result, err) @@ -893,6 +896,7 @@ func TestCleanupResultErr(t *testing.T) { } } +// TestPrepareClusterObjectSet covers migration defaults and prerequisite validation. func TestPrepareClusterObjectSet(t *testing.T) { establishedCRD := &apiextensionsv1.CustomResourceDefinition{ ObjectMeta: metav1.ObjectMeta{Name: clusterObjectSetCRDName}, @@ -935,6 +939,7 @@ func TestPrepareClusterObjectSetRejectsExistingClusterExtension(t *testing.T) { } } +// TestPrepareClusterObjectSetRejectsDeletingOperatorControllerNamespace ensures a terminating controller namespace prevents staging. func TestPrepareClusterObjectSetRejectsDeletingOperatorControllerNamespace(t *testing.T) { establishedCRD := &apiextensionsv1.CustomResourceDefinition{ ObjectMeta: metav1.ObjectMeta{Name: clusterObjectSetCRDName}, @@ -968,17 +973,18 @@ func TestPrepareClusterObjectSetRejectsDeletingOperatorControllerNamespace(t *te } } -func TestPrepareClusterObjectSetRequiresEstablishedCRD(t *testing.T) { +// TestReadinessRequiresEstablishedCRD retains the lightweight API diagnostic. +func TestReadinessRequiresEstablishedCRD(t *testing.T) { m := migrationTestClient(t) - if _, err := m.PrepareClusterObjectSet(context.Background(), Options{}); err == nil || !strings.Contains(err.Error(), clusterObjectSetCRDName) { - t.Fatalf("PrepareClusterObjectSet() error = %v, want missing CRD error", err) + if err := m.ensureClusterObjectSetCRD(context.Background()); err == nil || !strings.Contains(err.Error(), clusterObjectSetCRDName) { + t.Fatalf("ensureClusterObjectSetCRD() error = %v, want missing CRD error", err) } m = migrationTestClient(t, &apiextensionsv1.CustomResourceDefinition{ ObjectMeta: metav1.ObjectMeta{Name: clusterObjectSetCRDName}, }) - if _, err := m.PrepareClusterObjectSet(context.Background(), Options{}); err == nil || !strings.Contains(err.Error(), "not established") { - t.Fatalf("PrepareClusterObjectSet() error = %v, want unestablished CRD error", err) + if err := m.ensureClusterObjectSetCRD(context.Background()); err == nil || !strings.Contains(err.Error(), "not established") { + t.Fatalf("ensureClusterObjectSetCRD() error = %v, want unestablished CRD error", err) } } @@ -1272,12 +1278,12 @@ func TestPrerequisitesAndRecoveryErrors(t *testing.T) { } } -func TestGatherRequiresClusterObjectSetPrerequisites(t *testing.T) { +func TestGatherRequiresControllerNamespace(t *testing.T) { sub, csv := healthySubscriptionFixtures() m := migrationTestClient(t, sub, csv) _, err := m.Gather(context.Background(), Options{SubscriptionName: sub.Name, SubscriptionNamespace: sub.Namespace}) - if err == nil || !strings.Contains(err.Error(), "ClusterObjectSet CRD") { - t.Fatalf("Gather() without the target CRD = %v, want a prerequisite error", err) + if err == nil || !strings.Contains(err.Error(), "operator-controller Deployment") { + t.Fatalf("Gather() without the controller namespace = %v, want a prerequisite error", err) } if err := m.Client.Get(context.Background(), client.ObjectKeyFromObject(sub), &operatorsv1alpha1.Subscription{}); err != nil { t.Fatalf("Gather() changed source Subscription: %v", err) @@ -1897,3 +1903,24 @@ func TestRollbackRejectsMissingSourceNamespaceWithoutMutation(t *testing.T) { t.Fatalf("rollback deleted ClusterObjectSet before source namespace preflight: %v", err) } } + +// TestPrepareDefersCOSAPIValidation leaves schema and create validation to dry-run. +func TestPrepareDefersCOSAPIValidation(t *testing.T) { + for _, present := range []bool{false, true} { + t.Run(fmt.Sprintf("unestablished CRD present=%t", present), func(t *testing.T) { + m := migrationTestClient(t) + if present { + if err := m.Client.Create(t.Context(), &apiextensionsv1.CustomResourceDefinition{ObjectMeta: metav1.ObjectMeta{Name: clusterObjectSetCRDName}}); err != nil { + t.Fatal(err) + } + } + opts, err := m.PrepareClusterObjectSet(t.Context(), Options{ClusterExtensionName: "example", SystemNamespace: "controller"}) + if err != nil { + t.Fatal(err) + } + if opts.UseClusterObjectDeployment { + t.Fatal("selected COD without a COD API") + } + }) + } +} diff --git a/specs/20260821-migration-v0-to-v1/e2e.md b/specs/20260821-migration-v0-to-v1/e2e.md index f3ef931..2dceb07 100644 --- a/specs/20260821-migration-v0-to-v1/e2e.md +++ b/specs/20260821-migration-v0-to-v1/e2e.md @@ -14,7 +14,7 @@ refusals, not features this library is expected to implement. ### COD transition -The library API dependency and COD CI controller both use commit `77754d81ea01`. +The library API dependency and COD CI controller both use commit `9dd683afa190`. The handoff test checks that the ownerless migration COD has `apps.kubernetes.io/managed-by: operator-controller` before CE creation and retains the label and COD UID after adoption. @@ -26,7 +26,7 @@ Unit regressions cover definitive create rejection recovery, terminal rollout diagnostics, and rollback retries with dangling references to verified COD UIDs. Migration automatically creates a COD named after the CE when the COD CRD exists; -otherwise it directly creates a COS, including against the default v1.12.0 installation. +otherwise it directly creates a COS using the current API definitions. A present but unready COD CRD or a discovery error blocks migration rather than falling back. COD migration requires the COD API/controller and the COD-backed CE applier merged in operator-controller PR #3058. The library's pinned API dependency alone does not @@ -39,13 +39,20 @@ conversion and acknowledged rollback preserved the operator Deployment UID and i available replica, restored the Subscription, and removed the COD and both COS revisions. The `migration/test-e2e-cod-rollback` target now automates those rollback assertions and collects CLI coverage. A separate CI job builds and installs operator-controller from -pinned commit `77754d81ea0125d3a850e9fa57decf7a7255a409`, then runs the handoff and -rollback targets. Default suites continue to exercise the legacy COS path. +pinned commit `9dd683afa190a67bc6c719abbafa97faa2d68b96`, then runs the handoff and +rollback targets. Default suites also build this pinned controller from source, +using upstream build targets and the experimental installer. Docker, Git, Python 3, and +`envsubst` must be available locally. Setup loads the built images into the +existing kind cluster without recreating it. -Both covered targets passed locally against `77754d81ea01` on -kind Kubernetes 1.37: handoff in 25.7 seconds and fixture conversion/rollback in -26.7 seconds. This verifies the revision labels and COD adoption requirement with the -actual controller, as well as workload-preserving rollback after adoption. +COS/COD are experimental: only the current typed `inlineManifest`/`secretRef` +entries are supported. There is no conversion of older experimental resource +schemas. Recreate clusters installed with older definitions before running these +suites. Fixture rollback verifies restoration, not OLMv0 reconciliation, because +fixture clusters have no OLMv0 controllers. + +The covered targets verify revision encoding, COD adoption, and workload-preserving +rollback. Rerun them against the pinned controller whenever updating the API dependency. ### Existing suites @@ -55,27 +62,35 @@ actual controller, as well as workload-preserving rollback after adoption. | `real-operator` | separate kind cluster with OLMv0 + OLMv1 | OLMv0's installed OperatorHub catalog | Covers V5.2–V5.6 plus cleanup, healthy rollback, and remigration (V5.8). V5.7 upgrade remains a gap. | | `in-cluster-job` | fixture cluster | A replayed ecr-secret-operator installation | Proves both CLIs authenticate and migrate using only a Pod ServiceAccount. | -Do not use a mutable public `latest` image or an unpinned release installer in CI. The fixture +The live suite intentionally follows the upstream `operatorhubio` catalog tag. +Quay removes superseded catalog manifests, so pinning its resolved digest does not +provide a durable test input. The catalog-creation test uses the currently resolved +digest and reports failure if that content disappears during the run. Use fixture +suites for reproducible catalog content. Setup waits for object-controller, +operator-controller, and catalogd on every run. Controller builds fix image names +to match generated manifests, regardless of caller image overrides. + +Pin controller versions and installers in CI; the public live catalog above is an +explicit exception. The fixture registry's `latest` tag is private to the disposable cluster and rebuilt from committed inputs on -every setup. The default bootstrap pins OLMv0 to `v0.46.0`, OLMv1 to `v1.12.0`, and kind to +every setup. The default bootstrap pins OLMv0 to `v0.46.0`, OLMv1 to commit `9dd683afa190`, and kind to `v0.33.0` with the digest-pinned Kubernetes `v1.37.0` node image; CI should mirror those release artifacts and override the URLs when it cannot access GitHub. The job inputs -are the kind node image, OLMv0 manifest URL and digest, operator-controller release -manifest URL and digest, and (only for the smoke suite) the catalog image/package/channel/CSV +are the kind node image, OLMv0 manifest URL and digest, operator-controller source commit, and (only for the smoke suite) the catalog image/package/channel/CSV version. The fixture catalog is constructed from committed snapshots on every fixture-cluster setup, so it does not rely on a retained Quay digest or a mutable external catalog tag. ## Bootstrap -1. For the live suite, run `make migration/e2e-setup` to create (or reuse) an isolated kind cluster named `library-olm-e2e` using +1. For the live suite, run `make migration/e2e-setup` to create (or use an empty) an isolated kind cluster named `library-olm-e2e` using [`test/e2e/migration/kind-config.yaml`](../../test/e2e/migration/kind-config.yaml), exporting an explicit Kind-generated kubeconfig at `.kubeconfig/library-olm-e2e`. `E2E_KUBECONFIG` is only an optional override for that generated output path. 2. Live only: apply the pinned OLMv0 quickstart manifest and wait for both `olm-operator` and `catalog-operator` deployments to be Available. -3. Live only: install the pinned experimental operator-controller release and wait for its deployment, +3. Live only: build and install the pinned experimental operator-controller and wait for its deployment, catalogd, cert provider, and required CRDs to be established. -4. For the fixture suite, run `make migration/e2e-fixture-setup` to create (or reuse) the separate +4. For the fixture suite, run `make migration/e2e-fixture-setup` to create (or use an empty) the separate `library-olm-fixture-e2e` cluster and generate `.kubeconfig/library-olm-fixture-e2e`. This path applies OLMv0 CRDs without installing OLMv0 controllers, installs the pinned experimental operator-controller release, builds bundle and FBC images from committed snapshots, publishes @@ -195,8 +210,8 @@ in-cluster Job E2E, COS-supersession E2E, and pinned COD handoff/rollback E2E as live, COS-supersession, and COD tests publish coverage inputs; a dependent coverage job displays their combined report. The Job intentionally does not upload diagnostics or coverage artifacts. -The supersession check is deliberately separate from the conversion matrix. With the released -operator-controller v1.12.0, migration creates revision 1 with collision protection `None`; +The supersession check is deliberately separate from the conversion matrix. With the pinned +experimental controller, migration creates revision 1 with collision protection `None`; creating the ClusterExtension results in a controller-owned, catalog-derived revision 2 with collision protection `Prevent`. The check requires both revisions to succeed. @@ -228,7 +243,9 @@ nonzero results after partial failure (V1.7). Unit tests also verify that batch classification applies acknowledgment flags and rejects `-n` or `--ce-name` with `--all`. `make migration/test-e2e-live-batch` repeats the four-state selection check with -two operators installed by OLMv0 and three isolated state markers. It asserts +Redis and external-secrets installed by OLMv0 and three isolated state markers. +This avoids the ecr-secret bundle’s invalid custom-resource sample in repeated +conversions; ecr-secret remains covered by the live migration matrix. It asserts that both eligible operators are selected and converted. It has its own CLI coverage directory and runs in the live CI job. The live batch and fixture acceptance targets verify that their kubeconfig @@ -351,13 +368,20 @@ independently and in parallel with the live suite. ### In-cluster Job test -This focused test is independent of coverage collection. It provisions (or reuses) the fixture +This focused test is independent of coverage collection. After fixture setup, it uses the fixture cluster, builds and loads a locally built, uninstrumented image into Kind, then runs catalog and operator migration from a Job using projected ServiceAccount credentials (with a test-only `cluster-admin` binding). It intentionally retains the Job namespace for log inspection; the next invocation removes it before creating a fresh Job. ```bash +make migration/e2e-fixture-setup make migration/test-e2e-in-cluster-job E2E_CLUSTER_NAME=library-olm-fixture-e2e make migration/e2e-teardown ``` + +Readiness reporting includes a lightweight COS API availability check; this is diagnostic, not a guarantee that a later write will succeed. Preparation does not repeat that COS CRD check. COD discovery remains necessary to select the revision manager. Gather (including CLI dry-run) and migration validate the prepared revision with a strict server-side dry-run create before removing OLMv0 management. Validation and creation share the same revision and Secret-reference builders; dry-run does not persist revisions or packed Secrets. The API server validates schema, admission, and permissions, but does not run controller-level validation of referenced workloads. Rollback permits verified newer sibling handoffs while retaining resource-UID, owner, and management-label checks. + +Setup refuses existing OLM namespaces or APIs, including partial installations. Run `E2E_CLUSTER_NAME= make migration/e2e-teardown` before repeating setup. It installs the pinned controller from scratch and waits for the revision APIs, object-controller, operator-controller, and catalogd. Test targets reuse the prepared cluster without invoking setup. + +The live namespace-deletion target uses Redis. The ecr-secret-operator bundle includes a custom-resource sample with `spec.aws_iam_secret`, which is absent from its CRD schema and can block OLMv1 preflight in a new namespace. Ecr-secret-operator remains in the live migration matrix; the focused Redis scenario preserves all source-namespace deletion and label-transfer assertions. diff --git a/specs/20260821-migration-v0-to-v1/plan.md b/specs/20260821-migration-v0-to-v1/plan.md index c797a92..bd75f9c 100644 --- a/specs/20260821-migration-v0-to-v1/plan.md +++ b/specs/20260821-migration-v0-to-v1/plan.md @@ -44,7 +44,7 @@ Verified during Phase 8 E2E. **COD transition (R2.7), in progress:** the library selects COD creation when its CRD exists, current-generation rollout checks, and COD-aware rollback. API types are pinned to -operator-controller commit `77754d81ea01`, matching the COD CI controller and including +operator-controller commit `9dd683afa190`, matching the COD CI controller and including the adoption label requirement. Migration stamps `apps.kubernetes.io/managed-by: operator-controller` on the ownerless COD before handoff; unit and E2E assertions check this label and preservation of the original COD identity. Directly created @@ -58,8 +58,8 @@ PR #3058. On 2026-10-29, a disposable kind cluster running operator-controller m and its revisions 1 and 2 used `None` and `Prevent` collision protection. A separate full CLI fixture conversion and acknowledged rollback restored the Subscription, removed COD/COS resources, and preserved the operator Deployment UID and availability. -The default E2E setup remains pinned to v1.12.0 for the legacy path. A separate CI job -builds pinned COD-capable commit `77754d81ea0125d3a850e9fa57decf7a7255a409` and +The default E2E setup builds the pinned current experimental controller. A separate CI job +builds pinned COD-capable commit `9dd683afa190a67bc6c719abbafa97faa2d68b96` and runs covered handoff and workload-preserving rollback E2E targets. The rollback target passed locally on 2026-10-29. Both covered targets passed again on 2026-11-05 against `bbe43971eadd` on kind @@ -67,6 +67,9 @@ Kubernetes 1.37, verifying labeled COD adoption and rollback. The covered handoff and rollback targets also pass against `77754d81ea01`, including COS manager-label assertions. Direct COS creation and the `UnmanagedRevision` terminal condition are covered by unit regressions. +The current API uses typed `inlineManifest`/`secretRef` entries for creation and +rollback. Older experimental COS/COD schemas are not supported; the controller +and library must use matching definitions. --- @@ -173,7 +176,7 @@ an explicitly selected OLMv1 system-managed namespace mode. - Move collected namespace-scoped resources to the target namespace in the migration COS and, after the target CE is installed, remove their source copies. - Delete the source namespace only with `--acknowledge-namespace-delete`; retain it by default. -- `--system-managed-install-namespace` uses operator-controller `v1.12.0`'s experimental +- `--system-managed-install-namespace` uses the pinned operator-controller experimental optional-namespace CRD. It capability-gates the mode and omits the CE field. Migration prepares the bundle-metadata namespace before its COS and imports it for the catalog revision's ownership handoff, after which OLMv1 manages it. Unit tests @@ -232,3 +235,76 @@ Phase 1 (4717) ──► Phase 2 (4718) ──► Phase 3 (4719) ──► Phase Phase 7 (4723, operator-controller): APIService-owning operators remain unsupported; C3 is permanent ``` + +Readiness reporting includes a lightweight COS API availability check; this is diagnostic, not a guarantee that a later write will succeed. Preparation does not repeat that COS CRD check. COD discovery remains necessary to select the revision manager. Gather (including CLI dry-run) and migration validate the prepared revision with a strict server-side dry-run create before removing OLMv0 management. Validation and creation share the same revision and Secret-reference builders; dry-run does not persist revisions or packed Secrets. The API server validates schema, admission, and permissions, but does not run controller-level validation of referenced workloads. Rollback permits verified newer sibling handoffs while retaining resource-UID, owner, and management-label checks. + + +## Follow-ups from the COS/COD compatibility review + +These items remain outside PR93's initial compatibility scope. Keep them open +until their implementation and validation are complete; a review response alone +is not completion. + +### Protected handoff to ClusterExtension + +- [ ] Complete either [PR95 (COD-only)](https://github.com/operator-framework/library-olm/pull/95) + or [PR97 (COS+COD)](https://github.com/operator-framework/library-olm/pull/97). + These are alternative approaches, not sequential requirements. +- COD-only: create an adoption-disabled COD with `collisionProtection: None`, + wait for its initial rollout, then atomically enable `Prevent`, remove + phase/object overrides, and enable CE adoption. Complete the protected rollout + before creating the CE. +- COS+COD: complete initial COS adoption with `None` before creating the protected + COD with `Prevent`, then allow the CE handoff. +- Validate that initial resources are adopted, later unrelated-object collisions + are rejected, and failed handoffs preserve recovery information. + +Source: [handoff safety review](https://github.com/operator-framework/library-olm/pull/93#discussion_r4556776332). + +### Explicit migration annotation cleanup + +- [ ] Design an explicit API/CLI operation for users who no longer need migration + recovery metadata. Do not remove annotations automatically after migration; + users may still need rollback, and historical values can become stale. +- Classify provenance, invocation identity, backup data, and bundle metadata by + resource and consumer. Determine which fields can be removed safely and how + removing them affects rollback. Preserve metadata still used by controllers. +- Define dry-run output and explicit user acknowledgment for any loss of recovery + capability. Test resource ownership checks, repeated cleanup, and preservation + of active workloads and controller-owned metadata. +- Keep this operation distinct from the existing cleanup of OLMv0 conflicts. + +Source: [annotation retention discussion](https://github.com/operator-framework/library-olm/pull/93#discussion_r4556715778). + +### Align owner labels with upstream controllers + +- [ ] Revisit `LabelOwnerKind`, `LabelOwnerName`, and managed-by labels once + operator-controller/object-controller settle their requirements. +- Until then, retain alignment with the pinned controller on COD metadata, COD + template metadata, and directly created COS resources. Do not remove labels + preemptively. +- Coordinate any change with adoption, resource discovery, rollback, and cleanup + tests so removing a label does not break identity or ownership checks. + +Sources: [COD labels](https://github.com/operator-framework/library-olm/pull/93#discussion_r4556739359), +[template labels](https://github.com/operator-framework/library-olm/pull/93#discussion_r4556747596), +[COS labels](https://github.com/operator-framework/library-olm/pull/93#discussion_r4556851701). + +### Shared revision content conversion and typed construction + +- [ ] Centralize conversion from supported bundle formats and collected migration + resources to `ClusterObjectSetContent` in library-olm. Migration's `PhaseSort` + and operator-controller's internal phase construction currently duplicate + ordering and content-conversion logic. +- Define a reusable converter with explicit inputs, shared phase-ordering tests, + and adapters for both callers. Keep controller reconciliation, migration + ownership, and Secret persistence outside the converter. +- [ ] Replace the apply-configuration JSON marshal/unmarshal round-trip with a + consistent typed-object construction path. Address phase sorting and Secret + packing together rather than adding a manual conversion layer solely at the + COD constructor. Assess changes to exported APIs such as `PhaseSort` explicitly. +- Preserve shared builders for server-side dry-run and actual creation, and test + inline manifests, packed references, optional fields, labels, and annotations. + +Sources: [shared converter](https://github.com/operator-framework/library-olm/pull/93#discussion_r4554296554), +[typed construction](https://github.com/operator-framework/library-olm/pull/93#discussion_r4556794570). diff --git a/specs/20260821-migration-v0-to-v1/requirements.md b/specs/20260821-migration-v0-to-v1/requirements.md index 510d701..8f7a4c1 100644 --- a/specs/20260821-migration-v0-to-v1/requirements.md +++ b/specs/20260821-migration-v0-to-v1/requirements.md @@ -119,10 +119,10 @@ breaking API changes permitted while `v0`. Two binaries. Prow + GitHub Actions C **R2.2** — Target OLMv1's `ClusterObjectSet` (COS). The `perdasilva` prototype uses the old `ClusterExtensionRevision` name throughout; all references must be updated to -`ClusterObjectSet` / `ClusterObjectSetList` / `ClusterObjectSetTypeSucceeded`. +`ClusterObjectSet` / `ClusterObjectSetList`. **R2.3** — The migration tool **creates** the COS, then **waits** for the COS controller -to set `Succeeded=True`, then creates the `ClusterExtension`. With operator-controller v1.12.0, +to set `status.completedAt`, then creates the `ClusterExtension`. the controller creates a subsequent catalog-derived COS revision rather than adopting the migration COS. The tool **must not** write status on any OLMv1 API. No operator-controller changes are required (verified — see @@ -152,8 +152,8 @@ The directory is created if it does not exist. Failure to list associated plans **R2.7 — Boxcutter phase 2.** Support one `ClusterObjectDeployment` (COD) per ClusterExtension, with controller-managed COS revisions. The initial implementation is -selected automatically when the COD CRD exists; when absent, the released v1.12.0 COS -workflow is retained. Discovery errors must fail rather than silently fall back. COD migration requires an established +selected automatically when the COD CRD exists; when absent, the direct COS +workflow uses the current COS definitions. Discovery errors must fail rather than silently fall back. COD migration requires an established COD CRD and operator-controller's COD-backed ClusterExtension applier (upstream PR #3058). Create the deployment with collision protection `None`, wait for current-generation rollout completion and availability, then create the CE to hand management to operator-controller. @@ -166,6 +166,10 @@ Directly created migration COS revisions carry `apps.kubernetes.io/managed-by: object-controller` so a COD can adopt an ownerless revision in its group. 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 +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. Persist verified deployment UIDs on the CE before deletion so late revisions with @@ -374,3 +378,5 @@ unreferenced source would be deleted without changing it. - Hosted Control Planes — OLMv1 is not supported on HCP yet; the design must not foreclose it (e.g. don't hardcode a single kubeconfig). - Binary packaging / `oc` plugin / container images — deferred to the downstream TP phase ([OCPSTRAT-2692](https://redhat.atlassian.net/browse/OCPSTRAT-2692)). - Console UI. + +Readiness reporting includes a lightweight COS API availability check; this is diagnostic, not a guarantee that a later write will succeed. Preparation does not repeat that COS CRD check. COD discovery remains necessary to select the revision manager. Gather (including CLI dry-run) and migration validate the prepared revision with a strict server-side dry-run create before removing OLMv0 management. Validation and creation share the same revision and Secret-reference builders; dry-run does not persist revisions or packed Secrets. The API server validates schema, admission, and permissions, but does not run controller-level validation of referenced workloads. Rollback permits verified newer sibling handoffs while retaining resource-UID, owner, and management-label checks. diff --git a/specs/20260821-migration-v0-to-v1/validation.md b/specs/20260821-migration-v0-to-v1/validation.md index 2f75c70..4ac7b4a 100644 --- a/specs/20260821-migration-v0-to-v1/validation.md +++ b/specs/20260821-migration-v0-to-v1/validation.md @@ -13,14 +13,14 @@ kind cluster with both OLMv0 and OLMv1 installed. - **V1.1** `check -n ` on a healthy AllNamespaces operator with an available catalog reports all checks green and exits 0; makes no cluster changes. - **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 legacy COS mode, the COS reaches `Succeeded=True` 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.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. - **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. - **V1.8** No command ever blocks on interactive input. An operator whose name collides with a verb (e.g. `check`) is migratable as a positional argument (`convert check -n `). -- **V1.9** Manager detection selects legacy COS when the COD CRD is absent and COD when it is present and established. Discovery errors and unmet prerequisites fail before deleting OLMv0 resources. Validate COD name/group constraints and reject an existing COD rather than overwriting it. CRD presence is the supported capability signal; controller-version detection is not required. +- **V1.9** Manager detection selects direct COS when the COD CRD is absent and COD when it is present and established. Discovery errors and unmet prerequisites fail before deleting OLMv0 resources. Validate COD name/group constraints and reject an existing COD rather than overwriting it. CRD presence is the supported capability signal; controller-version detection is not required. - **V1.10** The COD template preserves migration labels, annotations, packed Secret references, and `CollisionProtection: None`. Readiness requires completion and availability for the current generation; stale status cannot satisfy the wait. Invalid-specification and deadline failures report actionable errors. Once a COD may have reconciled, failure preserves migration resources and refuses automatic OLMv0 recovery. The COD itself carries `apps.kubernetes.io/managed-by: operator-controller` before CE creation and after adoption. It has no controller owner during @@ -31,6 +31,9 @@ kind cluster with both OLMv0 and OLMv1 installed. object-controller` and remain ownerless during staging. COD-generated migration and catalog revisions carry the same COS label, while the COD retains its distinct `operator-controller` value. + Assert inline and Secret-backed object encodings using the current COS/COD + definitions, including workload preservation during rollback. Older experimental + schemas are outside the compatibility requirements. Assert prompt failures for all current-generation terminal `Progressing=False` reasons except successful completion, including revision collisions and invalid revisions; preserve the controller's reason and message. Definitive COS/COD create rejections restore OLMv0 and report that the target cannot be active; timeouts and transport failures refuse automatic recovery. Rollback persists verified COD UIDs before deletion and accepts matching dangling references even after restarting rollback. Unknown UIDs remain rejected, and failure to persist verified identity prevents COD deletion. @@ -85,7 +88,7 @@ flag flips it to `Eligible`: - **V4.5** OperatorCondition disambiguation: an operator with OLMv0-stamped OperatorCondition RBAC but **empty** `status.conditions` is **Eligible** (RBAC is not treated as usage). - **V4.6** Large bundle exceeding inline size limits migrates successfully via SecretPacker. - **V4.7** Namespace change copies `pod-security.kubernetes.io/*` and `security.openshift.io/scc.podSecurityLabelSync` to the new namespace. An existing target with no explicit PSA `enforce` label is rejected when the source sets one, because its cluster default is not observable. Collected source Deployments scale to zero before target creation so two controllers do not overlap. They return to their original replica count only when target COS creation failed before it may have reconciled; otherwise migration reports that the target may be active, leaves the source scaled down, and refuses automatic OLMv0 recovery. The target operator resources are present and their collected source copies are removed. The fixture scenario retains the old namespace by default; the live scenario passes `--acknowledge-namespace-delete` and verifies the source namespace is deleted after OLMv0 finalizes its CSV. -- **V4.8** System-managed namespace: against operator-controller `v1.12.0`'s experimental CRD, +- **V4.8** System-managed namespace: against the pinned operator-controller experimental CRD, explicit system-managed conversion omits `ClusterExtension.spec.namespace`, prepares the bundle-metadata namespace for the preceding COS, includes it in the migration revision, and verifies the catalog revision takes Namespace ownership while OLMv1 manages the installation there. @@ -105,7 +108,7 @@ flag flips it to `Eligible`: - **V5.8** `rollback --acknowledge-installed` → Subscription restored, CE and COS revisions deleted, preserved Deployments released from OLMv1 ownership; a second `convert` creates new CE/COS UIDs, installs successfully, and adopts the same Deployment UIDs. In COD mode, also verify the COD is deleted and no COS remains in its group, while the Deployment UID and availability are preserved. Fixture tests assert restored Subscription state; OLMv0 reconciliation requires the live environment. - **V5.9** Fresh cluster with operators in all four states → `check --all` → correct four-section output; `convert --all` warns on Conflicts and migrates only Eligible. -- **V5.10** On a COD-capable controller, fixture migration creates one COD named for the CE. Catalog handoff retains that COD's UID, establishes CE ownership of the COD and COD ownership of successive COS revisions in the same group, and retains the migration revision (`None`) alongside a new catalog revision (`Prevent`). Verify the migration COS retains its UID and both revisions retain their respective collision-protection settings. Run handoff and fixture conversion/rollback (V5.8) in the dedicated COD CI job, collecting coverage separately from legacy COS tests. +- **V5.10** On a COD-capable controller, fixture migration creates one COD named for the CE. Catalog handoff retains that COD's UID, establishes CE ownership of the COD and COD ownership of successive COS revisions in the same group, and retains the migration revision (`None`) alongside a new catalog revision (`Prevent`). Verify the migration COS retains its UID and both revisions retain their respective collision-protection settings. Run handoff and fixture conversion/rollback (V5.8) in the dedicated COD CI job, collecting coverage separately from the other fixture tests. ## V6. Non-functional (Jira deployment considerations) @@ -151,3 +154,5 @@ flag flips it to `Eligible`: | R8 CatalogSource→ClusterCatalog | V3.8–V3.11, V3.13–V3.17, V3.19 | | R9 Edge cases | V4.1–V4.8 | | R10 Non-goals | V6.4, V6.5 | + +Readiness reporting includes a lightweight COS API availability check; this is diagnostic, not a guarantee that a later write will succeed. Preparation does not repeat that COS CRD check. COD discovery remains necessary to select the revision manager. Gather (including CLI dry-run) and migration validate the prepared revision with a strict server-side dry-run create before removing OLMv0 management. Validation and creation share the same revision and Secret-reference builders; dry-run does not persist revisions or packed Secrets. The API server validates schema, admission, and permissions, but does not run controller-level validation of referenced workloads. Rollback permits verified newer sibling handoffs while retaining resource-UID, owner, and management-label checks. diff --git a/test/e2e/migration/backup_directory_test.go b/test/e2e/migration/backup_directory_test.go index 9b95a3c..eb685ed 100644 --- a/test/e2e/migration/backup_directory_test.go +++ b/test/e2e/migration/backup_directory_test.go @@ -91,7 +91,7 @@ func TestFixtureBackupDirectory(t *testing.T) { } } if scenario == "delete-denied" { - args[len(args)-1] = backupReadOnlyKubeconfig(t, c) + args[len(args)-1] = backupDeletionDeniedKubeconfig(t, c) } out, err := output(cli, args...) switch scenario { @@ -180,13 +180,16 @@ func assertBackupManifest(t *testing.T, path string, expected client.Object, api } } -func backupReadOnlyKubeconfig(t *testing.T, c client.Client) string { +func backupDeletionDeniedKubeconfig(t *testing.T, c client.Client) string { t.Helper() const identity = "migration-backup-reader" run(t, "kubectl", "delete", "clusterrolebinding/"+identity, "clusterrole/"+identity, "--ignore-not-found") role := &rbacv1.ClusterRole{ObjectMeta: metav1.ObjectMeta{Name: identity}, Rules: []rbacv1.PolicyRule{ {APIGroups: []string{"*"}, Resources: []string{"*"}, Verbs: []string{"get", "list", "watch"}}, {APIGroups: []string{""}, Resources: []string{"pods/portforward"}, Verbs: []string{"create"}}, + // Server-side dry-run requires create permission. Keep deletion denied + // so the scenario still verifies that backup precedes Subscription removal. + {APIGroups: []string{ocv1.GroupVersion.Group}, Resources: []string{"clusterobjectsets", "clusterobjectdeployments"}, Verbs: []string{"create"}}, }} binding := &rbacv1.ClusterRoleBinding{ObjectMeta: metav1.ObjectMeta{Name: identity}, RoleRef: rbacv1.RoleRef{APIGroup: rbacv1.GroupName, Kind: "ClusterRole", Name: identity}, Subjects: []rbacv1.Subject{{Kind: "User", APIGroup: rbacv1.GroupName, Name: identity}}} t.Cleanup(func() {