Search in sources :

Example 1 with StatefulSetUpdateStrategyBuilder

use of io.fabric8.kubernetes.api.model.apps.StatefulSetUpdateStrategyBuilder in project strimzi by strimzi.

the class AbstractModel method createStatefulSet.

protected StatefulSet createStatefulSet(Map<String, String> stsAnnotations, Map<String, String> podAnnotations, List<Volume> volumes, List<PersistentVolumeClaim> volumeClaims, Affinity affinity, List<Container> initContainers, List<Container> containers, List<LocalObjectReference> imagePullSecrets, boolean isOpenShift) {
    PodSecurityContext securityContext = templateSecurityContext;
    // This is to give each pod write permissions under a specific group so that if a pod changes users it does not have permission issues.
    if (ModelUtils.containsPersistentStorage(storage) && !isOpenShift && securityContext == null) {
        securityContext = new PodSecurityContextBuilder().withFsGroup(AbstractModel.DEFAULT_FS_GROUPID).build();
    }
    StatefulSet statefulSet = new StatefulSetBuilder().withNewMetadata().withName(name).withLabels(getLabelsWithStrimziName(name, templateStatefulSetLabels).toMap()).withNamespace(namespace).withAnnotations(Util.mergeLabelsOrAnnotations(stsAnnotations, templateStatefulSetAnnotations)).withOwnerReferences(createOwnerReference()).endMetadata().withNewSpec().withPodManagementPolicy(templatePodManagementPolicy.toValue()).withUpdateStrategy(new StatefulSetUpdateStrategyBuilder().withType("OnDelete").build()).withSelector(new LabelSelectorBuilder().withMatchLabels(getSelectorLabels().toMap()).build()).withServiceName(headlessServiceName).withReplicas(replicas).withNewTemplate().withNewMetadata().withName(name).withLabels(getLabelsWithStrimziName(name, templatePodLabels).toMap()).withAnnotations(Util.mergeLabelsOrAnnotations(podAnnotations, templatePodAnnotations)).endMetadata().withNewSpec().withServiceAccountName(getServiceAccountName()).withEnableServiceLinks(templatePodEnableServiceLinks).withAffinity(affinity).withInitContainers(initContainers).withContainers(containers).withVolumes(volumes).withTolerations(getTolerations()).withTerminationGracePeriodSeconds(Long.valueOf(templateTerminationGracePeriodSeconds)).withImagePullSecrets(templateImagePullSecrets != null ? templateImagePullSecrets : imagePullSecrets).withSecurityContext(securityContext).withPriorityClassName(templatePodPriorityClassName).withSchedulerName(templatePodSchedulerName != null ? templatePodSchedulerName : "default-scheduler").withHostAliases(templatePodHostAliases).withTopologySpreadConstraints(templatePodTopologySpreadConstraints).endSpec().endTemplate().withVolumeClaimTemplates(volumeClaims).endSpec().build();
    return statefulSet;
}
Also used : LabelSelectorBuilder(io.fabric8.kubernetes.api.model.LabelSelectorBuilder) PodSecurityContextBuilder(io.fabric8.kubernetes.api.model.PodSecurityContextBuilder) PodSecurityContext(io.fabric8.kubernetes.api.model.PodSecurityContext) StatefulSetUpdateStrategyBuilder(io.fabric8.kubernetes.api.model.apps.StatefulSetUpdateStrategyBuilder) StatefulSet(io.fabric8.kubernetes.api.model.apps.StatefulSet) StatefulSetBuilder(io.fabric8.kubernetes.api.model.apps.StatefulSetBuilder)

Example 2 with StatefulSetUpdateStrategyBuilder

use of io.fabric8.kubernetes.api.model.apps.StatefulSetUpdateStrategyBuilder in project strimzi-kafka-operator by strimzi.

the class AbstractModel method createStatefulSet.

protected StatefulSet createStatefulSet(Map<String, String> stsAnnotations, Map<String, String> podAnnotations, List<Volume> volumes, List<PersistentVolumeClaim> volumeClaims, Affinity affinity, List<Container> initContainers, List<Container> containers, List<LocalObjectReference> imagePullSecrets, boolean isOpenShift) {
    PodSecurityContext securityContext = templateSecurityContext;
    // This is to give each pod write permissions under a specific group so that if a pod changes users it does not have permission issues.
    if (ModelUtils.containsPersistentStorage(storage) && !isOpenShift && securityContext == null) {
        securityContext = new PodSecurityContextBuilder().withFsGroup(AbstractModel.DEFAULT_FS_GROUPID).build();
    }
    StatefulSet statefulSet = new StatefulSetBuilder().withNewMetadata().withName(name).withLabels(getLabelsWithStrimziName(name, templateStatefulSetLabels).toMap()).withNamespace(namespace).withAnnotations(Util.mergeLabelsOrAnnotations(stsAnnotations, templateStatefulSetAnnotations)).withOwnerReferences(createOwnerReference()).endMetadata().withNewSpec().withPodManagementPolicy(templatePodManagementPolicy.toValue()).withUpdateStrategy(new StatefulSetUpdateStrategyBuilder().withType("OnDelete").build()).withSelector(new LabelSelectorBuilder().withMatchLabels(getSelectorLabels().toMap()).build()).withServiceName(headlessServiceName).withReplicas(replicas).withNewTemplate().withNewMetadata().withName(name).withLabels(getLabelsWithStrimziName(name, templatePodLabels).toMap()).withAnnotations(Util.mergeLabelsOrAnnotations(podAnnotations, templatePodAnnotations)).endMetadata().withNewSpec().withServiceAccountName(getServiceAccountName()).withEnableServiceLinks(templatePodEnableServiceLinks).withAffinity(affinity).withInitContainers(initContainers).withContainers(containers).withVolumes(volumes).withTolerations(getTolerations()).withTerminationGracePeriodSeconds(Long.valueOf(templateTerminationGracePeriodSeconds)).withImagePullSecrets(templateImagePullSecrets != null ? templateImagePullSecrets : imagePullSecrets).withSecurityContext(securityContext).withPriorityClassName(templatePodPriorityClassName).withSchedulerName(templatePodSchedulerName != null ? templatePodSchedulerName : "default-scheduler").withHostAliases(templatePodHostAliases).withTopologySpreadConstraints(templatePodTopologySpreadConstraints).endSpec().endTemplate().withVolumeClaimTemplates(volumeClaims).endSpec().build();
    return statefulSet;
}
Also used : LabelSelectorBuilder(io.fabric8.kubernetes.api.model.LabelSelectorBuilder) PodSecurityContextBuilder(io.fabric8.kubernetes.api.model.PodSecurityContextBuilder) PodSecurityContext(io.fabric8.kubernetes.api.model.PodSecurityContext) StatefulSetUpdateStrategyBuilder(io.fabric8.kubernetes.api.model.apps.StatefulSetUpdateStrategyBuilder) StatefulSet(io.fabric8.kubernetes.api.model.apps.StatefulSet) StatefulSetBuilder(io.fabric8.kubernetes.api.model.apps.StatefulSetBuilder)

Example 3 with StatefulSetUpdateStrategyBuilder

use of io.fabric8.kubernetes.api.model.apps.StatefulSetUpdateStrategyBuilder 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;
}
Also used : LabelSelectorBuilder(io.fabric8.kubernetes.api.model.LabelSelectorBuilder) HashMap(java.util.HashMap) PodSecurityContext(io.fabric8.kubernetes.api.model.PodSecurityContext) StatefulSetUpdateStrategyBuilder(io.fabric8.kubernetes.api.model.extensions.StatefulSetUpdateStrategyBuilder) ArrayList(java.util.ArrayList) StatefulSetBuilder(io.fabric8.kubernetes.api.model.extensions.StatefulSetBuilder) Container(io.fabric8.kubernetes.api.model.Container) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) PodSecurityContextBuilder(io.fabric8.kubernetes.api.model.PodSecurityContextBuilder) StatefulSet(io.fabric8.kubernetes.api.model.extensions.StatefulSet)

Aggregations

LabelSelectorBuilder (io.fabric8.kubernetes.api.model.LabelSelectorBuilder)3 PodSecurityContext (io.fabric8.kubernetes.api.model.PodSecurityContext)3 PodSecurityContextBuilder (io.fabric8.kubernetes.api.model.PodSecurityContextBuilder)3 StatefulSet (io.fabric8.kubernetes.api.model.apps.StatefulSet)2 StatefulSetBuilder (io.fabric8.kubernetes.api.model.apps.StatefulSetBuilder)2 StatefulSetUpdateStrategyBuilder (io.fabric8.kubernetes.api.model.apps.StatefulSetUpdateStrategyBuilder)2 Container (io.fabric8.kubernetes.api.model.Container)1 ContainerBuilder (io.fabric8.kubernetes.api.model.ContainerBuilder)1 StatefulSet (io.fabric8.kubernetes.api.model.extensions.StatefulSet)1 StatefulSetBuilder (io.fabric8.kubernetes.api.model.extensions.StatefulSetBuilder)1 StatefulSetUpdateStrategyBuilder (io.fabric8.kubernetes.api.model.extensions.StatefulSetUpdateStrategyBuilder)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1