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();
}
Aggregations