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");
}
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;
}
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));
}
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);
}
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()));
}
Aggregations