Java Code Examples for io.fabric8.kubernetes.api.model.Container#getEnvFrom()

The following examples show how to use io.fabric8.kubernetes.api.model.Container#getEnvFrom() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KubernetesAppDeployerIntegrationTests.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 4 votes vote down vote up
@Test
public void testSecretRef() throws InterruptedException {
	log.info("Testing {}...", "SecretRef");

	Secret secret = randomSecret();

	KubernetesDeployerProperties kubernetesDeployerProperties = new KubernetesDeployerProperties();
	kubernetesDeployerProperties.setSecretRefs(Collections.singletonList(secret.getMetadata().getName()));

	KubernetesAppDeployer kubernetesAppDeployer = new KubernetesAppDeployer(kubernetesDeployerProperties, kubernetesClient);

	AppDefinition definition = new AppDefinition(randomName(), null);
	Resource resource = testApplication();
	AppDeploymentRequest request = new AppDeploymentRequest(definition, resource);

	log.info("Deploying {}...", request.getDefinition().getName());
	String deploymentId = kubernetesAppDeployer.deploy(request);
	Timeout timeout = deploymentTimeout();
	assertThat(deploymentId, eventually(hasStatusThat(
			Matchers.hasProperty("state", is(deployed))), timeout.maxAttempts, timeout.pause));

	Container container = kubernetesClient.apps().deployments().withName(deploymentId).get().getSpec()
			.getTemplate().getSpec().getContainers().get(0);

	List<EnvFromSource> envFromSources = container.getEnvFrom();

	assertThat(envFromSources, is(notNullValue()));
	assertThat(envFromSources.size(), is(1));

	EnvFromSource envFromSource = envFromSources.get(0);
	assertEquals(envFromSource.getSecretRef().getName(), secret.getMetadata().getName());

	String podEnvironment = getPodEnvironment(deploymentId);

	assertEquals(secret.getData().size(), 2);

	for(Map.Entry<String, String> secretData : secret.getData().entrySet()) {
		String decodedValue = new String(Base64.getDecoder().decode(secretData.getValue()));
		assertTrue(podEnvironment.contains(secretData.getKey() + "=" + decodedValue));
	}

	log.info("Undeploying {}...", deploymentId);
	timeout = undeploymentTimeout();
	kubernetesAppDeployer.undeploy(deploymentId);
	assertThat(deploymentId, eventually(hasStatusThat(
			Matchers.hasProperty("state", is(unknown))), timeout.maxAttempts, timeout.pause));

	kubernetesClient.secrets().delete(secret);
}
 
Example 2
Source File: KubernetesAppDeployerIntegrationTests.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 4 votes vote down vote up
@Test
public void testSecretRefFromDeployerProperty() throws InterruptedException {
	log.info("Testing {}...", "SecretRefFromDeployerProperty");

	Secret secret = randomSecret();

	KubernetesAppDeployer kubernetesAppDeployer = new KubernetesAppDeployer(new KubernetesDeployerProperties(),
			kubernetesClient);

	Map<String, String> props = new HashMap<>();
	props.put("spring.cloud.deployer.kubernetes.secretRefs", secret.getMetadata().getName());

	AppDefinition definition = new AppDefinition(randomName(), null);
	Resource resource = testApplication();
	AppDeploymentRequest request = new AppDeploymentRequest(definition, resource, props);

	log.info("Deploying {}...", request.getDefinition().getName());
	String deploymentId = kubernetesAppDeployer.deploy(request);
	Timeout timeout = deploymentTimeout();
	assertThat(deploymentId, eventually(hasStatusThat(
			Matchers.hasProperty("state", is(deployed))), timeout.maxAttempts, timeout.pause));

	Container container = kubernetesClient.apps().deployments().withName(deploymentId).get().getSpec()
			.getTemplate().getSpec().getContainers().get(0);

	List<EnvFromSource> envFromSources = container.getEnvFrom();

	assertThat(envFromSources, is(notNullValue()));
	assertThat(envFromSources.size(), is(1));

	EnvFromSource envFromSource = envFromSources.get(0);
	assertEquals(envFromSource.getSecretRef().getName(), secret.getMetadata().getName());

	String podEnvironment = getPodEnvironment(deploymentId);

	assertEquals(secret.getData().size(), 2);

	for(Map.Entry<String, String> secretData : secret.getData().entrySet()) {
		String decodedValue = new String(Base64.getDecoder().decode(secretData.getValue()));
		assertTrue(podEnvironment.contains(secretData.getKey() + "=" + decodedValue));
	}

	log.info("Undeploying {}...", deploymentId);
	timeout = undeploymentTimeout();
	kubernetesAppDeployer.undeploy(deploymentId);
	assertThat(deploymentId, eventually(hasStatusThat(
			Matchers.hasProperty("state", is(unknown))), timeout.maxAttempts, timeout.pause));

	kubernetesClient.secrets().delete(secret);
}
 
Example 3
Source File: KubernetesAppDeployerIntegrationTests.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 4 votes vote down vote up
@Test
public void testSecretRefFromPropertyMultiple() throws InterruptedException {
	log.info("Testing {}...", "SecretRefFromPropertyMultiple");

	Secret secret1 = randomSecret();
	Secret secret2 = randomSecret();

	List<String> secrets = new ArrayList<>();
	secrets.add(secret1.getMetadata().getName());
	secrets.add(secret2.getMetadata().getName());

	KubernetesDeployerProperties kubernetesDeployerProperties = new KubernetesDeployerProperties();
	kubernetesDeployerProperties.setSecretRefs(secrets);

	KubernetesAppDeployer kubernetesAppDeployer = new KubernetesAppDeployer(kubernetesDeployerProperties,
			kubernetesClient);

	AppDefinition definition = new AppDefinition(randomName(), null);
	Resource resource = testApplication();
	AppDeploymentRequest request = new AppDeploymentRequest(definition, resource, null);

	log.info("Deploying {}...", request.getDefinition().getName());
	String deploymentId = kubernetesAppDeployer.deploy(request);
	Timeout timeout = deploymentTimeout();
	assertThat(deploymentId, eventually(hasStatusThat(
			Matchers.hasProperty("state", is(deployed))), timeout.maxAttempts, timeout.pause));

	Container container = kubernetesClient.apps().deployments().withName(deploymentId).get().getSpec()
			.getTemplate().getSpec().getContainers().get(0);

	List<EnvFromSource> envFromSources = container.getEnvFrom();

	assertThat(envFromSources, is(notNullValue()));
	assertThat(envFromSources.size(), is(2));

	String podEnvironment = getPodEnvironment(deploymentId);

	EnvFromSource envFromSource1 = envFromSources.get(0);
	assertEquals(envFromSource1.getSecretRef().getName(), secret1.getMetadata().getName());

	EnvFromSource envFromSource2 = envFromSources.get(1);
	assertEquals(envFromSource2.getSecretRef().getName(), secret2.getMetadata().getName());

	Map<String, String> mergedSecretData = new HashMap<>();
	mergedSecretData.putAll(secret1.getData());
	mergedSecretData.putAll(secret2.getData());

	assertEquals(4, mergedSecretData.size());

	for(Map.Entry<String, String> secretData : secret1.getData().entrySet()) {
		String decodedValue = new String(Base64.getDecoder().decode(secretData.getValue()));
		assertTrue(podEnvironment.contains(secretData.getKey() + "=" + decodedValue));
	}

	log.info("Undeploying {}...", deploymentId);
	timeout = undeploymentTimeout();
	kubernetesAppDeployer.undeploy(deploymentId);
	assertThat(deploymentId, eventually(hasStatusThat(
			Matchers.hasProperty("state", is(unknown))), timeout.maxAttempts, timeout.pause));

	kubernetesClient.secrets().delete(secret1);
	kubernetesClient.secrets().delete(secret2);
}
 
Example 4
Source File: KubernetesAppDeployerIntegrationTests.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 4 votes vote down vote up
@Test
public void testSecretRefFromDeploymentPropertyMultiple() throws InterruptedException {
	log.info("Testing {}...", "SecretRefFromDeploymentPropertyMultiple");

	Secret secret1 = randomSecret();
	Secret secret2 = randomSecret();

	Map<String, String> props = new HashMap<>();
	props.put("spring.cloud.deployer.kubernetes.secretRefs", "[" + secret1.getMetadata().getName() + "," +
			secret2.getMetadata().getName() + "]");

	KubernetesAppDeployer kubernetesAppDeployer = new KubernetesAppDeployer(new KubernetesDeployerProperties(),
			kubernetesClient);

	AppDefinition definition = new AppDefinition(randomName(), null);
	Resource resource = testApplication();
	AppDeploymentRequest request = new AppDeploymentRequest(definition, resource, props);

	log.info("Deploying {}...", request.getDefinition().getName());
	String deploymentId = kubernetesAppDeployer.deploy(request);
	Timeout timeout = deploymentTimeout();
	assertThat(deploymentId, eventually(hasStatusThat(
			Matchers.hasProperty("state", is(deployed))), timeout.maxAttempts, timeout.pause));

	Container container = kubernetesClient.apps().deployments().withName(deploymentId).get().getSpec()
			.getTemplate().getSpec().getContainers().get(0);

	List<EnvFromSource> envFromSources = container.getEnvFrom();

	assertThat(envFromSources, is(notNullValue()));
	assertThat(envFromSources.size(), is(2));

	String podEnvironment = getPodEnvironment(deploymentId);

	EnvFromSource envFromSource1 = envFromSources.get(0);
	assertEquals(envFromSource1.getSecretRef().getName(), secret1.getMetadata().getName());

	EnvFromSource envFromSource2 = envFromSources.get(1);
	assertEquals(envFromSource2.getSecretRef().getName(), secret2.getMetadata().getName());

	Map<String, String> mergedSecretData = new HashMap<>();
	mergedSecretData.putAll(secret1.getData());
	mergedSecretData.putAll(secret2.getData());

	assertEquals(4, mergedSecretData.size());

	for(Map.Entry<String, String> secretData : secret1.getData().entrySet()) {
		String decodedValue = new String(Base64.getDecoder().decode(secretData.getValue()));
		assertTrue(podEnvironment.contains(secretData.getKey() + "=" + decodedValue));
	}

	log.info("Undeploying {}...", deploymentId);
	timeout = undeploymentTimeout();
	kubernetesAppDeployer.undeploy(deploymentId);
	assertThat(deploymentId, eventually(hasStatusThat(
			Matchers.hasProperty("state", is(unknown))), timeout.maxAttempts, timeout.pause));

	kubernetesClient.secrets().delete(secret1);
	kubernetesClient.secrets().delete(secret2);
}
 
Example 5
Source File: KubernetesAppDeployerIntegrationTests.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 4 votes vote down vote up
@Test
public void testConfigMapRef() throws InterruptedException {
	log.info("Testing {}...", "ConfigMapRef");

	ConfigMap configMap = randomConfigMap();

	KubernetesDeployerProperties kubernetesDeployerProperties = new KubernetesDeployerProperties();
	kubernetesDeployerProperties.setConfigMapRefs(Collections.singletonList(configMap.getMetadata().getName()));

	KubernetesAppDeployer kubernetesAppDeployer = new KubernetesAppDeployer(kubernetesDeployerProperties, kubernetesClient);

	AppDefinition definition = new AppDefinition(randomName(), null);
	Resource resource = testApplication();
	AppDeploymentRequest request = new AppDeploymentRequest(definition, resource);

	log.info("Deploying {}...", request.getDefinition().getName());
	String deploymentId = kubernetesAppDeployer.deploy(request);
	Timeout timeout = deploymentTimeout();
	assertThat(deploymentId, eventually(hasStatusThat(
			Matchers.hasProperty("state", is(deployed))), timeout.maxAttempts, timeout.pause));

	Container container = kubernetesClient.apps().deployments().withName(deploymentId).get().getSpec()
			.getTemplate().getSpec().getContainers().get(0);

	List<EnvFromSource> envFromSources = container.getEnvFrom();

	assertThat(envFromSources, is(notNullValue()));
	assertThat(envFromSources.size(), is(1));

	EnvFromSource envFromSource = envFromSources.get(0);
	assertEquals(envFromSource.getConfigMapRef().getName(), configMap.getMetadata().getName());

	String podEnvironment = getPodEnvironment(deploymentId);

	assertEquals(configMap.getData().size(), 2);

	for(Map.Entry<String, String> configMapData : configMap.getData().entrySet()) {
		assertTrue(podEnvironment.contains(configMapData.getKey() + "=" + configMapData.getValue()));
	}

	log.info("Undeploying {}...", deploymentId);
	timeout = undeploymentTimeout();
	kubernetesAppDeployer.undeploy(deploymentId);
	assertThat(deploymentId, eventually(hasStatusThat(
			Matchers.hasProperty("state", is(unknown))), timeout.maxAttempts, timeout.pause));

	kubernetesClient.configMaps().delete(configMap);
}
 
Example 6
Source File: KubernetesAppDeployerIntegrationTests.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 4 votes vote down vote up
@Test
public void testConfigMapRefFromDeployerProperty() throws InterruptedException {
	log.info("Testing {}...", "ConfigMapRefFromDeployerProperty");

	ConfigMap configMap = randomConfigMap();

	KubernetesAppDeployer kubernetesAppDeployer = new KubernetesAppDeployer(new KubernetesDeployerProperties(),
			kubernetesClient);

	Map<String, String> props = new HashMap<>();
	props.put("spring.cloud.deployer.kubernetes.configMapRefs", configMap.getMetadata().getName());

	AppDefinition definition = new AppDefinition(randomName(), null);
	Resource resource = testApplication();
	AppDeploymentRequest request = new AppDeploymentRequest(definition, resource, props);

	log.info("Deploying {}...", request.getDefinition().getName());
	String deploymentId = kubernetesAppDeployer.deploy(request);
	Timeout timeout = deploymentTimeout();
	assertThat(deploymentId, eventually(hasStatusThat(
			Matchers.hasProperty("state", is(deployed))), timeout.maxAttempts, timeout.pause));

	Container container = kubernetesClient.apps().deployments().withName(deploymentId).get().getSpec()
			.getTemplate().getSpec().getContainers().get(0);

	List<EnvFromSource> envFromSources = container.getEnvFrom();

	assertThat(envFromSources, is(notNullValue()));
	assertThat(envFromSources.size(), is(1));

	EnvFromSource envFromSource = envFromSources.get(0);
	assertEquals(envFromSource.getConfigMapRef().getName(), configMap.getMetadata().getName());

	String podEnvironment = getPodEnvironment(deploymentId);

	assertEquals(configMap.getData().size(), 2);

	for(Map.Entry<String, String> configMapData : configMap.getData().entrySet()) {
		assertTrue(podEnvironment.contains(configMapData.getKey() + "=" + configMapData.getValue()));
	}

	log.info("Undeploying {}...", deploymentId);
	timeout = undeploymentTimeout();
	kubernetesAppDeployer.undeploy(deploymentId);
	assertThat(deploymentId, eventually(hasStatusThat(
			Matchers.hasProperty("state", is(unknown))), timeout.maxAttempts, timeout.pause));

	kubernetesClient.configMaps().delete(configMap);
}
 
Example 7
Source File: KubernetesAppDeployerIntegrationTests.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 4 votes vote down vote up
@Test
public void testConfigMapRefFromDeployerPropertyOverride() throws IOException, InterruptedException {
	log.info("Testing {}...", "ConfigMapRefFromDeployerPropertyOverride");

	ConfigMap propertyConfigMap = randomConfigMap();
	ConfigMap deployerPropertyConfigMap = randomConfigMap();

	KubernetesDeployerProperties kubernetesDeployerProperties = new KubernetesDeployerProperties();
	kubernetesDeployerProperties.setConfigMapRefs(Collections.singletonList(propertyConfigMap.getMetadata().getName()));

	KubernetesAppDeployer kubernetesAppDeployer = new KubernetesAppDeployer(kubernetesDeployerProperties,
			kubernetesClient);

	Map<String, String> props = new HashMap<>();
	props.put("spring.cloud.deployer.kubernetes.configMapRefs", deployerPropertyConfigMap.getMetadata().getName());

	AppDefinition definition = new AppDefinition(randomName(), null);
	Resource resource = testApplication();
	AppDeploymentRequest request = new AppDeploymentRequest(definition, resource, props);

	log.info("Deploying {}...", request.getDefinition().getName());
	String deploymentId = kubernetesAppDeployer.deploy(request);
	Timeout timeout = deploymentTimeout();
	assertThat(deploymentId, eventually(hasStatusThat(
			Matchers.hasProperty("state", is(deployed))), timeout.maxAttempts, timeout.pause));

	Container container = kubernetesClient.apps().deployments().withName(deploymentId).get().getSpec()
			.getTemplate().getSpec().getContainers().get(0);

	List<EnvFromSource> envFromSources = container.getEnvFrom();

	assertThat(envFromSources, is(notNullValue()));
	assertThat(envFromSources.size(), is(1));

	EnvFromSource envFromSource = envFromSources.get(0);
	assertEquals(envFromSource.getConfigMapRef().getName(), deployerPropertyConfigMap.getMetadata().getName());

	String podEnvironment = getPodEnvironment(deploymentId);

	for(Map.Entry<String, String> deployerPropertyConfigMapData : deployerPropertyConfigMap.getData().entrySet()) {
		assertTrue(podEnvironment.contains(deployerPropertyConfigMapData.getKey() + "="
				+ deployerPropertyConfigMapData.getValue()));
	}

	for(Map.Entry<String, String> propertyConfigMapData : propertyConfigMap.getData().entrySet()) {
		assertFalse(podEnvironment.contains(propertyConfigMapData.getKey() + "=" + propertyConfigMapData.getValue()));
	}

	log.info("Undeploying {}...", deploymentId);
	timeout = undeploymentTimeout();
	kubernetesAppDeployer.undeploy(deploymentId);
	assertThat(deploymentId, eventually(hasStatusThat(
			Matchers.hasProperty("state", is(unknown))), timeout.maxAttempts, timeout.pause));

	kubernetesClient.configMaps().delete(propertyConfigMap);
	kubernetesClient.configMaps().delete(deployerPropertyConfigMap);
}
 
Example 8
Source File: KubernetesAppDeployerIntegrationTests.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 4 votes vote down vote up
@Test
public void testConfigMapRefFromPropertyMultiple() throws InterruptedException {
	log.info("Testing {}...", "ConfigMapRefFromPropertyMultiple");

	ConfigMap configMap1 = randomConfigMap();
	ConfigMap configMap2 = randomConfigMap();

	List<String> configMaps = new ArrayList<>();
	configMaps.add(configMap1.getMetadata().getName());
	configMaps.add(configMap2.getMetadata().getName());

	KubernetesDeployerProperties kubernetesDeployerProperties = new KubernetesDeployerProperties();
	kubernetesDeployerProperties.setConfigMapRefs(configMaps);

	KubernetesAppDeployer kubernetesAppDeployer = new KubernetesAppDeployer(kubernetesDeployerProperties,
			kubernetesClient);

	AppDefinition definition = new AppDefinition(randomName(), null);
	Resource resource = testApplication();
	AppDeploymentRequest request = new AppDeploymentRequest(definition, resource, null);

	log.info("Deploying {}...", request.getDefinition().getName());
	String deploymentId = kubernetesAppDeployer.deploy(request);
	Timeout timeout = deploymentTimeout();
	assertThat(deploymentId, eventually(hasStatusThat(
			Matchers.hasProperty("state", is(deployed))), timeout.maxAttempts, timeout.pause));

	Container container = kubernetesClient.apps().deployments().withName(deploymentId).get().getSpec()
			.getTemplate().getSpec().getContainers().get(0);

	List<EnvFromSource> envFromSources = container.getEnvFrom();

	assertThat(envFromSources, is(notNullValue()));
	assertThat(envFromSources.size(), is(2));

	String podEnvironment = getPodEnvironment(deploymentId);

	EnvFromSource envFromSource1 = envFromSources.get(0);
	assertEquals(envFromSource1.getConfigMapRef().getName(), configMap1.getMetadata().getName());

	EnvFromSource envFromSource2 = envFromSources.get(1);
	assertEquals(envFromSource2.getConfigMapRef().getName(), configMap2.getMetadata().getName());

	Map<String, String> mergedConfigMapData = new HashMap<>();
	mergedConfigMapData.putAll(configMap1.getData());
	mergedConfigMapData.putAll(configMap2.getData());

	assertEquals(4, mergedConfigMapData.size());

	for(Map.Entry<String, String> configMapData : configMap1.getData().entrySet()) {
		assertTrue(podEnvironment.contains(configMapData.getKey() + "=" + configMapData.getValue()));
	}

	log.info("Undeploying {}...", deploymentId);
	timeout = undeploymentTimeout();
	kubernetesAppDeployer.undeploy(deploymentId);
	assertThat(deploymentId, eventually(hasStatusThat(
			Matchers.hasProperty("state", is(unknown))), timeout.maxAttempts, timeout.pause));

	kubernetesClient.configMaps().delete(configMap1);
	kubernetesClient.configMaps().delete(configMap2);
}
 
Example 9
Source File: KubernetesAppDeployerIntegrationTests.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 4 votes vote down vote up
@Test
public void testConfigMapRefFromDeploymentPropertyMultiple() throws InterruptedException {
	log.info("Testing {}...", "ConfigMapRefFromDeploymentPropertyMultiple");

	ConfigMap configMap1 = randomConfigMap();
	ConfigMap configMap2 = randomConfigMap();

	Map<String, String> props = new HashMap<>();
	props.put("spring.cloud.deployer.kubernetes.configMapRefs", "[" + configMap1.getMetadata().getName() + "," +
			configMap2.getMetadata().getName() + "]");

	KubernetesAppDeployer kubernetesAppDeployer = new KubernetesAppDeployer(new KubernetesDeployerProperties(),
			kubernetesClient);

	AppDefinition definition = new AppDefinition(randomName(), null);
	Resource resource = testApplication();
	AppDeploymentRequest request = new AppDeploymentRequest(definition, resource, props);

	log.info("Deploying {}...", request.getDefinition().getName());
	String deploymentId = kubernetesAppDeployer.deploy(request);
	Timeout timeout = deploymentTimeout();
	assertThat(deploymentId, eventually(hasStatusThat(
			Matchers.hasProperty("state", is(deployed))), timeout.maxAttempts, timeout.pause));

	Container container = kubernetesClient.apps().deployments().withName(deploymentId).get().getSpec()
			.getTemplate().getSpec().getContainers().get(0);

	List<EnvFromSource> envFromSources = container.getEnvFrom();

	assertThat(envFromSources, is(notNullValue()));
	assertThat(envFromSources.size(), is(2));

	String podEnvironment = getPodEnvironment(deploymentId);

	EnvFromSource envFromSource1 = envFromSources.get(0);
	assertEquals(envFromSource1.getConfigMapRef().getName(), configMap1.getMetadata().getName());

	EnvFromSource envFromSource2 = envFromSources.get(1);
	assertEquals(envFromSource2.getConfigMapRef().getName(), configMap2.getMetadata().getName());

	Map<String, String> mergedConfigMapData = new HashMap<>();
	mergedConfigMapData.putAll(configMap1.getData());
	mergedConfigMapData.putAll(configMap2.getData());

	assertEquals(4, mergedConfigMapData.size());

	for(Map.Entry<String, String> configMapData : configMap1.getData().entrySet()) {
		assertTrue(podEnvironment.contains(configMapData.getKey() + "=" + configMapData.getValue()));
	}

	log.info("Undeploying {}...", deploymentId);
	timeout = undeploymentTimeout();
	kubernetesAppDeployer.undeploy(deploymentId);
	assertThat(deploymentId, eventually(hasStatusThat(
			Matchers.hasProperty("state", is(unknown))), timeout.maxAttempts, timeout.pause));

	kubernetesClient.configMaps().delete(configMap1);
	kubernetesClient.configMaps().delete(configMap2);
}