From 2bda3c77ad6b3cad0e086ac916516a067be62d75 Mon Sep 17 00:00:00 2001 From: erabii Date: Wed, 5 Jul 2023 16:30:03 +0300 Subject: [PATCH] refactor fabric8 test (#1379) --- .../action.yaml | 5 +++ .../action.yaml | 18 -------- .github/workflows/maven.yaml | 39 ++---------------- .../fabric8/istio/Fabric8IstioIT.java | 23 ++++------- .../integration/tests/commons/Commons.java | 10 +++++ .../istio-cli}/istio-1.16.0/bin/istioctl | Bin 6 files changed, 26 insertions(+), 69 deletions(-) delete mode 100644 .github/workflows/composites/fabric8-istio-integration-test/action.yaml rename {istio-cli => spring-cloud-kubernetes-test-support/src/main/resources/istio-cli}/istio-1.16.0/bin/istioctl (100%) diff --git a/.github/workflows/composites/build-integration-tests-project/action.yaml b/.github/workflows/composites/build-integration-tests-project/action.yaml index ffed7a1d..23fbb33a 100644 --- a/.github/workflows/composites/build-integration-tests-project/action.yaml +++ b/.github/workflows/composites/build-integration-tests-project/action.yaml @@ -6,6 +6,11 @@ runs: - name: build integration tests project without tests shell: bash run: | + + cd spring-cloud-kubernetes-test-support + .././mvnw clean install -U + cd .. + cd spring-cloud-kubernetes-integration-tests # build the images, but dont run the tests .././mvnw -T 1C clean install -DskipTests diff --git a/.github/workflows/composites/fabric8-istio-integration-test/action.yaml b/.github/workflows/composites/fabric8-istio-integration-test/action.yaml deleted file mode 100644 index 203b5a93..00000000 --- a/.github/workflows/composites/fabric8-istio-integration-test/action.yaml +++ /dev/null @@ -1,18 +0,0 @@ -name: run fabric8 istio integration test -description: run fabric8 istio integration test -runs: - using: "composite" - steps: - - name: run fabric8 istio integration test - shell: bash - run: | - - cd spring-cloud-kubernetes-test-support - .././mvnw clean install - cd .. - - docker load -i /tmp/docker/images/spring-cloud-kubernetes-fabric8-istio-it.tar - rm -fr /tmp/docker/images/spring-cloud-kubernetes-fabric8-istio-it.tar - cd spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-istio-it/ - ../.././mvnw clean install -Dskip.build.image=true - cd ../.. diff --git a/.github/workflows/maven.yaml b/.github/workflows/maven.yaml index c5214612..090fc540 100644 --- a/.github/workflows/maven.yaml +++ b/.github/workflows/maven.yaml @@ -11,6 +11,7 @@ jobs: runs-on: ubuntu-latest env: TESTCONTAINERS_REUSE_ENABLE: false + SEGMENT_DOWNLOAD_TIMEOUT_MINS: 30 steps: - name: checkout project @@ -61,44 +62,12 @@ jobs: uses: ./.github/workflows/composites/upload-docker-images if: env.BASE_BRANCH != '2.1.x' - # we need to run some test, so that K3s container is started and then all other instances will re-use this one. - # Otherwise, (since we use static ports) there might be two instances starting at the same time, and ports might conflict - # This does not run on '2.1.x' branch. - fabric8_istio_integration_test: - needs: build - runs-on: ubuntu-latest - - steps: - - name: checkout project - uses: actions/checkout@v2 - - - name: set env variables - uses: ./.github/workflows/composites/env-variables - - - name: setup project - uses: ./.github/workflows/composites/setup-jdk17 - if: env.BASE_BRANCH == 'main' || env.BASE_BRANCH == '3.0.x' - - - name: cache local maven repository - uses: ./.github/workflows/composites/cache - if: env.BASE_BRANCH != '2.1.x' - - - name: download docker images - uses: ./.github/workflows/composites/download-docker-images - if: env.BASE_BRANCH != '2.1.x' - - - name: echo saved images - uses: ./.github/workflows/composites/echo-saved-images - if: env.BASE_BRANCH != '2.1.x' - - - name: integration test fabric8 istio - uses: ./.github/workflows/composites/fabric8-istio-integration-test - if: env.BASE_BRANCH != '2.1.x' - test: - needs: [ build, fabric8_istio_integration_test ] + needs: [ build ] runs-on: ubuntu-latest timeout-minutes: 60 + env: + SEGMENT_DOWNLOAD_TIMEOUT_MINS: 30 strategy: fail-fast: true diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-istio-it/src/test/java/org/springframework/cloud/kubernetes/fabric8/istio/Fabric8IstioIT.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-istio-it/src/test/java/org/springframework/cloud/kubernetes/fabric8/istio/Fabric8IstioIT.java index 43a29944..247ec912 100644 --- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-istio-it/src/test/java/org/springframework/cloud/kubernetes/fabric8/istio/Fabric8IstioIT.java +++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-istio-it/src/test/java/org/springframework/cloud/kubernetes/fabric8/istio/Fabric8IstioIT.java @@ -16,7 +16,6 @@ package org.springframework.cloud.kubernetes.fabric8.istio; -import java.io.File; import java.io.InputStream; import java.time.Duration; import java.util.List; @@ -57,12 +56,6 @@ class Fabric8IstioIT { private static final String ISTIO_PILOT = "istio/pilot"; - private static final String ISTIO_VERSION = "1.16.0"; - - private static final String LOCAL_ISTIO_BIN_PATH = "../../istio-cli/istio-" + ISTIO_VERSION + "/bin"; - - private static final String CONTAINER_ISTIO_BIN_PATH = "/tmp/istio/istio-bin/bin/"; - private static KubernetesClient client; private static Util util; @@ -71,26 +64,24 @@ class Fabric8IstioIT { @BeforeAll static void beforeAll() throws Exception { - // Path passed to K3S container must be absolute - String absolutePath = new File(LOCAL_ISTIO_BIN_PATH).getAbsolutePath(); - K3S = Commons.container().withFileSystemBind(absolutePath, CONTAINER_ISTIO_BIN_PATH); + K3S = Commons.container(); K3S.start(); util = new Util(K3S); client = util.client(); Commons.validateImage(IMAGE_NAME, K3S); Commons.loadSpringCloudKubernetesImage(IMAGE_NAME, K3S); - Commons.pullImage(ISTIO_PROXY, ISTIO_VERSION, K3S); - Commons.loadImage(ISTIO_PROXY, ISTIO_VERSION, "istioproxy", K3S); - Commons.pullImage(ISTIO_PILOT, ISTIO_VERSION, K3S); - Commons.loadImage(ISTIO_PILOT, ISTIO_VERSION, "istiopilot", K3S); + Commons.pullImage(ISTIO_PROXY, Commons.ISTIO_VERSION, K3S); + Commons.loadImage(ISTIO_PROXY, Commons.ISTIO_VERSION, "istioproxy", K3S); + Commons.pullImage(ISTIO_PILOT, Commons.ISTIO_VERSION, K3S); + Commons.loadImage(ISTIO_PILOT, Commons.ISTIO_VERSION, "istiopilot", K3S); processExecResult(K3S.execInContainer("sh", "-c", "kubectl create namespace istio-test")); processExecResult( K3S.execInContainer("sh", "-c", "kubectl label namespace istio-test istio-injection=enabled")); - processExecResult(K3S.execInContainer("sh", "-c", CONTAINER_ISTIO_BIN_PATH + "istioctl" - + " --kubeconfig=/etc/rancher/k3s/k3s.yaml install --set profile=minimal -y")); + processExecResult(K3S.execInContainer("sh", "-c", + "/tmp/istioctl" + " --kubeconfig=/etc/rancher/k3s/k3s.yaml install --set profile=minimal -y")); util.setUpIstio(NAMESPACE); diff --git a/spring-cloud-kubernetes-test-support/src/main/java/org/springframework/cloud/kubernetes/integration/tests/commons/Commons.java b/spring-cloud-kubernetes-test-support/src/main/java/org/springframework/cloud/kubernetes/integration/tests/commons/Commons.java index 861557a0..222bb1d6 100644 --- a/spring-cloud-kubernetes-test-support/src/main/java/org/springframework/cloud/kubernetes/integration/tests/commons/Commons.java +++ b/spring-cloud-kubernetes-test-support/src/main/java/org/springframework/cloud/kubernetes/integration/tests/commons/Commons.java @@ -38,6 +38,7 @@ import org.junit.jupiter.api.Assertions; import org.testcontainers.containers.Container; import org.testcontainers.k3s.K3sContainer; import org.testcontainers.utility.DockerImageName; +import org.testcontainers.utility.MountableFile; import org.springframework.core.io.ClassPathResource; import org.springframework.util.ReflectionUtils; @@ -56,6 +57,13 @@ public final class Commons { private static final Log LOG = LogFactory.getLog(Commons.class); + /** + * istio version used in our integration tests. + */ + public static final String ISTIO_VERSION = "1.16.0"; + + private static final String LOCAL_ISTIO_BIN_PATH = "istio-cli/istio-" + ISTIO_VERSION + "/bin"; + private Commons() { throw new AssertionError("No instance provided"); } @@ -85,6 +93,8 @@ public final class Commons { private static final K3sContainer CONTAINER = new FixedPortsK3sContainer(DockerImageName.parse(Commons.RANCHER)) .configureFixedPorts(EXPOSED_PORTS).withFileSystemBind(TEMP_FOLDER, TEMP_FOLDER) + .withCopyFileToContainer(MountableFile.forClasspathResource(LOCAL_ISTIO_BIN_PATH + "/istioctl", 0744), + "/tmp/istioctl") .withCommand(Commons.RANCHER_COMMAND).withReuse(true); public static K3sContainer container() { diff --git a/istio-cli/istio-1.16.0/bin/istioctl b/spring-cloud-kubernetes-test-support/src/main/resources/istio-cli/istio-1.16.0/bin/istioctl similarity index 100% rename from istio-cli/istio-1.16.0/bin/istioctl rename to spring-cloud-kubernetes-test-support/src/main/resources/istio-cli/istio-1.16.0/bin/istioctl