Skip to content

Commit

Permalink
[k8s-suppport] - Adding Kubernetes tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiobrz committed Jul 4, 2023
1 parent 37e82a8 commit 1e5f955
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .ci/openshift-ci/build-root/e2e-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,4 @@ cat test.properties

mkdir local-repo
mvn clean install -Dmaven.repo.local=./local-repo -DskipTests
mvn test -Dmaven.repo.local=./local-repo -pl testsuite/
mvn test -Dmaven.repo.local=./local-repo -pl testsuite/ -Pts.openshift
167 changes: 155 additions & 12 deletions .github/workflows/kubernetes-e2e.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,169 @@
name: Intersmash - Simple build workflow
name: Kubernetes E2E Tests

on:
workflow_dispatch:
push:
branches: [ "main" ]
branches:
- main
pull_request:
branches: [ "main" ]
paths-ignore:
- 'doc/**'
- 'ide-config/**'
- '**.md'

concurrency:
# Only run once for latest commit per ref and cancel other (previous) runs.
group: ci-e2e-intersmash-${{ github.ref }}
cancel-in-progress: true

jobs:
simple-build:
if: '! github.event.pull_request.draft'
minikube:
name: K8S
runs-on: ubuntu-latest

if: github.repository == 'Intersmash/intersmash'
strategy:
fail-fast: false
matrix:
kubernetes: [v1.25.0, v1.24.0]
#, v1.23.3, v1.22.6, v1.20.15, v1.19.16]
steps:
- name: Set up Maven
uses: stCarolas/[email protected]
- name: Checkout
uses: actions/checkout@v3
- name: Setup Minikube-Kubernetes
uses: manusa/[email protected]
with:
minikube version: v1.28.0
kubernetes version: ${{ matrix.kubernetes }}
github token: ${{ secrets.GITHUB_TOKEN }}
start args: '--force'
- name: Cache .m2 registry
uses: actions/cache@v3
with:
maven-version: 3.8.7
- uses: actions/checkout@v3
path: ~/.m2/repository
key: cache-e2e-${{ github.sha }}-${{ github.run_id }}
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Build with Maven
run: mvn -version ; mvn clean install -U -B -DskipTests
- name: Install and Run Integration Tests
run: |
set -x
# cat our ~/.kube/config contents
#
cat ~/.kube/config
#
# operator-sdk must be installed manually, see
#
export ARCH=$(case $(uname -m) in x86_64) echo -n amd64 ;; aarch64) echo -n arm64 ;; *) echo -n $(uname -m) ;; esac)
export OS=$(uname | awk '{print tolower($0)}')
export OPERATOR_SDK_DL_URL=https://github.com/operator-framework/operator-sdk/releases/download/v1.28.0
curl -LO ${OPERATOR_SDK_DL_URL}/operator-sdk_${OS}_${ARCH}
chmod +x operator-sdk_${OS}_${ARCH} && sudo mv operator-sdk_${OS}_${ARCH} /usr/local/bin/operator-sdk
operator-sdk olm install
#
# then we need an ingress controller
#
minikube addons enable ingress
minikube addons enable ingress-dns
export NET_MANAGER_CONF_DIR=/etc/NetworkManager
export NET_MANAGER_CONF_PATH=$NET_MANAGER_CONF_DIR/NetworkManager.conf
export DNS_MASQ_NET_MANAGER_CONF_DIR=$NET_MANAGER_CONF_DIR/dnsmasq.d
export DNS_MASQ_NET_MANAGER_CONF_PATH=$DNS_MASQ_NET_MANAGER_CONF_DIR/minikube.conf
echo $NET_MANAGER_CONF_PATH
sudo ls -la $NET_MANAGER_CONF_DIR
# if [[ -d "$NET_MANAGER_CONF_DIR" ]]
# then
# if [[ -f "$NET_MANAGER_CONF_PATH" ]]; then
# sudo cp $NET_MANAGER_CONF_PATH $NET_MANAGER_CONF_PATH.bak
# fi
#
# sudo cat >> NetworkManager.conf.tmp <<EOL
# [main]
# dns=dnsmasq
# [logging]
#
# EOL
# sudo cp NetworkManager.conf.tmp $NET_MANAGER_CONF_PATH
#
# if [[ ! -d "$DNS_MASQ_NET_MANAGER_CONF_DIR" ]]
# then
# sudo mkdir $DNS_MASQ_NET_MANAGER_CONF_DIR
# fi
#
# sudo ls -la $DNS_MASQ_NET_MANAGER_CONF_DIR
#
# if [[ -f "$DNS_MASQ_NET_MANAGER_CONF_PATH" ]]; then
# sudo cp $DNS_MASQ_NET_MANAGER_CONF_PATH $DNS_MASQ_NET_MANAGER_CONF_PATH.bak
# fi
#
# sudo echo "server=/hyperfoil/$(minikube ip)" >minikube.conf.tmp
# sudo cp minikube.conf.tmp $DNS_MASQ_NET_MANAGER_CONF_PATH
#
# sudo systemctl restart NetworkManager
# else
#
# echo "No $NET_MANAGER_CONF_DIR"
#
# export RESOLVE_CONF_DIR=/etc/resolvconf/resolv.conf.d
# export RESOLVE_CONF_PATH=$RESOLVE_CONF_DIR/base
#
# sudo ls -la $RESOLVE_CONF_DIR
#
# if [[ -d "$RESOLVE_CONF_DIR" ]]
# then
#
# if [ -f "$RESOLVE_CONF_PATH" ]; then
# sudo cp $RESOLVE_CONF_PATH $RESOLVE_CONF_PATH.bak
# fi
#
# sudo cat >> $RESOLVE_CONF_PATH <<EOL
# search test
# nameserver $( minikube ip )
# timeout 5
#
# EOL
#
# sudo resolvconf -u
# sudo systemctl disable --now resolvconf.service
#
# else
# echo "No $RESOLVE_CONF_DIR"
# exit 1
# fi
# fi
#
# export HOSTS_DIR=/etc
# export HOSTS_PATH=$HOSTS_DIR/hosts
#
# sudo ls -la $HOSTS_DIR
#
# if [ -f "$HOSTS_PATH" ]; then
# sudo cat $HOSTS_PATH
# sudo cp $HOSTS_PATH $HOSTS_PATH.bak
# fi
#
# sudo cat $HOSTS_PATH >> hosts.tmp
# cat >> hosts.tmp <<EOL
# hyperfoil $( minikube ip )
#
# EOL
#
# sudo cp hosts.tmp $HOSTS_PATH
curl http://host.minikube.internal -v
curl http://control-plane.minikube.internal -v
mkdir local-repo
mvn clean install -Dmaven.repo.local=./local-repo -DskipTests
mvn test -Dmaven.repo.local=./local-repo -pl testsuite/ -Pts.k8s \
-Dintersmash.kubernetes.url=https://$( minikube ip):8443 \
-Dintersmash.kubernetes.namespace=test-k8s-1 \
-Dintersmash.olm.operators.catalog_source=community-operators \
-Dintersmash.olm.operators.namespace=olm \
-Dintersmash.hyperfoil.operators.catalog_source=operatorhubio-catalog
29 changes: 29 additions & 0 deletions testsuite/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,33 @@
</dependency>
</dependencies>

<profiles>
<profile>
<id>ts.k8s</id>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<groups>ts.k8s</groups>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>ts.openshift</id>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<groups>ts.k8s</groups>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.jboss.intersmash.testsuite.k8s;

import org.junit.jupiter.api.Tag;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.junit.jupiter.api.Tag;

/**
* Mark test that runs against Kubernetes.
* Used per class.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.jboss.intersmash.testsuite.openshift;

import org.junit.jupiter.api.Tag;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.junit.jupiter.api.Tag;

/**
* Mark test that runs against OpenShift.
* Used per class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

import org.jboss.intersmash.testsuite.openshift.OpenShiftTest;
import org.jboss.intersmash.testsuite.openshift.ProjectCreationCapable;
import org.jboss.intersmash.tools.application.operator.KeycloakRealmImportOperatorApplication;
import org.jboss.intersmash.tools.application.openshift.PostgreSQLImageOpenShiftApplication;
import org.jboss.intersmash.tools.application.operator.KeycloakRealmImportOperatorApplication;
import org.jboss.intersmash.tools.junit5.IntersmashExtension;
import org.jboss.intersmash.tools.provision.openshift.KeycloakRealmImportOpenShiftOperatorProvisioner;
import org.jboss.intersmash.tools.provision.openshift.PostgreSQLImageOpenShiftProvisioner;
Expand All @@ -51,6 +51,7 @@
import org.keycloak.k8s.v2alpha1.keycloakspec.db.UsernameSecret;
import org.slf4j.event.Level;

import cz.xtf.core.config.OpenShiftConfig;
import cz.xtf.core.openshift.OpenShiftWaiters;
import cz.xtf.core.openshift.OpenShifts;
import cz.xtf.core.waiting.SimpleWaiter;
Expand Down Expand Up @@ -105,7 +106,8 @@ public String getDbName() {
private static final PostgreSQLImageOpenShiftProvisioner POSTGRESQL_IMAGE_PROVISIONER = new PostgreSQLImageOpenShiftProvisioner(
pgSQLApplication);

private static KeycloakRealmImportOpenShiftOperatorProvisioner initializeOperatorProvisioner(final Keycloak keycloak, final String appName) {
private static KeycloakRealmImportOpenShiftOperatorProvisioner initializeOperatorProvisioner(final Keycloak keycloak,
final String appName) {
KeycloakRealmImportOpenShiftOperatorProvisioner operatorProvisioner = new KeycloakRealmImportOpenShiftOperatorProvisioner(
new KeycloakRealmImportOperatorApplication() {

Expand All @@ -130,9 +132,10 @@ public String getName() {
@BeforeAll
public static void createOperatorGroup() throws IOException {
matchLabels.put("app", "sso");
IntersmashExtension.operatorCleanup();
IntersmashExtension.operatorCleanup(false, true);
// create operator group - this should be done by InteropExtension
OpenShifts.adminBinary().execute("apply", "-f", OperatorGroup.SINGLE_NAMESPACE.save().getAbsolutePath());
OpenShifts.adminBinary().execute("apply", "-f",
new OperatorGroup(OpenShiftConfig.namespace()).save().getAbsolutePath());
}

@AfterAll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
import org.jboss.intersmash.deployments.IntersmashSharedDeployments;
import org.jboss.intersmash.testsuite.openshift.OpenShiftTest;
import org.jboss.intersmash.tools.IntersmashConfig;
import org.jboss.intersmash.tools.application.input.BinarySource;
import org.jboss.intersmash.tools.application.input.BuildInput;
import org.jboss.intersmash.tools.application.input.BuildInputBuilder;
import org.jboss.intersmash.tools.application.openshift.BootableJarOpenShiftApplication;
import org.jboss.intersmash.tools.application.operator.KafkaOperatorApplication;
import org.jboss.intersmash.tools.application.openshift.MysqlImageOpenShiftApplication;
import org.jboss.intersmash.tools.application.openshift.PostgreSQLImageOpenShiftApplication;
import org.jboss.intersmash.tools.application.openshift.WildflyImageOpenShiftApplication;
import org.jboss.intersmash.tools.application.input.BinarySource;
import org.jboss.intersmash.tools.application.input.BuildInput;
import org.jboss.intersmash.tools.application.input.BuildInputBuilder;
import org.jboss.intersmash.tools.application.operator.KafkaOperatorApplication;
import org.jboss.intersmash.tools.util.IntersmashToolsProvisionersProperties;

import cz.xtf.builder.builders.SecretBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public void apply(String namespace, List<String> sourcePaths) {
}

public void namespace(String projectName) {
// see https://kubernetes.io/docs/reference/kubectl/cheatsheet/#kubectl-context-and-configuration
this.execute("config", "set-context", "--current", String.format("--namespace=%s", projectName));
}

Expand Down

0 comments on commit 1e5f955

Please sign in to comment.