Skip to content

Commit

Permalink
Initial Chaos Test integration for SharedInformers
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaTP committed Aug 30, 2023
1 parent 9a72eb2 commit d4edad5
Show file tree
Hide file tree
Showing 16 changed files with 1,015 additions and 5 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/e2e-httpclient-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,49 @@ jobs:
- name: Run Integration Tests
run: |
./mvnw ${MAVEN_ARGS} -P"httpclient-${{ matrix.httpclient }}" -Pitests -pl $IT_MODULE verify
chaos-tests:
name: K8S Chaos Test
runs-on: ubuntu-latest
if: github.repository == 'fabric8io/kubernetes-client'
strategy:
fail-fast: false
matrix:
kubernetes: [v1.25.0]
java-version: [11,17]
http-client: [okhttp,jdk,jetty,vertx]
chaos-test: ["network-delay.yaml", "network-loss.yaml", "network-duplicate.yaml"]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Minikube-Kubernetes
uses: manusa/actions-setup-minikube@v2.7.2
with:
minikube version: v1.28.0
kubernetes version: ${{ matrix.kubernetes }}
github token: ${{ secrets.GITHUB_TOKEN }}
start args: '--force'
- name: Setup Kubectl
uses: azure/setup-kubectl@v3
with:
version: ${{ matrix.kubernetes }}
- name: Setup Java ${{ matrix.java-version }}
uses: actions/setup-java@v3
with:
java-version: "${{ matrix.java-version }}"
distribution: "temurin"
cache: maven
- name: Install Chaos Mesh
run: |
curl -sSL https://mirrors.chaos-mesh.org/v2.6.0/install.sh | bash
kubectl wait --for=condition=Ready pods --all-namespaces --all --timeout=600s
- name: Build the Support apps containers
run: |
# eval $(minikube -p minikube docker-env) -> check if needed in CI
./mvnw ${MAVEN_ARGS} -U -Pitests -P"httpclient-${{ matrix.http-client }}" -Pchecker clean package k8s:build -pl chaos-tests -DskipTests
./mvnw ${MAVEN_ARGS} -U -Pitests -P"httpclient-${{ matrix.http-client }}" -Pcontrol clean package k8s:build -pl chaos-tests -DskipTests
- name: Run Chaos Tests
env:
CHAOS_TEST: ${{ matrix.chaos-test }}
run: |
./mvnw ${MAVEN_ARGS} -Pitests verify -pl chaos-tests
58 changes: 58 additions & 0 deletions chaos-tests/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Chaos Mesh tests for Kubernetes Client SharedInformer

This module will run automated Chaos Tests for the SharedInformers

### Setup

Start minikube, e.g.:

```bash
minikube start --driver=docker --memory 8192 --cpus 3
```

Install ChaosMesh on minikube:

```bash
curl -sSL https://mirrors.chaos-mesh.org/v2.6.0/install.sh | bash
```

Wait for the pods to be all ready:

```bash
kubectl wait --for=condition=Ready pods -n chaos-mesh --all --timeout=600s
```

Build the control and checker Docker images in the minikube docker-env:

```bash
eval $(minikube -p minikube docker-env)
mvn -Pitests -Phttpclient-jdk -Pchecker clean package k8s:build -pl chaos-tests -DskipTests
mvn -Pitests -Phttpclient-jdk -Pcontrol clean package k8s:build -pl chaos-tests -DskipTests
```

and finally run the test:

```bash
mvn -Pitests verify -pl chaos-tests
```

### Glossary

- checker: run the SharedInformer to get notifications over the shared resource
- control: apply timely changes to the shared resource

## What's going on?

As of today this is the main flow of the tests(please double-check the implementation if this documentation is not accurate anymore):

- Starts a "Checker" application(as a Pod in a cluster) which starts a SharedInformer on a ConfigMap
- Starts a "Control" application(as a Pod in the cluster) which keeps incrementing a counter stored in the previously mentioned ConfigMap
- The "Checker" is waiting for the number to reach a specific value N
- The "Control" keeps incrementing the counter up to the same number N
- We start a Chaos Experiment targeting the "Checker" app, in this setup, we are using 3 different Network disruption scenarios
- The Chaos Experiment lasts for 12 minutes
- After the Experiment is finished we do expect that the "Checker" app SharedInformer recovers and eventually reaches the target N
- Eventually, both the 2 Control and Checker Pods should be in a Successful state

We are testing the resiliency of the WebSocket communication used under the cover by the SharedInformers and we guarantee that they do recover appropriately when something happens.
We guarantee that we don't have regressions and this tests can be used as a gate for other HTTP client implementations.
225 changes: 225 additions & 0 deletions chaos-tests/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2015 Red Hat, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>kubernetes-client-project</artifactId>
<groupId>io.fabric8</groupId>
<version>6.8-SNAPSHOT</version>
</parent>

<artifactId>chaos-tests</artifactId>
<packaging>jar</packaging>
<name>Fabric8 :: Chaos Tests</name>

<properties>
<jkube.version>1.13.1</jkube.version>
<picocli.version>4.7.4</picocli.version>
</properties>

<repositories>
<repository>
<id>sonatype-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>

<dependencies>
<!-- Support applications -->
<dependency>
<groupId>info.picocli</groupId>
<artifactId>picocli</artifactId>
<version>${picocli.version}</version>
</dependency>

<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-client</artifactId>
<exclusions>
<exclusion>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-httpclient-okhttp</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-httpclient-okhttp</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- We cleanup system properties an env vars, so that we can test in a predictable env -->
<environmentVariables>
<KUBERNETES_MASTER />
<KUBERNETES_API_VERSION />
<KUBERNETES_TRUST_CERTIFICATES />
<KUBERNETES_CERTS_CA_FILE />
<KUBERNETES_CERTS_CA_DATA />
<KUBERNETES_CERTS_CLIENT_FILE />
<KUBERNETES_CERTS_CLIENT_DATA />
<KUBERNETES_CERTS_CLIENT_KEY_FILE />
<KUBERNETES_CERTS_CLIENT_KEY_DATA />
<KUBERNETES_CERTS_CLIENT_KEY_ALGO />
<KUBERNETES_CERTS_CLIENT_KEY_PASSPHRASE />
<KUBERNETES_AUTH_BASIC_USERNAME />
<KUBERNETES_AUTH_BASIC_PASSWORD />
<KUBERNETES_AUTH_TRYKUBECONFIG />
<KUBERNETES_AUTH_TRYSERVICEACCOUNT />
<KUBERNETES_AUTH_TOKEN />
<KUBERNETES_WATCH_RECONNECTINTERVAL />
<KUBERNETES_WATCH_RECONNECTLIMIT />
<KUBERNETES_REQUEST_TIMEOUT />
<KUBERNETES_NAMESPACE />
<KUBERNETES_TLS_VERSIONS>TLSv1.2,TLSv1.1,TLSv1</KUBERNETES_TLS_VERSIONS>
</environmentVariables>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eclipse.jkube</groupId>
<artifactId>kubernetes-maven-plugin</artifactId>
<version>${jkube.version}</version>
<configuration>
<images>
<image>
<name>chaos-test-${app-name}:latest</name>
<build>
<from>openjdk:latest</from>
<cmd>java -jar /maven/${project.artifactId}-${project.version}.jar</cmd>
</build>
</image>
</images>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>${main-class}</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<!-- HTTP client injection -->
<profile>
<id>httpclient-okhttp</id>
<dependencies>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-httpclient-okhttp</artifactId>
</dependency>
</dependencies>
</profile>
<profile>
<id>httpclient-jdk</id>
<dependencies>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-httpclient-jdk</artifactId>
</dependency>
</dependencies>
</profile>
<profile>
<id>httpclient-vertx</id>
<dependencies>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-httpclient-vertx</artifactId>
</dependency>
</dependencies>
</profile>
<profile>
<id>httpclient-jetty</id>
<dependencies>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-httpclient-jetty</artifactId>
</dependency>
</dependencies>
</profile>

<!-- Support Apps container configuration -->
<profile>
<id>checker</id>
<properties>
<app-name>checker</app-name>
<main-class>io.fabric8.it.CheckerCommand</main-class>
</properties>
</profile>
<profile>
<id>control</id>
<properties>
<app-name>control</app-name>
<main-class>io.fabric8.it.ControlCommand</main-class>
</properties>
</profile>
</profiles>

</project>
Loading

0 comments on commit d4edad5

Please sign in to comment.