You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+28-73Lines changed: 28 additions & 73 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,40 +1,47 @@
1
-
# java-operator-sdk
2
-

1
+
# 
2
+

3
3
4
-
SDK for building Kubernetes Operators in Java. Inspired by [operator-sdk](https://github.com/operator-framework/operator-sdk).
5
-
User (you) only writes the logic in a Controller that creates/updates or deletes resources related to a custom resource.
6
-
All the issues around are handled by the framework for you.
7
-
Check out this [blog post](https://blog.container-solutions.com/a-deep-dive-into-the-java-operator-sdk)
8
-
about the non-trivial yet common problems needs to be solved for every operator.
9
-
10
-
## Join us on Discord!
4
+
Build Kubernetes Operators in Java without hassle. Inspired by [operator-sdk](https://github.com/operator-framework/operator-sdk).
11
5
12
-
[Discord Invite Link](https://discord.gg/DacEhAy)
6
+
#### Features
7
+
* Framework for handling Kubernetes API events
8
+
* Registering Custom Resource watches
9
+
* Retry action on failure
10
+
* Smart event scheduling (only handle latest event for the same resource)
13
11
14
-
## Roadmap
12
+
Check out this [blog post](https://blog.container-solutions.com/a-deep-dive-into-the-java-operator-sdk)
13
+
about the non-trivial yet common problems needs to be solved for every operator.
15
14
16
-
Feature we would like to implement and invite the community to help us implement in the future:
15
+
#### Why build your own Operator?
16
+
* Infrastructure automation using the power and flexibility of Java. See [blog post](https://blog.container-solutions.com/cloud-native-java-infrastructure-automation-with-kubernetes-operators).
17
+
* Provisioning of complex applications - avoiding Helm chart hell
18
+
* Integration with Cloud services - e.g. Secret stores
19
+
* Safer deployment of applications - only expose cluster to users by Custom Resources
17
20
18
-
*~~Spring Boot support~~
19
-
* Class generation from CRD to POJO
20
-
* GraalVM / Quarkus support
21
+
#### Roadmap
22
+
* Testing of the framework and all samples while running on a real cluster.
23
+
* Generate a project skeleton
24
+
* Generate Java classes from CRD definion (and/or the other way around)
25
+
* Integrate with Quarkus (including native image build)
26
+
* Integrate with OLM (Operator Lifecycle Manager)
21
27
22
-
##Additional Features
28
+
#### Join us on Discord!
23
29
24
-
* Configurable Retry Handling
25
-
* Smart Event Processing Scheduling
30
+
[Discord Invite Link](https://discord.gg/DacEhAy)
26
31
27
-
## User Guide
32
+
####User Guide
28
33
29
34
You can (will) find detailed documentation [here](docs/DOCS.md).
30
35
Note that these docs are currently in progress.
31
36
32
-
## Usage
37
+
####Usage
33
38
34
39
We have several sample Operators under the samples directory:
35
40
**basic*: Minimal Operator implementation which only parses the Custom Resource and prints to stdout.
36
41
Implemented with and without Spring Boot support. The two samples share the common module.
37
42
**webserver*: More realistic example creating an nginx webserver from a Custom Resource containing html code.
43
+
**mysql-schema*: Operator managing schemas in a MySQL database
44
+
**spring-boot-plain/auto-config*: Samples showing integration with Spring Boot.
38
45
39
46
Add [dependency](https://search.maven.org/search?q=a:operator-framework) to your project:
40
47
@@ -120,7 +127,7 @@ public class WebServerSpec {
120
127
}
121
128
```
122
129
123
-
### Spring Boot
130
+
####Spring Boot
124
131
125
132
You can also let Spring Boot wire your application together and automatically register the controllers.
126
133
@@ -143,55 +150,3 @@ public class Application {
143
150
}
144
151
}
145
152
```
146
-
147
-
add Spring's `@Service` annotation to your controller classes so they will be automatically registered as resource controllers.
148
-
149
-
The Operator's Spring Boot integration leverages [Spring's configuration mechanisms](https://docs.spring.io/spring-boot/docs/1.0.1.RELEASE/reference/html/boot-features-external-config.html) to configure
This library relies on the amazing [kubernetes-client](https://github.com/fabric8io/kubernetes-client) from fabric8.
156
-
Most of the heavy lifting is actually done by kubernetes-client.
157
-
158
-
What the framework adds on top of the bare client:
159
-
* Management of events from the Kubernetes API. All events are inserted into a queue by the EventScheduler. The
160
-
framework makes sure only the latest event for a certain resource is processed. This is especially important since
161
-
on startup the operator can receive a whole series of obsolete events.
162
-
* Retrying of failed actions. When an event handler throws an exception the event is put back in the queue.
163
-
* A clean interface to the user of the framework to receive events related to the Controller's resource.
164
-
165
-
### Dealing with Consistency
166
-
167
-
#### Run Single Instance
168
-
169
-
There should be always just one instance of an operator running at a time (think process). If there there would be
170
-
two ore more, in general it could lead to concurrency issues. Note that we are also doing optimistic locking when we update a resource.
171
-
In this way the operator is not highly available. However for operators this not necessary an issue,
172
-
if the operator just gets restarted after it went down.
173
-
174
-
#### At Least Once
175
-
176
-
To implement controller logic, we have to override two methods: `createOrUpdateResource` and `deleteResource`.
177
-
These methods are called if a resource is create/changed or marked for deletion. In most cases these methods will be
178
-
called just once, but in some rare cases can happen that are called more then once. In practice this means that the
179
-
implementation needs to be **idempotent**.
180
-
181
-
#### Smart Scheduling
182
-
183
-
In our scheduling algorithm we make sure, that no events are processed concurrently for a resource. In addition we provide
184
-
a customizable retry mechanism to deal with temporal errors.
185
-
186
-
#### Operator Restarts
187
-
188
-
When an operator is started we got events for every resource (of a type we listen to) already on the cluster. Even if the resource is not changed
189
-
(We use `kubectl get ... --watch` in the background). This can be a huge amount of resources depending on your use case.
190
-
So it could be a good case just have a status field on the resource which is checked, if there anything needs to be done.
191
-
192
-
#### Deleting a Resource
193
-
194
-
During deletion process we use [Kubernetes finalizers](https://kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definitions/#finalizers
195
-
"Kubernetes docs") finalizers. This is required, since it can happen that the operator is not running while the delete
196
-
of resource is executed (think `oc delete`). In this case we would not catch the delete event. So we automatically add a
197
-
finalizer first time we update the resource if its not there.
Copy file name to clipboardExpand all lines: docs/DOCS.md
+34-2Lines changed: 34 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,8 +35,6 @@ the cluster's API server.
35
35
Controllers are where you implement the business logic of the Operator. An Operator can host multiple Controllers,
36
36
each handling a different type of Custom Resource. In our samples each Operator has a single Controller.
37
37
38
-
### Generation Awareness
39
-
40
38
## Automatic Retries
41
39
42
40
## Running The Operator
@@ -53,3 +51,37 @@ TODO: explain running operator locally against a cluster
53
51
### Generation Awareness
54
52
55
53
## Spring Boot Support
54
+
55
+
## Dealing with Consistency
56
+
57
+
### Run Single Instance
58
+
59
+
There should be always just one instance of an operator running at a time (think process). If there there would be
60
+
two ore more, in general it could lead to concurrency issues. Note that we are also doing optimistic locking when we update a resource.
61
+
In this way the operator is not highly available. However for operators this not necessary an issue,
62
+
if the operator just gets restarted after it went down.
63
+
64
+
### At Least Once
65
+
66
+
To implement controller logic, we have to override two methods: `createOrUpdateResource` and `deleteResource`.
67
+
These methods are called if a resource is create/changed or marked for deletion. In most cases these methods will be
68
+
called just once, but in some rare cases can happen that are called more then once. In practice this means that the
69
+
implementation needs to be **idempotent**.
70
+
71
+
### Smart Scheduling
72
+
73
+
In our scheduling algorithm we make sure, that no events are processed concurrently for a resource. In addition we provide
74
+
a customizable retry mechanism to deal with temporal errors.
75
+
76
+
### Operator Restarts
77
+
78
+
When an operator is started we got events for every resource (of a type we listen to) already on the cluster. Even if the resource is not changed
79
+
(We use `kubectl get ... --watch` in the background). This can be a huge amount of resources depending on your use case.
80
+
So it could be a good case just have a status field on the resource which is checked, if there anything needs to be done.
81
+
82
+
### Deleting a Resource
83
+
84
+
During deletion process we use [Kubernetes finalizers](https://kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definitions/#finalizers
85
+
"Kubernetes docs") finalizers. This is required, since it can happen that the operator is not running while the delete
86
+
of resource is executed (think `oc delete`). In this case we would not catch the delete event. So we automatically add a
87
+
finalizer first time we update the resource if its not there.
0 commit comments