diff --git a/.github/workflows/nightly-postgresql-upgrade-test.yaml b/.github/workflows/nightly-postgresql-upgrade-test.yaml new file mode 100644 index 000000000..85f91dbf2 --- /dev/null +++ b/.github/workflows/nightly-postgresql-upgrade-test.yaml @@ -0,0 +1,114 @@ +name: Nightly PostgreSQL Upgrade Test + +on: + workflow_dispatch: + schedule: + - cron: "25 0 * * *" + +jobs: + postgresql-upgrade: + name: E2E PostgreSQL ${{ matrix.from_branch }} to ${{ matrix.to_branch }} + concurrency: + group: ${{ github.workflow }}-${{ matrix.from_branch }}-${{ matrix.to_branch }} + cancel-in-progress: true + runs-on: ubuntu-latest + timeout-minutes: 90 + strategy: + fail-fast: false + matrix: + include: + - from_branch: release-1.10 + to_branch: main + permissions: + contents: read + env: + CONTAINER_ENGINE: docker + FROM_OPERATOR_MANIFEST: https://raw.githubusercontent.com/${{ github.repository }}/refs/heads/${{ matrix.from_branch }}/dist/rhdh/install.yaml + TO_OPERATOR_MANIFEST: ${{ github.workspace }}/dist/rhdh/install.yaml + + steps: + - name: Checkout + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ matrix.to_branch }} + fetch-depth: 0 + persist-credentials: false + + - name: Setup Go + uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7 + with: + go-version-file: 'go.mod' + + - name: Resolve source operator image + run: | + FROM_OPERATOR_IMAGE=$(curl --proto '=https' --proto-redir '=https' -fsSL "$FROM_OPERATOR_MANIFEST" | yq 'select(.kind == "Deployment" and .metadata.labels.app == "rhdh-operator") | .spec.template.spec.containers[0].image') + test -n "$FROM_OPERATOR_IMAGE" + skopeo inspect "docker://$FROM_OPERATOR_IMAGE" > /dev/null + echo "FROM_OPERATOR_IMAGE=$FROM_OPERATOR_IMAGE" >> "$GITHUB_ENV" + + - name: Remove unnecessary files to free up disk space + uses: endersonmenezes/free-disk-space@2a22f8c59cae9cddae7194b33e6b92d023b2b4b8 # v4 + with: + remove_android: true + remove_dotnet: true + remove_haskell: true + rm_cmd: "rmz" + + - name: Build target operator image and manifest + env: + TO_OPERATOR_IMAGE: localhost/rhdh-operator:nightly-${{ matrix.from_branch }}-to-${{ matrix.to_branch }}-${{ github.run_id }} + run: | + make image-build build-installer PROFILE=rhdh IMG="$TO_OPERATOR_IMAGE" + MANIFEST_IMAGE=$(yq 'select(.kind == "Deployment" and .metadata.labels.app == "rhdh-operator") | .spec.template.spec.containers[0].image' "$TO_OPERATOR_MANIFEST") + test "$MANIFEST_IMAGE" = "$TO_OPERATOR_IMAGE" + echo "TO_OPERATOR_IMAGE=$TO_OPERATOR_IMAGE" >> "$GITHUB_ENV" + + - name: Generate Kind config + run: | + cat < "$RUNNER_TEMP/kind-config.yaml" + apiVersion: kind.x-k8s.io/v1alpha4 + kind: Cluster + nodes: + - role: control-plane + extraPortMappings: + - containerPort: 80 + hostPort: 80 + protocol: TCP + - containerPort: 443 + hostPort: 443 + protocol: TCP + kubeadmConfigPatches: + - | + apiVersion: kubelet.config.k8s.io/v1beta1 + kind: KubeletConfiguration + imageGCHighThresholdPercent: 70 + imageGCLowThresholdPercent: 50 + imageMinimumGCAge: 2m + EOF + + - name: Create Kind cluster + uses: helm/kind-action@a1b0e391336a6ee6713a0583f8c6240d70863de3 # v1.12.0 + with: + cluster_name: test-cluster + config: ${{ runner.temp }}/kind-config.yaml + ignore_failed_clean: true + + - name: Load target operator image + run: kind load docker-image --name test-cluster "$TO_OPERATOR_IMAGE" + + - name: Install Ingress Controller + run: | + kubectl apply -f https://kind.sigs.k8s.io/examples/ingress/deploy-ingress-nginx.yaml + kubectl wait --namespace ingress-nginx \ + --for=condition=ready pod \ + --selector=app.kubernetes.io/component=controller \ + --timeout=90s + + - name: Run PostgreSQL upgrade E2E test + env: + BACKSTAGE_OPERATOR_TESTS_PLATFORM: kind + BACKSTAGE_OPERATOR_TESTS_POSTGRESQL_UPGRADE: 'true' + PROFILE: 'rhdh' + OPERATOR_MANIFEST: ${{ env.TO_OPERATOR_MANIFEST }} + IMG: ${{ env.TO_OPERATOR_IMAGE }} + run: make test-e2e-upgrade diff --git a/.github/workflows/nightly-upgrade-test.yaml b/.github/workflows/nightly-upgrade-test.yaml index 112ccea6f..d9be68b0f 100644 --- a/.github/workflows/nightly-upgrade-test.yaml +++ b/.github/workflows/nightly-upgrade-test.yaml @@ -79,12 +79,12 @@ jobs: FROM_OPERATOR_MANIFEST="https://raw.githubusercontent.com/${{ github.repository }}/refs/heads/${{ matrix.from_branch }}/${distLocation}" echo "FROM_OPERATOR_MANIFEST=${FROM_OPERATOR_MANIFEST}" >> $GITHUB_ENV - FROM_OPERATOR_IMAGE=$(curl -s "${FROM_OPERATOR_MANIFEST}" | yq 'select(.kind == "Deployment" and .metadata.labels.app == "rhdh-operator") | .spec.template.spec.containers[0].image') + FROM_OPERATOR_IMAGE=$(curl --proto '=https' --proto-redir '=https' -fsSL "${FROM_OPERATOR_MANIFEST}" | yq 'select(.kind == "Deployment" and .metadata.labels.app == "rhdh-operator") | .spec.template.spec.containers[0].image') echo "FROM_OPERATOR_IMAGE=${FROM_OPERATOR_IMAGE}" >> $GITHUB_ENV TO_OPERATOR_MANIFEST="https://raw.githubusercontent.com/${{ github.repository }}/refs/heads/${{ matrix.to_branch }}/${distLocation}" echo "TO_OPERATOR_MANIFEST=${TO_OPERATOR_MANIFEST}" >> $GITHUB_ENV - TO_OPERATOR_IMAGE=$(curl -s "${TO_OPERATOR_MANIFEST}" | yq 'select(.kind == "Deployment" and .metadata.labels.app == "rhdh-operator") | .spec.template.spec.containers[0].image') + TO_OPERATOR_IMAGE=$(curl --proto '=https' --proto-redir '=https' -fsSL "${TO_OPERATOR_MANIFEST}" | yq 'select(.kind == "Deployment" and .metadata.labels.app == "rhdh-operator") | .spec.template.spec.containers[0].image') echo "TO_OPERATOR_IMAGE=${TO_OPERATOR_IMAGE}" >> $GITHUB_ENV - name: Check if operator images exist in remote registry diff --git a/.rhdh/scripts/prepare-restricted-environment.sh b/.rhdh/scripts/prepare-restricted-environment.sh index 7c5eec063..6aa622a0f 100755 --- a/.rhdh/scripts/prepare-restricted-environment.sh +++ b/.rhdh/scripts/prepare-restricted-environment.sh @@ -1481,8 +1481,8 @@ EOF spec: imageDigestMirrors: - mirrors: - - ${registry_url_internal}/rhel9/postgresql-15 - source: registry.redhat.io/rhel9/postgresql-15 + - ${registry_url_internal}/rhel10/postgresql-18 + source: registry.redhat.io/rhel10/postgresql-18 - mirrors: - ${registry_url_internal}/rhdh source: registry.redhat.io/rhdh diff --git a/bundle/backstage.io/manifests/backstage-default-config_v1_configmap.yaml b/bundle/backstage.io/manifests/backstage-default-config_v1_configmap.yaml index 50e5a6676..1a9c1d003 100644 --- a/bundle/backstage.io/manifests/backstage-default-config_v1_configmap.yaml +++ b/bundle/backstage.io/manifests/backstage-default-config_v1_configmap.yaml @@ -84,7 +84,7 @@ data: value: /var/lib/pgsql/data - name: PGDATA value: /var/lib/pgsql/data/userdata - image: quay.io/fedora/postgresql-15:latest # will be replaced with the actual image + image: quay.io/fedora/postgresql-18:latest # will be replaced with the actual image imagePullPolicy: IfNotPresent securityContext: # runAsUser:26 does not work for Openshift but looks work for AKS/EKS diff --git a/bundle/rhdh/manifests/backstage-operator.clusterserviceversion.yaml b/bundle/rhdh/manifests/backstage-operator.clusterserviceversion.yaml index a4a79bcd1..dc58a3671 100644 --- a/bundle/rhdh/manifests/backstage-operator.clusterserviceversion.yaml +++ b/bundle/rhdh/manifests/backstage-operator.clusterserviceversion.yaml @@ -342,7 +342,7 @@ spec: - name: OPERATOR_DP_PROCESSING value: "true" - name: RELATED_IMAGE_postgresql - value: quay.io/fedora/postgresql-15:latest + value: quay.io/fedora/postgresql-18:latest - name: RELATED_IMAGE_backstage value: quay.io/rhdh-community/rhdh:next - name: RELATED_IMAGE_plugin_installer @@ -486,7 +486,7 @@ spec: name: Red Hat Inc. url: https://www.redhat.com/ relatedImages: - - image: quay.io/fedora/postgresql-15:latest + - image: quay.io/fedora/postgresql-18:latest name: postgresql - image: quay.io/rhdh-community/rhdh:next name: backstage diff --git a/bundle/rhdh/manifests/rhdh-default-config_v1_configmap.yaml b/bundle/rhdh/manifests/rhdh-default-config_v1_configmap.yaml index b348fc2df..e31d08943 100644 --- a/bundle/rhdh/manifests/rhdh-default-config_v1_configmap.yaml +++ b/bundle/rhdh/manifests/rhdh-default-config_v1_configmap.yaml @@ -69,7 +69,7 @@ data: value: /var/lib/pgsql/data - name: PGDATA value: /var/lib/pgsql/data/userdata - image: quay.io/fedora/postgresql-15:latest # will be replaced with the actual image + image: quay.io/fedora/postgresql-18:latest # will be replaced with the actual image imagePullPolicy: IfNotPresent securityContext: # runAsUser:26 does not work for Openshift but looks work for AKS/EKS diff --git a/bundle/rhdh/manifests/rhdh-plugin-deps_v1_configmap.yaml b/bundle/rhdh/manifests/rhdh-plugin-deps_v1_configmap.yaml index 6fe7f72fb..e361e618f 100644 --- a/bundle/rhdh/manifests/rhdh-plugin-deps_v1_configmap.yaml +++ b/bundle/rhdh/manifests/rhdh-plugin-deps_v1_configmap.yaml @@ -25,7 +25,7 @@ data: spec: containers: - name: psql - image: quay.io/fedora/postgresql-15:latest + image: quay.io/fedora/postgresql-18:latest resources: limits: cpu: "100m" diff --git a/config/profile/backstage.io/default-config/db-statefulset.yaml b/config/profile/backstage.io/default-config/db-statefulset.yaml index 232a7b8f2..f18219757 100644 --- a/config/profile/backstage.io/default-config/db-statefulset.yaml +++ b/config/profile/backstage.io/default-config/db-statefulset.yaml @@ -33,7 +33,7 @@ spec: value: /var/lib/pgsql/data - name: PGDATA value: /var/lib/pgsql/data/userdata - image: quay.io/fedora/postgresql-15:latest # will be replaced with the actual image + image: quay.io/fedora/postgresql-18:latest # will be replaced with the actual image imagePullPolicy: IfNotPresent securityContext: # runAsUser:26 does not work for Openshift but looks work for AKS/EKS diff --git a/config/profile/rhdh/default-config/db-statefulset.yaml b/config/profile/rhdh/default-config/db-statefulset.yaml index 232a7b8f2..f18219757 100644 --- a/config/profile/rhdh/default-config/db-statefulset.yaml +++ b/config/profile/rhdh/default-config/db-statefulset.yaml @@ -33,7 +33,7 @@ spec: value: /var/lib/pgsql/data - name: PGDATA value: /var/lib/pgsql/data/userdata - image: quay.io/fedora/postgresql-15:latest # will be replaced with the actual image + image: quay.io/fedora/postgresql-18:latest # will be replaced with the actual image imagePullPolicy: IfNotPresent securityContext: # runAsUser:26 does not work for Openshift but looks work for AKS/EKS diff --git a/config/profile/rhdh/patches/deployment-patch.yaml b/config/profile/rhdh/patches/deployment-patch.yaml index 9aade9d1c..bd06cd861 100644 --- a/config/profile/rhdh/patches/deployment-patch.yaml +++ b/config/profile/rhdh/patches/deployment-patch.yaml @@ -23,7 +23,7 @@ spec: - name: OPERATOR_DP_PROCESSING value: "{{OPERATOR_DP_PROCESSING}}" - name: RELATED_IMAGE_postgresql - value: quay.io/fedora/postgresql-15:latest + value: quay.io/fedora/postgresql-18:latest - name: RELATED_IMAGE_backstage value: quay.io/rhdh-community/rhdh:next - name: RELATED_IMAGE_plugin_installer diff --git a/config/profile/rhdh/plugin-deps/sonataflow.yaml b/config/profile/rhdh/plugin-deps/sonataflow.yaml index 5fffa3b9c..098063252 100644 --- a/config/profile/rhdh/plugin-deps/sonataflow.yaml +++ b/config/profile/rhdh/plugin-deps/sonataflow.yaml @@ -9,7 +9,7 @@ spec: spec: containers: - name: psql - image: quay.io/fedora/postgresql-15:latest + image: quay.io/fedora/postgresql-18:latest resources: limits: cpu: "100m" diff --git a/dist/backstage.io/install.yaml b/dist/backstage.io/install.yaml index 9f72f6bb0..b6b8d4a29 100644 --- a/dist/backstage.io/install.yaml +++ b/dist/backstage.io/install.yaml @@ -2844,7 +2844,7 @@ data: value: /var/lib/pgsql/data - name: PGDATA value: /var/lib/pgsql/data/userdata - image: quay.io/fedora/postgresql-15:latest # will be replaced with the actual image + image: quay.io/fedora/postgresql-18:latest # will be replaced with the actual image imagePullPolicy: IfNotPresent securityContext: # runAsUser:26 does not work for Openshift but looks work for AKS/EKS diff --git a/dist/rhdh/install.yaml b/dist/rhdh/install.yaml index 4aacb1469..1d59b4184 100644 --- a/dist/rhdh/install.yaml +++ b/dist/rhdh/install.yaml @@ -2892,7 +2892,7 @@ data: value: /var/lib/pgsql/data - name: PGDATA value: /var/lib/pgsql/data/userdata - image: quay.io/fedora/postgresql-15:latest # will be replaced with the actual image + image: quay.io/fedora/postgresql-18:latest # will be replaced with the actual image imagePullPolicy: IfNotPresent securityContext: # runAsUser:26 does not work for Openshift but looks work for AKS/EKS @@ -3931,7 +3931,7 @@ data: spec: containers: - name: psql - image: quay.io/fedora/postgresql-15:latest + image: quay.io/fedora/postgresql-18:latest resources: limits: cpu: "100m" @@ -4486,7 +4486,7 @@ spec: - name: OPERATOR_DP_PROCESSING value: 'true' - name: RELATED_IMAGE_postgresql - value: quay.io/fedora/postgresql-15:latest + value: quay.io/fedora/postgresql-18:latest - name: RELATED_IMAGE_backstage value: quay.io/rhdh-community/rhdh:next - name: RELATED_IMAGE_plugin_installer diff --git a/pkg/model/db-statefulset_test.go b/pkg/model/db-statefulset_test.go index f01e44b99..d5a09b961 100644 --- a/pkg/model/db-statefulset_test.go +++ b/pkg/model/db-statefulset_test.go @@ -2,7 +2,6 @@ package model import ( "context" - "os" "testing" "github.com/redhat-developer/rhdh-operator/pkg/platform" @@ -41,6 +40,7 @@ func TestDefault(t *testing.T) { dbStatefulSet := model.GetRuntimeObject(DbStatefulSetKey).(*DbStatefulSet) assert.Equal(t, dbService.service.Name, dbStatefulSet.statefulSet.Spec.ServiceName) assert.Equal(t, corev1.ClusterIPNone, dbService.service.Spec.ClusterIP) + assert.Equal(t, "quay.io/fedora/postgresql-18:latest", dbStatefulSet.statefulSet.Spec.Template.Spec.Containers[0].Image) } // It tests the overriding image feature @@ -52,7 +52,7 @@ func TestOverrideDbImage(t *testing.T) { testObj := createBackstageTest(bs).withDefaultConfig(true). addToDefaultConfig("db-statefulset.yaml", "rhdh-db-statefulset.yaml").withLocalDb(true) - _ = os.Setenv(LocalDbImageEnvVar, "dummy") + t.Setenv(LocalDbImageEnvVar, "dummy") model, err := InitObjects(context.TODO(), bs, testObj.externalConfig, platform.Default, testObj.scheme) assert.NoError(t, err) diff --git a/pkg/model/testdata/default-config/db-statefulset.yaml b/pkg/model/testdata/default-config/db-statefulset.yaml index f95020ab6..bd79b3f50 100644 --- a/pkg/model/testdata/default-config/db-statefulset.yaml +++ b/pkg/model/testdata/default-config/db-statefulset.yaml @@ -24,7 +24,7 @@ spec: value: /var/lib/pgsql/data - name: PGDATA value: /var/lib/pgsql/data/userdata - image: quay.io/fedora/postgresql-15:latest + image: quay.io/fedora/postgresql-18:latest imagePullPolicy: IfNotPresent securityContext: runAsNonRoot: true diff --git a/pkg/model/testdata/ips-db-statefulset.yaml b/pkg/model/testdata/ips-db-statefulset.yaml index 462060584..2044454dd 100644 --- a/pkg/model/testdata/ips-db-statefulset.yaml +++ b/pkg/model/testdata/ips-db-statefulset.yaml @@ -18,6 +18,6 @@ spec: - name: ips-db2 automountServiceAccountToken: false containers: - - image: quay.io/fedora/postgresql-15:latest + - image: quay.io/fedora/postgresql-18:latest name: postgres diff --git a/pkg/model/testdata/rhdh-db-statefulset.yaml b/pkg/model/testdata/rhdh-db-statefulset.yaml index df262551d..f415eb856 100644 --- a/pkg/model/testdata/rhdh-db-statefulset.yaml +++ b/pkg/model/testdata/rhdh-db-statefulset.yaml @@ -23,7 +23,7 @@ spec: value: /var/lib/pgsql/data - name: PGDATA value: /var/lib/pgsql/data/userdata - image: quay.io/fedora/postgresql-15:latest # will be replaced with the actual image + image: quay.io/fedora/postgresql-18:latest # will be replaced with the actual image imagePullPolicy: IfNotPresent securityContext: runAsNonRoot: true diff --git a/tests/e2e/README.md b/tests/e2e/README.md index 89a4e8235..a972d8455 100644 --- a/tests/e2e/README.md +++ b/tests/e2e/README.md @@ -33,6 +33,7 @@ The behavior is configurable using the following environment variables: | `BACKSTAGE_OPERATOR_TESTS_AIRGAP_MIRROR_REGISTRY` | string | Existing mirror registry to use in the airgap scenario.
Relevant if `BACKSTAGE_OPERATOR_TEST_MODE` is `rhdh-airgap`. | | `my-registry.example.com` | | `BACKSTAGE_OPERATOR_TESTS_K8S_CREATE_INGRESS` | bool | Whether to test access using an Ingress resource on K8s | | `true` | | `BACKSTAGE_OPERATOR_TESTS_K8S_INGRESS_DOMAIN` | string | Ingress domain. Relevant only if `BACKSTAGE_OPERATOR_TESTS_K8S_CREATE_INGRESS` is `true`. | | `$(minikube ip).nip.io` | +| `BACKSTAGE_OPERATOR_TESTS_POSTGRESQL_UPGRADE` | bool | Enables the PostgreSQL 15 to 18 dump, volume replacement, and restore flow in the Operator upgrade test. Requires `FROM_OPERATOR_MANIFEST` and `TO_OPERATOR_MANIFEST`. | `false` | `true` | ### Examples @@ -109,6 +110,24 @@ This requires OLM to be installed in the cluster. $ make test-e2e BACKSTAGE_OPERATOR_TEST_MODE=olm ``` +#### Testing the PostgreSQL 15 to 18 Operator upgrade + +The upgrade test can validate the local PostgreSQL major-version migration while upgrading an existing Operator installation. It stops Backstage, creates a logical dump with `pg_dumpall`, deletes the test instance's generated PostgreSQL StatefulSet and PVC, restores the dump into PostgreSQL 18, and verifies that the test data remains available. The generated PostgreSQL Secret is preserved. + +The command below uses RHDH 1.10 as the PostgreSQL 15 source and the current working tree's generated manifest as the PostgreSQL 18 target: + +```shell +$ BACKSTAGE_OPERATOR_TESTS_PLATFORM=kind \ + BACKSTAGE_OPERATOR_TESTS_POSTGRESQL_UPGRADE=true \ + PROFILE=rhdh \ + FROM_OPERATOR_MANIFEST=https://raw.githubusercontent.com/redhat-developer/rhdh-operator/refs/heads/release-1.10/dist/rhdh/install.yaml \ + TO_OPERATOR_MANIFEST="$(pwd)/dist/rhdh/install.yaml" \ + OPERATOR_MANIFEST="$(pwd)/dist/rhdh/install.yaml" \ + make test-e2e-upgrade +``` + +Run this only against a disposable cluster. The upgrade suite replaces the Operator installation and its cluster-scoped resources, and this test permanently deletes the generated PVC in its temporary namespace. + #### Testing a downstream build of Red Hat Developer Hub (RHDH) In this scenario, you want to run the E2E tests against a downstream build of RHDH. diff --git a/tests/e2e/e2e_suite_test.go b/tests/e2e/e2e_suite_test.go index 421e2080c..f5665f0e0 100644 --- a/tests/e2e/e2e_suite_test.go +++ b/tests/e2e/e2e_suite_test.go @@ -48,6 +48,15 @@ func installRhdhOperatorManifest(operatorManifest string) { cmd := exec.Command(helper.GetPlatformTool(), "apply", "-f", p) _, err := helper.Run(cmd) + if err != nil { + GinkgoWriter.Printf("Initial manifest apply failed; waiting for CRDs before retrying: %v\n", err) + cmd = exec.Command(helper.GetPlatformTool(), "wait", "--for=condition=Established", "crd", "--all", "--timeout=2m") + _, waitErr := helper.Run(cmd) + Expect(waitErr).ShouldNot(HaveOccurred()) + + cmd = exec.Command(helper.GetPlatformTool(), "apply", "-f", p) + _, err = helper.Run(cmd) + } Expect(err).ShouldNot(HaveOccurred()) } @@ -211,7 +220,11 @@ var _ = SynchronizedAfterSuite(func() { }, // the function below *only* on process #1 func() { - defer uninstallOperator() + defer func() { + uninstallOperator() + deleteOperatorManifest(os.Getenv("FROM_OPERATOR_MANIFEST")) + deleteOperatorManifest(os.Getenv("TO_OPERATOR_MANIFEST")) + }() fmt.Println(fetchOperatorLogs(managerPodLabel, false)()) }, ) @@ -324,6 +337,14 @@ func uninstallOperator() { } } +func deleteOperatorManifest(operatorManifest string) { + if operatorManifest == "" { + return + } + cmd := exec.Command(helper.GetPlatformTool(), "delete", "-f", operatorManifest, "--ignore-not-found=true") + _, _ = helper.Run(cmd) +} + func uninstallRhdhOperator(withAirgap bool) { cmd := exec.Command( helper.GetPlatformTool(), "delete", "subscription", "rhdh", "-n", _namespace, "--ignore-not-found=true") diff --git a/tests/e2e/e2e_upgrade_test.go b/tests/e2e/e2e_upgrade_test.go index 3751dc8ce..aad65c1f2 100644 --- a/tests/e2e/e2e_upgrade_test.go +++ b/tests/e2e/e2e_upgrade_test.go @@ -5,6 +5,7 @@ import ( "io" "os" "os/exec" + "strings" "time" "github.com/redhat-developer/rhdh-operator/tests/helper" @@ -18,6 +19,11 @@ var _ = Describe("Operator upgrade with existing instances", func() { var ns string BeforeEach(func() { + if isEnvEnabled("BACKSTAGE_OPERATOR_TESTS_POSTGRESQL_UPGRADE") { + suiteConfig, _ := GinkgoConfiguration() + Expect(suiteConfig.ParallelTotal).To(Equal(1), + "the PostgreSQL upgrade test scales the shared Operator deployment and must run with one Ginkgo process") + } ns = fmt.Sprintf("e2e-test-%d-%s", GinkgoParallelProcess(), helper.RandString(5)) helper.CreateNamespace(ns) }) @@ -40,6 +46,7 @@ var _ = Describe("Operator upgrade with existing instances", func() { // Uninstall the current version of the operator (which was installed in the SynchronizedBeforeSuite), // because this test needs to start from a previous version, then perform the upgrade. uninstallOperator() + waitForNamespaceDeletion(_namespace) fromDeploymentManifest = os.Getenv("FROM_OPERATOR_MANIFEST") Expect(fromDeploymentManifest).NotTo(BeEmpty(), "The FROM_OPERATOR_MANIFEST env var must not be empty") @@ -81,34 +88,33 @@ metadata: Should(Succeed()) }) - AfterEach(func() { - for _, m := range []string{"FROM", "TO"} { - if manifest := os.Getenv(m + "_OPERATOR_MANIFEST"); manifest != "" { - cmd := exec.Command(helper.GetPlatformTool(), "delete", "-f", manifest, "--ignore-not-found=true") - _, _ = helper.Run(cmd) - } - } - uninstallOperator() - - if fromDeploymentManifest != "" { - cmd := exec.Command(helper.GetPlatformTool(), "delete", "-f", fromDeploymentManifest, "--ignore-not-found=true") - _, _ = helper.Run(cmd) + JustAfterEach(func() { + if isEnvEnabled("BACKSTAGE_OPERATOR_TESTS_POSTGRESQL_UPGRADE") && CurrentSpecReport().Failed() { + GinkgoWriter.Println(postgresqlUpgradeDiagnostics(ns, crName)) } }) It("should successfully reconcile existing CR when upgrading the operator", func() { + var postgresqlUpgrade *postgresqlUpgradeState + if isEnvEnabled("BACKSTAGE_OPERATOR_TESTS_POSTGRESQL_UPGRADE") { + postgresqlUpgrade = preparePostgresqlUpgrade(ns, crName) + } + By("Upgrading the operator", func() { if toOperatorManifest := os.Getenv("TO_OPERATOR_MANIFEST"); toOperatorManifest != "" { - cmd := exec.Command(helper.GetPlatformTool(), "apply", "-f", toOperatorManifest) - _, err := helper.Run(cmd) - Expect(err).ShouldNot(HaveOccurred()) + installRhdhOperatorManifest(toOperatorManifest) } else { installOperatorWithMakeDeploy(false) } + waitForOperatorRollout() EventuallyWithOffset(1, verifyControllerUp, 5*time.Minute, 10*time.Second). WithArguments(managerPodLabel).Should(Succeed()) }) + if postgresqlUpgrade != nil { + completePostgresqlUpgrade(ns, crName, postgresqlUpgrade) + } + crLabel := fmt.Sprintf("rhdh.redhat.com/app=backstage-%s", crName) // TODO(rm3l): this might never work because the Deployment may not necessarily @@ -164,3 +170,25 @@ metadata: }) }) + +func waitForOperatorRollout() { + cmd := exec.Command(helper.GetPlatformTool(), "-n", _namespace, "rollout", "status", "deployment/rhdh-operator", "--timeout=5m") + _, err := helper.Run(cmd) + ExpectWithOffset(1, err).NotTo(HaveOccurred()) + + if expectedImage := os.Getenv("IMG"); expectedImage != "" { + cmd = exec.Command(helper.GetPlatformTool(), "-n", _namespace, "get", "deployment", "rhdh-operator", + "-o", "jsonpath={.spec.template.spec.containers[0].image}") + out, err := helper.Run(cmd) + ExpectWithOffset(1, err).NotTo(HaveOccurred()) + ExpectWithOffset(1, string(out)).To(Equal(expectedImage)) + } +} + +func waitForNamespaceDeletion(namespace string) { + EventuallyWithOffset(1, func() bool { + cmd := exec.Command(helper.GetPlatformTool(), "get", "namespace", namespace) + _, err := helper.Run(cmd) + return err != nil && strings.Contains(strings.ToLower(err.Error()), "not found") + }, 5*time.Minute, 5*time.Second).Should(BeTrue()) +} diff --git a/tests/e2e/postgresql_upgrade_test.go b/tests/e2e/postgresql_upgrade_test.go new file mode 100644 index 000000000..10e6691b3 --- /dev/null +++ b/tests/e2e/postgresql_upgrade_test.go @@ -0,0 +1,414 @@ +package e2e + +import ( + "bytes" + "fmt" + "io" + "os" + "os/exec" + "regexp" + "strings" + "time" + + "github.com/redhat-developer/rhdh-operator/tests/helper" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" +) + +const ( + postgresqlSourceImage = "postgresql-15" + postgresqlSourceVersion = "15." + postgresqlTargetImage = "postgresql-18" + postgresqlTargetVersion = "18." + postgresqlProofDatabase = "backstage_plugin_catalog" + postgresqlProofValue = "postgresql-15-to-18" +) + +type postgresqlUpgradeState struct { + dumpPath string + postgresPodUID string + pvcUID string + secretUID string + backstagePodUID string + databaseNames []string +} + +func logPostgresqlUpgradeCheckpoint(name string, fields ...string) { + checkpoint := "postgresql-upgrade: " + name + if len(fields) > 0 { + checkpoint += " " + strings.Join(fields, " ") + } + fmt.Println(checkpoint) +} + +func postgresqlUpgradeDiagnostics(namespace, crName string) string { + crLabel := fmt.Sprintf("rhdh.redhat.com/app=backstage-%s", crName) + postgresqlLabel := fmt.Sprintf("rhdh.redhat.com/app=%s", postgresqlStatefulSetName(crName)) + return fmt.Sprintf( + "=== PostgreSQL upgrade diagnostics ===\n"+ + "=== Operator and operand logs ===\n%s"+ + "=== PostgreSQL logs ===\n%s"+ + "=== PostgreSQL description ===\n%s", + fetchOperatorAndOperandLogs(managerPodLabel, namespace, crLabel), + getPodLogs(namespace, "", postgresqlLabel), + describePod(namespace, postgresqlLabel), + ) +} + +func preparePostgresqlUpgrade(namespace, crName string) *postgresqlUpgradeState { + state := &postgresqlUpgradeState{} + postgresPod := waitForPostgresql(namespace, crName, postgresqlSourceImage, postgresqlSourceVersion) + state.databaseNames = postgresqlDatabaseNames(namespace, postgresPod) + Expect(state.databaseNames).To(ContainElement(postgresqlProofDatabase)) + + By("seeding data that must survive the PostgreSQL upgrade") + _, err := runPostgresqlSQL(namespace, postgresPod, postgresqlProofDatabase, ` +CREATE TABLE public.rhdh_postgresql_upgrade_test (marker text PRIMARY KEY); +INSERT INTO public.rhdh_postgresql_upgrade_test VALUES ('`+postgresqlProofValue+`');`) + Expect(err).NotTo(HaveOccurred()) + Expect(queryPostgresqlUpgradeProof(namespace, postgresPod)).To(Equal(postgresqlProofValue)) + + state.postgresPodUID = resourceUID(namespace, "pod", postgresPod) + state.pvcUID = resourceUID(namespace, "pvc", postgresqlPVCName(crName)) + state.secretUID = resourceUID(namespace, "secret", postgresqlSecretName(crName)) + state.backstagePodUID = readyPodUID(namespace, fmt.Sprintf("rhdh.redhat.com/app=backstage-%s", crName)) + logPostgresqlUpgradeCheckpoint("source-ready", + fmt.Sprintf("pod=%s", postgresPod), + fmt.Sprintf("podUID=%s", state.postgresPodUID), + fmt.Sprintf("pvcUID=%s", state.pvcUID), + fmt.Sprintf("secretUID=%s", state.secretUID), + fmt.Sprintf("backstagePodUID=%s", state.backstagePodUID), + fmt.Sprintf("databases=%d", len(state.databaseNames)), + fmt.Sprintf("proofDatabase=%s", postgresqlProofDatabase), + fmt.Sprintf("proofValue=%s", postgresqlProofValue), + ) + + By("stopping Backstage before taking the PostgreSQL dump") + setBackstageReplicas(namespace, crName, 0) + waitForNoPods(namespace, fmt.Sprintf("rhdh.redhat.com/app=backstage-%s", crName)) + + By("dumping all PostgreSQL 15 databases and roles") + state.dumpPath = dumpPostgresql(namespace, postgresPod) + + return state +} + +func completePostgresqlUpgrade(namespace, crName string, state *postgresqlUpgradeState) { + statefulSetName := postgresqlStatefulSetName(crName) + + By("waiting for the upgraded operator to select the PostgreSQL 18 image") + Eventually(func(g Gomega) { + out, err := helper.Run(exec.Command(helper.GetPlatformTool(), "-n", namespace, "get", "statefulset", + statefulSetName, "-o", "jsonpath={.spec.template.spec.containers[0].image}")) + g.Expect(err).NotTo(HaveOccurred()) + g.Expect(strings.TrimSpace(string(out))).To(ContainSubstring(postgresqlTargetImage)) + }, 5*time.Minute, 5*time.Second).Should(Succeed()) + + operatorScaledDown := false + DeferCleanup(func() { + if operatorScaledDown { + if err := scaleDeploymentCommand(_namespace, "rhdh-operator", 1); err != nil { + GinkgoWriter.Printf("Warning: failed to restore the operator replica: %v\n", err) + } + } + }) + + By("stopping the operator while replacing the PostgreSQL volume") + scaleDeployment(_namespace, "rhdh-operator", 0) + operatorScaledDown = true + waitForNoPods(_namespace, managerPodLabel) + + By("deleting the PostgreSQL 15 StatefulSet and persistent volume") + deleteResource(namespace, "statefulset", statefulSetName) + deleteResource(namespace, "pvc", postgresqlPVCName(crName)) + Expect(resourceUID(namespace, "secret", postgresqlSecretName(crName))).To(Equal(state.secretUID)) + + By("restarting the operator to provision a fresh PostgreSQL 18 database") + scaleDeployment(_namespace, "rhdh-operator", 1) + operatorScaledDown = false + waitForOperatorRollout() + EventuallyWithOffset(1, verifyControllerUp, 5*time.Minute, 5*time.Second). + WithArguments(managerPodLabel).Should(Succeed()) + + postgresPod := waitForPostgresql(namespace, crName, postgresqlTargetImage, postgresqlTargetVersion) + targetPostgresPodUID := resourceUID(namespace, "pod", postgresPod) + targetPVCUID := resourceUID(namespace, "pvc", postgresqlPVCName(crName)) + targetSecretUID := resourceUID(namespace, "secret", postgresqlSecretName(crName)) + Expect(targetPostgresPodUID).NotTo(Equal(state.postgresPodUID)) + Expect(targetPVCUID).NotTo(Equal(state.pvcUID)) + Expect(targetSecretUID).To(Equal(state.secretUID)) + logPostgresqlUpgradeCheckpoint("target-ready", + fmt.Sprintf("pod=%s", postgresPod), + fmt.Sprintf("previousPodUID=%s", state.postgresPodUID), + fmt.Sprintf("podUID=%s", targetPostgresPodUID), + fmt.Sprintf("previousPVCUID=%s", state.pvcUID), + fmt.Sprintf("pvcUID=%s", targetPVCUID), + fmt.Sprintf("secretUID=%s", targetSecretUID), + "secretPreserved=true", + ) + + By("restoring the PostgreSQL 15 dump into PostgreSQL 18") + restorePostgresql(namespace, postgresPod, state.dumpPath) + restoredDatabaseNames := postgresqlDatabaseNames(namespace, postgresPod) + Expect(restoredDatabaseNames).To(Equal(state.databaseNames)) + refreshPostgresqlCollations(namespace, postgresPod) + Expect(queryPostgresqlUpgradeProof(namespace, postgresPod)).To(Equal(postgresqlProofValue)) + logPostgresqlUpgradeCheckpoint("restore-verified", + fmt.Sprintf("databases=%d", len(restoredDatabaseNames)), + fmt.Sprintf("proofDatabase=%s", postgresqlProofDatabase), + fmt.Sprintf("proofValue=%s", postgresqlProofValue), + ) + + By("starting Backstage against the restored PostgreSQL 18 database") + setBackstageReplicas(namespace, crName, 1) + waitForBackstagePodReplacement(namespace, crName, state.backstagePodUID) +} + +func waitForPostgresql(namespace, crName, imageSubstring, versionPrefix string) string { + var podName string + label := fmt.Sprintf("rhdh.redhat.com/app=%s", postgresqlStatefulSetName(crName)) + + Eventually(func(g Gomega) { + out, err := helper.Run(exec.Command(helper.GetPlatformTool(), "-n", namespace, "get", "pods", "-l", label, + "-o", "go-template={{ range .items }}{{ if not .metadata.deletionTimestamp }}{{ .metadata.name }}{{ \"\\n\" }}{{ end }}{{ end }}")) + g.Expect(err).NotTo(HaveOccurred()) + podNames := helper.GetNonEmptyLines(string(out)) + g.Expect(podNames).To(HaveLen(1)) + podName = podNames[0] + + out, err = helper.Run(exec.Command(helper.GetPlatformTool(), "-n", namespace, "get", "pod", podName, + "-o", `jsonpath={.status.conditions[?(@.type=="Ready")].status}`)) + g.Expect(err).NotTo(HaveOccurred()) + g.Expect(strings.TrimSpace(string(out))).To(Equal("True")) + + out, err = helper.Run(exec.Command(helper.GetPlatformTool(), "-n", namespace, "get", "pod", podName, + "-o", "jsonpath={.spec.containers[0].image}")) + g.Expect(err).NotTo(HaveOccurred()) + g.Expect(strings.TrimSpace(string(out))).To(ContainSubstring(imageSubstring)) + + out, err = helper.Run(postgresqlSQLCommand(namespace, podName, "postgres", "-tA", "-c", "SHOW server_version;")) + g.Expect(err).NotTo(HaveOccurred()) + g.Expect(strings.TrimSpace(string(out))).To(HavePrefix(versionPrefix)) + }, 10*time.Minute, 10*time.Second).Should(Succeed()) + + return podName +} + +func postgresqlSQLCommand(namespace, podName, database string, args ...string) *exec.Cmd { + return buildPostgresqlSQLCommand(namespace, podName, database, false, args...) +} + +func postgresqlSQLCommandWithStdin(namespace, podName, database string, args ...string) *exec.Cmd { + return buildPostgresqlSQLCommand(namespace, podName, database, true, args...) +} + +func buildPostgresqlSQLCommand(namespace, podName, database string, withStdin bool, args ...string) *exec.Cmd { + commandArgs := []string{"-n", namespace, "exec"} + if withStdin { + commandArgs = append(commandArgs, "-i") + } + commandArgs = append(commandArgs, + podName, "--", + "psql", "-X", "-U", "postgres", "-d", database, + ) + commandArgs = append(commandArgs, args...) + return exec.Command(helper.GetPlatformTool(), commandArgs...) +} + +func runPostgresqlSQL(namespace, podName, database, sql string) ([]byte, error) { + return helper.Run(postgresqlSQLCommand(namespace, podName, database, + "-v", "ON_ERROR_STOP=1", "-c", sql)) +} + +func queryPostgresqlUpgradeProof(namespace, podName string) string { + out, err := helper.Run(postgresqlSQLCommand(namespace, podName, postgresqlProofDatabase, + "-tA", "-v", "ON_ERROR_STOP=1", "-c", "SELECT marker FROM public.rhdh_postgresql_upgrade_test;")) + Expect(err).NotTo(HaveOccurred()) + return strings.TrimSpace(string(out)) +} + +func dumpPostgresql(namespace, podName string) string { + dumpFile, err := os.CreateTemp("", "rhdh-postgresql-15-*.sql") + Expect(err).NotTo(HaveOccurred()) + dumpPath := dumpFile.Name() + DeferCleanup(func() { + Expect(os.Remove(dumpPath)).To(Succeed()) + }) + + var stderr bytes.Buffer + cmd := exec.Command(helper.GetPlatformTool(), "-n", namespace, "exec", podName, "--", "pg_dumpall", "-U", "postgres") + err = runCommand(cmd, nil, dumpFile, io.MultiWriter(GinkgoWriter, &stderr)) + closeErr := dumpFile.Close() + Expect(err).NotTo(HaveOccurred(), stderr.String()) + Expect(closeErr).NotTo(HaveOccurred()) + + info, err := os.Stat(dumpPath) + Expect(err).NotTo(HaveOccurred()) + Expect(info.Size()).To(BeNumerically(">", 0)) + logPostgresqlUpgradeCheckpoint("dump-created", fmt.Sprintf("bytes=%d", info.Size())) + return dumpPath +} + +func restorePostgresql(namespace, podName, dumpPath string) { + dumpFile, err := os.Open(dumpPath) + Expect(err).NotTo(HaveOccurred()) + defer func() { + Expect(dumpFile.Close()).To(Succeed()) + }() + + var stdout, stderr bytes.Buffer + cmd := postgresqlSQLCommandWithStdin(namespace, podName, "postgres", "-v", "ON_ERROR_STOP=0", "--quiet") + err = runCommand(cmd, dumpFile, io.MultiWriter(GinkgoWriter, &stdout), io.MultiWriter(GinkgoWriter, &stderr)) + Expect(err).NotTo(HaveOccurred(), stderr.String()) + + Expect(validatePostgresqlRestoreErrors(stderr.String())).To(Succeed()) +} + +func validatePostgresqlRestoreErrors(stderr string) error { + errorLines := make([]string, 0) + for _, line := range strings.Split(stderr, "\n") { + lowerLine := strings.ToLower(line) + if strings.Contains(line, "ERROR:") || strings.Contains(line, "FATAL:") || strings.Contains(lowerLine, "psql: error:") { + errorLines = append(errorLines, strings.TrimSpace(line)) + } + } + if len(errorLines) != 1 { + if len(errorLines) == 0 { + return fmt.Errorf("expected one bootstrap role conflict, got none") + } + return fmt.Errorf("unexpected PostgreSQL restore errors: %s", strings.Join(errorLines, "; ")) + } + if !regexp.MustCompile(`^ERROR:\s+role "postgres" already exists$`).MatchString(errorLines[0]) { + return fmt.Errorf("unexpected PostgreSQL restore errors: %s", errorLines[0]) + } + return nil +} + +func postgresqlDatabaseNames(namespace, podName string) []string { + out, err := helper.Run(postgresqlSQLCommand(namespace, podName, "postgres", + "-tA", "-v", "ON_ERROR_STOP=1", "-c", + "SELECT datname FROM pg_database WHERE datistemplate = false ORDER BY datname;")) + Expect(err).NotTo(HaveOccurred()) + return helper.GetNonEmptyLines(strings.TrimSpace(string(out))) +} + +func refreshPostgresqlCollations(namespace, podName string) { + out, err := helper.Run(postgresqlSQLCommand(namespace, podName, "postgres", + "-tA", "-v", "ON_ERROR_STOP=1", "-c", + "SELECT format('ALTER DATABASE %I REFRESH COLLATION VERSION;', datname) FROM pg_database WHERE datallowconn AND datname <> 'template0' ORDER BY datname;")) + Expect(err).NotTo(HaveOccurred()) + + statements := helper.GetNonEmptyLines(string(out)) + for _, statement := range statements { + _, err = runPostgresqlSQL(namespace, podName, "postgres", statement) + Expect(err).NotTo(HaveOccurred()) + } + logPostgresqlUpgradeCheckpoint("collations-refreshed", fmt.Sprintf("databases=%d", len(statements))) +} + +func runCommand(cmd *exec.Cmd, stdin io.Reader, stdout, stderr io.Writer) error { + projectDir, err := helper.GetProjectDir() + if err != nil { + return err + } + cmd.Dir = projectDir + cmd.Env = os.Environ() + cmd.Stdin = stdin + cmd.Stdout = stdout + cmd.Stderr = stderr + GinkgoWriter.Printf("running: %s\n", strings.Join(cmd.Args, " ")) + return cmd.Run() +} + +func setBackstageReplicas(namespace, crName string, replicas int) { + patch := fmt.Sprintf(`{"spec":{"deployment":{"patch":{"spec":{"replicas":%d}}}}}`, replicas) + err := helper.PatchBackstageCR(namespace, crName, patch, "merge") + Expect(err).NotTo(HaveOccurred()) +} + +func scaleDeployment(namespace, name string, replicas int) { + err := scaleDeploymentCommand(namespace, name, replicas) + Expect(err).NotTo(HaveOccurred()) +} + +func scaleDeploymentCommand(namespace, name string, replicas int) error { + _, err := helper.Run(exec.Command(helper.GetPlatformTool(), "-n", namespace, "scale", "deployment", name, + fmt.Sprintf("--replicas=%d", replicas))) + return err +} + +func waitForNoPods(namespace, label string) { + Eventually(func(g Gomega) { + out, err := helper.Run(exec.Command(helper.GetPlatformTool(), "-n", namespace, "get", "pods", "-l", label, + "-o", "name")) + g.Expect(err).NotTo(HaveOccurred()) + g.Expect(strings.TrimSpace(string(out))).To(BeEmpty()) + }, 5*time.Minute, 5*time.Second).Should(Succeed()) +} + +func deleteResource(namespace, kind, name string) { + _, err := helper.Run(exec.Command(helper.GetPlatformTool(), "-n", namespace, "delete", kind, name, + "--wait=true", "--timeout=5m")) + Expect(err).NotTo(HaveOccurred()) +} + +func resourceUID(namespace, kind, name string) string { + out, err := helper.Run(exec.Command(helper.GetPlatformTool(), "-n", namespace, "get", kind, name, + "-o", "jsonpath={.metadata.uid}")) + Expect(err).NotTo(HaveOccurred()) + uid := strings.TrimSpace(string(out)) + Expect(uid).NotTo(BeEmpty()) + return uid +} + +func readyPodUID(namespace, label string) string { + var uid string + Eventually(func(g Gomega) { + out, err := helper.Run(exec.Command(helper.GetPlatformTool(), "-n", namespace, "get", "pods", "-l", label, + "-o", `jsonpath={range .items[?(@.status.phase=="Running")]}{.metadata.uid}{" "}{.status.conditions[?(@.type=="Ready")].status}{"\n"}{end}`)) + g.Expect(err).NotTo(HaveOccurred()) + lines := helper.GetNonEmptyLines(string(out)) + g.Expect(lines).To(HaveLen(1)) + fields := strings.Fields(lines[0]) + g.Expect(fields).To(HaveLen(2)) + g.Expect(fields[1]).To(Equal("True")) + uid = fields[0] + }, 10*time.Minute, 10*time.Second).Should(Succeed()) + return uid +} + +func waitForBackstagePodReplacement(namespace, crName, previousUID string) { + label := fmt.Sprintf("rhdh.redhat.com/app=backstage-%s", crName) + var replacementUID string + Eventually(func(g Gomega) { + out, err := helper.Run(exec.Command(helper.GetPlatformTool(), "-n", namespace, "get", "pods", "-l", label, + "-o", `jsonpath={range .items[*]}{.metadata.uid}{" "}{.status.phase}{" "}{.status.conditions[?(@.type=="Ready")].status}{"\n"}{end}`)) + g.Expect(err).NotTo(HaveOccurred()) + g.Expect(string(out)).NotTo(ContainSubstring(previousUID)) + lines := helper.GetNonEmptyLines(string(out)) + g.Expect(lines).To(HaveLen(1)) + fields := strings.Fields(lines[0]) + g.Expect(fields).To(HaveLen(3)) + g.Expect(fields[0]).NotTo(Equal(previousUID)) + g.Expect(fields[1]).To(Equal("Running")) + g.Expect(fields[2]).To(Equal("True")) + replacementUID = fields[0] + }, 15*time.Minute, 10*time.Second).Should(Succeed()) + logPostgresqlUpgradeCheckpoint("backstage-ready", + fmt.Sprintf("previousPodUID=%s", previousUID), + fmt.Sprintf("podUID=%s", replacementUID), + ) +} + +func postgresqlStatefulSetName(crName string) string { + return fmt.Sprintf("backstage-psql-%s", crName) +} + +func postgresqlPVCName(crName string) string { + return fmt.Sprintf("data-%s-0", postgresqlStatefulSetName(crName)) +} + +func postgresqlSecretName(crName string) string { + return fmt.Sprintf("backstage-psql-secret-%s", crName) +}