use of io.fabric8.kubernetes.api.model.PodSecurityContextBuilder in project strimzi by strimzi.
the class AbstractModel method createStatefulSet.
protected StatefulSet createStatefulSet(List<ContainerPort> ports, List<Volume> volumes, List<PersistentVolumeClaim> volumeClaims, List<VolumeMount> volumeMounts, Probe livenessProbe, Probe readinessProbe, boolean isOpenShift) {
Map<String, String> annotations = new HashMap<>();
annotations.put(String.format("%s/%s", ClusterController.STRIMZI_CLUSTER_CONTROLLER_DOMAIN, Storage.DELETE_CLAIM_FIELD), String.valueOf(storage.isDeleteClaim()));
Container container = new ContainerBuilder().withName(name).withImage(getImage()).withEnv(getEnvVars()).withVolumeMounts(volumeMounts).withPorts(ports).withLivenessProbe(livenessProbe).withReadinessProbe(readinessProbe).build();
List<Container> initContainers = new ArrayList<>();
PodSecurityContext securityContext = null;
// there is an hack on volume mounting which needs an "init-container"
if ((this.storage.type() == Storage.StorageType.PERSISTENT_CLAIM) && !isOpenShift) {
String chown = String.format("chown -R %d:%d %s", AbstractModel.VOLUME_MOUNT_HACK_GROUPID, AbstractModel.VOLUME_MOUNT_HACK_GROUPID, volumeMounts.get(0).getMountPath());
Container initContainer = new ContainerBuilder().withName(AbstractModel.VOLUME_MOUNT_HACK_NAME).withImage(AbstractModel.VOLUME_MOUNT_HACK_IMAGE).withVolumeMounts(volumeMounts.get(0)).withCommand("sh", "-c", chown).build();
initContainers.add(initContainer);
securityContext = new PodSecurityContextBuilder().withFsGroup(AbstractModel.VOLUME_MOUNT_HACK_GROUPID).build();
}
StatefulSet statefulSet = new StatefulSetBuilder().withNewMetadata().withName(name).withLabels(getLabelsWithName()).withNamespace(namespace).withAnnotations(annotations).endMetadata().withNewSpec().withPodManagementPolicy("Parallel").withUpdateStrategy(new StatefulSetUpdateStrategyBuilder().withType("OnDelete").build()).withSelector(new LabelSelectorBuilder().withMatchLabels(getLabelsWithName()).build()).withServiceName(headlessName).withReplicas(replicas).withNewTemplate().withNewMetadata().withName(name).withLabels(getLabelsWithName()).withAnnotations(getPrometheusAnnotations()).endMetadata().withNewSpec().withSecurityContext(securityContext).withInitContainers(initContainers).withContainers(container).withVolumes(volumes).endSpec().endTemplate().withVolumeClaimTemplates(volumeClaims).endSpec().build();
return statefulSet;
}
Aggregations