Search in sources :

Example 1 with EnvVarBuilder

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

the class MergeResourceTest method testMergeDeploymentTemplateMetadata.

@Test
public void testMergeDeploymentTemplateMetadata() throws Exception {
    Deployment resource = new DeploymentBuilder().withNewMetadata().withName("cheese").endMetadata().withNewSpec().withNewTemplate().withNewSpec().addNewContainer().withImage("cheese-image").endContainer().endSpec().withNewMetadata().addToAnnotations("overwriteKey", "originalValue").addToAnnotations("unchangedKey", "shouldNotChange").addToAnnotations("unchangedBlankKey", "").addToAnnotations("deletedKey", "shouldBeDeleted").endMetadata().endTemplate().endSpec().build();
    Deployment override = new DeploymentBuilder().withNewMetadata().withName("cheese").endMetadata().withNewSpec().withNewTemplate().withNewSpec().addNewContainer().addToEnv(new EnvVarBuilder().withName("ENV_FOO").withValue("FOO_VALUE").build()).endContainer().endSpec().withNewMetadata().addToAnnotations("overwriteKey", "newValue").addToAnnotations("deletedKey", "").endMetadata().endTemplate().endSpec().build();
    HasMetadata answer = KubernetesResourceUtil.mergeResources(resource, override, log, false);
    assertNotNull(answer);
    log.info("Override metadata on Deployment generated: " + KubernetesHelper.toYaml(answer));
    assertThat(answer).describedAs("mergeResult").isInstanceOf(Deployment.class);
    Deployment deployment = (Deployment) answer;
    Map<String, String> annotations = deployment.getSpec().getTemplate().getMetadata().getAnnotations();
    assertDataModified(annotations, "Deployment.spec.template.metadata.annotations");
    assertDataNotModified(resource.getSpec().getTemplate().getMetadata().getAnnotations(), "Original Deployment.spec.template.metadata.annotations");
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment) EnvVarBuilder(io.fabric8.kubernetes.api.model.EnvVarBuilder) DeploymentBuilder(io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder) Test(org.junit.Test)

Example 2 with EnvVarBuilder

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

the class KubernetesResourceUtil method setEnvVar.

public static boolean setEnvVar(List<EnvVar> envVarList, String name, String value) {
    for (EnvVar envVar : envVarList) {
        String envVarName = envVar.getName();
        if (io.fabric8.utils.Objects.equal(name, envVarName)) {
            String oldValue = envVar.getValue();
            if (io.fabric8.utils.Objects.equal(value, oldValue)) {
                return false;
            } else {
                envVar.setValue(value);
                return true;
            }
        }
    }
    EnvVar env = new EnvVarBuilder().withName(name).withValue(value).build();
    envVarList.add(env);
    return true;
}
Also used : EnvVar(io.fabric8.kubernetes.api.model.EnvVar) EnvVarBuilder(io.fabric8.kubernetes.api.model.EnvVarBuilder)

Example 3 with EnvVarBuilder

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

the class EnvVarHandlerTest method envVarHandlerTest.

@Test
public void envVarHandlerTest() {
    // Some Environment Variable in Config
    EnvVar var1 = new EnvVarBuilder().withName("TEST1").withValue("OK").build();
    EnvVar var2 = new EnvVarBuilder().withName("TEST2").withValue("DONE").build();
    EnvVar var3 = new EnvVarBuilder().withName("TEST3").withValue("").build();
    env.clear();
    env.put(var1.getName(), var1.getValue());
    env.put(var2.getName(), var2.getValue());
    env.put(var3.getName(), var3.getValue());
    EnvVarHandler envVarHandler = new EnvVarHandler(project);
    new Expectations() {

        {
            externalEnvVarHandler.getExportedEnvironmentVariables(project, env);
            ret.putAll(env);
            result = ret;
        }
    };
    List<EnvVar> envVars = envVarHandler.getEnvironmentVariables(env);
    assertNotNull(envVars);
    assertEquals(4, envVars.size());
    assertTrue(envVars.contains(var1));
    assertTrue(envVars.contains(var2));
    assertTrue(envVars.contains(var3));
    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 4 with EnvVarBuilder

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

the class OpenShiftServiceImplTest method testDeploy.

@SuppressWarnings({ "PMD.ExcessiveMethodLength", "PMD.JUnitTestsShouldIncludeAssert" })
@Test
public void testDeploy() {
    String name = "test-deployment";
    OpenShiftConfigurationProperties config = new OpenShiftConfigurationProperties();
    OpenShiftServiceImpl service = new OpenShiftServiceImpl(client, config);
    DeploymentData deploymentData = new DeploymentData.Builder().addAnnotation("testName", testName.getMethodName()).addLabel("type", "test").addSecretEntry("secret-key", "secret-val").withImage("testimage").build();
    ImageStream expectedImageStream = new ImageStreamBuilder().withNewMetadata().withName(name).endMetadata().build();
    Secret expectedSecret = new SecretBuilder().withNewMetadata().withName(name).addToAnnotations(deploymentData.getAnnotations()).addToLabels(deploymentData.getLabels()).endMetadata().withStringData(deploymentData.getSecret()).build();
    DeploymentConfig expectedDeploymentConfig = new DeploymentConfigBuilder().withNewMetadata().withName(OpenShiftServiceImpl.openshiftName(name)).addToAnnotations(deploymentData.getAnnotations()).addToLabels(deploymentData.getLabels()).endMetadata().withNewSpec().withReplicas(1).addToSelector("integration", name).withNewStrategy().withType("Recreate").withNewResources().addToLimits("memory", new Quantity(config.getDeploymentMemoryLimitMi() + "Mi")).addToRequests("memory", new Quantity(config.getDeploymentMemoryRequestMi() + "Mi")).endResources().endStrategy().withRevisionHistoryLimit(0).withNewTemplate().withNewMetadata().addToLabels("integration", name).addToLabels(OpenShiftServiceImpl.COMPONENT_LABEL, "integration").addToLabels(deploymentData.getLabels()).addToAnnotations(deploymentData.getAnnotations()).addToAnnotations("prometheus.io/scrape", "true").addToAnnotations("prometheus.io/port", "9779").endMetadata().withNewSpec().addNewContainer().withImage(deploymentData.getImage()).withImagePullPolicy("Always").withName(name).addToEnv(new EnvVarBuilder().withName("LOADER_HOME").withValue(config.getIntegrationDataPath()).build()).addToEnv(new EnvVarBuilder().withName("AB_JMX_EXPORTER_CONFIG").withValue("/tmp/src/prometheus-config.yml").build()).addNewPort().withName("jolokia").withContainerPort(8778).endPort().addNewVolumeMount().withName("secret-volume").withMountPath("/deployments/config").withReadOnly(false).endVolumeMount().endContainer().addNewVolume().withName("secret-volume").withNewSecret().withSecretName(expectedSecret.getMetadata().getName()).endSecret().endVolume().endSpec().endTemplate().addNewTrigger().withType("ConfigChange").endTrigger().endSpec().withNewStatus().withLatestVersion(1L).endStatus().build();
    server.expect().withPath("/oapi/v1/namespaces/test/imagestreams").andReturn(200, expectedImageStream).always();
    server.expect().withPath("/api/v1/namespaces/test/secrets").andReturn(200, expectedSecret).always();
    server.expect().withPath("/oapi/v1/namespaces/test/deploymentconfigs").andReturn(200, expectedDeploymentConfig).always();
    server.expect().withPath("/oapi/v1/namespaces/test/deploymentconfigs/i-test-deployment").andReturn(200, expectedDeploymentConfig).always();
    server.expect().withPath("/oapi/v1/namespaces/test/deploymentconfigs/test-deployment").andReturn(200, expectedDeploymentConfig).always();
    service.deploy(name, deploymentData);
}
Also used : DeploymentConfigBuilder(io.fabric8.openshift.api.model.DeploymentConfigBuilder) ImageStream(io.fabric8.openshift.api.model.ImageStream) Quantity(io.fabric8.kubernetes.api.model.Quantity) EnvVarBuilder(io.fabric8.kubernetes.api.model.EnvVarBuilder) ImageStreamBuilder(io.fabric8.openshift.api.model.ImageStreamBuilder) Secret(io.fabric8.kubernetes.api.model.Secret) SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) Test(org.junit.Test)

Example 5 with EnvVarBuilder

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

the class KubernetesFactoryWithPodTemplateTestBase method testEnvFromPodTemplate.

@Test
public void testEnvFromPodTemplate() {
    final Container mainContainer = KubernetesPodTemplateTestUtils.getContainerWithName(resultPod.getSpec(), Constants.MAIN_CONTAINER_NAME);
    assertThat(mainContainer.getEnv(), // The expected env is defined in the test/resources/testing-pod-template.yaml.
    hasItems(new EnvVarBuilder().withName("ENV_OF_POD_TEMPLATE").withValue("env-value-of-pod-template").build()));
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) EnvVarBuilder(io.fabric8.kubernetes.api.model.EnvVarBuilder) Test(org.junit.Test)

Aggregations

EnvVarBuilder (io.fabric8.kubernetes.api.model.EnvVarBuilder)14 EnvVar (io.fabric8.kubernetes.api.model.EnvVar)8 Test (org.junit.Test)7 Container (io.fabric8.kubernetes.api.model.Container)3 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 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 Pod (io.fabric8.kubernetes.api.model.Pod)1