Search in sources :

Example 16 with EnvVarBuilder

use of io.fabric8.kubernetes.api.model.EnvVarBuilder in project keycloak by keycloak.

the class KeycloakDeployment method createBaseDeployment.

private Deployment createBaseDeployment() {
    var is = this.getClass().getResourceAsStream("/base-keycloak-deployment.yaml");
    Deployment baseDeployment = Serialization.unmarshal(is, Deployment.class);
    baseDeployment.getMetadata().setName(getName());
    baseDeployment.getMetadata().setNamespace(getNamespace());
    baseDeployment.getSpec().getSelector().setMatchLabels(Constants.DEFAULT_LABELS);
    baseDeployment.getSpec().setReplicas(keycloakCR.getSpec().getInstances());
    baseDeployment.getSpec().getTemplate().getMetadata().setLabels(Constants.DEFAULT_LABELS);
    Container container = baseDeployment.getSpec().getTemplate().getSpec().getContainers().get(0);
    container.setImage(Optional.ofNullable(keycloakCR.getSpec().getImage()).orElse(config.keycloak().image()));
    var serverConfig = new HashMap<>(Constants.DEFAULT_DIST_CONFIG);
    if (keycloakCR.getSpec().getServerConfiguration() != null) {
        serverConfig.putAll(keycloakCR.getSpec().getServerConfiguration());
    }
    container.setImagePullPolicy(config.keycloak().imagePullPolicy());
    container.setEnv(serverConfig.entrySet().stream().map(e -> new EnvVarBuilder().withName(e.getKey()).withValue(e.getValue()).build()).collect(Collectors.toList()));
    addInitContainer(baseDeployment, keycloakCR.getSpec().getExtensions());
    mergePodTemplate(baseDeployment.getSpec().getTemplate());
    return baseDeployment;
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) HashMap(java.util.HashMap) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) EnvVarBuilder(io.fabric8.kubernetes.api.model.EnvVarBuilder)

Aggregations

EnvVarBuilder (io.fabric8.kubernetes.api.model.EnvVarBuilder)16 EnvVar (io.fabric8.kubernetes.api.model.EnvVar)8 Test (org.junit.Test)7 Container (io.fabric8.kubernetes.api.model.Container)4 ArrayList (java.util.ArrayList)3 ContainerBuilder (io.fabric8.kubernetes.api.model.ContainerBuilder)2 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)2 VolumeMount (io.fabric8.kubernetes.api.model.VolumeMount)2 VolumeMountBuilder (io.fabric8.kubernetes.api.model.VolumeMountBuilder)2 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)2 DeploymentBuilder (io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder)2 HashMap (java.util.HashMap)2 CustomSizing (com.netflix.spinnaker.halyard.config.model.v1.node.CustomSizing)1 DeploymentEnvironment (com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentEnvironment)1 ConfigSource (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ConfigSource)1 ServiceSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings)1 KubernetesContainerClient (de.zalando.ep.zalenium.container.kubernetes.KubernetesContainerClient)1 ContainerPortBuilder (io.fabric8.kubernetes.api.model.ContainerPortBuilder)1 HostAlias (io.fabric8.kubernetes.api.model.HostAlias)1 HostAliasBuilder (io.fabric8.kubernetes.api.model.HostAliasBuilder)1