Skip to content
This repository was archived by the owner on Jan 4, 2022. It is now read-only.

Feature/switch to skip i ts #12

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
302b789
update maven cache step
adam-sandor Aug 12, 2021
e4fee9f
try to remove unnecessary-looking steps
adam-sandor Aug 12, 2021
fc9ec88
small improvements
adam-sandor Aug 12, 2021
b0025fc
add documentation and move into right package
adam-sandor Aug 12, 2021
192757f
remove unused imports
adam-sandor Aug 12, 2021
304ac2a
improving the code (untilAsserted)
adam-sandor Aug 12, 2021
4c203c9
small code improvements
adam-sandor Aug 18, 2021
bd4622b
testing KIND_REGISTRY on github action
Aug 20, 2021
9868d4b
correct cluster name
Aug 20, 2021
7917f89
correct cluster name
Aug 20, 2021
f0a7036
set
Aug 20, 2021
e0a71ea
set $KIND_REGISTRY
kanedafromparis Aug 20, 2021
886096d
set -Djib.allowInsecureRegistries=true
kanedafromparis Aug 20, 2021
cc4042b
renamed and clean actions
kanedafromparis Aug 20, 2021
7c39b22
add test for webapp deployment
adam-sandor Aug 20, 2021
706b60a
improve logging configuration for tests
adam-sandor Aug 20, 2021
c38821f
WebappController now waits until Tomcat is fully up and running befor…
adam-sandor Aug 21, 2021
b5ca270
IntegrationTest uses a curl Pod to verify if Webapp is correctly depl…
adam-sandor Aug 21, 2021
7793ee9
logging configuration
adam-sandor Aug 21, 2021
f671d7f
add documentation
adam-sandor Aug 21, 2021
a860b2c
upgrade to jdk v 1.9.2
adam-sandor Aug 21, 2021
6315926
put a cleanner break
kanedafromparis Aug 23, 2021
6f2e0fa
merge
kanedafromparis Aug 23, 2021
06a873a
clean ressource after test
kanedafromparis Aug 23, 2021
cceb2fa
increase time out
kanedafromparis Aug 23, 2021
c164a91
change webapps path
kanedafromparis Aug 24, 2021
5ee5527
reverte to default image (deploy change in the github action)
kanedafromparis Aug 24, 2021
716b962
improve feedback on webapps download
kanedafromparis Aug 24, 2021
d5b9048
add Waiting 5 seconds for Tomcat to unpack the downloaded war
kanedafromparis Aug 24, 2021
efedf39
testing full
kanedafromparis Aug 24, 2021
a020001
correct callimg the wrong namespace
kanedafromparis Aug 24, 2021
d49b13e
improving sleeping time for webapp deployment
kanedafromparis Aug 24, 2021
f3c8e77
set use of jib+kind for local run
kanedafromparis Aug 30, 2021
11d7e0e
put test that need a kubernetes cluster (kind) into failsafe:integrat…
kanedafromparis Aug 31, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
165 changes: 152 additions & 13 deletions .github/workflows/TomcatIntegrationTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,174 @@ on:
jobs:
tomcat_integration_test:
runs-on: ubuntu-latest
env:
KIND_CL_NAME: tomcat-integration
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Helm
uses: azure/setup-helm@v1
with:
version: v3.4.0

- uses: actions/setup-python@v2
with:
python-version: 3.7

- name: clean resident local docker
if: ${{ env.ACT }}
continue-on-error: true
run: |
for DIMG in "$KIND_CL_NAME-control-plane "; do
docker stop $DIMG ; docker rm $DIMG ;
done ;
sleep 1

- name: Create kind cluster
uses: helm/[email protected]
with:
cluster_name: ${{ env.KIND_CL_NAME }}

- name: Apply CRDs
run: kubectl apply -f tomcat/k8s/crd.yaml

- name: Set up Java and Maven
uses: actions/setup-java@v1
uses: actions/setup-java@v2
with:
java-version: 15
distribution: adopt-hotspot

- name: cache
uses: actions/cache@v2
if: ${{ !env.ACT }}
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-m2

- name: Set up Maven
uses: stCarolas/setup-maven@v4
if: ${{ env.ACT }}
with:
maven-version: 3.8.1

- name: Run unit tests
if: ${{ env.ACT }}
run: mvn --version

- name: Run unit tests
run: mvn -B failsafe:integration-test --file tomcat/pom.xml

tomcat_local_apply_setup_test:
runs-on: ubuntu-latest
env:
KIND_CL_NAME: tomcat-local-apply
steps:
- name: Checkout
uses: actions/checkout@v2

- name: clean resident local docker
if: ${{ env.ACT }}
continue-on-error: true
run: |
for DIMG in "$KIND_CL_NAME-control-plane "; do
docker stop $DIMG ; docker rm $DIMG ;
done ;
sleep 1

- name: Create Kubernetes KinD Cluster
uses: container-tools/[email protected]
with:
cluster_name: ${{ env.KIND_CL_NAME }}
registry: false

# for DIMG in "tomcat-local-apply-control-plane kind-registry tomcat_local_apply_setup_test "; do docker stop $DIMG ; docker rm $DIMG ; done ; sleep 1

- name: Set up Java and Maven
uses: actions/setup-java@v2
with:
# java-version: ${{ matrix.java }}
java-version: 15
- uses: actions/cache@v2
distribution: adopt-hotspot

- name: cache
uses: actions/cache@v2
if: ${{ !env.ACT }}
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Run unit tests
run: mvn -B test --file tomcat/pom.xml

- name: Set up Maven for local ACT
uses: stCarolas/setup-maven@v4
if: ${{ env.ACT }}
with:
maven-version: 3.8.1

- name: build jib
run: |
mvn -B package jib:dockerBuild jib:buildTar -Djib-maven-image=tomcat-operator --file tomcat/pom.xml -DskipTests
kind load image-archive tomcat/target/jib-image.tar --name=${{ env.KIND_CL_NAME }}

- name: Apply CRDs
run: kubectl apply -f tomcat/k8s/crd.yaml

- name: install tomcat operator
run: |
kubectl apply -f tomcat/k8s/operator.yaml

- name: create ns tomcatoperator-sample
run: kubectl create ns tomcatoperator-sample

- name: debug local kind
if: ${{ env.ACT }}
run: |
kubectl get pods -n tomcat-operator -l app=tomcat-operator -o yaml | tee -a debug.log

- name: wait for operators ready
run: |
LOOP=0 &&\
while [[ $(kubectl get pods -n tomcat-operator -l app=tomcat-operator -o 'jsonpath={..status.conditions[?(@.type=="Ready")].status}') != "True" ]]; do \
echo "waiting for pod" &&\
kubectl logs -n tomcat-operator -l app=tomcat-operator &&\
(( LOOP++ )) &&\
if [[ $LOOP -gt 10 ]]; then exit 1; fi &&\
echo "loop number $LOOP" &&\
sleep 5; \
done

- name: install sample operators
run: |
for sample in $(ls tomcat/k8s/*sample*); do
kubectl -n tomcatoperator-sample apply -f $sample;
done

- name: check pod correctly started
run: |
LOOP=0 &&\
while [[ $(kubectl get pods -n tomcatoperator-sample -o 'jsonpath={..status.conditions[?(@.type=="Ready")].status}') != "True True True True True True" ]]; do \
echo "waiting for pod" &&\
kubectl logs -n tomcat-operator -l app=tomcat-operator &&\
kubectl get pods -n tomcatoperator-sample &&\
(( LOOP++ )) &&\
if [[ $LOOP -gt 10 ]]; then exit 1; fi &&\
echo "loop number $LOOP" &&\
sleep 10; \
done
#Waiting 5 seconds for Tomcat to unpack the downloaded war
sleep 5;

- name: Get webapps
run: |
kubectl get tomcats,webapps -A -o yaml | tee -a debug
kubectl -n tomcatoperator-sample -c tomcat logs -l app=test-tomcat1 | grep startup

- name: check code
run: |
kubectl -n tomcatoperator-sample run sample1 --labels=app=curl --image=curlimages/curl:7.78.0 --restart=Never --timeout=30s --command -- curl -s -v http://test-tomcat1/mysample/;
kubectl -n tomcatoperator-sample run sample2 --labels=app=curl --image=curlimages/curl:7.78.0 --restart=Never --timeout=30s --command -- curl -s -v http://test-tomcat2/othercontext/;
LOOP=0 &&\
while [[ $(kubectl get pods -n tomcatoperator-sample -l app=curl -o 'jsonpath={..status.phase}') != "Succeeded Succeeded" ]]; do \
echo "waiting for pod" &&\
kubectl logs -n tomcatoperator-sample -l app=curl &&\
(( LOOP++ )) &&\
if [[ $LOOP -gt 5 ]]; then exit 1; fi &&\
echo "loop number $LOOP" &&\
sleep 5; \
done
if [[ $(kubectl logs -n tomcatoperator-sample sample1 --tail=500 | grep tomcat.gif | wc -l) -ne 1 ]]; then exit 1; fi
if [[ $(kubectl logs -n tomcatoperator-sample sample2 --tail=500 | grep dog.jpeg | wc -l) -ne 1 ]]; then exit 1; fi
4 changes: 4 additions & 0 deletions tomcat/k8s/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ spec:
properties:
deployedArtifact:
type: string
deploymentStatus:
type: array
items:
type: string
required: [spec]
# either Namespaced or Cluster
scope: Namespaced
Expand Down
19 changes: 19 additions & 0 deletions tomcat/k8s/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,27 @@ metadata:
rules:
- apiGroups:
- ""
- "extensions"
- "apps"
resources:
- deployments
- services
- pods
- pods/exec
verbs:
- '*'
- apiGroups:
- "apiextensions.k8s.io"
resources:
- customresourcedefinitions
verbs:
- '*'
- apiGroups:
- "tomcatoperator.io"
resources:
- tomcats
- tomcats/status
- webapps
- webapps/status
verbs:
- '*'
2 changes: 1 addition & 1 deletion tomcat/k8s/webapp-sample2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ metadata:
spec:
tomcat: test-tomcat2
url: charlottemach.com/assets/jax.war
contextPath: mysample
contextPath: othercontext
15 changes: 13 additions & 2 deletions tomcat/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<jib-maven-plugin.version>2.7.1</jib-maven-plugin.version>
<jib-maven-plugin.version>3.1.4</jib-maven-plugin.version>

</properties>

<dependencies>
<dependency>
<groupId>io.javaoperatorsdk</groupId>
<artifactId>operator-framework</artifactId>
<version>1.8.4</version>
<version>1.9.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
Expand Down Expand Up @@ -72,6 +73,16 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M5</version>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import io.fabric8.kubernetes.api.model.apps.Deployment;
import io.fabric8.kubernetes.client.Watcher;
import io.javaoperatorsdk.operator.processing.event.AbstractEvent;
import io.javaoperatorsdk.operator.processing.event.DefaultEvent;

public class DeploymentEvent extends AbstractEvent {
public class DeploymentEvent extends DefaultEvent {

private final Watcher.Action action;
private final Deployment deployment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Used by the TomcatController to watch changes on Deployment objects. As the Pods of the Deployment start up
* the TomcatController updates the status.readyReplicas field.
*/
public class DeploymentEventSource extends AbstractEventSource implements Watcher<Deployment> {
private static final Logger log = LoggerFactory.getLogger(DeploymentEventSource.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
import java.util.Objects;
import java.util.Optional;

/**
* Runs a specified number of Tomcat app server Pods. It uses a Deployment to create the Pods. Also creates a
* Service over which the Pods can be accessed.
*/
@Controller
public class TomcatController implements ResourceController<Tomcat> {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package io.javaoperatorsdk.operator.sample;

import io.fabric8.kubernetes.client.Watcher;
import io.javaoperatorsdk.operator.processing.event.DefaultEvent;

public class TomcatEvent extends DefaultEvent {

private final Watcher.Action action;
private final Tomcat tomcat;

public TomcatEvent(
Watcher.Action action, Tomcat resource, TomcatEventSource tomcatEventSource, String webappUid) {
super(webappUid, tomcatEventSource);
this.action = action;
this.tomcat = resource;
}

public Watcher.Action getAction() {
return action;
}

public String resourceUid() {
return getTomcat().getMetadata().getUid();
}

@Override
public String toString() {
return "CustomResourceEvent{"
+ "action="
+ action
+ ", resource=[ name="
+ getTomcat().getMetadata().getName()
+ ", kind="
+ getTomcat().getKind()
+ ", apiVersion="
+ getTomcat().getApiVersion()
+ " ,resourceVersion="
+ getTomcat().getMetadata().getResourceVersion()
+ ", markedForDeletion: "
+ (getTomcat().getMetadata().getDeletionTimestamp() != null
&& !getTomcat().getMetadata().getDeletionTimestamp().isEmpty())
+ " ]"
+ '}';
}

public Tomcat getTomcat() {
return tomcat;
}
}
Loading