|
24 | 24 | import io.javaoperatorsdk.operator.glue.dependent.GCGenericBulkDependentResource;
|
25 | 25 | import io.javaoperatorsdk.operator.glue.dependent.GCGenericDependentResource;
|
26 | 26 | import io.javaoperatorsdk.operator.glue.dependent.GenericDependentResource;
|
27 |
| -import io.javaoperatorsdk.operator.glue.dependent.GenericResourceDiscriminator; |
28 | 27 | import io.javaoperatorsdk.operator.glue.reconciler.ValidationAndErrorHandler;
|
29 | 28 | import io.javaoperatorsdk.operator.glue.reconciler.operator.GlueOperatorReconciler;
|
30 | 29 | import io.javaoperatorsdk.operator.glue.templating.GenericTemplateHandler;
|
31 |
| -import io.javaoperatorsdk.operator.processing.dependent.BulkDependentResource; |
32 | 30 | import io.javaoperatorsdk.operator.processing.dependent.workflow.Condition;
|
33 | 31 | import io.javaoperatorsdk.operator.processing.dependent.workflow.KubernetesResourceDeletedCondition;
|
34 | 32 | import io.javaoperatorsdk.operator.processing.dependent.workflow.WorkflowBuilder;
|
|
38 | 36 | import static io.javaoperatorsdk.operator.glue.reconciler.operator.GlueOperatorReconciler.PARENT_RELATED_RESOURCE_NAME;
|
39 | 37 |
|
40 | 38 | @ControllerConfiguration(name = GlueReconciler.GLUE_RECONCILER_NAME)
|
41 |
| -public class GlueReconciler implements Reconciler<Glue>, Cleaner<Glue>, ErrorStatusHandler<Glue> { |
| 39 | +public class GlueReconciler implements Reconciler<Glue>, Cleaner<Glue> { |
42 | 40 |
|
43 | 41 | private static final Logger log = LoggerFactory.getLogger(GlueReconciler.class);
|
44 | 42 | public static final String DEPENDENT_NAME_ANNOTATION_KEY =
|
@@ -107,7 +105,7 @@ public DeleteControl cleanup(Glue primary, Context<Glue> context) {
|
107 | 105 | return DeleteControl.noFinalizerRemoval();
|
108 | 106 | } else {
|
109 | 107 | removeFinalizerForParent(primary, context);
|
110 |
| - actualWorkflow.getDependentResourcesByNameWithoutActivationCondition().forEach((n, dr) -> { |
| 108 | + actualWorkflow.getDependentResourcesWithoutActivationCondition().forEach(dr -> { |
111 | 109 | var genericDependentResource = (GenericDependentResource) dr;
|
112 | 110 | informerRegister.deRegisterInformer(genericDependentResource.getGroupVersionKind(),
|
113 | 111 | primary, context);
|
@@ -201,55 +199,51 @@ private void createAndAddDependentToWorkflow(Glue primary, Context<Glue> context
|
201 | 199 | targetNamespace.map(n -> n.trim().equals(primary.getMetadata().getNamespace().trim()))
|
202 | 200 | .orElse(true);
|
203 | 201 |
|
204 |
| - var dr = createDependentResource(spec, leafDependent, resourceInSameNamespaceAsPrimary); |
| 202 | + var name = genericTemplateHandler.processTemplate(Utils.getName(spec), primary, false, context); |
| 203 | + var dr = createDependentResource(name, spec, leafDependent, resourceInSameNamespaceAsPrimary, |
| 204 | + targetNamespace.orElse(null)); |
205 | 205 | var gvk = dr.getGroupVersionKind();
|
206 | 206 |
|
207 |
| - if (!(dr instanceof BulkDependentResource<?, ?>)) { |
208 |
| - dr.setResourceDiscriminator(new GenericResourceDiscriminator(dr.getGroupVersionKind(), |
209 |
| - genericTemplateHandler.processTemplate(Utils.getName(spec), primary, false, context), |
210 |
| - targetNamespace.orElse(null))); |
211 |
| - } |
212 |
| - |
213 | 207 | var es = informerRegister.registerInformer(context, gvk, primary);
|
214 |
| - dr.configureWith(es); |
| 208 | + dr.setEventSource(es); |
215 | 209 |
|
216 |
| - builder.addDependentResource(dr); |
217 |
| - spec.getDependsOn().forEach(s -> builder.dependsOn(genericDependentResourceMap.get(s))); |
218 |
| - // if a resources does not depend on another there is no reason to add cleanup condition |
| 210 | + var nodeBuilder = builder.addDependentResourceAndConfigure(dr); |
| 211 | + spec.getDependsOn().forEach(s -> nodeBuilder.dependsOn(genericDependentResourceMap.get(s))); |
| 212 | + // if resources do not depend on another, there is no reason to add cleanup condition |
219 | 213 | if (!spec.getDependsOn().isEmpty()) {
|
220 |
| - builder.withDeletePostcondition(deletePostCondition); |
| 214 | + nodeBuilder.withDeletePostcondition(deletePostCondition); |
221 | 215 | }
|
222 | 216 | genericDependentResourceMap.put(spec.getName(), dr);
|
223 | 217 |
|
224 | 218 | Optional.ofNullable(spec.getReadyPostCondition())
|
225 |
| - .ifPresent(c -> builder.withReadyPostcondition(toCondition(c))); |
| 219 | + .ifPresent(c -> nodeBuilder.withReadyPostcondition(toCondition(c))); |
226 | 220 | Optional.ofNullable(spec.getCondition())
|
227 |
| - .ifPresent(c -> builder.withReconcilePrecondition(toCondition(c))); |
| 221 | + .ifPresent(c -> nodeBuilder.withReconcilePrecondition(toCondition(c))); |
228 | 222 | }
|
229 | 223 |
|
230 |
| - private GenericDependentResource createDependentResource(DependentResourceSpec spec, |
231 |
| - boolean leafDependent, Boolean resourceInSameNamespaceAsPrimary) { |
| 224 | + private GenericDependentResource createDependentResource(String name, DependentResourceSpec spec, |
| 225 | + boolean leafDependent, Boolean resourceInSameNamespaceAsPrimary, String namespace) { |
232 | 226 |
|
233 | 227 | if (leafDependent && resourceInSameNamespaceAsPrimary && !spec.isClusterScoped()) {
|
234 | 228 | return spec.getResourceTemplate() != null
|
235 | 229 | ? spec.getBulk()
|
236 | 230 | ? new GCGenericBulkDependentResource(genericTemplateHandler,
|
237 | 231 | spec.getResourceTemplate(),
|
238 |
| - spec.getName(), |
| 232 | + name, |
239 | 233 | spec.isClusterScoped(), spec.getMatcher())
|
240 | 234 | : new GCGenericDependentResource(genericTemplateHandler, spec.getResourceTemplate(),
|
241 |
| - spec.getName(), |
| 235 | + name, namespace, |
242 | 236 | spec.isClusterScoped(), spec.getMatcher())
|
243 | 237 | : new GCGenericDependentResource(genericTemplateHandler, spec.getResource(),
|
244 |
| - spec.getName(), |
| 238 | + name, namespace, |
245 | 239 | spec.isClusterScoped(), spec.getMatcher());
|
246 | 240 | } else {
|
247 | 241 | return spec.getResourceTemplate() != null
|
248 | 242 | ? new GenericDependentResource(genericTemplateHandler,
|
249 |
| - spec.getResourceTemplate(), spec.getName(), spec.isClusterScoped(), |
| 243 | + spec.getResourceTemplate(), name, namespace, spec.isClusterScoped(), |
250 | 244 | spec.getMatcher())
|
251 | 245 | : new GenericDependentResource(genericTemplateHandler,
|
252 |
| - spec.getResource(), spec.getName(), spec.isClusterScoped(), spec.getMatcher()); |
| 246 | + spec.getResource(), name, namespace, spec.isClusterScoped(), spec.getMatcher()); |
253 | 247 | }
|
254 | 248 | }
|
255 | 249 |
|
|
0 commit comments