diff --git a/src/main/java/org/entando/kubernetes/controller/app/CustomConfigFromOperator.java b/src/main/java/org/entando/kubernetes/controller/app/CustomConfigFromOperator.java index 21e6317..e68215a 100644 --- a/src/main/java/org/entando/kubernetes/controller/app/CustomConfigFromOperator.java +++ b/src/main/java/org/entando/kubernetes/controller/app/CustomConfigFromOperator.java @@ -1,10 +1,17 @@ package org.entando.kubernetes.controller.app; +import io.fabric8.kubernetes.api.model.EnvVar; +import java.util.List; + public class CustomConfigFromOperator { private String ecrPostInitConfiguration; private boolean tlsEnabled; + private List environmentVariablesAppEngine; + private List environmentVariablesComponentManager; + private List environmentVariablesSso; + public boolean isTlsEnabled() { return tlsEnabled; } @@ -21,4 +28,27 @@ public void setEcrPostInitConfiguration(String ecrPostInitConfiguration) { this.ecrPostInitConfiguration = ecrPostInitConfiguration; } + public List getEnvironmentVariablesAppEngine() { + return environmentVariablesAppEngine; + } + + public void setEnvironmentVariablesAppEngine(List environmentVariablesAppEngine) { + this.environmentVariablesAppEngine = environmentVariablesAppEngine; + } + + public List getEnvironmentVariablesComponentManager() { + return environmentVariablesComponentManager; + } + + public void setEnvironmentVariablesComponentManager(List environmentVariablesComponentManager) { + this.environmentVariablesComponentManager = environmentVariablesComponentManager; + } + + public List getEnvironmentVariablesSso() { + return environmentVariablesSso; + } + + public void setEnvironmentVariablesSso(List environmentVariablesSso) { + this.environmentVariablesSso = environmentVariablesSso; + } } diff --git a/src/main/java/org/entando/kubernetes/controller/app/EntandoAppController.java b/src/main/java/org/entando/kubernetes/controller/app/EntandoAppController.java index 04815db..79abaf5 100644 --- a/src/main/java/org/entando/kubernetes/controller/app/EntandoAppController.java +++ b/src/main/java/org/entando/kubernetes/controller/app/EntandoAppController.java @@ -45,6 +45,7 @@ import org.entando.kubernetes.controller.spi.common.EntandoOperatorSpiConfig; import org.entando.kubernetes.controller.spi.common.NameUtils; import org.entando.kubernetes.controller.spi.common.ResourceUtils; +import org.entando.kubernetes.controller.spi.container.DeployableContainer; import org.entando.kubernetes.controller.spi.container.ProvidedDatabaseCapability; import org.entando.kubernetes.controller.spi.container.ProvidedSsoCapability; import org.entando.kubernetes.controller.spi.deployable.IngressingDeployable; @@ -106,28 +107,24 @@ public void run() { (EntandoApp) k8sClientForControllers.resolveCustomResourceToProcess(Collections.singletonList(EntandoApp.class))); try { entandoApp.set(k8sClientForControllers.deploymentStarted(entandoApp.get())); + + // PRE this.createDefaultLimitRange(); + + // REQUIREMENTS final DatabaseConnectionInfo dbConnectionInfo = provideDatabaseIfRequired(); final SsoConnectionInfo ssoConnectionInfo = provideSso(); - final int timeoutForDbAware = calculateDbAwareTimeout(); + + // SETTINGS final CustomConfigFromOperator customConfig = readEntandoAppCustomConfig(); - queueDeployable(new EntandoAppServerDeployable(entandoApp.get(), ssoConnectionInfo, dbConnectionInfo, - simpleK8SClient.secrets(), customConfig), timeoutForDbAware); + final int timeoutForDbAware = calculateDbAwareTimeout(); final int timeoutForNonDbAware = EntandoOperatorSpiConfig.getPodReadinessTimeoutSeconds(); - queueDeployable(new AppBuilderDeployable(entandoApp.get()), timeoutForNonDbAware); - EntandoK8SService k8sService = new EntandoK8SService( - k8sClientForControllers.loadControllerService(EntandoAppController.ENTANDO_K8S_SERVICE)); - queueDeployable( - new ComponentManagerDeployable(entandoApp.get(), ssoConnectionInfo, k8sService, dbConnectionInfo, - simpleK8SClient.secrets(), customConfig), - timeoutForDbAware); - executor.shutdown(); - final int totalTimeout = timeoutForDbAware * 2 + timeoutForNonDbAware; - if (!executor.awaitTermination(totalTimeout, TimeUnit.SECONDS)) { - throw new TimeoutException( - format("Could not complete deployment of EntandoApp in %s seconds", totalTimeout)); - } - entandoApp.updateAndGet(k8sClientForControllers::deploymentEnded); + + // MODULES + deployAppEngine(ssoConnectionInfo, dbConnectionInfo, customConfig, timeoutForDbAware); + deployAppBuilder(timeoutForNonDbAware); + deployComponentManager(ssoConnectionInfo, dbConnectionInfo, customConfig, timeoutForDbAware); + waitCompletionAndFinalized(timeoutForDbAware, timeoutForNonDbAware); } catch (Exception e) { attachControllerFailure(e, EntandoAppController.class, NameUtils.MAIN_QUALIFIER); } @@ -137,6 +134,42 @@ public void run() { }); } + private void waitCompletionAndFinalized(int timeoutForDbAware, int timeoutForNonDbAware) throws InterruptedException, TimeoutException { + executor.shutdown(); + final int totalTimeout = timeoutForDbAware * 2 + timeoutForNonDbAware; + if (!executor.awaitTermination(totalTimeout, TimeUnit.SECONDS)) { + throw new TimeoutException( + format("Could not complete deployment of EntandoApp in %s seconds", totalTimeout)); + } + entandoApp.updateAndGet(k8sClientForControllers::deploymentEnded); + } + + private void deployAppBuilder(int timeoutForNonDbAware) { + queueDeployable(new AppBuilderDeployable(entandoApp.get()), timeoutForNonDbAware); + } + + private void deployComponentManager(SsoConnectionInfo ssoConnectionInfo, DatabaseConnectionInfo dbConnectionInfo, + CustomConfigFromOperator customConfig, int timeoutForDbAware) { + EntandoK8SService k8sService = new EntandoK8SService( + k8sClientForControllers.loadControllerService(EntandoAppController.ENTANDO_K8S_SERVICE)); + queueDeployable( + new ComponentManagerDeployable(entandoApp.get(), ssoConnectionInfo, k8sService, dbConnectionInfo, + simpleK8SClient.secrets(), customConfig), + timeoutForDbAware); + } + + private void deployAppEngine( + SsoConnectionInfo ssoConnectionInfo, DatabaseConnectionInfo dbConnectionInfo, + CustomConfigFromOperator customConfig, int timeoutForDbAware + ) { + var deployable = new EntandoAppServerDeployable( + entandoApp.get(), ssoConnectionInfo, dbConnectionInfo, + simpleK8SClient.secrets(), customConfig + ); + + queueDeployable(deployable, timeoutForDbAware); + } + private CustomConfigFromOperator readEntandoAppCustomConfig() { CustomConfigFromOperator customConfig = new CustomConfigFromOperator(); customConfig.setEcrPostInitConfiguration(lookupProperty(KEY_ENTANDO_ECR_POSTINIT_CONFIGURATION).orElse("")); diff --git a/src/main/java/org/entando/kubernetes/controller/app/EntandoAppDeployableContainer.java b/src/main/java/org/entando/kubernetes/controller/app/EntandoAppDeployableContainer.java index 8795079..5d30c6d 100644 --- a/src/main/java/org/entando/kubernetes/controller/app/EntandoAppDeployableContainer.java +++ b/src/main/java/org/entando/kubernetes/controller/app/EntandoAppDeployableContainer.java @@ -134,21 +134,8 @@ public String getNameQualifier() { @Override public List getEnvironmentVariables() { - List vars = new ArrayList<>(); - vars.add(new EnvVar("JGROUPS_CLUSTER_PASSWORD", SecretUtils.randomAlphanumeric(10), null)); - vars.add(new EnvVar("JGROUPS_JOIN_TIMEOUT", "3000", null)); - String labelExpression = LabelNames.DEPLOYMENT.getName() + "=" + entandoApp.getMetadata().getName() + "-" - + NameUtils.DEFAULT_SERVER_QUALIFIER; - if (determineStandardImage() == JeeServer.EAP) { - vars.add(new EnvVar("JGROUPS_PING_PROTOCOL", "openshift.KUBE_PING", null)); - vars.add(new EnvVar("OPENSHIFT_KUBE_PING_NAMESPACE", entandoApp.getMetadata().getNamespace(), null)); - vars.add(new EnvVar("OPENSHIFT_KUBE_PING_LABELS", labelExpression, null)); - } else { - vars.add(new EnvVar("KUBERNETES_NAMESPACE", entandoApp.getMetadata().getNamespace(), null)); - vars.add(new EnvVar("KUBERNETES_LABELS", labelExpression, null)); - } - vars.add(new EnvVar("ENTANDO_WEB_CONTEXT", getWebContextPath(), null)); - vars.add(new EnvVar(ENTANDO_APP_USE_TLS, "" + customConfig.isTlsEnabled(), null)); + var vars = getBaseEnvironmentVariables(); + vars.addAll(customConfig.getEnvironmentVariablesAppEngine()); return vars; } @@ -190,6 +177,26 @@ public Optional getDatabasePopulator() { return Optional.of(new EntandoAppDatabasePopulator(this)); } + protected List getBaseEnvironmentVariables() { + List vars = new ArrayList<>(); + vars.add(new EnvVar("JGROUPS_CLUSTER_PASSWORD", SecretUtils.randomAlphanumeric(10), null)); + vars.add(new EnvVar("JGROUPS_JOIN_TIMEOUT", "3000", null)); + String labelExpression = LabelNames.DEPLOYMENT.getName() + "=" + entandoApp.getMetadata().getName() + "-" + + NameUtils.DEFAULT_SERVER_QUALIFIER; + if (determineStandardImage() == JeeServer.EAP) { + vars.add(new EnvVar("JGROUPS_PING_PROTOCOL", "openshift.KUBE_PING", null)); + vars.add(new EnvVar("OPENSHIFT_KUBE_PING_NAMESPACE", entandoApp.getMetadata().getNamespace(), null)); + vars.add(new EnvVar("OPENSHIFT_KUBE_PING_LABELS", labelExpression, null)); + } else { + vars.add(new EnvVar("KUBERNETES_NAMESPACE", entandoApp.getMetadata().getNamespace(), null)); + vars.add(new EnvVar("KUBERNETES_LABELS", labelExpression, null)); + } + vars.add(new EnvVar("ENTANDO_WEB_CONTEXT", getWebContextPath(), null)); + vars.add(new EnvVar(ENTANDO_APP_USE_TLS, "" + customConfig.isTlsEnabled(), null)); + + return vars; + } + private void addEntandoDbConnectionVars(List vars, int schemaIndex, String varNamePrefix) { if (dbmsVendor == DbmsVendor.EMBEDDED) { vars.add(new EnvVar(varNamePrefix + "DRIVER", "derby", null)); @@ -266,7 +273,7 @@ public List getCommand() { @Override public List getEnvironmentVariables() { - return entandoAppDeployableContainer.getDatabaseConnectionVariables(); + return entandoAppDeployableContainer.getBaseEnvironmentVariables(); } }