|
23 | 23 | import io.javaoperatorsdk.operator.api.reconciler.Reconciler;
|
24 | 24 | import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResourceFactory;
|
25 | 25 | import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent;
|
| 26 | +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResource; |
| 27 | +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResourceConfig; |
| 28 | +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.ResourceUpdaterMatcher; |
26 | 29 | import io.javaoperatorsdk.operator.processing.dependent.workflow.ManagedWorkflowFactory;
|
27 | 30 |
|
28 | 31 | /** An interface from which to retrieve configuration information. */
|
@@ -358,6 +361,32 @@ default boolean ssaBasedCreateUpdateMatchForDependentResources() {
|
358 | 361 | return true;
|
359 | 362 | }
|
360 | 363 |
|
| 364 | + /** |
| 365 | + * This is mostly useful as an integration point for downstream projects to be able to reuse the |
| 366 | + * logic used to determine whether a given {@link KubernetesDependentResource} should use SSA or |
| 367 | + * not. |
| 368 | + * |
| 369 | + * @param dependentResource the {@link KubernetesDependentResource} under consideration |
| 370 | + * @return {@code true} if SSA should be used for |
| 371 | + * @param <R> the dependent resource type |
| 372 | + * @param <P> the primary resource type |
| 373 | + * @since 4.9.4 |
| 374 | + */ |
| 375 | + default <R extends HasMetadata, P extends HasMetadata> boolean shouldUseSSA( |
| 376 | + KubernetesDependentResource<R, P> dependentResource) { |
| 377 | + if (dependentResource instanceof ResourceUpdaterMatcher) { |
| 378 | + return false; |
| 379 | + } |
| 380 | + Optional<Boolean> useSSAConfig = dependentResource.configuration() |
| 381 | + .flatMap(KubernetesDependentResourceConfig::useSSA); |
| 382 | + // don't use SSA for certain resources by default, only if explicitly overriden |
| 383 | + if (useSSAConfig.isEmpty() |
| 384 | + && defaultNonSSAResource().contains(dependentResource.resourceType())) { |
| 385 | + return false; |
| 386 | + } |
| 387 | + return useSSAConfig.orElse(ssaBasedCreateUpdateMatchForDependentResources()); |
| 388 | + } |
| 389 | + |
361 | 390 | /**
|
362 | 391 | * Returns the set of default resources for which Server-Side Apply (SSA) will not be used, even
|
363 | 392 | * if it is the default behavior for dependent resources as specified by
|
|
0 commit comments