Skip to content

Commit

Permalink
AppEngine draft
Browse files Browse the repository at this point in the history
  • Loading branch information
w-caffiero-entando committed Mar 4, 2024
1 parent 62bef46 commit 1d4efdd
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -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<EnvVar> environmentVariablesAppEngine;
private List<EnvVar> environmentVariablesComponentManager;
private List<EnvVar> environmentVariablesSso;

public boolean isTlsEnabled() {
return tlsEnabled;
}
Expand All @@ -21,4 +28,27 @@ public void setEcrPostInitConfiguration(String ecrPostInitConfiguration) {
this.ecrPostInitConfiguration = ecrPostInitConfiguration;
}

public List<EnvVar> getEnvironmentVariablesAppEngine() {
return environmentVariablesAppEngine;
}

public void setEnvironmentVariablesAppEngine(List<EnvVar> environmentVariablesAppEngine) {
this.environmentVariablesAppEngine = environmentVariablesAppEngine;
}

public List<EnvVar> getEnvironmentVariablesComponentManager() {
return environmentVariablesComponentManager;
}

public void setEnvironmentVariablesComponentManager(List<EnvVar> environmentVariablesComponentManager) {
this.environmentVariablesComponentManager = environmentVariablesComponentManager;
}

public List<EnvVar> getEnvironmentVariablesSso() {
return environmentVariablesSso;
}

public void setEnvironmentVariablesSso(List<EnvVar> environmentVariablesSso) {
this.environmentVariablesSso = environmentVariablesSso;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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(""));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,21 +134,8 @@ public String getNameQualifier() {

@Override
public List<EnvVar> getEnvironmentVariables() {
List<EnvVar> 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;
}

Expand Down Expand Up @@ -190,6 +177,26 @@ public Optional<DatabasePopulator> getDatabasePopulator() {
return Optional.of(new EntandoAppDatabasePopulator(this));
}

protected List<EnvVar> getBaseEnvironmentVariables() {
List<EnvVar> 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<EnvVar> vars, int schemaIndex, String varNamePrefix) {
if (dbmsVendor == DbmsVendor.EMBEDDED) {
vars.add(new EnvVar(varNamePrefix + "DRIVER", "derby", null));
Expand Down Expand Up @@ -266,7 +273,7 @@ public List<String> getCommand() {

@Override
public List<EnvVar> getEnvironmentVariables() {
return entandoAppDeployableContainer.getDatabaseConnectionVariables();
return entandoAppDeployableContainer.getBaseEnvironmentVariables();
}

}
Expand Down

0 comments on commit 1d4efdd

Please sign in to comment.