use of io.fabric8.kubernetes.api.model.apps.StatefulSetBuilder in project strimzi by strimzi.
the class StatefulSetDiffTest method testCpuResources.
public StatefulSetDiff testCpuResources(ResourceRequirements requirements1, ResourceRequirements requirements2) {
StatefulSet ss1 = new StatefulSetBuilder().withNewMetadata().withNamespace("test").withName("foo").endMetadata().withNewSpec().withNewTemplate().withNewSpec().addNewContainer().withResources(requirements1).endContainer().endSpec().endTemplate().endSpec().build();
StatefulSet ss2 = new StatefulSetBuilder().withNewMetadata().withNamespace("test").withName("foo").endMetadata().withNewSpec().withNewTemplate().withNewSpec().addNewContainer().withResources(requirements2).endContainer().endSpec().endTemplate().endSpec().build();
return new StatefulSetDiff(Reconciliation.DUMMY_RECONCILIATION, ss1, ss2);
}
use of io.fabric8.kubernetes.api.model.apps.StatefulSetBuilder in project strimzi by strimzi.
the class StatefulSetDiffTest method testPvcSizeChangeIgnored.
@Test
public void testPvcSizeChangeIgnored() {
StatefulSet ss1 = new StatefulSetBuilder().withNewMetadata().withNamespace("test").withName("foo").endMetadata().withNewSpec().withNewTemplate().withNewSpec().addToVolumes(0, new VolumeBuilder().withConfigMap(new ConfigMapVolumeSourceBuilder().withDefaultMode(1).build()).build()).endSpec().endTemplate().withVolumeClaimTemplates(new PersistentVolumeClaimBuilder().withNewSpec().withNewResources().withRequests(singletonMap("storage", new Quantity("100Gi"))).endResources().endSpec().build()).endSpec().build();
StatefulSet ss2 = new StatefulSetBuilder().withNewMetadata().withNamespace("test").withName("foo").endMetadata().withNewSpec().withNewTemplate().withNewSpec().addToVolumes(0, new VolumeBuilder().withConfigMap(new ConfigMapVolumeSourceBuilder().withDefaultMode(2).build()).build()).endSpec().endTemplate().withVolumeClaimTemplates(new PersistentVolumeClaimBuilder().withNewSpec().withNewResources().withRequests(singletonMap("storage", new Quantity("110Gi"))).endResources().endSpec().build()).endSpec().build();
assertThat(new StatefulSetDiff(Reconciliation.DUMMY_RECONCILIATION, ss1, ss2).changesVolumeClaimTemplates(), is(false));
assertThat(new StatefulSetDiff(Reconciliation.DUMMY_RECONCILIATION, ss1, ss2).changesVolumeSize(), is(true));
}
use of io.fabric8.kubernetes.api.model.apps.StatefulSetBuilder 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;
}
use of io.fabric8.kubernetes.api.model.apps.StatefulSetBuilder 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;
}
use of io.fabric8.kubernetes.api.model.apps.StatefulSetBuilder in project strimzi-kafka-operator by strimzi.
the class KafkaUpgradeDowngradeMockTest method testUpgradeRecoveryWithMessageAndProtocolVersions.
// Tests recovery from failed upgrade with the message format and protocol versions configured to the same Kafka
// version as we are upgrading from.
@Test
public void testUpgradeRecoveryWithMessageAndProtocolVersions(VertxTestContext context) {
Kafka initialKafka = kafkaWithVersions(KafkaVersionTestUtils.PREVIOUS_KAFKA_VERSION, KafkaVersionTestUtils.PREVIOUS_FORMAT_VERSION, KafkaVersionTestUtils.PREVIOUS_PROTOCOL_VERSION);
Kafka updatedKafka = kafkaWithVersions(KafkaVersionTestUtils.LATEST_KAFKA_VERSION, KafkaVersionTestUtils.PREVIOUS_FORMAT_VERSION, KafkaVersionTestUtils.PREVIOUS_PROTOCOL_VERSION);
Checkpoint reconciliation = context.checkpoint();
initialize(context, initialKafka).onComplete(context.succeeding(v -> {
context.verify(() -> {
assertVersionsInStatefulSet(KafkaVersionTestUtils.PREVIOUS_KAFKA_VERSION, KafkaVersionTestUtils.PREVIOUS_FORMAT_VERSION, KafkaVersionTestUtils.PREVIOUS_PROTOCOL_VERSION, KafkaVersionTestUtils.PREVIOUS_KAFKA_IMAGE);
});
})).compose(v -> {
StatefulSet sts = client.apps().statefulSets().inNamespace(NAMESPACE).withName(CLUSTER_NAME + "-kafka").get();
StatefulSet modifiedSts = new StatefulSetBuilder(sts).editMetadata().addToAnnotations(KafkaCluster.ANNO_STRIMZI_IO_KAFKA_VERSION, KafkaVersionTestUtils.LATEST_KAFKA_VERSION).endMetadata().editSpec().editTemplate().editMetadata().addToAnnotations(KafkaCluster.ANNO_STRIMZI_IO_KAFKA_VERSION, KafkaVersionTestUtils.LATEST_KAFKA_VERSION).addToAnnotations(StatefulSetOperator.ANNO_STRIMZI_IO_GENERATION, "1").endMetadata().editSpec().editContainer(0).withImage(KafkaVersionTestUtils.LATEST_KAFKA_IMAGE).endContainer().endSpec().endTemplate().endSpec().build();
client.apps().statefulSets().inNamespace(NAMESPACE).withName(CLUSTER_NAME + "-kafka").createOrReplace(modifiedSts);
Pod pod = client.pods().inNamespace(NAMESPACE).withName(CLUSTER_NAME + "-kafka-" + 1).get();
Pod modifiedPod = new PodBuilder(pod).editMetadata().addToAnnotations(KafkaCluster.ANNO_STRIMZI_IO_KAFKA_VERSION, KafkaVersionTestUtils.LATEST_KAFKA_VERSION).addToAnnotations(StatefulSetOperator.ANNO_STRIMZI_IO_GENERATION, "1").endMetadata().editSpec().editContainer(0).withImage(KafkaVersionTestUtils.LATEST_KAFKA_IMAGE).endContainer().endSpec().build();
client.pods().inNamespace(NAMESPACE).withName(CLUSTER_NAME + "-kafka-" + 1).createOrReplace(modifiedPod);
return Future.succeededFuture();
}).compose(v -> operator.createOrUpdate(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, NAMESPACE, CLUSTER_NAME), updatedKafka)).onComplete(context.succeeding(v -> context.verify(() -> {
assertVersionsInStatefulSet(KafkaVersionTestUtils.LATEST_KAFKA_VERSION, KafkaVersionTestUtils.PREVIOUS_FORMAT_VERSION, KafkaVersionTestUtils.PREVIOUS_PROTOCOL_VERSION, KafkaVersionTestUtils.LATEST_KAFKA_IMAGE);
reconciliation.flag();
})));
}
Aggregations