From 5b350572749cb433531d8c64ceb18d8c6661fa2f Mon Sep 17 00:00:00 2001 From: Lucas Koehler Date: Thu, 31 Aug 2023 11:03:06 +0200 Subject: [PATCH] #221: Continue cancelled handling for AppDefinitions 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 --- .../impl/LazyStartAppDefinitionHandler.java | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/java/operator/org.eclipse.theia.cloud.operator/src/main/java/org/eclipse/theia/cloud/operator/handler/impl/LazyStartAppDefinitionHandler.java b/java/operator/org.eclipse.theia.cloud.operator/src/main/java/org/eclipse/theia/cloud/operator/handler/impl/LazyStartAppDefinitionHandler.java index 224dbc4c..555c79da 100644 --- a/java/operator/org.eclipse.theia.cloud.operator/src/main/java/org/eclipse/theia/cloud/operator/handler/impl/LazyStartAppDefinitionHandler.java +++ b/java/operator/org.eclipse.theia.cloud.operator/src/main/java/org/eclipse/theia/cloud/operator/handler/impl/LazyStartAppDefinitionHandler.java @@ -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,