@@ -164,10 +164,7 @@ The `Memcached` is the Schema for the Memcacheds API.
164
164
165
165
@Version("v1")
166
166
@Group("cache.example.com")
167
- @Kind("Memcached")
168
- @Plural("memcacheds")
169
- public class Memcached extends CustomResource<MemcachedSpec, MemcachedStatus>
170
- implements Namespaced {}
167
+ public class Memcached extends CustomResource<MemcachedSpec, MemcachedStatus> implements Namespaced {}
171
168
```
172
169
173
170
You have now created the necessary classes for the API.
@@ -259,18 +256,18 @@ This controller implements the `ResourceController` interface from the
259
256
` java-operator-sdk ` . This interface has some important and useful methods.
260
257
261
258
Initially the ` MemcachedController.java ` will contain the empty stubs for
262
- ` createOrUpdateResource ` . In this section we will fill in
259
+ ` reconcile ` . In this section we will fill in
263
260
the controller logic in these methods. We will also add a
264
261
` createMemcachedDeployment ` method that will create the Deployment for our
265
262
operator and a ` labelsForMemcached ` method that returns the labels.
266
263
267
- The ` createOrUpdateResource ` get called whenever some
268
- update/create/delete event occurs in the cluster. This will allow us to react to
264
+ The ` reconcile ` get called whenever some
265
+ update/create event occurs in the cluster. This will allow us to react to
269
266
changes to the Deployment.
270
267
271
- ### createOrUpdateResource
268
+ ### reconcile
272
269
273
- In this section we will focus on implementing the ` createOrUpdateResource `
270
+ In this section we will focus on implementing the ` reconcile `
274
271
method. In the ` MemcachedController.java ` you will see a ` // TODO: fill in logic `
275
272
comment. At this line we will first add code to get the Deployment.
276
273
@@ -285,7 +282,7 @@ comment. At this line we will first add code to get the Deployment.
285
282
286
283
Once we get the ` deployment ` , we have a couple of decisions to make. If it is
287
284
` null ` it does not exist which means we need to create the deployment. In the
288
- ` MemachedController.java ` , in the ` createOrUpdateResource ` method just below the
285
+ ` MemachedController.java ` , in the ` reconcile ` method just below the
289
286
get deployment code we added above, add the following:
290
287
291
288
```
@@ -302,7 +299,7 @@ method.
302
299
303
300
Once we create the deployment, we need to decide whether we have to reconcile it or not.
304
301
If there is no need of reconciliation then return ` UpdateControl.noUpdate() `
305
- else we need to return ` UpdateControl.updateStatusSubResource (resource) `
302
+ else we need to return ` UpdateControl.updateStatus (resource) `
306
303
307
304
After getting the Deployment, we get the current and required replicas. Add the
308
305
following lines below the ` if (deployment == null) ` block in your
@@ -358,13 +355,13 @@ mismatch in either of these conditions then we need to do a reconciliation.
358
355
}
359
356
```
360
357
361
- That's it we have completed the ` createOrUpdateResource ` method. The method
358
+ That's it we have completed the ` reconcile ` method. The method
362
359
should now look like the following:
363
360
364
361
```
365
362
@Override
366
- public UpdateControl<Memcached> createOrUpdateResource (
367
- Memcached resource, Context<Memcached> context) {
363
+ public UpdateControl<Memcached> reconcile (
364
+ Memcached resource, Context context) {
368
365
// TODO: fill in logic
369
366
Deployment deployment = client.apps()
370
367
.deployments()
@@ -427,7 +424,7 @@ Let's create the utility method first.
427
424
### labelsForMemcached
428
425
429
426
A simple utility method to return a map of the labels we want to attach to some
430
- of the resources. Below the ` createOrUpdateResource ` method add the following
427
+ of the resources. Below the ` reconcile ` method add the following
431
428
helper:
432
429
433
430
```
@@ -447,7 +444,7 @@ In the next section, we will walk you through creating the
447
444
Creating Kubernetes objects via APIs can be quite verbose which is why putting
448
445
them in helper methods can make the code more readable. The
449
446
` MemcachedController.java ` needs to create a Deployment if it does not exist. In
450
- the ` createOrUpdateResource ` we make a call to a helper,
447
+ the ` reconcile ` we make a call to a helper,
451
448
` createMemcachedDeployment ` .
452
449
453
450
Let's create the ` createMemcachedDeployment ` method. The following code will use
@@ -501,7 +498,7 @@ Below your `labelsForMemcached(Memcached m)` block in the
501
498
}
502
499
```
503
500
504
- Now we have a ` createOrUpdateResource ` method. It calls
501
+ Now we have a ` reconcile ` method. It calls
505
502
` createMemcachedDeployment ` which we have implemented above.
506
503
507
504
We have now implemented the ` MemcachedController.java ` .
0 commit comments