Skip to content

Commit

Permalink
#221: Continue cancelled handling for AppDefinitions
Browse files Browse the repository at this point in the history
Adds support to the operator to handle AppDefinitions that are in
HANDLING state. This happens when the operator was unexpectedly shut
down while handling the AppDefinition before.

No logic changes in creating Kubernetes resources are necessary because
the handling was already idempotent.

Contributed on behalf of STMicroelectronics
  • Loading branch information
lucas-koehler committed Aug 31, 2023
1 parent a6b6388 commit 5b35057
Showing 1 changed file with 19 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,32 +71,34 @@ protected boolean doAppDefinitionAdded(AppDefinition appDefinition, String corre
+ appDefinition));
return true;
}
if (OperatorStatus.HANDLING.equals(operatorStatus)) {
// TODO We should not return but continue where we left off.
LOGGER.warn(formatLogMessage(correlationId,
"AppDefinition handling was unexpectedly interrupted before. AppDefinition is skipped now and its status is set to ERROR. AppDefinition: "
+ appDefinition));
client.appDefinitions().updateStatus(correlationId, appDefinition, s -> {
s.setOperatorStatus(OperatorStatus.ERROR);
s.setOperatorMessage("Handling was unexpectedly interrupted before. CorrelationId: " + correlationId);
});
return false;
}
if (OperatorStatus.ERROR.equals(operatorStatus)) {
LOGGER.warn(formatLogMessage(correlationId,
"AppDefinition could not be handled before and is skipped now. AppDefinition: " + appDefinition));
return false;
}

// Set app definition status to being handled
client.appDefinitions().updateStatus(correlationId, appDefinition, s -> {
s.setOperatorStatus(OperatorStatus.HANDLING);
});
if (OperatorStatus.HANDLING.equals(operatorStatus)) {
LOGGER.debug(formatLogMessage(correlationId,
"AppDefinition handling was unexpectedly interrupted before and is continued now. AppDefinition: "
+ appDefinition));
client.appDefinitions().updateStatus(correlationId, appDefinition, s -> {
// Reset status message
s.setOperatorMessage("");
});
} else {
// Set app definition status to being handled
client.appDefinitions().updateStatus(correlationId, appDefinition, s -> {
s.setOperatorStatus(OperatorStatus.HANDLING);
});
}

AppDefinitionSpec spec = appDefinition.getSpec();
String appDefinitionResourceName = appDefinition.getMetadata().getName();

/* Create ingress if not existing */
/*
* Create ingress if not existing. As this operation is idempotent, no special
* handling is necessary if the resource was already in HANDLING state before
* this handler.
*/
if (!TheiaCloudIngressUtil.checkForExistingIngressAndAddOwnerReferencesIfMissing(client.kubernetes(),
client.namespace(), appDefinition, correlationId)) {
LOGGER.error(formatLogMessage(correlationId,
Expand Down

0 comments on commit 5b35057

Please sign in to comment.