-
Notifications
You must be signed in to change notification settings - Fork 222
Description
When the AbstractDependentResource
already exist prior to creating the primary resource, the reconciler should know about it to be able to handle the situation and update the primary resource status accordingly.
For eg., the reconciler may set a CONFLICT status to let the user knows the observed spec conflict with an existing resource.
I have pushed a commit to demonstrate the use case on mysql-schema sample : https://github.com/scrocquesel/java-operator-sdk/tree/schema-already-exist
Be aware that, on startup, when match
is true, the dependent resource alone cannot tell if there is a possible conflict or if it is what it should be from a prior reconciliation, actual and desired just match. Only the reconciler can tell apart if it saves the previous observed state.
For eg.
return context.get(BUILT_SCHEMA, Schema.class).map(s -> {
updateStatusPojo(schema, context.getMandatory(MYSQL_SECRET_NAME, String.class),
context.getMandatory(MYSQL_SECRET_USERNAME, String.class));
log.info("Schema {} created - updating CR status", schema.getMetadata().getName());
return UpdateControl.updateStatus(schema);
}).orElseGet(() -> context.get(EXISTING_SCHEMA, Schema.class).map(s -> {
if (schema.getStatus().getStatus() != "CREATED")
schema.getStatus().setStatus("CONFLICT");
log.info("Schema {} already exists - updating CR status", schema.getMetadata().getName());
return UpdateControl.updateStatus(schema);
}).orElse(UpdateControl.noUpdate()));