From 99e94e4e2c5eb7be20212e59c40812bfd647af4c Mon Sep 17 00:00:00 2001 From: Pascal Zimmermann Date: Wed, 18 Nov 2026 22:30:42 +0100 Subject: [PATCH] feat: Run the V2 integration tests against a dedicated CAPI version Newer CAPI releases disable the CC V2 API, so the integration tests are split: - V2 tests (@RequiresV2Api, now tagged "v2") run against the pinned capi chart 1.249.0, the last one serving V2, on kind-deployment v0.26.0. - All other tests run against the latest capi chart, resolved at runtime, on a newer kind-deployment with SKIP_V2_TESTS=true. - @IfCloudFoundryVersion compares 2.x versions with the V2 and 3.x versions with the V3 API version of the server, so V3 gates such as PCF_4_v3 no longer get compared with the V2 version. - SUPPORTED_API_VERSION is 2.299.0 (CAPI 1.249.0), SUPPORTED_API_VERSION_V3 is 3.237.0 (CAPI 1.252.0). --- .github/scripts/resolve-capi-version.sh | 48 ------------ .github/scripts/resolve-latest-capi-chart.sh | 20 +++++ .github/workflows/integration-test.yml | 71 ++++++++++-------- .../client/CloudFoundryClient.java | 4 +- .../CloudFoundryVersionConditionalRule.java | 73 +++++++++++++++---- .../IntegrationTestConfiguration.java | 7 +- .../java/org/cloudfoundry/RequiresV2Api.java | 9 +++ 7 files changed, 136 insertions(+), 96 deletions(-) delete mode 100755 .github/scripts/resolve-capi-version.sh create mode 100755 .github/scripts/resolve-latest-capi-chart.sh diff --git a/.github/scripts/resolve-capi-version.sh b/.github/scripts/resolve-capi-version.sh deleted file mode 100755 index 5ff2dfec33..0000000000 --- a/.github/scripts/resolve-capi-version.sh +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env bash -# Prints the newest capi-release version whose CC API (v2) version equals SUPPORTED_API_VERSION -# from CloudFoundryClient.java. Needs only git and curl, no GitHub API and so no token. -# -# A capi-release tag pins cloud_controller_ng as a submodule, and that repo records its v2 API -# version in config/version_v2. The release notes aren't reliable for this. The v2 version only -# grows with the tags, so a binary search over the sorted tags is enough. -set -euo pipefail - -source_file="$(dirname "$0")/../../cloudfoundry-client/src/main/java/org/cloudfoundry/client/CloudFoundryClient.java" -target="$(sed -n 's/.*String SUPPORTED_API_VERSION = "\([0-9.]*\)";.*/\1/p' "$source_file")" -[ -n "$target" ] || { echo "SUPPORTED_API_VERSION not found in $source_file" >&2; exit 1; } - -workdir="$(mktemp -d)" -trap 'rm -rf "$workdir"' EXIT -# commits and trees only, which is all it takes to read the submodule commit of a tag -git clone --quiet --bare --filter=blob:none https://github.com/cloudfoundry/capi-release.git "$workdir/capi-release" - -mapfile -t tags < <(git -C "$workdir/capi-release" tag -l | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | sort -V) - -v2_version() { - local sha - sha="$(git -C "$workdir/capi-release" ls-tree "$1" src/cloud_controller_ng | awk '{print $3}')" - curl -fsSL --retry 3 "https://raw.githubusercontent.com/cloudfoundry/cloud_controller_ng/$sha/config/version_v2" | tr -d '[:space:]' -} - -# highest index whose v2 version is <= target -lo=0 -hi=$((${#tags[@]} - 1)) -found=-1 -while [ "$lo" -le "$hi" ]; do - mid=$(((lo + hi) / 2)) - v="$(v2_version "${tags[$mid]}")" - if [ "$(printf '%s\n%s\n' "$v" "$target" | sort -V | tail -1)" = "$target" ]; then - found=$mid - lo=$((mid + 1)) - else - hi=$((mid - 1)) - fi -done - -if [ "$found" -lt 0 ] || [ "$(v2_version "${tags[$found]}")" != "$target" ]; then - echo "No capi-release found for CC API version $target" >&2 - exit 1 -fi - -echo "CC API $target -> capi-release ${tags[$found]}" >&2 -echo "${tags[$found]}" diff --git a/.github/scripts/resolve-latest-capi-chart.sh b/.github/scripts/resolve-latest-capi-chart.sh new file mode 100755 index 0000000000..bcff0ea023 --- /dev/null +++ b/.github/scripts/resolve-latest-capi-chart.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +# Prints the newest version of the capi Helm chart (ghcr.io/cloudfoundry/helm/capi) that +# kind-deployment deploys. Needs only curl and python3, the registry allows anonymous pulls. +# +# Only release versions (1.252.0) and chart revisions of a release (1.252.1-1) count. Other tags, +# such as 1.237.1-fix1, are skipped. +set -euo pipefail + +repository="cloudfoundry/helm/capi" +token="$(curl -fsSL --retry 3 "https://ghcr.io/token?scope=repository:$repository:pull" | + python3 -c 'import json, sys; print(json.load(sys.stdin)["token"])')" + +version="$(curl -fsSL --retry 3 -H "Authorization: Bearer $token" "https://ghcr.io/v2/$repository/tags/list?n=10000" | + python3 -c 'import json, sys; print("\n".join(json.load(sys.stdin)["tags"]))' | + grep -E '^[0-9]+\.[0-9]+\.[0-9]+(-[0-9]+)?$' | sort -V | tail -1)" + +[ -n "$version" ] || { echo "No capi chart version found in ghcr.io/$repository" >&2; exit 1; } + +echo "latest capi chart -> $version" >&2 +echo "$version" diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index c27d202142..d70638eab5 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -9,7 +9,7 @@ on: required: false default: '[8, 11, 17, 21]' preview: - description: 'Deploy the latest cf-deployment versions instead of the default ones' + description: 'Deploy the latest cf-deployment versions instead of the default ones (v3 job only)' type: boolean required: false default: false @@ -23,7 +23,7 @@ on: required: false default: '[8, 11, 17, 21]' preview: - description: 'Deploy the latest cf-deployment versions instead of the default ones' + description: 'Deploy the latest cf-deployment versions instead of the default ones (v3 job only)' type: boolean required: false default: false @@ -50,54 +50,64 @@ jobs: fail-fast: false matrix: java: ${{ fromJSON(inputs.java-versions || (github.event_name == 'schedule' && '[21]' || '[8, 11, 17, 21]')) }} - name: Java ${{ matrix.java }} integration test${{ (inputs.preview || github.event_name == 'schedule') && ' (preview)' || '' }} + api: [v2, v3] + include: + # Newer CAPI releases disable the CC v2 API, so the v2 tests (@RequiresV2Api, JUnit tag + # "v2") run against a dedicated, pinned CAPI. The capi chart 1.249.0 is the last one that + # serves v2: from 1.249.1-1 on, v2 is behind cloudController.config.temporaryEnableV2, + # which kind-deployment v0.26.0 doesn't set. Newer kind-deployment versions don't deploy + # these older charts any more (their capi values schema changed with 1.249.1-1). + # Keep capi-version in sync with SUPPORTED_API_VERSION (2.299.0) in CloudFoundryClient.java. + - api: v2 + kind-deployment-ref: b42a88a35756595bd4108d2b525ded5b014a9515 # v0.26.0 + capi-version: 1.249.0 + test-selection: -Dgroups=v2 + skip-v2-tests: 'false' + # All other tests run against the latest capi chart, with v2 disabled. + - api: v3 + kind-deployment-ref: 6b6882c54a23bfd23982299052ae681f481ad231 # main, 2026-11-13 + capi-version: latest + test-selection: -DexcludedGroups=v2 + skip-v2-tests: 'true' + name: Java ${{ matrix.java }} ${{ matrix.api }} integration test${{ matrix.api == 'v3' && (inputs.preview || github.event_name == 'schedule') && ' (preview)' || '' }} steps: - uses: actions/checkout@v7 with: submodules: recursive - # Validation runs deploy the capi-release that matches SUPPORTED_API_VERSION. Preview runs - # (scheduled, or started by hand with `preview`) keep the latest versions. - name: Resolve CAPI version id: capi - if: ${{ !(inputs.preview || github.event_name == 'schedule') }} + env: + CAPI_VERSION: ${{ matrix.capi-version }} run: | - # separate assignment, so that a failing resolver fails the step - version="$(.github/scripts/resolve-capi-version.sh)" - echo "version=$version" >> "$GITHUB_OUTPUT" + if [ "$CAPI_VERSION" = latest ]; then + # separate assignment, so that a failing resolver fails the step + CAPI_VERSION="$(.github/scripts/resolve-latest-capi-chart.sh)" + fi + echo "version=$CAPI_VERSION" >> "$GITHUB_OUTPUT" # All components share one Postgres, which runs out of its default 100 connections during a full - # test run. Written first, the CAPI override below appends to the same file. - - name: Write PostgreSQL values override + # test run. + # The capi chart version overrides the one of kind-deployment (merged last by Helmfile), also in + # preview runs. + - name: Write values override + env: + CAPI_VERSION: ${{ steps.capi.outputs.version }} run: | cat > "$RUNNER_TEMP/cf-values.yaml" <> "$RUNNER_TEMP/cf-values.yaml" < serverV2, Version serverV3) { + this.serverV2 = serverV2.orElse(V2_DISABLED); + this.serverV3 = serverV3; } @Override @@ -41,10 +61,7 @@ public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext con IfCloudFoundryVersion annotation = AnnotationUtils.findAnnotation(element, IfCloudFoundryVersion.class); - boolean enabled = - Optional.ofNullable(annotation) - .map(c -> isTestEnabled(c, CloudFoundryVersionConditionalRule.this.server)) - .orElse(true); + boolean enabled = Optional.ofNullable(annotation).map(this::isTestEnabled).orElse(true); return enabled ? ConditionEvaluationResult.enabled("Test enabled") @@ -55,33 +72,61 @@ public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext con element)); } - private static boolean isTestEnabled(IfCloudFoundryVersion condition, Version server) { + private boolean isTestEnabled(IfCloudFoundryVersion condition) { boolean enabled = true; if (condition.lessThan() != UNSPECIFIED) { - enabled = enabled && server.lessThan(condition.lessThan().getVersion()); + enabled = + enabled + && server(condition.lessThan()) + .isLowerThan(version(condition.lessThan())); } if (condition.lessThanOrEqualTo() != UNSPECIFIED) { enabled = - enabled && server.lessThanOrEqualTo(condition.lessThanOrEqualTo().getVersion()); + enabled + && server(condition.lessThanOrEqualTo()) + .isLowerThanOrEquivalentTo( + version(condition.lessThanOrEqualTo())); } if (condition.equalTo() != UNSPECIFIED) { - enabled = enabled && server.equals(condition.equalTo().getVersion()); + enabled = enabled && server(condition.equalTo()).equals(version(condition.equalTo())); } if (condition.greaterThanOrEqualTo() != UNSPECIFIED) { enabled = enabled - && server.greaterThanOrEqualTo( - condition.greaterThanOrEqualTo().getVersion()); + && server(condition.greaterThanOrEqualTo()) + .isHigherThanOrEquivalentTo( + version(condition.greaterThanOrEqualTo())); } if (condition.greaterThan() != UNSPECIFIED) { - enabled = enabled && server.greaterThan(condition.greaterThan().getVersion()); + enabled = + enabled + && server(condition.greaterThan()) + .isHigherThan(version(condition.greaterThan())); } return enabled; } + + private Version server(CloudFoundryVersion version) { + long major = version(version).majorVersion(); + if (major == 2) { + return this.serverV2; + } + if (major == 3) { + return this.serverV3; + } + throw new IllegalArgumentException( + String.format( + "%s is neither a V2 (2.x) nor a V3 (3.x) API version: %s", + version, version(version))); + } + + private static Version version(CloudFoundryVersion version) { + return version.getVersion(); + } } diff --git a/integration-test/src/test/java/org/cloudfoundry/IntegrationTestConfiguration.java b/integration-test/src/test/java/org/cloudfoundry/IntegrationTestConfiguration.java index 553b6999ce..b4439f313e 100644 --- a/integration-test/src/test/java/org/cloudfoundry/IntegrationTestConfiguration.java +++ b/integration-test/src/test/java/org/cloudfoundry/IntegrationTestConfiguration.java @@ -309,8 +309,11 @@ DefaultCloudFoundryOperations cloudFoundryOperations( } @Bean - CloudFoundryVersionConditionalRule cloudFoundryVersionConditionalRule(Version serverVersion) { - return new CloudFoundryVersionConditionalRule(serverVersion); + CloudFoundryVersionConditionalRule cloudFoundryVersionConditionalRule( + @Qualifier("admin") CloudFoundryClient cloudFoundryClient) { + return new CloudFoundryVersionConditionalRule( + serverVersionV2(cloudFoundryClient).blockOptional(), + serverVersionV3(cloudFoundryClient).block()); } @Bean diff --git a/integration-test/src/test/java/org/cloudfoundry/RequiresV2Api.java b/integration-test/src/test/java/org/cloudfoundry/RequiresV2Api.java index b11fe8ca06..7ec40f1fd1 100644 --- a/integration-test/src/test/java/org/cloudfoundry/RequiresV2Api.java +++ b/integration-test/src/test/java/org/cloudfoundry/RequiresV2Api.java @@ -22,6 +22,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.extension.ConditionEvaluationResult; import org.junit.jupiter.api.extension.ExecutionCondition; import org.junit.jupiter.api.extension.ExtendWith; @@ -43,14 +44,22 @@ *
  * export SKIP_V2_TESTS=true
  * 
+ * + *

Tests annotated with this are also tagged with {@value #TAG}, so that they can be selected + * ({@code -Dgroups=v2}) or excluded ({@code -DexcludedGroups=v2}) on their own, e.g. to run them + * against a Cloud Foundry that still serves the V2 API. */ @Target({ElementType.METHOD, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited @ExtendWith(RequiresV2Api.V2ApiCondition.class) +@Tag(RequiresV2Api.TAG) public @interface RequiresV2Api { + /** JUnit tag of all tests that require the V2 API. */ + String TAG = "v2"; + /** Environment variable name used to skip V2 API tests. */ String SKIP_V2_TESTS_ENV = "SKIP_V2_TESTS";