-
Notifications
You must be signed in to change notification settings - Fork 220
Add tomcat operator sample #659
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
Merged
Merged
Changes from all commits
Commits
Show all changes
55 commits
Select commit
Hold shift + click to select a range
231608d
initial commit for moving tomcat sample back to main repo
adam-sandor 7b5616f
improve build pipeline based on PR feedback
adam-sandor b64ea77
fix bug in pipeline
adam-sandor ab3d818
fix bug in pipeline
adam-sandor 5be04f9
add groupid
adam-sandor a5e569c
set sdk version to 1.9.8
adam-sandor d98be67
remove unnecessary namespace creation, list namespaces during the dump
adam-sandor 3ae2de6
more diagnostic dumping
adam-sandor cce5e49
reorganize dump and prevent stop on error
adam-sandor 6f3ecb2
fix bug in printing tomcat-operator output
adam-sandor 6b78630
use framework version 1.9.2
adam-sandor 7fdfefa
Reformat TomcatOperator & add to pom structure
adam-sandor 6d21f6a
Build SDK before running Tomcat JIB build
adam-sandor 0c2613e
Rename E2E test
adam-sandor 83e61ce
Rename E2E test
adam-sandor cfbb66c
Rename E2E test
adam-sandor 4e7ade8
also print status of tomcat and webapp objects
adam-sandor 3c96fb7
add start method
adam-sandor c8316d2
chore(deps): bump spring-boot.version from 2.5.5 to 2.5.6 (#617)
dependabot[bot] db4b4d6
chore(deps): bump awaitility from 4.1.0 to 4.1.1
dependabot[bot] dbc83c8
fix: prevent double registration of same CR with different controllers
metacosm 1be67dd
Set new SNAPSHOT version into pom files.
actions-user 101db14
fix: restart event handler (#632)
metacosm 0bb296e
Set new SNAPSHOT version into pom files.
actions-user 9a5aa5b
update to framework version 1.9.11-SNAPSHOT
adam-sandor 464f892
add start call to operator
adam-sandor 2e5e60e
fix dependency version of operator-framework
adam-sandor d118ab6
removing ready check from namespce as it's causing problems
adam-sandor 579a65e
enable maven cache
adam-sandor ff98e0c
improve logging
adam-sandor f2e481e
add nicers tostring methods
adam-sandor e3bbc75
rename integration test to e2e test
adam-sandor 8202787
better handling of curl pod at the end of the test
adam-sandor 6585101
remove integration test references
adam-sandor c0004c5
docs: webpage docs skeleton (#631)
csviri 13e1f91
fix: replace jandex plugin by Quarkus detection of beans.xml files
metacosm 53a6178
fix: improve duplicated controller detection, add tests
metacosm 6ed14d5
Set new SNAPSHOT version into pom files.
actions-user 944e08a
chore(deps): bump formatter-maven-plugin from 2.16.0 to 2.17.0 (#644)
dependabot[bot] 28e40b0
docs: link for basic operato articles (#643)
csviri c34aa65
fix: use `close` as destroyMethod of Bean (#645)
KimDoubleB a97c3dd
docs: finalizers and best braticies page (#647)
csviri 9097659
fix: typo in docs (#649)
csviri dc2a543
fix: jekyll build warning with highliting (#650)
csviri 7af9900
chore(deps): bump auto-service from 1.0 to 1.0.1 (#652)
dependabot[bot] 7f97b44
remove integration test references
adam-sandor 95b4985
Merge branch 'master' into add_tomcat_operator_sample
csviri 715126b
fix: parent version update from master
csviri 2115de4
fix: migrated tomcat operator to informers, some minor changes to mak…
csviri 9e13536
refactor: rename samples to smoke test samples
csviri 7eb3aa7
feature: log warning when passing a running event source
csviri 289841f
docs: tomcat sample DeploymentEventSource to InformerEventSource in docs
csviri f23a78d
docs: explanation for cache usage
csviri 116134f
chore(docs): update to point to `sample-operators` director
metacosm 114062f
refactor: generate CRDs automatically and use them
metacosm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# End to end integration test which deploys the Tomcat operator to a Kubernetes | ||
# (Kind) cluster and creates custom resources to verify the operator's functionality | ||
name: TomcatOperator End to End test | ||
on: | ||
push: | ||
branches: | ||
- "*" | ||
jobs: | ||
tomcat_e2e_test: | ||
runs-on: ubuntu-latest | ||
env: | ||
KIND_CL_NAME: e2e-test | ||
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: e2e-test | ||
registry: false | ||
|
||
- name: Set up Java and Maven | ||
uses: actions/setup-java@v2 | ||
with: | ||
java-version: 11 | ||
distribution: adopt-hotspot | ||
cache: 'maven' | ||
|
||
- name: Build SDK | ||
run: mvn install -DskipTests | ||
|
||
- name: build jib | ||
working-directory: sample-operators/tomcat-operator | ||
run: | | ||
mvn --version | ||
mvn -B package jib:dockerBuild jib:buildTar -Djib-maven-image=tomcat-operator -DskipTests | ||
kind load image-archive target/jib-image.tar --name=${{ env.KIND_CL_NAME }} | ||
|
||
- name: Apply CRDs | ||
working-directory: sample-operators/tomcat-operator | ||
run: | | ||
kubectl apply -f target/classes/META-INF/fabric8/tomcats.tomcatoperator.io-v1.yml | ||
kubectl apply -f target/classes/META-INF/fabric8/webapps.tomcatoperator.io-v1.yml | ||
|
||
- name: Deploy Tomcat Operator | ||
working-directory: sample-operators/tomcat-operator | ||
run: | | ||
kubectl apply -f k8s/operator.yaml | ||
|
||
- name: Run E2E Tests | ||
working-directory: sample-operators/tomcat-operator | ||
run: mvn -B test -P end-to-end-tests | ||
|
||
- name: Dump state | ||
if: ${{ failure() }} | ||
run: | | ||
set +e | ||
echo "All namespaces" | ||
kubectl get ns | ||
echo "All objects in tomcat-operator" | ||
kubectl get all -n tomcat-operator -o yaml | ||
echo "Output of tomcat-operator pod" | ||
kubectl logs -l app=tomcat-operator -n tomcat-operator | ||
echo "All objects in tomcat-test" | ||
kubectl get deployment,pod,tomcat,webapp -n tomcat-test -o yaml | ||
echo "Output of curl command" | ||
kubectl logs curl -n tomcat-test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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> | ||
<groupId>io.javaoperatorsdk</groupId> | ||
<artifactId>java-operator-sdk</artifactId> | ||
<version>1.9.12-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>sample-operators</artifactId> | ||
<name>Operator SDK - Samples</name> | ||
<packaging>pom</packaging> | ||
|
||
<properties> | ||
<jib-maven-plugin.version>3.1.4</jib-maven-plugin.version> | ||
</properties> | ||
|
||
<modules> | ||
<module>tomcat-operator</module> | ||
</modules> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.javaoperatorsdk</groupId> | ||
<artifactId>operator-framework</artifactId> | ||
<version>1.9.2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.logging.log4j</groupId> | ||
<artifactId>log4j-slf4j-impl</artifactId> | ||
<version>2.13.3</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.takes</groupId> | ||
<artifactId>takes</artifactId> | ||
<version>1.19</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.13.1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.awaitility</groupId> | ||
<artifactId>awaitility</artifactId> | ||
<version>4.1.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>com.google.cloud.tools</groupId> | ||
<artifactId>jib-maven-plugin</artifactId> | ||
<version>${jib-maven-plugin.version}</version> | ||
<configuration> | ||
<from> | ||
<image>gcr.io/distroless/java:11</image> | ||
</from> | ||
<to> | ||
<image>tomcat-operator</image> | ||
</to> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.1</version> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# Tomcat Operator | ||
|
||
Creates a Tomcat deployment from a Custom Resource, while keeping the WAR separated with another Custom Resource. | ||
|
||
This sample demonstrates the following capabilities of the Java Operator SDK: | ||
* Multiple Controllers in a single Operator. The Tomcat resource is managed by the TomcatController while the Webapp | ||
resource is managed by the WebappController. | ||
* Reacting to events about resources created by the controller. The TomcatController will receive events about the | ||
Deployment resources it created. See EventSource section below for more detail. | ||
|
||
## Example input for creating a Tomcat instance | ||
``` | ||
apiVersion: "tomcatoperator.io/v1" | ||
kind: Tomcat | ||
metadata: | ||
name: test-tomcat1 | ||
spec: | ||
version: 9.0 | ||
replicas: 2 | ||
``` | ||
|
||
## Example input for the Webapp | ||
``` | ||
apiVersion: "tomcatoperator.io/v1" | ||
kind: Webapp | ||
metadata: | ||
name: sample-webapp1 | ||
spec: | ||
tomcat: test-tomcat1 | ||
url: http://tomcat.apache.org/tomcat-7.0-doc/appdev/sample/sample.war | ||
contextPath: mysample | ||
``` | ||
|
||
## Getting started / Testing | ||
|
||
The quickest way to try the operator is to run it on your local machine, while it connects to a | ||
local or remote Kubernetes cluster. When you start it, it will use the current kubectl context on | ||
your machine to connect to the cluster. | ||
|
||
Before you run it you have to install the CRDs on your cluster by running: | ||
- `kubectl apply -f target/classes/META-INF/fabric8/tomcats.tomcatoperator.io-v1.yml` | ||
- `kubectl apply -f target/classes/META-INF/fabric8/webapps.tomcatoperator.io-v1.yml` | ||
|
||
The CRDs are generated automatically from your code by simply adding the `crd-generator-apt` | ||
dependency to your `pom.xml` file. | ||
|
||
When the Operator is running you can create some Tomcat Custom Resources. You can find a sample | ||
custom resources in the k8s folder. | ||
|
||
If you want the Operator to be running as a deployment in your cluster, follow the below steps. | ||
|
||
## Build | ||
|
||
You can build the sample using `mvn install jib:dockerBuild` this will produce a Docker image you | ||
can push to the registry of your choice. The JAR file is built using your local Maven and JDK and | ||
then copied into the Docker image. | ||
|
||
## Install Operator into cluster | ||
|
||
Install the CRDs as shown above if you haven't already, then | ||
run `kubectl apply -f k8s/operator.yaml`. Now you can create Tomcat instances with CRs (see examples | ||
above). | ||
|
||
## EventSources | ||
The TomcatController is listening to events about Deployments created by the TomcatOperator by registering a | ||
InformerEventSource with the EventSourceManager. The InformerEventSource will in turn register a watch on | ||
all Deployments managed by the Controller (identified by the `app.kubernetes.io/managed-by` label). | ||
When an event from a Deployment is received we have to identify which Tomcat object does the Deployment | ||
belong to. This is done when the InformerEventSource creates the event. | ||
|
||
The TomcatController has to take care of setting the `app.kubernetes.io/managed-by` label on the Deployment so the | ||
InformerEventSource can watch the right Deployments. | ||
The TomcatController also has to set `ownerReference` on the Deployment so later the InformerEventSource can | ||
identify which Tomcat does the Deployment belong to. This is necessary so the frameowork can call the Controller | ||
`createOrUpdate` method correctly. | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.