Search in sources :

Example 36 with EnvVar

use of io.fabric8.kubernetes.api.model.EnvVar in project fabric8-maven-plugin by fabric8io.

the class EnvVarHandlerTest method envVarHandlerWithoutNameTest.

@Test
public void envVarHandlerWithoutNameTest() {
    // Environment Variable without name in Config
    EnvVar var1 = new EnvVarBuilder().withName(null).withValue("OK").build();
    env.clear();
    env.put(null, var1.getValue());
    EnvVarHandler envVarHandler = new EnvVarHandler(project);
    new Expectations() {

        {
            externalEnvVarHandler.getExportedEnvironmentVariables(project, env);
            ret.put(null, "OK");
            result = ret;
        }
    };
    List<EnvVar> envVars = envVarHandler.getEnvironmentVariables(env);
    assertNotNull(envVars);
    assertEquals(1, envVars.size());
    assertTrue(!envVars.contains(var1));
    assertEquals("KUBERNETES_NAMESPACE", envVars.get(0).getName());
    assertTrue(envVars.contains(var4));
}
Also used : Expectations(mockit.Expectations) ExternalEnvVarHandler(io.fabric8.maven.core.extenvvar.ExternalEnvVarHandler) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) EnvVarBuilder(io.fabric8.kubernetes.api.model.EnvVarBuilder) Test(org.junit.Test)

Example 37 with EnvVar

use of io.fabric8.kubernetes.api.model.EnvVar in project fabric8-maven-plugin by fabric8io.

the class EnvVarHandlerTest method emptyEnvVarHandlerTest.

@Test
public void emptyEnvVarHandlerTest() {
    // Empty Environment Variable in Config
    EnvVarHandler envVarHandler = new EnvVarHandler(project);
    env.clear();
    new Expectations() {

        {
            externalEnvVarHandler.getExportedEnvironmentVariables(project, env);
            ret.putAll(env);
            result = ret;
        }
    };
    List<EnvVar> envVars = envVarHandler.getEnvironmentVariables(env);
    assertNotNull(envVars);
    assertEquals(1, envVars.size());
    assertEquals("KUBERNETES_NAMESPACE", envVars.get(0).getName());
    assertTrue(envVars.contains(var4));
}
Also used : Expectations(mockit.Expectations) ExternalEnvVarHandler(io.fabric8.maven.core.extenvvar.ExternalEnvVarHandler) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) Test(org.junit.Test)

Example 38 with EnvVar

use of io.fabric8.kubernetes.api.model.EnvVar in project fabric8-maven-plugin by fabric8io.

the class EnvVarHandler method convertToEnvVarMap.

// ==============================================================================================
private Map<String, EnvVar> convertToEnvVarMap(Map<String, String> envs) {
    Map<String, EnvVar> envMap = new HashMap<>();
    for (Map.Entry<String, String> entry : envs.entrySet()) {
        String name = entry.getKey();
        String value = entry.getValue();
        if (name != null) {
            EnvVar env = new EnvVarBuilder().withName(name).withValue(value).build();
            envMap.put(name, env);
        }
    }
    return envMap;
}
Also used : EnvVar(io.fabric8.kubernetes.api.model.EnvVar) EnvVarBuilder(io.fabric8.kubernetes.api.model.EnvVarBuilder)

Example 39 with EnvVar

use of io.fabric8.kubernetes.api.model.EnvVar in project halyard by spinnaker.

the class ResourceBuilder method buildContainer.

static Container buildContainer(String name, ServiceSettings settings, List<ConfigSource> configSources, DeploymentEnvironment deploymentEnvironment) {
    int port = settings.getPort();
    List<EnvVar> envVars = settings.getEnv().entrySet().stream().map(e -> {
        EnvVarBuilder envVarBuilder = new EnvVarBuilder();
        return envVarBuilder.withName(e.getKey()).withValue(e.getValue()).build();
    }).collect(Collectors.toList());
    configSources.forEach(c -> {
        c.getEnv().entrySet().forEach(envEntry -> {
            EnvVarBuilder envVarBuilder = new EnvVarBuilder();
            envVars.add(envVarBuilder.withName(envEntry.getKey()).withValue(envEntry.getValue()).build());
        });
    });
    ProbeBuilder probeBuilder = new ProbeBuilder();
    if (settings.getHealthEndpoint() != null) {
        probeBuilder = probeBuilder.withNewHttpGet().withNewPort(port).withPath(settings.getHealthEndpoint()).endHttpGet();
    } else {
        probeBuilder = probeBuilder.withNewTcpSocket().withNewPort().withIntVal(port).endPort().endTcpSocket();
    }
    List<VolumeMount> volumeMounts = configSources.stream().map(c -> {
        return new VolumeMountBuilder().withMountPath(c.getMountPath()).withName(c.getId()).build();
    }).collect(Collectors.toList());
    ContainerBuilder containerBuilder = new ContainerBuilder();
    containerBuilder = containerBuilder.withName(name).withImage(settings.getArtifactId()).withPorts(new ContainerPortBuilder().withContainerPort(port).build()).withVolumeMounts(volumeMounts).withEnv(envVars).withReadinessProbe(probeBuilder.build()).withResources(buildResourceRequirements(name, deploymentEnvironment));
    return containerBuilder.build();
}
Also used : DeploymentEnvironment(com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentEnvironment) VolumeMount(io.fabric8.kubernetes.api.model.VolumeMount) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) Container(io.fabric8.kubernetes.api.model.Container) CustomSizing(com.netflix.spinnaker.halyard.config.model.v1.node.CustomSizing) ResourceRequirementsBuilder(io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder) EnvVarBuilder(io.fabric8.kubernetes.api.model.EnvVarBuilder) QuantityBuilder(io.fabric8.kubernetes.api.model.QuantityBuilder) Collectors(java.util.stream.Collectors) List(java.util.List) ResourceRequirements(io.fabric8.kubernetes.api.model.ResourceRequirements) VolumeMountBuilder(io.fabric8.kubernetes.api.model.VolumeMountBuilder) Map(java.util.Map) ConfigSource(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ConfigSource) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) ServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings) ContainerPortBuilder(io.fabric8.kubernetes.api.model.ContainerPortBuilder) ProbeBuilder(io.fabric8.kubernetes.api.model.ProbeBuilder) ProbeBuilder(io.fabric8.kubernetes.api.model.ProbeBuilder) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) ContainerPortBuilder(io.fabric8.kubernetes.api.model.ContainerPortBuilder) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) VolumeMount(io.fabric8.kubernetes.api.model.VolumeMount) VolumeMountBuilder(io.fabric8.kubernetes.api.model.VolumeMountBuilder) EnvVarBuilder(io.fabric8.kubernetes.api.model.EnvVarBuilder)

Example 40 with EnvVar

use of io.fabric8.kubernetes.api.model.EnvVar in project kubernetes by ballerinax.

the class DeploymentHandler method populateEnvVar.

private List<EnvVar> populateEnvVar(Map<String, String> envMap) {
    List<EnvVar> envVars = new ArrayList<>();
    if (envMap == null) {
        return envVars;
    }
    envMap.forEach((k, v) -> {
        EnvVar envVar = new EnvVarBuilder().withName(k).withValue(v).build();
        envVars.add(envVar);
    });
    return envVars;
}
Also used : ArrayList(java.util.ArrayList) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) EnvVarBuilder(io.fabric8.kubernetes.api.model.EnvVarBuilder)

Aggregations

EnvVar (io.fabric8.kubernetes.api.model.EnvVar)51 ArrayList (java.util.ArrayList)15 Test (org.junit.Test)15 ContainerPortBuilder (io.fabric8.kubernetes.api.model.ContainerPortBuilder)11 EnvVarBuilder (io.fabric8.kubernetes.api.model.EnvVarBuilder)10 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)10 HashMap (java.util.HashMap)10 Container (io.fabric8.kubernetes.api.model.Container)9 ContainerPort (io.fabric8.kubernetes.api.model.ContainerPort)9 ServicePortBuilder (io.fabric8.kubernetes.api.model.ServicePortBuilder)9 File (java.io.File)8 List (java.util.List)8 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)7 Pod (io.fabric8.kubernetes.api.model.Pod)7 ServiceSpecBuilder (io.fabric8.kubernetes.api.model.ServiceSpecBuilder)7 Map (java.util.Map)7 Test (org.testng.annotations.Test)7 LinkedList (java.util.LinkedList)6 ContainerBuilder (io.fabric8.kubernetes.api.model.ContainerBuilder)5 VolumeMount (io.fabric8.kubernetes.api.model.VolumeMount)5