Search in sources :

Example 66 with Deployment

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);
}
Also used : Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) File(java.io.File) Test(org.testng.annotations.Test)

Example 67 with Deployment

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);
}
Also used : HashMap(java.util.HashMap) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) File(java.io.File) Test(org.testng.annotations.Test)

Example 68 with Deployment

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);
}
Also used : Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) File(java.io.File) Test(org.testng.annotations.Test)

Example 69 with Deployment

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);
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) Test(org.testng.annotations.Test)

Example 70 with Deployment

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);
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) Test(org.testng.annotations.Test)

Aggregations

File (java.io.File)62 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)52 Test (org.testng.annotations.Test)50 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)47 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)43 Container (io.fabric8.kubernetes.api.model.Container)32 Service (io.fabric8.kubernetes.api.model.Service)28 Test (org.junit.Test)28 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)27 InputStream (java.io.InputStream)26 DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)25 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)25 Deployment (org.jboss.arquillian.container.test.api.Deployment)21 OSGiManifestBuilder (org.jboss.osgi.metadata.OSGiManifestBuilder)21 Asset (org.jboss.shrinkwrap.api.asset.Asset)21 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)21 IOException (java.io.IOException)20 ServiceTracker (org.osgi.util.tracker.ServiceTracker)20 FileInputStream (java.io.FileInputStream)19 CommandSupport (io.fabric8.itests.support.CommandSupport)18