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..ee68ef2f32 --- /dev/null +++ b/.github/scripts/resolve-latest-capi-chart.sh @@ -0,0 +1,30 @@ +#!/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"])')" + +headers="$(mktemp)" +trap 'rm -f "$headers"' EXIT +tags="$(curl -fsSL --retry 3 -D "$headers" -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"] or []))')" + +# The registry lists the tags in push order, so a truncated (paginated) list would miss the newest +if grep -qi '^link:.*rel="next"' "$headers"; then + echo "The tag list of ghcr.io/$repository is paginated, which this script doesn't support" >&2 + exit 1 +fi + +# grep fails without a match, which would end the script (pipefail) before the error below +version="$(printf '%s\n' "$tags" | { grep -E '^[0-9]+\.[0-9]+\.[0-9]+(-[0-9]+)?$' || true; } | 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..576efb0f6b 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 and capi chart 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 and capi chart instead of the default ones (v3 job only)' type: boolean required: false default: false @@ -50,54 +50,71 @@ 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 with v2 disabled, against the capi chart of SUPPORTED_API_VERSION_V3 + # (3.237.0, capi-release 1.252.0), so that a new capi chart can't break validation runs. + # Preview runs deploy the latest capi chart instead. + # Keep capi-version in sync with SUPPORTED_API_VERSION_V3 in CloudFoundryClient.java. + - api: v3 + kind-deployment-ref: 6b6882c54a23bfd23982299052ae681f481ad231 # main, 2026-11-13 + capi-version: 1.252.1-1 + 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 }} + # The v2 job stays on its pinned version, preview runs only affect the v3 job + USE_LATEST_CAPI: ${{ matrix.api == 'v3' && (inputs.preview || github.event_name == 'schedule') }} run: | - # separate assignment, so that a failing resolver fails the step - version="$(.github/scripts/resolve-capi-version.sh)" - echo "version=$version" >> "$GITHUB_OUTPUT" + if [ "$USE_LATEST_CAPI" = true ]; 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 public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { AnnotatedElement element = context.getElement().orElse(null); - IfCloudFoundryVersion annotation = - AnnotationUtils.findAnnotation(element, IfCloudFoundryVersion.class); - + // This rule is registered on a test instance field, so JUnit only evaluates it for test + // methods, and a method lookup doesn't see the annotations of its class. A class-level + // @IfCloudFoundryVersion is therefore looked up on the test class as well. boolean enabled = - Optional.ofNullable(annotation) - .map(c -> isTestEnabled(c, CloudFoundryVersionConditionalRule.this.server)) - .orElse(true); + Stream.of(element, context.getTestClass().orElse(null)) + .filter(Objects::nonNull) + .map(e -> AnnotationUtils.findAnnotation(e, IfCloudFoundryVersion.class)) + .filter(Objects::nonNull) + .allMatch(this::isTestEnabled); return enabled ? ConditionEvaluationResult.enabled("Test enabled") @@ -55,33 +79,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"; diff --git a/integration-test/src/test/java/org/cloudfoundry/client/RootEndpointTest.java b/integration-test/src/test/java/org/cloudfoundry/client/RootEndpointTest.java index 84b0479420..37de189e42 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/RootEndpointTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/RootEndpointTest.java @@ -1,5 +1,7 @@ package org.cloudfoundry.client; +import static org.assertj.core.api.Assertions.assertThat; + import com.github.zafarkhaja.semver.Version; import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; @@ -21,7 +23,7 @@ void rootVersion() { .map(GetRootResponse::getApiVersionV3) .map(Version::parse) .as(StepVerifier::create) - .consumeNextWith(v -> v.isHigherThan(Version.of(3))) + .consumeNextWith(v -> assertThat(v.isHigherThan(Version.of(3))).isTrue()) .expectComplete() .verify(Duration.ofMinutes(1)); } diff --git a/integration-test/src/test/java/org/cloudfoundry/networking/v1/PoliciesTest.java b/integration-test/src/test/java/org/cloudfoundry/networking/v1/PoliciesTest.java index eaa9916908..a91f6fed4e 100644 --- a/integration-test/src/test/java/org/cloudfoundry/networking/v1/PoliciesTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/networking/v1/PoliciesTest.java @@ -23,8 +23,11 @@ import org.cloudfoundry.CloudFoundryVersion; import org.cloudfoundry.IfCloudFoundryVersion; import org.cloudfoundry.client.CloudFoundryClient; -import org.cloudfoundry.client.v2.applications.CreateApplicationRequest; -import org.cloudfoundry.client.v2.applications.CreateApplicationResponse; +import org.cloudfoundry.client.v3.Relationship; +import org.cloudfoundry.client.v3.ToOneRelationship; +import org.cloudfoundry.client.v3.applications.ApplicationRelationships; +import org.cloudfoundry.client.v3.applications.CreateApplicationRequest; +import org.cloudfoundry.client.v3.applications.CreateApplicationResponse; import org.cloudfoundry.networking.NetworkingClient; import org.cloudfoundry.networking.v1.policies.CreatePoliciesRequest; import org.cloudfoundry.networking.v1.policies.DeletePoliciesRequest; @@ -34,7 +37,6 @@ import org.cloudfoundry.networking.v1.policies.Policy; import org.cloudfoundry.networking.v1.policies.Ports; import org.cloudfoundry.networking.v1.policies.Source; -import org.cloudfoundry.util.ResourceUtils; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Mono; @@ -290,21 +292,26 @@ public void listFiltered() { private static Mono createApplicationId( CloudFoundryClient cloudFoundryClient, String applicationName, String spaceId) { return requestCreateApplication(cloudFoundryClient, spaceId, applicationName) - .map(ResourceUtils::getId); + .map(CreateApplicationResponse::getId); } private static Mono requestCreateApplication( CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { return cloudFoundryClient - .applicationsV2() + .applicationsV3() .create( CreateApplicationRequest.builder() - .buildpack("staticfile_buildpack") - .diego(true) - .diskQuota(512) - .memory(64) .name(applicationName) - .spaceId(spaceId) + .relationships( + ApplicationRelationships.builder() + .space( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(spaceId) + .build()) + .build()) + .build()) .build()); } diff --git a/integration-test/src/test/java/org/cloudfoundry/networking/v1/TagsTest.java b/integration-test/src/test/java/org/cloudfoundry/networking/v1/TagsTest.java index 6393f0c2d0..a0dc57e22d 100644 --- a/integration-test/src/test/java/org/cloudfoundry/networking/v1/TagsTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/networking/v1/TagsTest.java @@ -23,8 +23,11 @@ import org.cloudfoundry.CloudFoundryVersion; import org.cloudfoundry.IfCloudFoundryVersion; import org.cloudfoundry.client.CloudFoundryClient; -import org.cloudfoundry.client.v2.applications.CreateApplicationRequest; -import org.cloudfoundry.client.v2.applications.CreateApplicationResponse; +import org.cloudfoundry.client.v3.Relationship; +import org.cloudfoundry.client.v3.ToOneRelationship; +import org.cloudfoundry.client.v3.applications.ApplicationRelationships; +import org.cloudfoundry.client.v3.applications.CreateApplicationRequest; +import org.cloudfoundry.client.v3.applications.CreateApplicationResponse; import org.cloudfoundry.networking.NetworkingClient; import org.cloudfoundry.networking.v1.policies.CreatePoliciesRequest; import org.cloudfoundry.networking.v1.policies.Destination; @@ -33,7 +36,6 @@ import org.cloudfoundry.networking.v1.policies.Source; import org.cloudfoundry.networking.v1.tags.ListTagsRequest; import org.cloudfoundry.networking.v1.tags.ListTagsResponse; -import org.cloudfoundry.util.ResourceUtils; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Mono; @@ -94,21 +96,26 @@ public void create() { private static Mono createApplicationId( CloudFoundryClient cloudFoundryClient, String applicationName, String spaceId) { return requestCreateApplication(cloudFoundryClient, spaceId, applicationName) - .map(ResourceUtils::getId); + .map(CreateApplicationResponse::getId); } private static Mono requestCreateApplication( CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { return cloudFoundryClient - .applicationsV2() + .applicationsV3() .create( CreateApplicationRequest.builder() - .buildpack("staticfile_buildpack") - .diego(true) - .diskQuota(512) - .memory(64) .name(applicationName) - .spaceId(spaceId) + .relationships( + ApplicationRelationships.builder() + .space( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(spaceId) + .build()) + .build()) + .build()) .build()); }