Search in sources :

Example 6 with EnvVarValueModel

use of org.ballerinax.kubernetes.models.EnvVarValueModel in project kubernetes by ballerinax.

the class KubernetesDeploymentGeneratorTests method testDeploymentGeneration.

@Test
public void testDeploymentGeneration() {
    DeploymentModel deploymentModel = new DeploymentModel();
    deploymentModel.setName(deploymentName);
    Map<String, String> labels = new HashMap<>();
    labels.put(KubernetesConstants.KUBERNETES_SELECTOR_KEY, selector);
    deploymentModel.addPort(9090);
    deploymentModel.addPort(9091);
    deploymentModel.addPort(9092);
    deploymentModel.setLabels(labels);
    deploymentModel.setImage(imageName);
    deploymentModel.setImagePullPolicy(imagePullPolicy);
    ProbeModel probeModel = new ProbeModel();
    probeModel.setPort(9090);
    deploymentModel.setLivenessProbe(probeModel);
    deploymentModel.setSingleYAML(false);
    Map<String, EnvVarValueModel> env = new HashMap<>();
    EnvVarValueModel testEnvVar = new EnvVarValueModel("ENV");
    env.put("ENV_VAR", testEnvVar);
    deploymentModel.setEnv(env);
    deploymentModel.setReplicas(replicas);
    dataHolder.setDeploymentModel(deploymentModel);
    try {
        new DeploymentHandler().createArtifacts();
        File tempFile = dataHolder.getK8sArtifactOutputPath().resolve("hello_deployment.yaml").toFile();
        Assert.assertTrue(tempFile.exists());
        testGeneratedYAML(tempFile);
        tempFile.deleteOnExit();
    } catch (IOException e) {
        Assert.fail("Unable to write to file");
    } catch (KubernetesPluginException e) {
        Assert.fail("Unable to generate yaml from service");
    }
}
Also used : DeploymentModel(org.ballerinax.kubernetes.models.DeploymentModel) HashMap(java.util.HashMap) ProbeModel(org.ballerinax.kubernetes.models.ProbeModel) EnvVarValueModel(org.ballerinax.kubernetes.models.EnvVarValueModel) IOException(java.io.IOException) KubernetesPluginException(org.ballerinax.kubernetes.exceptions.KubernetesPluginException) File(java.io.File) Test(org.testng.annotations.Test)

Example 7 with EnvVarValueModel

use of org.ballerinax.kubernetes.models.EnvVarValueModel in project kubernetes by ballerinax.

the class KubernetesJobGeneratorTests method testDeploymentGeneration.

@Test
public void testDeploymentGeneration() {
    JobModel jobModel = new JobModel();
    jobModel.setName(jobName);
    Map<String, String> labels = new HashMap<>();
    labels.put(KubernetesConstants.KUBERNETES_SELECTOR_KEY, selector);
    jobModel.setLabels(labels);
    jobModel.setImage(imageName);
    jobModel.setImagePullPolicy(imagePullPolicy);
    jobModel.setSingleYAML(false);
    Map<String, EnvVarValueModel> env = new HashMap<>();
    EnvVarValueModel testEnvVar = new EnvVarValueModel("ENV");
    env.put("ENV_VAR", testEnvVar);
    jobModel.setEnv(env);
    dataHolder.setJobModel(jobModel);
    try {
        new JobHandler().createArtifacts();
        File tempFile = dataHolder.getK8sArtifactOutputPath().resolve("hello_job.yaml").toFile();
        Assert.assertTrue(tempFile.exists());
        assertGeneratedYAML(tempFile);
        tempFile.deleteOnExit();
    } catch (IOException e) {
        Assert.fail("Unable to write to file");
    } catch (KubernetesPluginException e) {
        Assert.fail("Unable to generate yaml from service");
    }
}
Also used : HashMap(java.util.HashMap) EnvVarValueModel(org.ballerinax.kubernetes.models.EnvVarValueModel) JobModel(org.ballerinax.kubernetes.models.JobModel) IOException(java.io.IOException) KubernetesPluginException(org.ballerinax.kubernetes.exceptions.KubernetesPluginException) File(java.io.File) Test(org.testng.annotations.Test)

Aggregations

EnvVarValueModel (org.ballerinax.kubernetes.models.EnvVarValueModel)7 KubernetesPluginException (org.ballerinax.kubernetes.exceptions.KubernetesPluginException)5 DeploymentModel (org.ballerinax.kubernetes.models.DeploymentModel)4 File (java.io.File)3 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 Test (org.testng.annotations.Test)3 ProbeModel (org.ballerinax.kubernetes.models.ProbeModel)2 ConfigMapKeySelector (io.fabric8.kubernetes.api.model.ConfigMapKeySelector)1 ConfigMapKeySelectorBuilder (io.fabric8.kubernetes.api.model.ConfigMapKeySelectorBuilder)1 EnvVar (io.fabric8.kubernetes.api.model.EnvVar)1 EnvVarBuilder (io.fabric8.kubernetes.api.model.EnvVarBuilder)1 EnvVarSource (io.fabric8.kubernetes.api.model.EnvVarSource)1 EnvVarSourceBuilder (io.fabric8.kubernetes.api.model.EnvVarSourceBuilder)1 ObjectFieldSelector (io.fabric8.kubernetes.api.model.ObjectFieldSelector)1 ObjectFieldSelectorBuilder (io.fabric8.kubernetes.api.model.ObjectFieldSelectorBuilder)1 ResourceFieldSelector (io.fabric8.kubernetes.api.model.ResourceFieldSelector)1 ResourceFieldSelectorBuilder (io.fabric8.kubernetes.api.model.ResourceFieldSelectorBuilder)1 SecretKeySelector (io.fabric8.kubernetes.api.model.SecretKeySelector)1 SecretKeySelectorBuilder (io.fabric8.kubernetes.api.model.SecretKeySelectorBuilder)1