Search in sources :

Example 6 with PodTemplate

use of io.fabric8.kubernetes.api.model.PodTemplate in project flink by apache.

the class KubernetesJobManagerFactoryWithPodTemplateTest method getResultPod.

@Override
protected Pod getResultPod(FlinkPod podTemplate) throws Exception {
    final KubernetesJobManagerParameters kubernetesJobManagerParameters = new KubernetesJobManagerParameters(flinkConfig, new KubernetesClusterClientFactory().getClusterSpecification(flinkConfig));
    final KubernetesJobManagerSpecification kubernetesJobManagerSpecification = KubernetesJobManagerFactory.buildKubernetesJobManagerSpecification(podTemplate, kubernetesJobManagerParameters);
    final PodTemplateSpec podTemplateSpec = kubernetesJobManagerSpecification.getDeployment().getSpec().getTemplate();
    return new PodBuilder().withMetadata(podTemplateSpec.getMetadata()).withSpec(podTemplateSpec.getSpec()).build();
}
Also used : PodTemplateSpec(io.fabric8.kubernetes.api.model.PodTemplateSpec) KubernetesClusterClientFactory(org.apache.flink.kubernetes.KubernetesClusterClientFactory) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) KubernetesJobManagerSpecification(org.apache.flink.kubernetes.kubeclient.KubernetesJobManagerSpecification) KubernetesJobManagerParameters(org.apache.flink.kubernetes.kubeclient.parameters.KubernetesJobManagerParameters)

Example 7 with PodTemplate

use of io.fabric8.kubernetes.api.model.PodTemplate in project fabric8-maven-plugin by fabric8io.

the class AutoTLSEnricherTest method testAdapt.

@Test
public void testAdapt() throws Exception {
    final AdaptTestConfig[] data = new AdaptTestConfig[] { new AdaptTestConfig(PlatformMode.kubernetes, null, null, null, null, null, null, null, null), new AdaptTestConfig(PlatformMode.openshift, null, "tls-jks-converter", null, "jimmidyson/pemtokeystore:v0.1.0", null, "tls-pem", null, "tls-jks"), new AdaptTestConfig(PlatformMode.openshift, null, "tls-jks-converter", null, "jimmidyson/pemtokeystore:v0.1.0", "tls-a", "tls-a", null, "tls-jks"), new AdaptTestConfig(PlatformMode.openshift, null, "tls-jks-converter", null, "jimmidyson/pemtokeystore:v0.1.0", null, "tls-pem", "jks-b", "jks-b"), new AdaptTestConfig(PlatformMode.openshift, "test-container-name", "test-container-name", "image/123", "image/123", "tls-a", "tls-a", "jks-b", "jks-b") };
    for (final AdaptTestConfig tc : data) {
        TreeMap configMap = new TreeMap() {

            {
                put(AutoTLSEnricher.Config.pemToJKSInitContainerName.name(), tc.initContainerNameConfig);
                put(AutoTLSEnricher.Config.pemToJKSInitContainerImage.name(), tc.initContainerImageConfig);
                put(AutoTLSEnricher.Config.tlsSecretVolumeName.name(), tc.tlsSecretVolumeNameConfig);
                put(AutoTLSEnricher.Config.jksVolumeName.name(), tc.jksVolumeNameConfig);
            }
        };
        final ProcessorConfig config = new ProcessorConfig(null, null, Collections.singletonMap(AutoTLSEnricher.ENRICHER_NAME, configMap));
        final Properties projectProps = new Properties();
        projectProps.put(PlatformMode.FABRIC8_EFFECTIVE_PLATFORM_MODE, tc.mode.name());
        // Setup mock behaviour
        new Expectations() {

            {
                project.getProperties();
                result = projectProps;
                project.getArtifactId();
                result = "projectA";
                minTimes = 0;
                context.getProject();
                result = project;
                context.getConfig();
                result = config;
            }
        };
        AutoTLSEnricher enricher = new AutoTLSEnricher(context);
        KubernetesListBuilder klb = new KubernetesListBuilder().addNewPodTemplateItem().withNewMetadata().and().withNewTemplate().withNewMetadata().and().withNewSpec().and().and().and();
        enricher.adapt(klb);
        PodTemplate pt = (PodTemplate) klb.getItems().get(0);
        String initContainers = pt.getTemplate().getMetadata().getAnnotations().get(InitContainerHandler.INIT_CONTAINER_ANNOTATION);
        assertEquals(tc.mode == PlatformMode.openshift, initContainers != null);
        if (tc.mode == PlatformMode.kubernetes) {
            continue;
        }
        JSONArray ja = new JSONArray(initContainers);
        assertEquals(1, ja.length());
        JSONObject jo = ja.getJSONObject(0);
        assertEquals(tc.initContainerName, jo.get("name"));
        assertEquals(tc.initContainerImage, jo.get("image"));
        JSONArray mounts = jo.getJSONArray("volumeMounts");
        assertEquals(2, mounts.length());
        JSONObject mount = mounts.getJSONObject(0);
        assertEquals(tc.tlsSecretVolumeName, mount.get("name"));
        mount = mounts.getJSONObject(1);
        assertEquals(tc.jksVolumeName, mount.get("name"));
    }
}
Also used : Expectations(mockit.Expectations) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) ProcessorConfig(io.fabric8.maven.core.config.ProcessorConfig) PodTemplate(io.fabric8.kubernetes.api.model.PodTemplate) Test(org.junit.Test)

Example 8 with PodTemplate

use of io.fabric8.kubernetes.api.model.PodTemplate in project fabric8-maven-plugin by fabric8io.

the class VolumePermissionEnricherTest method testAdapt.

@Test
public void testAdapt() throws Exception {
    final TestConfig[] data = new TestConfig[] { new TestConfig(null, null), new TestConfig(null, VolumePermissionEnricher.ENRICHER_NAME, "volumeA"), new TestConfig(null, VolumePermissionEnricher.ENRICHER_NAME, "volumeA", "volumeB") };
    for (final TestConfig tc : data) {
        final ProcessorConfig config = new ProcessorConfig(null, null, Collections.singletonMap(VolumePermissionEnricher.ENRICHER_NAME, new TreeMap(Collections.singletonMap(VolumePermissionEnricher.Config.permission.name(), tc.permission))));
        // Setup mock behaviour
        new Expectations() {

            {
                context.getConfig();
                result = config;
            }
        };
        VolumePermissionEnricher enricher = new VolumePermissionEnricher(context);
        PodTemplateBuilder ptb = createEmptyPodTemplate();
        for (String vn : tc.volumeNames) {
            ptb = addVolume(ptb, vn);
        }
        KubernetesListBuilder klb = new KubernetesListBuilder().addToPodTemplateItems(ptb.build());
        enricher.adapt(klb);
        PodTemplate pt = (PodTemplate) klb.buildItem(0);
        String initContainers = pt.getTemplate().getMetadata().getAnnotations().get(InitContainerHandler.INIT_CONTAINER_ANNOTATION);
        boolean shouldHaveInitContainer = tc.volumeNames.length > 0;
        assertEquals(shouldHaveInitContainer, initContainers != null);
        if (!shouldHaveInitContainer) {
            continue;
        }
        JSONArray ja = new JSONArray(initContainers);
        assertEquals(1, ja.length());
        JSONObject jo = ja.getJSONObject(0);
        assertEquals(tc.initContainerName, jo.get("name"));
        String permission = Strings.isNullOrBlank(tc.permission) ? "777" : tc.permission;
        JSONArray chmodCmd = new JSONArray();
        chmodCmd.put("chmod");
        chmodCmd.put(permission);
        for (String vn : tc.volumeNames) {
            chmodCmd.put("/tmp/" + vn);
        }
        assertEquals(chmodCmd.toString(), jo.getJSONArray("command").toString());
    }
}
Also used : Expectations(mockit.Expectations) JSONArray(org.json.JSONArray) TreeMap(java.util.TreeMap) ProcessorConfig(io.fabric8.maven.core.config.ProcessorConfig) JSONObject(org.json.JSONObject) Test(org.junit.Test)

Example 9 with PodTemplate

use of io.fabric8.kubernetes.api.model.PodTemplate in project flink by apache.

the class KubernetesTaskManagerFactory method buildTaskManagerKubernetesPod.

public static KubernetesPod buildTaskManagerKubernetesPod(FlinkPod podTemplate, KubernetesTaskManagerParameters kubernetesTaskManagerParameters) {
    FlinkPod flinkPod = Preconditions.checkNotNull(podTemplate).copy();
    final KubernetesStepDecorator[] stepDecorators = new KubernetesStepDecorator[] { new InitTaskManagerDecorator(kubernetesTaskManagerParameters), new EnvSecretsDecorator(kubernetesTaskManagerParameters), new MountSecretsDecorator(kubernetesTaskManagerParameters), new CmdTaskManagerDecorator(kubernetesTaskManagerParameters), new HadoopConfMountDecorator(kubernetesTaskManagerParameters), new KerberosMountDecorator(kubernetesTaskManagerParameters), new FlinkConfMountDecorator(kubernetesTaskManagerParameters) };
    for (KubernetesStepDecorator stepDecorator : stepDecorators) {
        flinkPod = stepDecorator.decorateFlinkPod(flinkPod);
    }
    final Pod resolvedPod = new PodBuilder(flinkPod.getPodWithoutMainContainer()).editOrNewSpec().addToContainers(flinkPod.getMainContainer()).endSpec().build();
    return new KubernetesPod(resolvedPod);
}
Also used : KubernetesStepDecorator(org.apache.flink.kubernetes.kubeclient.decorators.KubernetesStepDecorator) EnvSecretsDecorator(org.apache.flink.kubernetes.kubeclient.decorators.EnvSecretsDecorator) Pod(io.fabric8.kubernetes.api.model.Pod) FlinkPod(org.apache.flink.kubernetes.kubeclient.FlinkPod) KubernetesPod(org.apache.flink.kubernetes.kubeclient.resources.KubernetesPod) FlinkPod(org.apache.flink.kubernetes.kubeclient.FlinkPod) InitTaskManagerDecorator(org.apache.flink.kubernetes.kubeclient.decorators.InitTaskManagerDecorator) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) CmdTaskManagerDecorator(org.apache.flink.kubernetes.kubeclient.decorators.CmdTaskManagerDecorator) FlinkConfMountDecorator(org.apache.flink.kubernetes.kubeclient.decorators.FlinkConfMountDecorator) HadoopConfMountDecorator(org.apache.flink.kubernetes.kubeclient.decorators.HadoopConfMountDecorator) KerberosMountDecorator(org.apache.flink.kubernetes.kubeclient.decorators.KerberosMountDecorator) MountSecretsDecorator(org.apache.flink.kubernetes.kubeclient.decorators.MountSecretsDecorator) KubernetesPod(org.apache.flink.kubernetes.kubeclient.resources.KubernetesPod)

Example 10 with PodTemplate

use of io.fabric8.kubernetes.api.model.PodTemplate in project keycloak by keycloak.

the class PodTemplateTest method testEnvVarsAreMerged.

@Test
public void testEnvVarsAreMerged() {
    // Arrange
    var env = "KC_SOMETHING";
    var value = "some-value";
    var additionalPodTemplate = new PodTemplateSpecBuilder().withNewSpec().addNewContainer().addNewEnv().withName(env).withValue(value).endEnv().endContainer().endSpec().build();
    // Act
    var podTemplate = getDeployment(additionalPodTemplate).getSpec().getTemplate();
    // Assert
    var envVar = podTemplate.getSpec().getContainers().get(0).getEnv().stream().filter(e -> e.getName().equals(env)).findFirst().get();
    assertEquals(env, envVar.getName());
    assertEquals(value, envVar.getValue());
}
Also used : PodTemplateSpecBuilder(io.fabric8.kubernetes.api.model.PodTemplateSpecBuilder) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Aggregations

QuarkusTest (io.quarkus.test.junit.QuarkusTest)6 Test (org.junit.jupiter.api.Test)6 PodTemplateSpecBuilder (io.fabric8.kubernetes.api.model.PodTemplateSpecBuilder)5 PodTemplateSpec (io.fabric8.kubernetes.api.model.PodTemplateSpec)3 PodBuilder (io.fabric8.kubernetes.api.model.PodBuilder)2 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)2 ReplicationControllerList (io.fabric8.kubernetes.api.model.ReplicationControllerList)2 ReplicationControllerSpec (io.fabric8.kubernetes.api.model.ReplicationControllerSpec)2 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)2 ProcessorConfig (io.fabric8.maven.core.config.ProcessorConfig)2 Expectations (mockit.Expectations)2 FlinkPod (org.apache.flink.kubernetes.kubeclient.FlinkPod)2 KubernetesJobManagerSpecification (org.apache.flink.kubernetes.kubeclient.KubernetesJobManagerSpecification)2 EnvSecretsDecorator (org.apache.flink.kubernetes.kubeclient.decorators.EnvSecretsDecorator)2 FlinkConfMountDecorator (org.apache.flink.kubernetes.kubeclient.decorators.FlinkConfMountDecorator)2 HadoopConfMountDecorator (org.apache.flink.kubernetes.kubeclient.decorators.HadoopConfMountDecorator)2 KerberosMountDecorator (org.apache.flink.kubernetes.kubeclient.decorators.KerberosMountDecorator)2 KubernetesStepDecorator (org.apache.flink.kubernetes.kubeclient.decorators.KubernetesStepDecorator)2 MountSecretsDecorator (org.apache.flink.kubernetes.kubeclient.decorators.MountSecretsDecorator)2 JSONArray (org.json.JSONArray)2