Skip to content

Commit 2e01de0

Browse files
authored
Docs updates for v2 (#715)
1 parent b91221b commit 2e01de0

File tree

8 files changed

+296
-276
lines changed

8 files changed

+296
-276
lines changed

README.md

+110-124
Large diffs are not rendered by default.

docs/documentation/features.md

+82-51
Large diffs are not rendered by default.

docs/documentation/getting-started.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ permalink: /docs/getting-started
1010
## Introduction & Resources on Operators
1111

1212
Operators are easy and simple way to manage resource on Kubernetes clusters but
13-
also outside of the cluster. The goal of this SDK is to allow writing operators in Java by
13+
also outside the cluster. The goal of this SDK is to allow writing operators in Java by
1414
providing a nice API and handling common issues regarding the operators on framework level.
1515

1616
For an introduction, what is an operator see this [blog post](https://blog.container-solutions.com/kubernetes-operators-explained).

docs/documentation/use-samples.md

+84-92
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,18 @@ layout: docs
55
permalink: /docs/using-samples
66
---
77

8-
98
# How to use sample Operators
109

11-
We have several sample Operators under the [samples](https://github.com/java-operator-sdk/java-operator-sdk/tree/master/samples) directory:
10+
We have several sample Operators under
11+
the [samples](https://github.com/java-operator-sdk/java-operator-sdk/tree/master/smoke-test-samples) directory:
1212

13-
* *pure-java*: Minimal Operator implementation which only parses the Custom Resource and prints to
14-
stdout. Implemented with and without Spring Boot support. The two samples share the common module.
13+
* *pure-java*: Minimal Operator implementation which only parses the Custom Resource and prints to stdout. Implemented
14+
with and without Spring Boot support. The two samples share the common module.
1515
* *spring-boot-plain*: Sample showing integration with Spring Boot.
1616

17-
There are also more samples in the
18-
standalone [samples repo](https://github.com/java-operator-sdk/samples):
17+
There are also more samples in the standalone [samples repo](https://github.com/java-operator-sdk/samples):
1918

20-
* *webserver*: Simple example creating an NGINX webserver from a Custom Resource containing HTML
21-
code.
19+
* *webserver*: Simple example creating an NGINX webserver from a Custom Resource containing HTML code.
2220
* *mysql-schema*: Operator managing schemas in a MySQL database.
2321
* *tomcat*: Operator with two controllers, managing Tomcat instances and Webapps for these.
2422

@@ -27,14 +25,14 @@ Add [dependency](https://search.maven.org/search?q=a:operator-framework) to your
2725
```xml
2826

2927
<dependency>
30-
<groupId>io.javaoperatorsdk</groupId>
31-
<artifactId>operator-framework</artifactId>
32-
<version>{see https://search.maven.org/search?q=a:operator-framework for latest version}</version>
28+
<groupId>io.javaoperatorsdk</groupId>
29+
<artifactId>operator-framework</artifactId>
30+
<version>{see https://search.maven.org/search?q=a:operator-framework for latest version}</version>
3331
</dependency>
3432
```
3533

36-
Or alternatively with Gradle, which also requires declaring the SDK as an annotation processor to
37-
generate the mappings between controllers and custom resource classes:
34+
Or alternatively with Gradle, which also requires declaring the SDK as an annotation processor to generate the mappings
35+
between controllers and custom resource classes:
3836

3937
```groovy
4038
dependencies {
@@ -43,16 +41,16 @@ dependencies {
4341
}
4442
```
4543

46-
Once you've added the dependency, define a main method initializing the Operator and registering a
47-
controller.
44+
Once you've added the dependency, define a main method initializing the Operator and registering a controller.
4845

4946
```java
5047
public class Runner {
5148

52-
public static void main(String[] args) {
53-
Operator operator = new Operator(DefaultConfigurationService.instance());
54-
operator.register(new WebServerController());
55-
}
49+
public static void main(String[] args) {
50+
Operator operator = new Operator(DefaultConfigurationService.instance());
51+
operator.register(new WebServerController());
52+
operator.start();
53+
}
5654
}
5755
```
5856

@@ -61,15 +59,15 @@ The Controller implements the business logic and describes all the classes neede
6159
```java
6260

6361
@Controller
64-
public class WebServerController implements ResourceController<WebServer> {
65-
66-
// Return the changed resource, so it gets updated. See javadoc for details.
67-
@Override
68-
public UpdateControl<CustomService> createOrUpdateResource(CustomService resource,
69-
Context<WebServer> context) {
70-
// ... your logic ...
71-
return UpdateControl.updateStatusSubResource(resource);
72-
}
62+
public class WebServerController implements Reconciler<WebServer> {
63+
64+
// Return the changed resource, so it gets updated. See javadoc for details.
65+
@Override
66+
public UpdateControl<CustomService> reconcile(CustomService resource,
67+
Context context) {
68+
// ... your logic ...
69+
return UpdateControl.updateStatus(resource);
70+
}
7371
}
7472
```
7573

@@ -80,51 +78,49 @@ A sample custom resource POJO representation
8078
@Group("sample.javaoperatorsdk")
8179
@Version("v1")
8280
public class WebServer extends CustomResource<WebServerSpec, WebServerStatus> implements
83-
Namespaced {
81+
Namespaced {
8482

8583
}
8684

8785
public class WebServerSpec {
8886

89-
private String html;
87+
private String html;
9088

91-
public String getHtml() {
92-
return html;
93-
}
89+
public String getHtml() {
90+
return html;
91+
}
9492

95-
public void setHtml(String html) {
96-
this.html = html;
97-
}
93+
public void setHtml(String html) {
94+
this.html = html;
95+
}
9896
}
9997
```
10098

10199
### Deactivating CustomResource implementations validation
102100

103101
The operator will, by default, query the deployed CRDs to check that the `CustomResource`
104-
implementations match what is known to the cluster. This requires an additional query to the cluster
105-
and, sometimes, elevated privileges for the operator to be able to read the CRDs from the cluster.
106-
This validation is mostly meant to help users new to operator development get started and avoid
107-
common mistakes. Advanced users or production deployments might want to skip this step. This is done
108-
by setting the `CHECK_CRD_ENV_KEY` environment variable to `false`.
102+
implementations match what is known to the cluster. This requires an additional query to the cluster and, sometimes,
103+
elevated privileges for the operator to be able to read the CRDs from the cluster. This validation is mostly meant to
104+
help users new to operator development get started and avoid common mistakes. Advanced users or production deployments
105+
might want to skip this step. This is done by setting the `CHECK_CRD_ENV_KEY` environment variable to `false`.
109106

110107
### Automatic generation of CRDs
111108

112-
To automatically generate CRD manifests from your annotated Custom Resource classes, you only need
113-
to add the following dependencies to your project:
109+
To automatically generate CRD manifests from your annotated Custom Resource classes, you only need to add the following
110+
dependencies to your project:
114111

115112
```xml
116113

117114
<dependency>
118-
<groupId>io.fabric8</groupId>
119-
<artifactId>crd-generator-apt</artifactId>
120-
<scope>provided</scope>
115+
<groupId>io.fabric8</groupId>
116+
<artifactId>crd-generator-apt</artifactId>
117+
<scope>provided</scope>
121118
</dependency>
122119
```
123120

124-
The CRD will be generated in `target/classes/META-INF/fabric8` (or
125-
in `target/test-classes/META-INF/fabric8`, if you use the `test` scope) with the CRD name suffixed
126-
by the generated spec version. For example, a CR using the `java-operator-sdk.io` group with
127-
a `mycrs` plural form will result in 2 files:
121+
The CRD will be generated in `target/classes/META-INF/fabric8` (or in `target/test-classes/META-INF/fabric8`, if you use
122+
the `test` scope) with the CRD name suffixed by the generated spec version. For example, a CR using
123+
the `java-operator-sdk.io` group with a `mycrs` plural form will result in 2 files:
128124

129125
- `mycrs.java-operator-sdk.io-v1.yml`
130126
- `mycrs.java-operator-sdk.io-v1beta1.yml`
@@ -134,64 +130,60 @@ a `mycrs` plural form will result in 2 files:
134130
135131
### Quarkus
136132

137-
A [Quarkus](https://quarkus.io) extension is also provided to ease the development of Quarkus-based
138-
operators.
133+
A [Quarkus](https://quarkus.io) extension is also provided to ease the development of Quarkus-based operators.
139134

140135
Add [this dependency](https://search.maven.org/search?q=a:quarkus-operator-sdk)
141136
to your project:
142137

143138
```xml
144139

145140
<dependency>
146-
<groupId>io.quarkiverse.operatorsdk</groupId>
147-
<artifactId>quarkus-operator-sdk</artifactId>
148-
<version>{see https://search.maven.org/search?q=a:quarkus-operator-sdk for latest version}
149-
</version>
141+
<groupId>io.quarkiverse.operatorsdk</groupId>
142+
<artifactId>quarkus-operator-sdk</artifactId>
143+
<version>{see https://search.maven.org/search?q=a:quarkus-operator-sdk for latest version}
144+
</version>
150145
</dependency>
151146
```
152147

153148
Create an Application, Quarkus will automatically create and inject a `KubernetesClient` (
154-
or `OpenShiftClient`), `Operator`, `ConfigurationService` and `ResourceController` instances that
155-
your application can use. Below, you can see the minimal code you need to write to get your operator
156-
and controllers up and running:
149+
or `OpenShiftClient`), `Operator`, `ConfigurationService` and `ResourceController` instances that your application can
150+
use. Below, you can see the minimal code you need to write to get your operator and controllers up and running:
157151

158152
```java
159153

160154
@QuarkusMain
161155
public class QuarkusOperator implements QuarkusApplication {
162156

163-
@Inject
164-
Operator operator;
157+
@Inject
158+
Operator operator;
165159

166-
public static void main(String... args) {
167-
Quarkus.run(QuarkusOperator.class, args);
168-
}
160+
public static void main(String... args) {
161+
Quarkus.run(QuarkusOperator.class, args);
162+
}
169163

170-
@Override
171-
public int run(String... args) throws Exception {
172-
operator.start();
173-
Quarkus.waitForExit();
174-
return 0;
175-
}
164+
@Override
165+
public int run(String... args) throws Exception {
166+
operator.start();
167+
Quarkus.waitForExit();
168+
return 0;
169+
}
176170
}
177171
```
178172

179173
### Spring Boot
180174

181-
You can also let Spring Boot wire your application together and automatically register the
182-
controllers.
175+
You can also let Spring Boot wire your application together and automatically register the controllers.
183176

184-
Add [this dependency](https://search.maven.org/search?q=a:operator-framework-spring-boot-starter) to
185-
your project:
177+
Add [this dependency](https://search.maven.org/search?q=a:operator-framework-spring-boot-starter) to your project:
186178

187179
```xml
188180

189181
<dependency>
190-
<groupId>io.javaoperatorsdk</groupId>
191-
<artifactId>operator-framework-spring-boot-starter</artifactId>
192-
<version>{see https://search.maven.org/search?q=a:operator-framework-spring-boot-starter for
193-
latest version}
194-
</version>
182+
<groupId>io.javaoperatorsdk</groupId>
183+
<artifactId>operator-framework-spring-boot-starter</artifactId>
184+
<version>{see https://search.maven.org/search?q=a:operator-framework-spring-boot-starter for
185+
latest version}
186+
</version>
195187
</dependency>
196188
```
197189

@@ -202,25 +194,25 @@ Create an Application
202194
@SpringBootApplication
203195
public class Application {
204196

205-
public static void main(String[] args) {
206-
SpringApplication.run(Application.class, args);
207-
}
197+
public static void main(String[] args) {
198+
SpringApplication.run(Application.class, args);
199+
}
208200
}
209201
```
210202

211203
#### Spring Boot test support
212204

213-
Adding the following dependency would let you mock the operator for the tests where loading the
214-
spring container is necessary, but it doesn't need real access to a Kubernetes cluster.
205+
Adding the following dependency would let you mock the operator for the tests where loading the spring container is
206+
necessary, but it doesn't need real access to a Kubernetes cluster.
215207

216208
```xml
217209

218210
<dependency>
219-
<groupId>io.javaoperatorsdk</groupId>
220-
<artifactId>operator-framework-spring-boot-starter-test</artifactId>
221-
<version>{see https://search.maven.org/search?q=a:operator-framework-spring-boot-starter for
222-
latest version}
223-
</version>
211+
<groupId>io.javaoperatorsdk</groupId>
212+
<artifactId>operator-framework-spring-boot-starter-test</artifactId>
213+
<version>{see https://search.maven.org/search?q=a:operator-framework-spring-boot-starter for
214+
latest version}
215+
</version>
224216
</dependency>
225217
```
226218

@@ -232,8 +224,8 @@ Mock the operator:
232224
@EnableMockOperator
233225
public class SpringBootStarterSampleApplicationTest {
234226

235-
@Test
236-
void contextLoads() {
237-
}
227+
@Test
228+
void contextLoads() {
229+
}
238230
}
239231
```

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ErrorStatusHandler.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ public interface ErrorStatusHandler<T extends HasMetadata> {
1010
* when the last reconciliation retry attempt is failed on the Reconciler. In that case the
1111
* updateErrorStatus is called automatically.
1212
* <p>
13-
* The result of the method call is used to make a status sub-resource update on the custom
14-
* resource. This is always a sub-resource update request, so no update on custom resource itself
15-
* (like spec of metadata) happens. Note that this update request will also produce an event, and
16-
* will result in a reconciliation if the controller is not generation aware.
13+
* The result of the method call is used to make a status update on the custom resource. This is
14+
* always a sub-resource update request, so no update on custom resource itself (like spec of
15+
* metadata) happens. Note that this update request will also produce an event, and will result in
16+
* a reconciliation if the controller is not generation aware.
1717
* <p>
1818
* Note that the scope of this feature is only the reconcile method of the reconciler, since there
1919
* should not be updates on custom resource after it is marked for deletion.

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceInitializer.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
public interface EventSourceInitializer<T extends HasMetadata> {
77

88
/**
9-
* In this typically you might want to register event sources. But can access
10-
* CustomResourceEventSource, what might be handy for some edge cases.
9+
* Reconciler can implement this interface typically to register event sources. But can access
10+
* CustomResourceEventSource, what might be useful for some edge cases.
1111
*
1212
* @param eventSourceRegistry the {@link EventSourceRegistry} where event sources can be
1313
* registered.
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
package io.javaoperatorsdk.operator.api.reconciler;
22

33
public interface RetryInfo {
4-
4+
/**
5+
* @return current retry attempt count. 0 if the current execution is not a retry.
6+
*/
57
int getAttemptCount();
68

9+
/**
10+
* @return true, if the current attempt is the last one in regard to the retry limit
11+
* configuration.
12+
*/
713
boolean isLastAttempt();
814
}

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/UpdateControl.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ private UpdateControl(
1919
this.updateResource = updateResource;
2020
}
2121

22+
/**
23+
* Creates an update control instance that instructs the framework to do an update on resource
24+
* itself, not on the status. Note that usually as a results of a reconciliation should be a
25+
* status update not an update to the resource itself.
26+
*/
2227
public static <T extends HasMetadata> UpdateControl<T> updateResource(T customResource) {
2328
return new UpdateControl<>(customResource, false, true);
2429
}
@@ -31,7 +36,7 @@ public static <T extends HasMetadata> UpdateControl<T> updateStatus(
3136
/**
3237
* As a results of this there will be two call to K8S API. First the custom resource will be
3338
* updates then the status sub-resource.
34-
*
39+
*
3540
* @param <T> resource type
3641
* @param customResource - custom resource to use in both API calls
3742
* @return UpdateControl instance

0 commit comments

Comments
 (0)