use of io.fabric8.kubernetes.api.model.apps.Deployment in project kubernetes by ballerinax.
the class EnvVarTest method fieldRefTest.
/**
* Build bal file with deployment having name and fieldRef environment variables.
* @throws IOException Error when loading the generated yaml.
* @throws InterruptedException Error when compiling the ballerina file.
* @throws KubernetesPluginException Error when deleting the generated artifacts folder.
*/
@Test
public void fieldRefTest() throws IOException, InterruptedException, KubernetesPluginException, DockerTestException {
Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(BAL_DIRECTORY, "field_ref_value.bal"), 0);
// Check if docker image exists and correct
validateDockerfile();
validateDockerImage();
// Validate deployment yaml
File deploymentYAML = KUBERNETES_TARGET_PATH.resolve("field_ref_value_deployment.yaml").toFile();
Assert.assertTrue(deploymentYAML.exists());
Deployment deployment = KubernetesTestUtils.loadYaml(deploymentYAML);
List<EnvVar> envVars = deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getEnv();
Assert.assertEquals(envVars.size(), 2, "Invalid number of environment variables found.");
Assert.assertEquals(envVars.get(0).getName(), "MY_NODE_NAME", "Invalid environment variable name found.");
Assert.assertEquals(envVars.get(0).getValueFrom().getFieldRef().getFieldPath(), "spec.nodeName", "Invalid environment variable value found.");
Assert.assertEquals(envVars.get(1).getName(), "MY_POD_NAME", "Invalid environment variable name found.");
Assert.assertEquals(envVars.get(1).getValueFrom().getFieldRef().getFieldPath(), "metadata.name", "Invalid environment variable value found.");
KubernetesUtils.deleteDirectory(KUBERNETES_TARGET_PATH);
KubernetesUtils.deleteDirectory(DOCKER_TARGET_PATH);
KubernetesTestUtils.deleteDockerImage(DOCKER_IMAGE);
}
use of io.fabric8.kubernetes.api.model.apps.Deployment in project kubernetes by ballerinax.
the class EnvVarTest method nameValueBuildEnvVarTest.
/**
* Build bal file with deployment having name value environment variables having build environment variable.
*
* @throws IOException Error when loading the generated yaml.
* @throws InterruptedException Error when compiling the ballerina file.
* @throws KubernetesPluginException Error when deleting the generated artifacts folder.
*/
@Test
public void nameValueBuildEnvVarTest() throws IOException, InterruptedException, KubernetesPluginException, DockerTestException {
Map<String, String> bRunEnvVar = new HashMap<>();
bRunEnvVar.put("DATABASE_USERNAME", "root");
bRunEnvVar.put("DATABASE_PASSWORD", "rootpwd");
Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(BAL_DIRECTORY, "build_name_value.bal", bRunEnvVar), 0);
// Check if docker image exists and correct
validateDockerfile();
validateDockerImage();
// Validate deployment yaml
File deploymentYAML = KUBERNETES_TARGET_PATH.resolve("build_name_value_deployment.yaml").toFile();
Assert.assertTrue(deploymentYAML.exists());
Deployment deployment = KubernetesTestUtils.loadYaml(deploymentYAML);
List<EnvVar> envVars = deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getEnv();
Assert.assertEquals(envVars.size(), 4, "Invalid number of environment variables found.");
Assert.assertEquals(envVars.get(0).getName(), "location", "Invalid environment variable name found.");
Assert.assertEquals(envVars.get(0).getValue(), "SL", "Invalid environment variable value found.");
Assert.assertEquals(envVars.get(1).getName(), "city", "Invalid environment variable name found.");
Assert.assertEquals(envVars.get(1).getValue(), "COLOMBO", "Invalid environment variable value found.");
Assert.assertEquals(envVars.get(2).getName(), "DATABASE_USERNAME", "Invalid environment variable name found.");
Assert.assertEquals(envVars.get(2).getValue(), "root", "Invalid environment variable value found.");
Assert.assertEquals(envVars.get(3).getName(), "DATABASE_PASSWORD", "Invalid environment variable name found.");
Assert.assertEquals(envVars.get(3).getValue(), "rootpwd", "Invalid environment variable value found.");
KubernetesUtils.deleteDirectory(KUBERNETES_TARGET_PATH);
KubernetesUtils.deleteDirectory(DOCKER_TARGET_PATH);
KubernetesTestUtils.deleteDockerImage(DOCKER_IMAGE);
}
use of io.fabric8.kubernetes.api.model.apps.Deployment in project kubernetes by ballerinax.
the class EnvVarTest method configMapKeyRefTest.
/**
* Build bal file with deployment having name and configMapKeyRef environment variables.
* @throws IOException Error when loading the generated yaml.
* @throws InterruptedException Error when compiling the ballerina file.
* @throws KubernetesPluginException Error when deleting the generated artifacts folder.
*/
@Test
public void configMapKeyRefTest() throws IOException, InterruptedException, KubernetesPluginException, DockerTestException {
Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(BAL_DIRECTORY, "config_map_key_ref.bal"), 0);
// Check if docker image exists and correct
validateDockerfile();
validateDockerImage();
// Validate deployment yaml
File deploymentYAML = KUBERNETES_TARGET_PATH.resolve("config_map_key_ref_deployment.yaml").toFile();
Assert.assertTrue(deploymentYAML.exists());
Deployment deployment = KubernetesTestUtils.loadYaml(deploymentYAML);
List<EnvVar> envVars = deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getEnv();
Assert.assertEquals(envVars.size(), 2, "Invalid number of environment variables found.");
Assert.assertEquals(envVars.get(0).getName(), "SPECIAL_LEVEL_KEY", "Invalid environment variable name found.");
Assert.assertEquals(envVars.get(0).getValueFrom().getConfigMapKeyRef().getName(), "special-config", "Invalid environment variable value found.");
Assert.assertEquals(envVars.get(0).getValueFrom().getConfigMapKeyRef().getKey(), "special.how", "Invalid environment variable value found.");
Assert.assertEquals(envVars.get(1).getName(), "LOG_LEVEL", "Invalid environment variable name found.");
Assert.assertEquals(envVars.get(1).getValueFrom().getConfigMapKeyRef().getName(), "env-config", "Invalid environment variable value found.");
Assert.assertEquals(envVars.get(1).getValueFrom().getConfigMapKeyRef().getKey(), "log_level", "Invalid environment variable value found.");
KubernetesUtils.deleteDirectory(KUBERNETES_TARGET_PATH);
KubernetesUtils.deleteDirectory(DOCKER_TARGET_PATH);
KubernetesTestUtils.deleteDockerImage(DOCKER_IMAGE);
}
use of io.fabric8.kubernetes.api.model.apps.Deployment in project kubernetes by ballerinax.
the class Sample10Test method validateBurgerDeployment.
@Test
public void validateBurgerDeployment() {
Assert.assertNotNull(burgerDeployment);
Assert.assertEquals(burgerDeployment.getMetadata().getName(), "john-burger-0-0-1-deployment");
Assert.assertEquals(burgerDeployment.getSpec().getReplicas().intValue(), 1);
Assert.assertEquals(burgerDeployment.getMetadata().getLabels().get(KubernetesConstants.KUBERNETES_SELECTOR_KEY), BURGER_SELECTOR);
Assert.assertEquals(burgerDeployment.getSpec().getTemplate().getSpec().getContainers().size(), 1);
// Assert Containers
Container container = burgerDeployment.getSpec().getTemplate().getSpec().getContainers().get(0);
Assert.assertEquals(container.getVolumeMounts().size(), 0);
Assert.assertEquals(container.getImage(), BURGER_DOCKER_IMAGE);
Assert.assertEquals(container.getImagePullPolicy(), KubernetesConstants.ImagePullPolicy.IfNotPresent.name());
Assert.assertEquals(container.getPorts().size(), 1);
}
use of io.fabric8.kubernetes.api.model.apps.Deployment in project kubernetes by ballerinax.
the class Sample14Test method validateDeployment.
@Test
public void validateDeployment() {
Assert.assertNotNull(deployment);
Assert.assertEquals(deployment.getMetadata().getName(), "hello-world-k8s-namespace-deployment");
Assert.assertEquals(deployment.getMetadata().getNamespace(), NAMESPACE);
Assert.assertEquals(deployment.getSpec().getReplicas().intValue(), 1);
Assert.assertEquals(deployment.getMetadata().getLabels().get(KubernetesConstants.KUBERNETES_SELECTOR_KEY), SELECTOR_APP);
Assert.assertEquals(deployment.getSpec().getTemplate().getSpec().getContainers().size(), 1);
Container container = deployment.getSpec().getTemplate().getSpec().getContainers().get(0);
Assert.assertEquals(container.getImage(), DOCKER_IMAGE);
Assert.assertEquals(container.getImagePullPolicy(), KubernetesConstants.ImagePullPolicy.IfNotPresent.name());
Assert.assertEquals(container.getPorts().size(), 1);
Assert.assertEquals(container.getEnv().size(), 0);
}
Aggregations