Skip to content

Commit d79057c

Browse files
authored
Merge pull request #40 from ContainerSolutions/nginx-www
webserver sample
2 parents 24624c9 + 6bb4f1a commit d79057c

File tree

22 files changed

+566
-4
lines changed

22 files changed

+566
-4
lines changed

.travis.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
11
language: java
2-
dist: bionic
3-
before_install:
4-
- openssl aes-256-cbc -K $encrypted_fda1a939a5f2_key -iv $encrypted_fda1a939a5f2_iv
5-
-in maven-settings.xml.enc -out maven-settings.xml -d
2+
dist: bionic

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# java-operator-sdk
2+
[![Build Status](https://travis-ci.org/ContainerSolutions/java-operator-sdk.svg?branch=master)](https://travis-ci.org/ContainerSolutions/java-operator-sdk)
23
> This project is in incubation phase.
34
45
SDK for building Kubernetes Operators in Java. Inspired by [operator-sdk](https://github.com/operator-framework/operator-sdk).

maven-settings.xml.enc

-560 Bytes
Binary file not shown.

samples/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<module>common</module>
1919
<module>pure-java</module>
2020
<module>spring-boot</module>
21+
<module>webserver</module>
2122
</modules>
2223

2324
</project>

samples/webserver/Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM openjdk:12-alpine
2+
3+
ENTRYPOINT ["java", "-jar", "/usr/share/operator/operator.jar"]
4+
5+
ARG JAR_FILE
6+
ADD target/${JAR_FILE} /usr/share/operator/operator.jar
7+

samples/webserver/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# WebServer Operator
2+
3+
This is a more complex example of how a Custom Resource backed by an Operator can serve as
4+
an abstraction layer. This Operator will use an webserver resource, which mainly contains a
5+
static webpage definition and creates a nginx Deployment backed by a ConfigMap which holds
6+
the html.
7+
8+
This is an example input:
9+
```yaml
10+
apiVersion: "sample.javaoperatorsdk/v1"
11+
kind: WebServer
12+
metadata:
13+
name: mynginx-hello
14+
spec:
15+
html: |
16+
<html>
17+
<head>
18+
<title>Webserver Operator</title>
19+
</head>
20+
<body>
21+
Hello World!!
22+
</body>
23+
</html>
24+
```

samples/webserver/crd/crd.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
apiVersion: apiextensions.k8s.io/v1beta1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
name: webservers.sample.javaoperatorsdk
5+
spec:
6+
group: sample.javaoperatorsdk
7+
version: v1
8+
scope: Namespaced
9+
names:
10+
plural: webservers
11+
singular: webserver
12+
kind: WebServer
13+
shortNames:
14+
- ws
15+
validation:
16+
openAPIV3Schema:
17+
type: object
18+
properties:
19+
spec:
20+
type: object
21+
properties:
22+
html:
23+
type: string

samples/webserver/crd/webserver.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: "sample.javaoperatorsdk/v1"
2+
kind: WebServer
3+
metadata:
4+
name: hellows
5+
spec:
6+
html: |
7+
<html>
8+
<head>
9+
<title>Hello Operator World</title>
10+
</head>
11+
<body>
12+
Hellooooo!! Operators!!
13+
</body>
14+
</html>

samples/webserver/k8s/deployment.yaml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: webserver-operator
5+
namespace: webserver-operator
6+
spec:
7+
selector:
8+
matchLabels:
9+
app: webserver-operator
10+
replicas: 1
11+
template:
12+
metadata:
13+
labels:
14+
app: webserver-operator
15+
spec:
16+
serviceAccount: webserver-operator
17+
containers:
18+
- name: operator
19+
image: webserver-operator
20+
imagePullPolicy: Never
21+
ports:
22+
- containerPort: 80
23+
readinessProbe:
24+
httpGet:
25+
path: /health
26+
port: 8080
27+
initialDelaySeconds: 1
28+
timeoutSeconds: 1
29+
livenessProbe:
30+
httpGet:
31+
path: /health
32+
port: 8080
33+
initialDelaySeconds: 30
34+
timeoutSeconds: 1
35+
---
36+
apiVersion: v1
37+
kind: ServiceAccount
38+
metadata:
39+
name: webserver-operator
40+
namespace: webserver-operator
41+
---
42+
apiVersion: rbac.authorization.k8s.io/v1
43+
kind: ClusterRoleBinding
44+
metadata:
45+
name: operator-admin
46+
subjects:
47+
- kind: ServiceAccount
48+
name: webserver-operator
49+
namespace: webserver-operator
50+
roleRef:
51+
kind: ClusterRole
52+
name: cluster-admin
53+
apiGroup: ""

samples/webserver/pom.xml

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.github.containersolutions</groupId>
7+
<artifactId>webserver-sample</artifactId>
8+
<version>0.3.2-SNAPSHOT</version>
9+
<packaging>jar</packaging>
10+
11+
<properties>
12+
<java.version>11</java.version>
13+
</properties>
14+
15+
<dependencies>
16+
<dependency>
17+
<groupId>com.github.containersolutions</groupId>
18+
<artifactId>operator-framework</artifactId>
19+
<version>${project.version}</version>
20+
</dependency>
21+
<dependency>
22+
<groupId>org.junit.jupiter</groupId>
23+
<artifactId>junit-jupiter-engine</artifactId>
24+
<version>5.4.2</version>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.apache.logging.log4j</groupId>
28+
<artifactId>log4j-slf4j-impl</artifactId>
29+
<version>2.11.2</version>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.takes</groupId>
33+
<artifactId>takes</artifactId>
34+
<version>1.17</version>
35+
</dependency>
36+
</dependencies>
37+
38+
<build>
39+
<plugins>
40+
<plugin>
41+
<groupId>org.apache.maven.plugins</groupId>
42+
<artifactId>maven-compiler-plugin</artifactId>
43+
<version>3.8.1</version>
44+
<configuration>
45+
<release>${java.version}</release>
46+
</configuration>
47+
</plugin>
48+
<plugin>
49+
<groupId>com.spotify</groupId>
50+
<artifactId>dockerfile-maven-plugin</artifactId>
51+
<version>1.4.12</version>
52+
<executions>
53+
<execution>
54+
<id>default</id>
55+
<phase>install</phase>
56+
<goals>
57+
<goal>build</goal>
58+
</goals>
59+
</execution>
60+
</executions>
61+
<configuration>
62+
<repository>webserver-operator</repository>
63+
<tag>latest</tag>
64+
<buildArgs>
65+
<JAR_FILE>${project.build.finalName}.jar</JAR_FILE>
66+
</buildArgs>
67+
</configuration>
68+
</plugin>
69+
<plugin>
70+
<groupId>org.apache.maven.plugins</groupId>
71+
<artifactId>maven-shade-plugin</artifactId>
72+
<version>2.4.3</version>
73+
<executions>
74+
<execution>
75+
<phase>package</phase>
76+
<goals>
77+
<goal>shade</goal>
78+
</goals>
79+
<configuration>
80+
<createDependencyReducedPom>false</createDependencyReducedPom>
81+
<transformers>
82+
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
83+
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
84+
<manifestEntries>
85+
<Main-Class>com.github.containersolutions.operator.sample.WebServerOperator</Main-Class>
86+
<Build-Number>1.0</Build-Number>
87+
<Multi-Release>true</Multi-Release>
88+
</manifestEntries>
89+
</transformer>
90+
</transformers>
91+
<filters>
92+
<filter>
93+
<artifact>io.fabric8:openshift-client</artifact>
94+
<excludes>
95+
<exclude>io/fabric8/kubernetes/client/Config*</exclude>
96+
</excludes>
97+
</filter>
98+
</filters>
99+
</configuration>
100+
</execution>
101+
</executions>
102+
</plugin>
103+
</plugins>
104+
</build>
105+
106+
</project>

0 commit comments

Comments
 (0)