Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resume K8s integration tests #1314

Merged
merged 9 commits into from
Sep 27, 2024
22 changes: 13 additions & 9 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ on:
- 'doc/**'
- '.circleci/**'
env:
# failsafe.groups configuration depends on the env setup.
FAILSAFE_GROUPS: ''
DOCKER_HOST: 'unix:///var/run/docker.sock'

jobs:
Expand All @@ -23,9 +21,12 @@ jobs:
fail-fast: false
matrix:
java: ['11']

target: ['docker', 'kubernetes']
env:
# failsafe.groups configuration depends on the env setup.
FAILSAFE_GROUPS: ''
steps:
- name: Setup Minikube
- name: Setup Minikube # add an if for the kubernetes target only?
uses: manusa/[email protected]
with:
driver: docker
Expand All @@ -34,8 +35,6 @@ jobs:
kubernetes version: 'v1.30.0'
github token: ${{ secrets.GITHUB_TOKEN }}
start args: "--memory='4gb' --cpus='2'"
env:
FAILSAFE_GROUPS: "-Dfailsafe.groups=\"org.arquillian.cube.docker.impl.requirement.RequiresDocker,org.arquillian.cube.kubernetes.impl.requirement.RequiresKubernetes\""
- name: Enable minikube registry
run: |
minikube addons enable registry
Expand All @@ -55,10 +54,15 @@ jobs:
distribution: 'adopt'
- name: Maven pre-fetch dependencies ${{ matrix.java }}
run: |
./mvnw verify -q -U -DskipTests # pre-fetch dependencies
- name: Build with Maven Java ${{ matrix.java }}
./mvnw clean package -q -U -DskipTests # pre-fetch dependencies
- name: Build and run integration tests for Docker target (${{ matrix.java }})
if: ${{ matrix.target == 'docker' }}
run: |
./mvnw package -Dfailsafe.groups=org.arquillian.cube.docker.impl.requirement.RequiresDocker -Dcontainerless.skip.tests=true
- name: Build and run integration tests for Kubernetes target (${{ matrix.java }})
if: ${{ matrix.target == 'kubernetes' }}
run: |
./mvnw -fae clean package ${{ env.FAILSAFE_GROUPS }}
./mvnw verify -Dfailsafe.groups=org.arquillian.cube.kubernetes.impl.requirement.RequiresKubernetes -Dcontainerless.skip.tests=true
- uses: actions/upload-artifact@v3
if: failure()
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class DockerHealthAwaitStrategyTest {
@BeforeClass
public static void createDockerClient() {
if (!System.getenv().containsKey(DOCKER_HOST) || System.getenv(DOCKER_HOST).equals("")){
environmentVariables.set(DOCKER_HOST, "unix:///var/run/podman.sock");
environmentVariables.set(DOCKER_HOST, "unix:///var/run/docker.sock");
}
dockerClient = DockerClientBuilder.getInstance().build();
healthSuccessImageId = dockerBuild("DockerHealthAwait/HealthSuccess/Dockerfile");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.arquillian.cube.kubernetes.assistant;

import io.fabric8.kubernetes.client.http.HttpClient;
import io.fabric8.kubernetes.client.jdkhttp.JdkHttpClientFactory;
import org.arquillian.cube.kubernetes.impl.KubernetesAssistant;
import org.arquillian.cube.kubernetes.impl.requirement.RequiresKubernetes;
import org.arquillian.cube.requirement.ArquillianConditionalRunner;
Expand All @@ -17,8 +15,6 @@
import static io.restassured.RestAssured.given;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.Matchers.hasKey;

// tag::k8_assistant_example[]
@RunWith(ArquillianConditionalRunner.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}
}
}, {
"apiVersion" : "extensions/v1beta1",
"apiVersion" : "apps/v1",
"kind" : "Deployment",
"metadata" : {
"name" : "hello-world"
Expand Down
5 changes: 5 additions & 0 deletions kubernetes/ftest-kubernetes-logs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some minor thing. Can we add this dependency under kubernetes/pom.xml instead of adding to each sub modules ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jimma the dependency is needed by 5 out of 9 child projects, and we don't really want for others that don't need it to inherit it, e.g.: the istio module should not depend on this artifact as they don't need it. The dependency management is already defined by the root POM, so in the end I don't think we should bring it up.
Do you agree?

<artifactId>kubernetes-client</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
5 changes: 5 additions & 0 deletions kubernetes/ftest-kubernetes-reporter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-client</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
5 changes: 5 additions & 0 deletions kubernetes/ftest-kubernetes-resources/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-client</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ spec:
selector:
app: hello-world
---
apiVersion: extensions/v1beta1
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-world
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ spec:
selector:
app: hello-world
---
apiVersion: extensions/v1beta1
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-world
Expand Down
5 changes: 5 additions & 0 deletions kubernetes/ftest-kubernetes/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-client</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
10 changes: 2 additions & 8 deletions kubernetes/ftest-kubernetes/src/test/java/HelloWorldIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import java.net.URL;

import io.restassured.RestAssured;
import io.restassured.builder.RequestSpecBuilder;
import io.restassured.specification.RequestSpecification;
import org.arquillian.cube.kubernetes.annotations.Named;
import org.arquillian.cube.kubernetes.annotations.PortForward;
import org.arquillian.cube.kubernetes.impl.requirement.RequiresKubernetes;
Expand All @@ -15,12 +13,8 @@
import org.junit.runner.RunWith;

import static junit.framework.TestCase.assertFalse;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.hasKey;
import static org.junit.Assert.assertEquals;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

@Category(RequiresKubernetes.class)
@RequiresKubernetes
Expand Down Expand Up @@ -55,7 +49,7 @@ public void shouldShowHelloWorld() throws IOException {
.then()
.assertThat()
.statusCode(200)
.body(contains("Hello OpenShift!\n"));
.body(is("Hello OpenShift!\n"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ spec:
selector:
app: hello-world
---
apiVersion: extensions/v1beta1
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-world
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,10 @@ public Optional<URL> getServiceUrl() {
}

private Optional<URL> createUrlForService(Service service) {
final String scheme = (service.getMetadata() != null && service.getMetadata().getAnnotations() != null) ?
final boolean useMetadataAnnotations = service.getMetadata().getAnnotations() != null && !service.getMetadata().getAnnotations().isEmpty();
final String scheme = (service.getMetadata() != null && useMetadataAnnotations) ?
service.getMetadata().getAnnotations().get("api.service.kubernetes.io/scheme") : "http";
final String path = (service.getMetadata() != null && service.getMetadata().getAnnotations() != null) ?
final String path = (service.getMetadata() != null && useMetadataAnnotations) ?
service.getMetadata().getAnnotations().get("api.service.kubernetes.io/path") : "/";
final int port = resolvePort(service);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import io.fabric8.kubernetes.api.model.Service;
import io.fabric8.kubernetes.api.model.ServiceList;
import io.fabric8.kubernetes.api.model.ServicePort;
import io.fabric8.kubernetes.api.model.extensions.ReplicaSet;
import io.fabric8.kubernetes.api.model.extensions.ReplicaSetList;
import io.fabric8.kubernetes.api.model.apps.ReplicaSet;
import io.fabric8.kubernetes.api.model.apps.ReplicaSetList;
import io.fabric8.kubernetes.client.KubernetesClient;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -270,7 +270,7 @@ public void clean(String status) {

@Override
public void display() {
ReplicaSetList replicaSetList = client.extensions().replicaSets().inNamespace(session.getNamespace()).list();
ReplicaSetList replicaSetList = client.apps().replicaSets().inNamespace(session.getNamespace()).list();
if (replicaSetList.getItems() != null) {
for (ReplicaSet replicaSet : replicaSetList.getItems()) {
session.getLogger().info("ReplicaSet: [" + replicaSet.getMetadata().getName() + "]");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io.undertow.protocols.spdy.SpdyChannelWithoutFlowControl;
import io.undertow.server.XnioByteBufferPool;
import io.undertow.util.Headers;
import io.undertow.util.HttpString;
import io.undertow.util.Methods;
import io.undertow.util.StringReadChannelListener;
import java.io.Closeable;
Expand Down Expand Up @@ -105,7 +106,8 @@ public X509Certificate[] getAcceptedIssuers() {
request.getRequestHeaders()
.put(Headers.HOST, this.portForwardURI.getHost())
.put(Headers.CONNECTION, "Upgrade")
.put(Headers.UPGRADE, "SPDY/3.1");
.put(Headers.UPGRADE, "SPDY/3.1")
.put(new HttpString("X-Stream-Protocol-Version"), "portforward.k8s.io");
if (config.getOauthToken() != null) {
request.getRequestHeaders().put(Headers.AUTHORIZATION, "Bearer " + config.getOauthToken());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void check(RequiresKubernetes context) throws UnsatisfiedRequirementExcep
HttpClient httpClient = httpClientFactory.newBuilder(httpClientConfig).build();
HttpRequest versionRequest = new StandardHttpRequest.Builder()
.url(new URL(URLUtils.join(client.getMasterUrl().toString(), "version").toString()))
.method("GET", "*/*", null)
.method("GET", "application/json", null)
.build();

HttpResponse<String> response = httpClient.sendAsync(versionRequest, String.class).get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ public static void setUpClass() {

MOCK.expect()
.get()
.withPath("/apis/extensions/v1beta1/namespaces/arquillian/replicasets")
.withPath("/apis/apps/v1/namespaces/arquillian/replicasets")
.andReturn(200, new ReplicaSetBuilder().build())
.always();

Expand Down
2 changes: 1 addition & 1 deletion openshift/ftest-oc-proxy/src/test/resources/openshift.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}
}
}, {
"apiVersion" : "extensions/v1beta1",
"apiVersion" : "apps/v1",
"kind" : "Deployment",
"metadata" : {
"name" : "hello-world"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}
}
}, {
"apiVersion" : "extensions/v1beta1",
"apiVersion" : "apps/v1",
"kind" : "Deployment",
"metadata" : {
"name" : "hello-world"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}
}
}, {
"apiVersion" : "extensions/v1beta1",
"apiVersion" : "apps/v1",
"kind" : "Deployment",
"metadata" : {
"name" : "hello-world"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}
}
}, {
"apiVersion" : "extensions/v1beta1",
"apiVersion" : "apps/v1",
"kind" : "Deployment",
"metadata" : {
"name" : "hello-world"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}
}
}, {
"apiVersion" : "extensions/v1beta1",
"apiVersion" : "apps/v1",
"kind" : "Deployment",
"metadata" : {
"name" : "hello-openshift"
Expand Down
Loading