From f9b1ea6385e0f538fa126eff8c6dc939fa7f53e9 Mon Sep 17 00:00:00 2001 From: Ryan Emerson Date: Thu, 26 Sep 2024 18:19:35 +0100 Subject: [PATCH] Automate adding new operands and generating documentation --- .github/workflows/add_operand.yml | 73 +++++++++ README.md | 36 ++--- .../attributes/community-attributes.adoc | 4 +- .../topics/ref_supported_versions.adoc | 97 +----------- .../topics/supported_operands/2_3_7.adoc | 15 ++ .../topics/supported_operands/2_4_0.adoc | 16 ++ .../topics/supported_operands/2_4_1.adoc | 16 ++ .../topics/supported_operands/2_4_2.adoc | 18 +++ .../topics/supported_operands/2_4_3.adoc | 18 +++ .../topics/supported_operands/2_4_4.adoc | 19 +++ .../supported_operands/operand_table.adoc | 32 ++++ scripts/ci/add_operand.sh | 25 +++ scripts/ci/add_operand_to_csv.sh | 17 +- .../ci/docs_generate_operator_operand_file.sh | 21 +++ .../docs_generate_operator_operand_table.sh | 33 ++++ scripts/ci/kind.sh | 11 +- scripts/ci/operand_common.sh | 23 +++ test/e2e/infinispan/dependencies_test.go | 2 +- test/e2e/utils/common.go | 149 ++++++++---------- test/e2e/utils/kubernetes.go | 17 +- version.txt | 1 + 21 files changed, 428 insertions(+), 215 deletions(-) create mode 100644 .github/workflows/add_operand.yml create mode 100644 documentation/asciidoc/topics/supported_operands/2_3_7.adoc create mode 100644 documentation/asciidoc/topics/supported_operands/2_4_0.adoc create mode 100644 documentation/asciidoc/topics/supported_operands/2_4_1.adoc create mode 100644 documentation/asciidoc/topics/supported_operands/2_4_2.adoc create mode 100644 documentation/asciidoc/topics/supported_operands/2_4_3.adoc create mode 100644 documentation/asciidoc/topics/supported_operands/2_4_4.adoc create mode 100644 documentation/asciidoc/topics/supported_operands/operand_table.adoc create mode 100755 scripts/ci/add_operand.sh create mode 100755 scripts/ci/docs_generate_operator_operand_file.sh create mode 100755 scripts/ci/docs_generate_operator_operand_table.sh create mode 100755 scripts/ci/operand_common.sh create mode 100644 version.txt diff --git a/.github/workflows/add_operand.yml b/.github/workflows/add_operand.yml new file mode 100644 index 000000000..963327598 --- /dev/null +++ b/.github/workflows/add_operand.yml @@ -0,0 +1,73 @@ +name: Add Operand + +on: + workflow_call: + inputs: + image: + description: "The FQN of the Operand image" + required: true + type: string + version: + description: "The upstream-version of the Operand" + required: true + type: string + ref: + description: "The git reference to checkout" + required: false + default: main + type: string + repository: + description: "The git repository to checkout" + required: false + type: string + + workflow_dispatch: + inputs: + image: + description: "The FQN of the Operand image" + required: true + type: string + version: + description: "The upstream-version of the Operand" + required: true + type: string + ref: + description: "The git reference to checkout" + required: false + default: main + type: string + repository: + description: "The git repository to checkout" + required: false + type: string + +jobs: + release: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + ref: ${{ inputs.ref }} + repository: ${{ inputs.repository }} + + - name: Add Operand + run: ./scripts/ci/add_operand.sh + env: + IMAGE: ${{ inputs.image }} + VERSION: ${{ inputs.version }} + + - name: Commit changes and create tag + run: | + git config user.email "infinispan@infinispan.org" + git config user.name "Infinispan" + git add config/manager/manager.yaml documentation/asciidoc/topics/attributes/community-attributes.adoc documentation/asciidoc/topics/supported_operands/ + git commit -m "Add Operand ${{ inputs.version }}" + + - name: Push Git changes + uses: ad-m/github-push-action@master + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + branch: ${{ inputs.ref }} + repository: ${{ inputs.repository }} diff --git a/README.md b/README.md index c6bd75c33..bb9b19b46 100644 --- a/README.md +++ b/README.md @@ -86,29 +86,29 @@ The bundle image can be created and pushed to a repository with: make bundle-build bundle-push VERSION= IMG= BUNDLE_IMG= ``` +# Operator Version +The next version of the Operator to be released is stored in the `./version.txt` at the root of the project. The content +of this file are used to control the generation of documentation and other resources. This file must be updated after an +Operator release. + +# Add a new Infinispan Operand +1. Call the "Add Operand" GitHub Action + # Release To create an Operator release perform the following: - -1. Update Operand references: - - `SERVER_TAGS` in `scripts/ci/kind.sh` to include the image tage all supported Operands - - `INFINISPAN_OPERAND_VERSIONS` json in `config/manager/manager.yaml` includes the latest Infinispan Server releases. Do not use the floating tags for an Operand image, e.g. `13.0`. - - `server_image_version` in `documentation/asciidoc/topics/attributes/community-attributes.adoc` to point to the latest Operand version - - `test/e2e/utils/common.go` VersionManager JSON to include the latest Operand - - `documentation/asciidoc/topics/ref_supported_versions.adoc` to include all supported Operands - - `documentation/asciidoc/topics/community-attributes.adoc` to use the latest supported Operand -2. Commit changes with appropriate commit message, e.g "Releasing Operator .Final" -3. Tag the release `git tag ` and push to GitHub -4. Create and push the multi-arch image using the created tag via the "Image Release" GitHub Action -5. Remove the old bundle from local `rm -rf bundle` -6. Create OLM bundle `make bundle VERSION= CHANNELS=stable DEFAULT_CHANNEL=stable IMG=quay.io/infinispan/operator:.Final` -7. Copy contents of `bundle/` and issue PRs to: +1. Tag the release `git tag ` and push to GitHub +2. Create and push the multi-arch image using the created tag via the "Image Release" GitHub Action +3. Remove the old bundle from local `rm -rf bundle` +4. Create OLM bundle `make bundle VERSION= CHANNELS=stable DEFAULT_CHANNEL=stable IMG=quay.io/infinispan/operator:.Final` +5. Copy contents of `bundle/` and issue PRs to: - https://github.com/k8s-operatorhub/community-operators - https://github.com/redhat-openshift-ecosystem/community-operators-prod -8. Once PR in 5 has been merged and Operator has been released to OperatorHub, update the "replaces" field in `config/manifests/bases/infinispan-operator.clusterserviceversion.yaml` +6. Once PR in 5 has been merged and Operator has been released to OperatorHub, update the "replaces" field in `config/manifests/bases/infinispan-operator.clusterserviceversion.yaml` to `replaces: infinispan-operator.v` -9. Update `scripts/ci/install-catalog-source.sh` `VERSION` field to the next release version -10. Update `scripts/create-olm-catalog.sh` to include the just released version in `BUNDLE_IMGS` and the next release version in the update graph -11. Commit changes with appropriate commit message, e.g "Next Version " +7. Update the `version.text` file to the next release version +8. Update `scripts/ci/install-catalog-source.sh` `VERSION` field to the next release version +9. Update `scripts/create-olm-catalog.sh` to include the just released version in `BUNDLE_IMGS` and the next release version in the update graph +10. Commit changes with appropriate commit message, e.g "Next Version " # Testing diff --git a/documentation/asciidoc/topics/attributes/community-attributes.adoc b/documentation/asciidoc/topics/attributes/community-attributes.adoc index 7f2916a04..ea508343a 100644 --- a/documentation/asciidoc/topics/attributes/community-attributes.adoc +++ b/documentation/asciidoc/topics/attributes/community-attributes.adoc @@ -26,8 +26,8 @@ :lib_path: /opt/infinispan/server/lib :backup_path: /opt/infinispan/backups :server_image: quay.io/infinispan/server -:server_image_version: 15.0.8 -:operand_version: 15.0.8 +:server_image_version: 16.0.1 +:operand_version: 16.0.1 :ispn_operator: Infinispan Operator :ispn_operator_version: 2.4 diff --git a/documentation/asciidoc/topics/ref_supported_versions.adoc b/documentation/asciidoc/topics/ref_supported_versions.adoc index 33cb39e4a..5beff4783 100644 --- a/documentation/asciidoc/topics/ref_supported_versions.adoc +++ b/documentation/asciidoc/topics/ref_supported_versions.adoc @@ -5,99 +5,4 @@ Since version 2.3.0 {ispn_operator} supports multiple {brandname} Server versions. You can upgrade the version of your cluster between supported {brandname} versions: -[%header,cols=2*] -|=== -| {ispn_operator} version -| {brandname} Server versions - -| 2.3.7 -| -13.0.10 -14.0.1 -14.0.6 -14.0.9 -14.0.13 -14.0.17 -14.0.19 -14.0.20 -14.0.21 -14.0.24 -14.0.27 -| 2.4.0 -| -13.0.10 -14.0.1 -14.0.6 -14.0.9 -14.0.13 -14.0.17 -14.0.19 -14.0.20 -14.0.21 -14.0.24 -14.0.27 -15.0.0 -| 2.4.1 -| -13.0.10 -14.0.1 -14.0.6 -14.0.9 -14.0.13 -14.0.17 -14.0.19 -14.0.20 -14.0.21 -14.0.24 -14.0.27 -15.0.0 -| 2.4.2 -| -13.0.10 -14.0.1 -14.0.6 -14.0.9 -14.0.13 -14.0.17 -14.0.19 -14.0.20 -14.0.21 -14.0.24 -14.0.27 -15.0.0 -15.0.3 -15.0.4 -| 2.4.3 -| -14.0.1 -14.0.6 -14.0.9 -14.0.13 -14.0.17 -14.0.19 -14.0.20 -14.0.21 -14.0.24 -14.0.27 -15.0.0 -15.0.3 -15.0.4 -15.0.5 -| 2.4.4 -| -14.0.1 -14.0.6 -14.0.9 -14.0.13 -14.0.17 -14.0.19 -14.0.20 -14.0.21 -14.0.24 -14.0.27 -14.0.32 -15.0.0 -15.0.3 -15.0.4 -15.0.8 -|=== +include::supported_operands/operand_table.adoc[] diff --git a/documentation/asciidoc/topics/supported_operands/2_3_7.adoc b/documentation/asciidoc/topics/supported_operands/2_3_7.adoc new file mode 100644 index 000000000..e0238afd5 --- /dev/null +++ b/documentation/asciidoc/topics/supported_operands/2_3_7.adoc @@ -0,0 +1,15 @@ +//// +Auto-generated file, do not update this manually. +To add additional Operands to this file, update the `INFINISPAN_OPERAND_VERSIONS` array in `config/manager/manager.yaml`. +//// +13.0.10 +14.0.1 +14.0.6 +14.0.9 +14.0.13 +14.0.17 +14.0.19 +14.0.20 +14.0.21 +14.0.24 +14.0.27 \ No newline at end of file diff --git a/documentation/asciidoc/topics/supported_operands/2_4_0.adoc b/documentation/asciidoc/topics/supported_operands/2_4_0.adoc new file mode 100644 index 000000000..2af32e806 --- /dev/null +++ b/documentation/asciidoc/topics/supported_operands/2_4_0.adoc @@ -0,0 +1,16 @@ +//// +Auto-generated file, do not update this manually. +To add additional Operands to this file, update the `INFINISPAN_OPERAND_VERSIONS` array in `config/manager/manager.yaml`. +//// +13.0.10 +14.0.1 +14.0.6 +14.0.9 +14.0.13 +14.0.17 +14.0.19 +14.0.20 +14.0.21 +14.0.24 +14.0.27 +15.0.0 \ No newline at end of file diff --git a/documentation/asciidoc/topics/supported_operands/2_4_1.adoc b/documentation/asciidoc/topics/supported_operands/2_4_1.adoc new file mode 100644 index 000000000..5290412b7 --- /dev/null +++ b/documentation/asciidoc/topics/supported_operands/2_4_1.adoc @@ -0,0 +1,16 @@ +//// +Auto-generated file, do not update this manually. +To add additional Operands to this file, update the `INFINISPAN_OPERAND_VERSIONS` array in `config/manager/manager.yaml`. +//// +13.0.10 +14.0.1 +14.0.6 +14.0.9 +14.0.13 +14.0.17 +14.0.19 +14.0.20 +14.0.21 +14.0.24 +14.0.27 += 15.0.0 \ No newline at end of file diff --git a/documentation/asciidoc/topics/supported_operands/2_4_2.adoc b/documentation/asciidoc/topics/supported_operands/2_4_2.adoc new file mode 100644 index 000000000..2a837e14e --- /dev/null +++ b/documentation/asciidoc/topics/supported_operands/2_4_2.adoc @@ -0,0 +1,18 @@ +//// +Auto-generated file, do not update this manually. +To add additional Operands to this file, update the `INFINISPAN_OPERAND_VERSIONS` array in `config/manager/manager.yaml`. +//// +13.0.10 +14.0.1 +14.0.6 +14.0.9 +14.0.13 +14.0.17 +14.0.19 +14.0.20 +14.0.21 +14.0.24 +14.0.27 +15.0.0 +15.0.3 +15.0.4 \ No newline at end of file diff --git a/documentation/asciidoc/topics/supported_operands/2_4_3.adoc b/documentation/asciidoc/topics/supported_operands/2_4_3.adoc new file mode 100644 index 000000000..ba9b41a27 --- /dev/null +++ b/documentation/asciidoc/topics/supported_operands/2_4_3.adoc @@ -0,0 +1,18 @@ +//// +Auto-generated file, do not update this manually. +To add additional Operands to this file, update the `INFINISPAN_OPERAND_VERSIONS` array in `config/manager/manager.yaml`. +//// +14.0.1 +14.0.6 +14.0.9 +14.0.13 +14.0.17 +14.0.19 +14.0.20 +14.0.21 +14.0.24 +14.0.27 +15.0.0 +15.0.3 +15.0.4 +15.0.5 \ No newline at end of file diff --git a/documentation/asciidoc/topics/supported_operands/2_4_4.adoc b/documentation/asciidoc/topics/supported_operands/2_4_4.adoc new file mode 100644 index 000000000..c9da461c7 --- /dev/null +++ b/documentation/asciidoc/topics/supported_operands/2_4_4.adoc @@ -0,0 +1,19 @@ +//// +Auto-generated file, do not update this manually. +To add additional Operands to this file, update the `INFINISPAN_OPERAND_VERSIONS` array in `config/manager/manager.yaml`. +//// +14.0.1 +14.0.6 +14.0.9 +14.0.13 +14.0.17 +14.0.19 +14.0.20 +14.0.21 +14.0.24 +14.0.27 +14.0.32 +15.0.0 +15.0.3 +15.0.4 +15.0.8 \ No newline at end of file diff --git a/documentation/asciidoc/topics/supported_operands/operand_table.adoc b/documentation/asciidoc/topics/supported_operands/operand_table.adoc new file mode 100644 index 000000000..b2101cc55 --- /dev/null +++ b/documentation/asciidoc/topics/supported_operands/operand_table.adoc @@ -0,0 +1,32 @@ +//// +Auto-generated file, do not update this manually, instead update `scripts/ci/docs_generate_operator_operand_table.sh` +//// +[%header,cols=2*] +|=== +| {ispn_operator} version +| {brandname} Server versions +| +2.3.7 +| +include::2_3_7.adoc[] +| +2.4.0 +| +include::2_4_0.adoc[] +| +2.4.1 +| +include::2_4_1.adoc[] +| +2.4.2 +| +include::2_4_2.adoc[] +| +2.4.3 +| +include::2_4_3.adoc[] +| +2.4.4 +| +include::2_4_4.adoc[] +|=== diff --git a/scripts/ci/add_operand.sh b/scripts/ci/add_operand.sh new file mode 100755 index 000000000..46dd75248 --- /dev/null +++ b/scripts/ci/add_operand.sh @@ -0,0 +1,25 @@ +#!/bin/bash +set -e + +if [[ "$RUNNER_DEBUG" == "1" ]]; then + set -x +fi + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +source "${SCRIPT_DIR}/operand_common.sh" + +requiredEnv IMAGE VERSION + +export OPERATOR_VERSION=$(cat ${SCRIPT_DIR}/../../version.txt) + +${SCRIPT_DIR}/add_operand_to_csv.sh +${SCRIPT_DIR}/docs_generate_operator_operand_file.sh +${SCRIPT_DIR}/docs_generate_operator_operand_table.sh + +# Only update the doc attributes if we have added the latest Operand +LATEST_OPERAND_VERSION=$(operandJson | jq -r '. | last | ."upstream-version"') +if [ "${LATEST_OPERAND_VERSION}" = "${VERSION}" ]; then + ATTR_FILE=documentation/asciidoc/topics/attributes/community-attributes.adoc + sed -i "s/^:server_image_version: .*$/:server_image_version: ${VERSION}/" ${ATTR_FILE} + sed -i "s/^:operand_version: .*$/:operand_version: ${VERSION}/" ${ATTR_FILE} +fi diff --git a/scripts/ci/add_operand_to_csv.sh b/scripts/ci/add_operand_to_csv.sh index 5fe8a3283..f704dff95 100755 --- a/scripts/ci/add_operand_to_csv.sh +++ b/scripts/ci/add_operand_to_csv.sh @@ -5,11 +5,16 @@ if [[ "$RUNNER_DEBUG" == "1" ]]; then set -x fi -IMAGE=$1 -DEPLOYMENT_FILE=config/manager/manager.yaml -EXISTING_OPERANDS=$(yq 'select(document_index == 1) | .spec.template.spec.containers[0].env[] | select(.name == "INFINISPAN_OPERAND_VERSIONS").value' ${DEPLOYMENT_FILE}) -LATEST_OPERAND_VERSION=$(echo ${EXISTING_OPERANDS} | jq -r '. | last | ."upstream-version"') -NEW_OPERAND_VERSION=$(echo ${LATEST_OPERAND_VERSION} | awk -F. -v OFS=. '{$NF += 1 ; print}') -NEW_OPERANDS=$(echo ${EXISTING_OPERANDS} | jq '.[. | length] |= . + {"upstream-version":"'${NEW_OPERAND_VERSION}'", "image":"'${IMAGE}'"}') +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +source "${SCRIPT_DIR}/operand_common.sh" +requiredEnv IMAGE + +LATEST_OPERAND_VERSION=$(operandJson | jq -r '. | last | ."upstream-version"') + +if [[ -z "${VERSION}" ]]; then + VERSION=$(echo "${LATEST_OPERAND_VERSION}" | awk -F. -v OFS=. '{$NF += 1 ; print}') +fi + +NEW_OPERANDS=$(operandJson | jq -r '.[. | length] |= . + {"upstream-version":"'${VERSION}'", "image":"'${IMAGE}'"} | sort_by(."upstream-version" | split(".") | map(tonumber))') operands=${NEW_OPERANDS} yq -i '(select(document_index == 1) | .spec.template.spec.containers[0].env[] | select(.name == "INFINISPAN_OPERAND_VERSIONS")).value = strenv(operands)' ${DEPLOYMENT_FILE} diff --git a/scripts/ci/docs_generate_operator_operand_file.sh b/scripts/ci/docs_generate_operator_operand_file.sh new file mode 100755 index 000000000..ee16c166c --- /dev/null +++ b/scripts/ci/docs_generate_operator_operand_file.sh @@ -0,0 +1,21 @@ +#!/bin/bash +set -e + +if [[ "$RUNNER_DEBUG" == "1" ]]; then + set -x +fi + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +source "${SCRIPT_DIR}/operand_common.sh" + +requiredEnv OPERATOR_VERSION + +# Create operator version file containing all upstream-versions currently defined in INFINISPAN_OPERAND_VERSIONS +OPERANDS=$(operandJson | jq -r '.[]."upstream-version"') +cat > "${DOCS_OPERAND_DIR}/${OPERATOR_VERSION//./_}.adoc" << EOF +//// +Auto-generated file, do not update this manually. +To add additional Operands to this file, update the \`INFINISPAN_OPERAND_VERSIONS\` array in \`config/manager/manager.yaml\`. +//// +${OPERANDS} +EOF diff --git a/scripts/ci/docs_generate_operator_operand_table.sh b/scripts/ci/docs_generate_operator_operand_table.sh new file mode 100755 index 000000000..0596415ee --- /dev/null +++ b/scripts/ci/docs_generate_operator_operand_table.sh @@ -0,0 +1,33 @@ +#!/bin/bash +set -e + +if [[ "$RUNNER_DEBUG" == "1" ]]; then + set -x +fi + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +source "${SCRIPT_DIR}/operand_common.sh" + +# Generate asciidoc table containing all Operator version files and their supported Operand versions +cat > "${DOCS_OPERAND_TABLE_FILE}" << EOF +//// +Auto-generated file, do not update this manually, instead update \`scripts/ci/docs_generate_operator_operand_table.sh\` +//// +[%header,cols=2*] +|=== +| {ispn_operator} version +| {brandname} Server versions +EOF + +for op in $(ls "${DOCS_OPERAND_DIR}" | grep -Po '([\d+]?)_([\d+]?)_(\d+]?).adoc'); do + version=${op%.adoc} + version=${version//_/.} + cat >> "${DOCS_OPERAND_TABLE_FILE}" << EOF +| +${version} +| +include::${op}[] +EOF +done + +echo "|===" >> "${DOCS_OPERAND_TABLE_FILE}" diff --git a/scripts/ci/kind.sh b/scripts/ci/kind.sh index c76f69938..9d1ab8465 100755 --- a/scripts/ci/kind.sh +++ b/scripts/ci/kind.sh @@ -2,7 +2,12 @@ # Modified version of the script found at https://kind.sigs.k8s.io/docs/user/local-registry/#create-a-cluster-and-registry set -o errexit -SERVER_TAGS=${SERVER_TAGS:-'14.0.1.Final 14.0.6.Final 14.0.9.Final 14.0.13.Final 14.0.17.Final 14.0.19.Final 14.0.20.Final 14.0.21.Final 14.0.24.Final 14.0.27.Final 14.0.32.Final 14.0 15.0.0.Final 15.0.3.Final 15.0.4.Final 15.0.5.Final 15.0.8.Final 15.0'} +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +source "${SCRIPT_DIR}/operand_common.sh" + +if [[ -z "${SERVER_IMAGES}" ]]; then + SERVER_IMAGES=$(operandJson | jq -r '.[].image') +fi DOCKER_REGISTRY_IMAGE=${DOCKER_REGISTRY_IMAGE:-"quay.io/infinispan-test/registry:2"} KINDEST_IMAGE=${KINDEST_IMAGE:-"quay.io/infinispan-test/kindest-node"} KINDEST_NODE_VERSION=${KINDEST_NODE_VERSION:-'v1.25.16'} @@ -41,8 +46,8 @@ EOF docker network connect "kind" "${reg_name}" || true # Attempt to load the servers image to prevent them being pulled again -for tag in ${SERVER_TAGS}; do - kind load docker-image "quay.io/infinispan/server:${tag}" || true +for img in ${SERVER_IMAGES}; do + kind load docker-image "${img}" || true done # Document the local registry diff --git a/scripts/ci/operand_common.sh b/scripts/ci/operand_common.sh new file mode 100755 index 000000000..9b4d7b10b --- /dev/null +++ b/scripts/ci/operand_common.sh @@ -0,0 +1,23 @@ +#!/bin/bash +set -e + +if [[ "$RUNNER_DEBUG" == "1" ]]; then + set -x +fi + +export DEPLOYMENT_FILE=config/manager/manager.yaml +export DOCS_OPERAND_DIR=documentation/asciidoc/topics/supported_operands +export DOCS_OPERAND_TABLE_FILE=${DOCS_OPERAND_DIR}/operand_table.adoc + +function operandJson() { + yq 'select(document_index == 1) | .spec.template.spec.containers[0].env[] | select(.name == "INFINISPAN_OPERAND_VERSIONS").value' ${DEPLOYMENT_FILE} +} + +function requiredEnv() { + for ENV in $@; do + if [ -z "${!ENV}" ]; then + echo "${ENV} variable must be set" + exit 1 + fi + done +} diff --git a/test/e2e/infinispan/dependencies_test.go b/test/e2e/infinispan/dependencies_test.go index 7ce4fa9ac..30c9e1b36 100644 --- a/test/e2e/infinispan/dependencies_test.go +++ b/test/e2e/infinispan/dependencies_test.go @@ -167,7 +167,7 @@ func TestExternalDependenciesHttp(t *testing.T) { func prepareWebServer() *corev1.ConfigMap { webServerConfig := &corev1.ConfigMap{} - testKube.LoadResourceFromYaml("../utils/data/external-libs-config.yaml", webServerConfig) + tutils.LoadResourceFromYaml("../utils/data/external-libs-config.yaml", webServerConfig) webServerConfig.Namespace = tutils.Namespace testKube.Create(webServerConfig) diff --git a/test/e2e/utils/common.go b/test/e2e/utils/common.go index c93eb6968..d9524aa9d 100644 --- a/test/e2e/utils/common.go +++ b/test/e2e/utils/common.go @@ -11,11 +11,13 @@ import ( "strings" "testing" + "github.com/blang/semver" "github.com/iancoleman/strcase" ispnv1 "github.com/infinispan/infinispan-operator/api/v1" "github.com/infinispan/infinispan-operator/controllers/constants" users "github.com/infinispan/infinispan-operator/pkg/infinispan/security" "github.com/infinispan/infinispan-operator/pkg/infinispan/version" + "github.com/infinispan/infinispan-operator/pkg/kubernetes" routev1 "github.com/openshift/api/route/v1" "github.com/redis/go-redis/v9" appsv1 "k8s.io/api/apps/v1" @@ -32,90 +34,73 @@ const ( ) var VersionManager = func() *version.Manager { - if os.Getenv(ispnv1.OperatorOperandVersionEnvVarName) == "" { - // Operand versions must be updated whenever the supported Operands change as the Operands are executed - // during the integration tests. - // The first release must be marked as deprecated to ensure TestOperandUpgrade passes. - // The final release must be a cve release in order for TestOperandCVEUpgrade to pass. This does not have to be - // a real release, but the image tag must differ from the oldest Operand release so that we can ensure the - // Pod Image was correctly updated. - _ = os.Setenv(ispnv1.OperatorOperandVersionEnvVarName, `[{ - "downstream-version": "0.2.0-1", - "upstream-version": "14.0.1", - "image": "quay.io/infinispan/server:14.0.1.Final", - "deprecated": true - },{ - "downstream-version": "0.2.1-1", - "upstream-version": "14.0.6", - "image": "quay.io/infinispan/server:14.0.6.Final" - },{ - "downstream-version": "0.2.2-1", - "upstream-version": "14.0.9", - "image": "quay.io/infinispan/server:14.0.9.Final" - },{ - "downstream-version": "0.2.3-1", - "upstream-version": "14.0.13", - "image": "quay.io/infinispan/server:14.0.13.Final" - },{ - "downstream-version": "0.2.4-1", - "upstream-version": "14.0.17", - "image": "quay.io/infinispan/server:14.0.17.Final" - },{ - "downstream-version": "0.2.5-1", - "upstream-version": "14.0.19", - "image": "quay.io/infinispan/server:14.0.19.Final" - },{ - "downstream-version": "0.2.6-1", - "upstream-version": "14.0.20", - "image": "quay.io/infinispan/server:14.0.20.Final" - },{ - "downstream-version": "0.2.7-1", - "upstream-version": "14.0.21", - "image": "quay.io/infinispan/server:14.0.21.Final" - },{ - "downstream-version": "0.2.8-1", - "upstream-version": "14.0.24", - "image": "quay.io/infinispan/server:14.0.24.Final" - },{ - "downstream-version": "0.2.9-1", - "upstream-version": "14.0.27", - "image": "quay.io/infinispan/server:14.0.27.Final" - },{ - "downstream-version": "0.2.10-1", - "upstream-version": "14.0.32", - "image": "quay.io/infinispan/server:14.0.32.Final" - },{ - "downstream-version": "0.3.0-1", - "upstream-version": "15.0.0", - "image": "quay.io/infinispan/server:15.0.0.Final" - },{ - "downstream-version": "0.3.1-1", - "upstream-version": "15.0.3", - "image": "quay.io/infinispan/server:15.0.3.Final" - },{ - "downstream-version": "0.3.2-1", - "upstream-version": "15.0.4", - "image": "quay.io/infinispan/server:15.0.4.Final" - },{ - "downstream-version": "0.3.3-1", - "upstream-version": "15.0.5", - "image": "quay.io/infinispan/server:15.0.5.Final" - },{ - "downstream-version": "0.3.4-1", - "upstream-version": "15.0.8", - "image": "quay.io/infinispan/server:15.0.8.Final" - },{ - "downstream-version": "0.3.4-2", - "upstream-version": "15.0.8", - "image": "quay.io/infinispan/server:15.0", - "cve": true - }]`) - } - if manager, err := version.ManagerFromEnv(ispnv1.OperatorOperandVersionEnvVarName); err != nil { - panic(err) - } else { + if os.Getenv(ispnv1.OperatorOperandVersionEnvVarName) != "" { + manager, err := version.ManagerFromEnv(ispnv1.OperatorOperandVersionEnvVarName) + ExpectNoError(err) return manager } + deployment := &appsv1.Deployment{} + LoadResourceFromYaml("./../../../config/manager/manager.yaml", &corev1.Namespace{}, deployment) + container := kubernetes.GetContainer("manager", &deployment.Spec.Template.Spec) + idx := kubernetes.GetEnvVarIndex(ispnv1.OperatorOperandVersionEnvVarName, &container.Env) + operandJson := container.Env[idx].Value + manager, err := version.ManagerFromJson(operandJson) + ExpectNoError(err) + + operands := manager.Operands + // The first release must be marked as deprecated to ensure TestOperandUpgrade passes. + operands[0].Deprecated = true + + // The final release must be a cve release in order for TestOperandCVEUpgrade to pass. This does not have to be + // a real release, but the image tag must differ from the oldest Operand release so that we can ensure the + // Pod Image was correctly updated. + lastOperand := operands[len(operands)-1] + operands = append(operands, + &version.Operand{ + CVE: true, + Image: fmt.Sprintf("%s:%d.%d", strings.Split(lastOperand.Image, ":")[0], lastOperand.UpstreamVersion.Major, lastOperand.UpstreamVersion.Minor), + UpstreamVersion: lastOperand.UpstreamVersion, + }, + ) + + // Add downstream version to each Operand + previousOp := operands[0] + downstreamVer := semver.MustParse("0.2.0-1") + operands[0].DownstreamVersion = &downstreamVer + for i := 1; i < len(operands)-1; i++ { + op := operands[i] + if op.UpstreamVersion.Major == previousOp.UpstreamVersion.Major { + // Increment patch version + op.DownstreamVersion = &semver.Version{ + Major: previousOp.DownstreamVersion.Major, + Minor: previousOp.DownstreamVersion.Minor, + Patch: previousOp.DownstreamVersion.Patch + 1, + Pre: previousOp.DownstreamVersion.Pre, + } + } else { + // Increment minor and reset patch + op.DownstreamVersion = &semver.Version{ + Major: previousOp.DownstreamVersion.Major, + Minor: previousOp.DownstreamVersion.Minor + 1, + Patch: 0, + Pre: previousOp.DownstreamVersion.Pre, + } + } + previousOp = op + } + operands[len(operands)-1].DownstreamVersion = &semver.Version{ + Major: previousOp.DownstreamVersion.Major, + Minor: previousOp.DownstreamVersion.Minor, + Patch: previousOp.DownstreamVersion.Patch, + Pre: []semver.PRVersion{{ + IsNum: true, + VersionNum: previousOp.DownstreamVersion.Pre[0].VersionNum + 1, + }}, + } + versionJson, err := manager.Json() + ExpectNoError(err) + ExpectNoError(os.Setenv(ispnv1.OperatorOperandVersionEnvVarName, versionJson)) + return manager } var CurrentOperand = GetCurrentOperand() diff --git a/test/e2e/utils/kubernetes.go b/test/e2e/utils/kubernetes.go index ba34ba266..ae32a7315 100644 --- a/test/e2e/utils/kubernetes.go +++ b/test/e2e/utils/kubernetes.go @@ -849,20 +849,23 @@ func (k TestKubernetes) RunOperator(namespace, crdsPath string) context.CancelFu func (k TestKubernetes) installCRD(path string) { crd := &apiextv1.CustomResourceDefinition{} - k.LoadResourceFromYaml(path, crd) + LoadResourceFromYaml(path, crd) k.CreateOrUpdateAndWaitForCRD(crd) } -func (k TestKubernetes) LoadResourceFromYaml(path string, obj runtime.Object) { +func LoadResourceFromYaml(path string, objects ...runtime.Object) { yamlReader, err := GetYamlReaderFromFile(path) ExpectNoError(err) // TODO: seems that new sdk puts a new line and a separator at the crd start - y, err := yamlReader.Read() - if y[0] == '\n' { - y, err = yamlReader.Read() + for i := 0; i < len(objects); i++ { + y, err := yamlReader.Read() + if y[0] == '\n' { + y, err = yamlReader.Read() + } + ExpectNoError(err) + obj := objects[i] + ExpectNoError(k8syaml.NewYAMLToJSONDecoder(strings.NewReader(string(y))).Decode(&obj)) } - ExpectNoError(err) - ExpectNoError(k8syaml.NewYAMLToJSONDecoder(strings.NewReader(string(y))).Decode(&obj)) } func RunOperator(m *testing.M, k *TestKubernetes) { diff --git a/version.txt b/version.txt new file mode 100644 index 000000000..59aa62c1f --- /dev/null +++ b/version.txt @@ -0,0 +1 @@ +2.4.5