Skip to content

Commit

Permalink
Merge pull request #71 from entando-k8s/ENG-4178_AppBuilder-menu-not-…
Browse files Browse the repository at this point in the history
…displayed-if-external-keycloak-is-used

ENG-4178 AppBuilder Menu is not displayed if an external keycloak is used
  • Loading branch information
entgigi authored Sep 15, 2022
2 parents 06305b3 + 137ce83 commit 347b916
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import org.entando.kubernetes.controller.app.ComponentManagerDeployableContainer.ComponentManagerCustomConfigFromOperator;
import org.entando.kubernetes.controller.spi.container.DeployableContainer;
import org.entando.kubernetes.controller.spi.deployable.DbAwareDeployable;
import org.entando.kubernetes.controller.spi.deployable.SsoAwareDeployable;
Expand All @@ -43,12 +44,12 @@ public ComponentManagerDeployable(EntandoApp entandoApp,
SsoConnectionInfo ssoConnectionInfo,
EntandoK8SService entandoK8SService,
DatabaseConnectionInfo databaseServiceResult,
SecretClient secretClient, String ecrPostinitConfiguration) {
SecretClient secretClient, ComponentManagerCustomConfigFromOperator customConfig) {
super(entandoApp);
this.ssoConnectionInfo = ssoConnectionInfo;
this.containers = Collections.singletonList(new ComponentManagerDeployableContainer(
entandoApp, ssoConnectionInfo, entandoK8SService, databaseServiceResult,
getSsoClientConfig(), secretClient, ecrPostinitConfiguration
getSsoClientConfig(), secretClient, customConfig
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import org.apache.commons.lang3.StringUtils;
import org.entando.kubernetes.controller.spi.common.EntandoOperatorConfigBase;
import org.entando.kubernetes.controller.spi.container.DatabaseSchemaConnectionInfo;
import org.entando.kubernetes.controller.spi.container.DbAwareContainer;
Expand All @@ -51,25 +52,26 @@ public class ComponentManagerDeployableContainer
private static final String DEDB = "dedb";
public static final String ECR_GIT_CONFIG_DIR = "/etc/ecr-git-config";
public static final String ENTANDO_ECR_POSTINIT = "ENTANDO_ECR_POSTINIT";
public static final String ENTANDO_APP_USE_TLS = "ENTANDO_APP_USE_TLS";
private final EntandoApp entandoApp;
private final SsoConnectionInfo keycloakConnectionConfig;
private final EntandoK8SService infrastructureConfig;
private final List<DatabaseSchemaConnectionInfo> databaseSchemaConnectionInfo;
private SsoClientConfig ssoClientConfig;
private final String ecrPostinitConfiguration;
private final ComponentManagerCustomConfigFromOperator customConfig;

public ComponentManagerDeployableContainer(
EntandoApp entandoApp,
SsoConnectionInfo keycloakConnectionConfig,
EntandoK8SService infrastructureConfig,
DatabaseConnectionInfo databaseServiceResult,
SsoClientConfig ssoClientConfig,
SecretClient secretClient, String ecrPostinitConfiguration) {
SecretClient secretClient, ComponentManagerCustomConfigFromOperator customConfig) {
this.entandoApp = entandoApp;
this.keycloakConnectionConfig = keycloakConnectionConfig;
this.infrastructureConfig = infrastructureConfig;
this.ssoClientConfig = ssoClientConfig;
this.ecrPostinitConfiguration = (ecrPostinitConfiguration != null) ? ecrPostinitConfiguration : "";
this.customConfig = customConfig;
this.databaseSchemaConnectionInfo = ofNullable(databaseServiceResult)
.map(dsr -> DbAwareContainer.buildDatabaseSchemaConnectionInfo(entandoApp, dsr,
Collections.singletonList(DEDB), secretClient))
Expand Down Expand Up @@ -106,9 +108,12 @@ public List<EnvVar> getEnvironmentVariables() {
List<EnvVar> vars = new ArrayList<>();
String entandoUrl = EntandoAppDeployableContainer.determineEntandoServiceBaseUrl(this.entandoApp);
vars.add(new EnvVar("ENTANDO_APP_NAME", entandoApp.getMetadata().getName(), null));
vars.add(new EnvVar("ENTANDO_APP_HOST_NAME", entandoApp.getSpec().getIngressHostName().orElse(""), null));
vars.add(new EnvVar(ENTANDO_APP_USE_TLS, "" + customConfig.isTlsEnabled(), null));
vars.add(new EnvVar("ENTANDO_URL", entandoUrl, null));
vars.add(new EnvVar("SERVER_PORT", String.valueOf(getPrimaryPort()), null));
List<String> ecrNamespacesToUse = ofNullable(entandoApp.getSpec().getComponentRepositoryNamespaces()).orElse(emptyList());
List<String> ecrNamespacesToUse = ofNullable(entandoApp.getSpec().getComponentRepositoryNamespaces()).orElse(
emptyList());
if (ecrNamespacesToUse.isEmpty()) {
ecrNamespacesToUse = lookupProperty(EntandoAppConfigProperty.ENTANDO_COMPONENT_REPOSITORY_NAMESPACES)
.map(s -> Arrays.asList(s.split(EntandoOperatorConfigBase.SEPERATOR_PATTERN)))
Expand All @@ -118,15 +123,20 @@ public List<EnvVar> getEnvironmentVariables() {
vars.add(new EnvVar("ENTANDO_COMPONENT_REPOSITORY_NAMESPACES", String.join(",", ecrNamespacesToUse), null));
}
vars.add(
new EnvVar("ENTANDO_K8S_SERVICE_URL", format("http://%s:%s/k8s", infrastructureConfig.getInternalServiceHostname(),
infrastructureConfig.getService().getSpec().getPorts().get(0).getPort()), null));
new EnvVar("ENTANDO_K8S_SERVICE_URL",
format("http://%s:%s/k8s", infrastructureConfig.getInternalServiceHostname(),
infrastructureConfig.getService().getSpec().getPorts().get(0).getPort()), null));
//The ssh files will be copied to /opt/.ssh and chmod to 400. This can only happen at runtime because Openshift generates a
// random userid
entandoApp.getSpec().getEcrGitSshSecretName().ifPresent(s -> vars.add(new EnvVar("GIT_SSH_COMMAND", "ssh "
+ "-o UserKnownHostsFile=/opt/.ssh/known_hosts "
+ "-i /opt/.ssh/id_rsa "
+ "-o IdentitiesOnly=yes", null)));
vars.add(new EnvVar(ENTANDO_ECR_POSTINIT, ecrPostinitConfiguration, null));

if (StringUtils.isNotBlank(customConfig.getEcrPostInitConfiguration())) {
vars.add(new EnvVar(ENTANDO_ECR_POSTINIT, customConfig.getEcrPostInitConfiguration(), null));
}

return vars;
}

Expand Down Expand Up @@ -192,4 +202,25 @@ public List<EnvVar> getEnvironmentVariableOverrides() {
return entandoApp.getSpec().getEnvironmentVariables();
}

public static class ComponentManagerCustomConfigFromOperator {

private String ecrPostInitConfiguration;
private boolean tlsEnabled;

public boolean isTlsEnabled() {
return tlsEnabled;
}

public void setTlsEnabled(boolean tlsEnabled) {
this.tlsEnabled = tlsEnabled;
}

public String getEcrPostInitConfiguration() {
return ecrPostInitConfiguration;
}

public void setEcrPostInitConfiguration(String ecrPostInitConfiguration) {
this.ecrPostInitConfiguration = ecrPostInitConfiguration;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.inject.Inject;
import org.apache.commons.lang3.StringUtils;
import org.entando.kubernetes.controller.app.ComponentManagerDeployableContainer.ComponentManagerCustomConfigFromOperator;
import org.entando.kubernetes.controller.spi.capability.CapabilityProvider;
import org.entando.kubernetes.controller.spi.capability.CapabilityProvisioningResult;
import org.entando.kubernetes.controller.spi.client.KubernetesClientForControllers;
Expand All @@ -51,6 +53,7 @@
import org.entando.kubernetes.controller.spi.result.DatabaseConnectionInfo;
import org.entando.kubernetes.controller.support.client.SimpleK8SClient;
import org.entando.kubernetes.controller.support.client.impl.DefaultSimpleK8SClient;
import org.entando.kubernetes.controller.support.common.EntandoOperatorConfigProperty;
import org.entando.kubernetes.model.app.EntandoApp;
import org.entando.kubernetes.model.capability.CapabilityRequirementBuilder;
import org.entando.kubernetes.model.capability.CapabilityScope;
Expand Down Expand Up @@ -128,20 +131,29 @@ public void run() {
} catch (Exception e) {
attachControllerFailure(e, EntandoAppController.class, NameUtils.MAIN_QUALIFIER);
}
entandoApp.get().getStatus().findFailedServerStatus().flatMap(ServerStatus::getEntandoControllerFailure).ifPresent(s -> {
throw new CommandLine.ExecutionException(new CommandLine(this), s.getDetailMessage());
});
entandoApp.get().getStatus().findFailedServerStatus().flatMap(ServerStatus::getEntandoControllerFailure)
.ifPresent(s -> {
throw new CommandLine.ExecutionException(new CommandLine(this), s.getDetailMessage());
});
}

private String readEntandoAppCustomConfig() {
return lookupProperty(KEY_ENTANDO_ECR_POSTINIT_CONFIGURATION).orElse("");
private ComponentManagerCustomConfigFromOperator readEntandoAppCustomConfig() {
ComponentManagerCustomConfigFromOperator customConfig = new ComponentManagerCustomConfigFromOperator();
customConfig.setEcrPostInitConfiguration(lookupProperty(KEY_ENTANDO_ECR_POSTINIT_CONFIGURATION).orElse(""));
customConfig.setTlsEnabled(StringUtils.isNotBlank(
lookupProperty(EntandoOperatorConfigProperty.ENTANDO_TLS_SECRET_NAME.getJvmSystemProperty()).orElseGet(
() -> entandoApp.get().getTlsSecretName().orElse(""))
));

return customConfig;
}

private int calculateDbAwareTimeout() {
final int timeoutForDbAware;
if (requiresDbmsService(EntandoAppHelper.determineDbmsVendor(entandoApp.get()))) {
timeoutForDbAware =
EntandoOperatorSpiConfig.getPodCompletionTimeoutSeconds() + EntandoOperatorSpiConfig.getPodReadinessTimeoutSeconds();
EntandoOperatorSpiConfig.getPodCompletionTimeoutSeconds()
+ EntandoOperatorSpiConfig.getPodReadinessTimeoutSeconds();
} else {
timeoutForDbAware = EntandoOperatorSpiConfig.getPodReadinessTimeoutSeconds();
}
Expand Down

0 comments on commit 347b916

Please sign in to comment.