Search in sources :

Example 1 with V1DownwardAPIVolumeSource

use of io.kubernetes.client.openapi.models.V1DownwardAPIVolumeSource in project cdap by caskdata.

the class KubeMasterEnvironment method createBasePodSpec.

/**
 * Creates the base pod spec to use as a template for all pods that Spark creates.
 *
 * @return pod template to use for Spark pods
 */
private V1PodSpec createBasePodSpec() {
    /*
        define the podinfo volume. This uses downwardAPI, which tells k8s to store pod information in files:

        - downwardAPI:
          defaultMode: 420
          items:
          - fieldRef:
              fieldPath: metadata.labels
            path: pod.labels.properties
          - fieldRef:
              fieldPath: metadata.name
            path: pod.name
          - fieldRef:
              fieldPath: metadata.uid
            path: pod.uid
        name: podinfo
     */
    V1PodSpecBuilder v1PodSpecBuilder = new V1PodSpecBuilder();
    List<V1Volume> volumes = new ArrayList<>();
    V1DownwardAPIVolumeFile labelsFile = new V1DownwardAPIVolumeFile().fieldRef(new V1ObjectFieldSelector().fieldPath("metadata.labels")).path(podLabelsFile.getName());
    V1DownwardAPIVolumeFile nameFile = new V1DownwardAPIVolumeFile().fieldRef(new V1ObjectFieldSelector().fieldPath("metadata.name")).path(podNameFile.getName());
    V1DownwardAPIVolumeFile uidFile = new V1DownwardAPIVolumeFile().fieldRef(new V1ObjectFieldSelector().fieldPath("metadata.uid")).path(podUidFile.getName());
    V1DownwardAPIVolumeSource podinfoVolume = new V1DownwardAPIVolumeSource().defaultMode(420).items(Arrays.asList(labelsFile, nameFile, uidFile));
    String podInfoVolumeName = "podinfo";
    volumes.add(new V1Volume().downwardAPI(podinfoVolume).name(podInfoVolumeName));
    List<V1VolumeMount> volumeMounts = new ArrayList<>();
    volumeMounts.add(new V1VolumeMount().name(podInfoVolumeName).mountPath(podInfoDir.getAbsolutePath()));
    v1PodSpecBuilder.withVolumes(volumes).withContainers(new V1ContainerBuilder().withVolumeMounts(volumeMounts).build());
    return v1PodSpecBuilder.build();
}
Also used : V1DownwardAPIVolumeFile(io.kubernetes.client.openapi.models.V1DownwardAPIVolumeFile) V1Volume(io.kubernetes.client.openapi.models.V1Volume) V1DownwardAPIVolumeSource(io.kubernetes.client.openapi.models.V1DownwardAPIVolumeSource) ArrayList(java.util.ArrayList) V1ObjectFieldSelector(io.kubernetes.client.openapi.models.V1ObjectFieldSelector) V1ContainerBuilder(io.kubernetes.client.openapi.models.V1ContainerBuilder) V1PodSpecBuilder(io.kubernetes.client.openapi.models.V1PodSpecBuilder) V1VolumeMount(io.kubernetes.client.openapi.models.V1VolumeMount)

Aggregations

V1ContainerBuilder (io.kubernetes.client.openapi.models.V1ContainerBuilder)1 V1DownwardAPIVolumeFile (io.kubernetes.client.openapi.models.V1DownwardAPIVolumeFile)1 V1DownwardAPIVolumeSource (io.kubernetes.client.openapi.models.V1DownwardAPIVolumeSource)1 V1ObjectFieldSelector (io.kubernetes.client.openapi.models.V1ObjectFieldSelector)1 V1PodSpecBuilder (io.kubernetes.client.openapi.models.V1PodSpecBuilder)1 V1Volume (io.kubernetes.client.openapi.models.V1Volume)1 V1VolumeMount (io.kubernetes.client.openapi.models.V1VolumeMount)1 ArrayList (java.util.ArrayList)1