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
Note also the Workflows feature makes it possible to also support this conditional creation use
332
332
case in managed dependent resources.
333
333
334
+
## Creating/Updating Kubernetes Resources
335
+
336
+
From version 4.4 of the framework the resources are created and updated
337
+
using [Server Side Apply](https://kubernetes.io/docs/reference/using-api/server-side-apply/)
338
+
, thus the desired state is simply sent using this approach to update the actual resource.
339
+
340
+
## Comparing desired and actual state (matching)
341
+
342
+
During the reconciliation of a dependent resource, the desired state is matched with the actual
343
+
state from the caches. The dependent resource only gets updated on the server if the actual,
344
+
observed state differs from the desired one. Comparing these two states is a complex problem
345
+
when dealing with Kubernetes resources because a strict equality check is usually not what is
346
+
wanted due to the fact that multiple fields might be automatically updated or added by
347
+
the platform (
348
+
by [dynamic admission controllers](https://kubernetes.io/docs/reference/access-authn-authz/extensible-admission-controllers/)
349
+
or validation webhooks, for example). Solving this problem in a generic way is therefore a tricky
350
+
proposition.
351
+
352
+
JOSDK provides such a generic matching implementation which is used by default:
Since SSA is a complex feature, JOSDK implements a feature flag allowing users to switch between
362
+
these implementations. See
363
+
in [ConfigurationService](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java#L332-L358).
364
+
365
+
It is, however, important to note that these implementations are default, generic
366
+
implementations that the framework can provide expected behavior out of the box. In many
367
+
situations, these will work just fine but it is also possible to provide matching algorithms
368
+
optimized for specific use cases. This is easily done by simply overriding
369
+
the `match(...)`[method](https://github.com/java-operator-sdk/java-operator-sdk/blob/e16559fd41bbb8bef6ce9d1f47bffa212a941b09/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java#L156-L156).
370
+
371
+
It is also possible to bypass the matching logic altogether to simply rely on the server-side
372
+
apply mechanism if always sending potentially unchanged resources to the cluster is not an issue.
373
+
JOSDK's matching mechanism allows to spare some potentially useless calls to the Kubernetes API
374
+
server. To bypass the matching feature completely, simply override the `match` method to always
375
+
return `false`, thus telling JOSDK that the actual state never matches the desired one, making
376
+
it always update the resources using SSA.
377
+
334
378
## Telling JOSDK how to find which secondary resources are associated with a given primary resource
there should be a shared event source between them, or a label selector on the event sources
468
512
to select only the relevant events, see
469
513
in [related integration test](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/orderedmanageddependent/ConfigMapDependentResource1.java)
470
-
.
514
+
.
471
515
472
516
## "Read-only" Dependent Resources vs. Event Source
473
517
474
-
See Integration test for a read-only dependent [here](https://github.com/java-operator-sdk/java-operator-sdk/blob/249b41f3c68c4d0e9c77c41eca647a69a24347b0/operator-framework/src/test/java/io/javaoperatorsdk/operator/PrimaryToSecondaryDependentIT.java).
0 commit comments