use of io.fabric8.kubernetes.api.model.ServiceAccountTokenProjection in project kubernetes by ballerinax.
the class DeploymentTest method projectedVolumeTest.
/**
* Build bal file with deployment having projectedVolume annotations.
*
* @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 projectedVolumeTest() throws IOException, InterruptedException, KubernetesPluginException, DockerTestException {
Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(BAL_DIRECTORY, "projected.bal"), 0);
// Check if docker image exists and correct
validateDockerfile();
validateDockerImage();
// Validate deployment yaml
File deploymentYAML = KUBERNETES_TARGET_PATH.resolve("projected_deployment.yaml").toFile();
Assert.assertTrue(deploymentYAML.exists());
Deployment deployment = KubernetesTestUtils.loadYaml(deploymentYAML);
Assert.assertNotNull(deployment.getSpec());
Assert.assertNotNull(deployment.getSpec().getTemplate());
final PodSpec spec = deployment.getSpec().getTemplate().getSpec();
Assert.assertNotNull(spec);
Assert.assertEquals(spec.getServiceAccountName(), "build-robot");
Assert.assertEquals(spec.getContainers().get(0).getVolumeMounts().size(), 1);
Assert.assertEquals(spec.getContainers().get(0).getVolumeMounts().get(0).getMountPath(), "/tmp/");
Assert.assertEquals(spec.getContainers().get(0).getVolumeMounts().get(0).getName(), "vault-volume");
Assert.assertEquals(spec.getVolumes().get(0).getName(), "vault-volume");
final ServiceAccountTokenProjection serviceAccountToken = spec.getVolumes().get(0).getProjected().getSources().get(0).getServiceAccountToken();
Assert.assertEquals(serviceAccountToken.getAudience(), "test");
Assert.assertEquals(serviceAccountToken.getPath(), "vault-volume");
Assert.assertEquals(serviceAccountToken.getExpirationSeconds(), Long.valueOf("600"));
KubernetesUtils.deleteDirectory(KUBERNETES_TARGET_PATH);
KubernetesUtils.deleteDirectory(DOCKER_TARGET_PATH);
KubernetesTestUtils.deleteDockerImage(DOCKER_IMAGE);
}
Aggregations