Skip to content
Merged
114 changes: 114 additions & 0 deletions .github/workflows/nightly-postgresql-upgrade-test.yaml
Comment thread
rm3l marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
@@ -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 <<EOF > "$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
4 changes: 2 additions & 2 deletions .github/workflows/nightly-upgrade-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions .rhdh/scripts/prepare-restricted-environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bundle/rhdh/manifests/rhdh-plugin-deps_v1_configmap.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion config/profile/rhdh/default-config/db-statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment thread
rm3l marked this conversation as resolved.
Resolved
imagePullPolicy: IfNotPresent
securityContext:
# runAsUser:26 does not work for Openshift but looks work for AKS/EKS
Expand Down
2 changes: 1 addition & 1 deletion config/profile/rhdh/patches/deployment-patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion config/profile/rhdh/plugin-deps/sonataflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion dist/backstage.io/install.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions dist/rhdh/install.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pkg/model/db-statefulset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package model

import (
"context"
"os"
"testing"

"github.com/redhat-developer/rhdh-operator/pkg/platform"
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/model/testdata/default-config/db-statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/model/testdata/ips-db-statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 changes: 1 addition & 1 deletion pkg/model/testdata/rhdh-db-statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions tests/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.<br>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

Expand Down Expand Up @@ -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.
Expand Down
23 changes: 22 additions & 1 deletion tests/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand Down Expand Up @@ -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)())
},
)
Expand Down Expand Up @@ -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")
Expand Down
Loading
Loading