|
10 | 10 | import io.fabric8.kubernetes.client.KubernetesClientException;
|
11 | 11 | import io.fabric8.kubernetes.client.dsl.base.PatchContext;
|
12 | 12 | import io.fabric8.kubernetes.client.dsl.base.PatchType;
|
| 13 | +import io.fabric8.kubernetes.client.utils.Serialization; |
13 | 14 | import io.javaoperatorsdk.operator.api.reconciler.*;
|
14 | 15 | import io.javaoperatorsdk.operator.glue.Utils;
|
15 | 16 | import io.javaoperatorsdk.operator.glue.conditions.JavaScripCondition;
|
@@ -47,17 +48,19 @@ public class GlueReconciler implements Reconciler<Glue>, Cleaner<Glue>, ErrorSta
|
47 | 48 |
|
48 | 49 | private final ValidationAndErrorHandler validationAndErrorHandler;
|
49 | 50 | private final InformerRegister informerRegister;
|
| 51 | + private final GenericTemplateHandler templateHandler; |
50 | 52 |
|
51 | 53 | private final KubernetesResourceDeletedCondition deletePostCondition =
|
52 | 54 | new KubernetesResourceDeletedCondition();
|
53 | 55 |
|
54 | 56 | private final GenericTemplateHandler genericTemplateHandler;
|
55 | 57 |
|
56 | 58 | public GlueReconciler(ValidationAndErrorHandler validationAndErrorHandler,
|
57 |
| - InformerRegister informerRegister, |
| 59 | + InformerRegister informerRegister, GenericTemplateHandler templateHandler, |
58 | 60 | GenericTemplateHandler genericTemplateHandler) {
|
59 | 61 | this.validationAndErrorHandler = validationAndErrorHandler;
|
60 | 62 | this.informerRegister = informerRegister;
|
| 63 | + this.templateHandler = templateHandler; |
61 | 64 | this.genericTemplateHandler = genericTemplateHandler;
|
62 | 65 | }
|
63 | 66 |
|
@@ -89,6 +92,7 @@ public UpdateControl<Glue> reconcile(Glue primary,
|
89 | 92 | cleanupRemovedResourcesFromWorkflow(context, primary);
|
90 | 93 | informerRegister.deRegisterInformerOnResourceFlowChange(context, primary);
|
91 | 94 | result.throwAggregateExceptionIfErrorsPresent();
|
| 95 | + patchRelatedResourcesStatus(context, primary); |
92 | 96 | return UpdateControl.noUpdate();
|
93 | 97 | }
|
94 | 98 |
|
@@ -222,6 +226,35 @@ private GenericDependentResource createDependentResource(DependentResourceSpec s
|
222 | 226 | }
|
223 | 227 | }
|
224 | 228 |
|
| 229 | + // todo add workflow result? |
| 230 | + private void patchRelatedResourcesStatus(Context<Glue> context, |
| 231 | + Glue primary) { |
| 232 | + |
| 233 | + var targetRelatedResources = primary.getSpec().getRelatedResources().stream() |
| 234 | + .filter(r -> r.getStatusPatch() != null || r.getStatusPatchTemplate() != null) |
| 235 | + .toList(); |
| 236 | + |
| 237 | + if (!targetRelatedResources.isEmpty()) { |
| 238 | + return; |
| 239 | + } |
| 240 | + var actualData = genericTemplateHandler.createDataWithResources(primary, context); |
| 241 | + |
| 242 | + targetRelatedResources.forEach(r -> { |
| 243 | + var relatedResources = Utils.getRelatedResources(primary, r, context); |
| 244 | + |
| 245 | + var template = r.getStatusPatchTemplate() != null ? r.getStatusPatchTemplate() |
| 246 | + : Serialization.asYaml(r.getStatusPatch()); |
| 247 | + var resultTemplate = |
| 248 | + genericTemplateHandler.processTemplate(actualData, template); |
| 249 | + var statusObjectMap = GenericTemplateHandler.parseTemplateToMapObject(resultTemplate); |
| 250 | + relatedResources.forEach((n, kr) -> { |
| 251 | + kr.setAdditionalProperty("status", statusObjectMap); |
| 252 | + context.getClient().resource(kr).patchStatus(); |
| 253 | + }); |
| 254 | + }); |
| 255 | + |
| 256 | + } |
| 257 | + |
225 | 258 | @SuppressWarnings({"rawtypes"})
|
226 | 259 | private Condition toCondition(ConditionSpec condition) {
|
227 | 260 | if (condition instanceof ReadyConditionSpec readyConditionSpec) {
|
|
0 commit comments