use of io.fabric8.kubernetes.api.model.apps.StatefulSetBuilder in project strimzi-kafka-operator by strimzi.
the class KafkaUpgradeDowngradeMockTest method testUpgradeFromUnsupportedKafkaVersionWithoutMessageAndProtocol.
// Tests upgrade from Kafka version not supported by the current version of the operator without message format and
// protocol versions specified.
@Test
public void testUpgradeFromUnsupportedKafkaVersionWithoutMessageAndProtocol(VertxTestContext context) {
KafkaVersion unsupported = VERSIONS.version("2.1.0");
Kafka initialKafka = kafkaWithVersions(KafkaVersionTestUtils.LATEST_KAFKA_VERSION, unsupported.messageVersion(), unsupported.protocolVersion());
Kafka updatedKafka = kafkaWithVersions(KafkaVersionTestUtils.LATEST_KAFKA_VERSION);
Checkpoint reconciliation = context.checkpoint();
initialize(context, initialKafka).onComplete(context.succeeding(v -> {
context.verify(() -> {
assertVersionsInStatefulSet(KafkaVersionTestUtils.LATEST_KAFKA_VERSION, unsupported.messageVersion(), unsupported.protocolVersion(), KafkaVersionTestUtils.LATEST_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, unsupported.version()).endMetadata().editSpec().editTemplate().editMetadata().removeFromAnnotations(KafkaCluster.ANNO_STRIMZI_IO_KAFKA_VERSION).removeFromAnnotations(KafkaCluster.ANNO_STRIMZI_IO_LOG_MESSAGE_FORMAT_VERSION).removeFromAnnotations(KafkaCluster.ANNO_STRIMZI_IO_INTER_BROKER_PROTOCOL_VERSION).endMetadata().editSpec().editContainer(0).withImage("strimzi/kafka:old-kafka-2.1.0").endContainer().endSpec().endTemplate().endSpec().build();
client.apps().statefulSets().inNamespace(NAMESPACE).withName(CLUSTER_NAME + "-kafka").createOrReplace(modifiedSts);
for (int i = 0; i < 3; i++) {
Pod pod = client.pods().inNamespace(NAMESPACE).withName(CLUSTER_NAME + "-kafka-" + i).get();
Pod modifiedPod = new PodBuilder(pod).editMetadata().removeFromAnnotations(KafkaCluster.ANNO_STRIMZI_IO_KAFKA_VERSION).removeFromAnnotations(KafkaCluster.ANNO_STRIMZI_IO_LOG_MESSAGE_FORMAT_VERSION).removeFromAnnotations(KafkaCluster.ANNO_STRIMZI_IO_INTER_BROKER_PROTOCOL_VERSION).endMetadata().editSpec().editContainer(0).withImage("strimzi/kafka:old-kafka-2.1.0").endContainer().endSpec().build();
client.pods().inNamespace(NAMESPACE).withName(CLUSTER_NAME + "-kafka-" + i).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, unsupported.messageVersion(), unsupported.protocolVersion(), KafkaVersionTestUtils.LATEST_KAFKA_IMAGE);
}))).compose(v -> operator.createOrUpdate(new Reconciliation("test-trigger2", Kafka.RESOURCE_KIND, NAMESPACE, CLUSTER_NAME), updatedKafka)).onComplete(context.succeeding(v -> context.verify(() -> {
assertVersionsInStatefulSet(KafkaVersionTestUtils.LATEST_KAFKA_VERSION, KafkaVersionTestUtils.LATEST_FORMAT_VERSION, KafkaVersionTestUtils.LATEST_PROTOCOL_VERSION, KafkaVersionTestUtils.LATEST_KAFKA_IMAGE);
reconciliation.flag();
})));
}
use of io.fabric8.kubernetes.api.model.apps.StatefulSetBuilder in project strimzi-kafka-operator by strimzi.
the class KafkaUpgradeDowngradeMockTest method testUpgradeWithoutAnyVersionInPodsOrStsFails.
// Tests upgrade when Kafka StatefulSet and/or Pods existing but without any of the version annotations. This
// indicates that the Statefulset / Pods were not using the current or recent Strimzi version and since we do not
// know the version, we should wail.
@Test
public void testUpgradeWithoutAnyVersionInPodsOrStsFails(VertxTestContext context) {
KafkaVersion unsupported = VERSIONS.version("2.1.0");
Kafka initialKafka = kafkaWithVersions(KafkaVersionTestUtils.LATEST_KAFKA_VERSION, unsupported.messageVersion(), unsupported.protocolVersion());
Kafka updatedKafka = kafkaWithVersions(KafkaVersionTestUtils.LATEST_KAFKA_VERSION);
Checkpoint reconciliation = context.checkpoint();
initialize(context, initialKafka).onComplete(context.succeeding(v -> {
context.verify(() -> {
assertVersionsInStatefulSet(KafkaVersionTestUtils.LATEST_KAFKA_VERSION, unsupported.messageVersion(), unsupported.protocolVersion(), KafkaVersionTestUtils.LATEST_KAFKA_IMAGE);
});
})).compose(v -> {
StatefulSet sts = client.apps().statefulSets().inNamespace(NAMESPACE).withName(CLUSTER_NAME + "-kafka").get();
StatefulSet modifiedSts = new StatefulSetBuilder(sts).editMetadata().removeFromAnnotations(KafkaCluster.ANNO_STRIMZI_IO_KAFKA_VERSION).endMetadata().editSpec().editTemplate().editMetadata().removeFromAnnotations(KafkaCluster.ANNO_STRIMZI_IO_KAFKA_VERSION).removeFromAnnotations(KafkaCluster.ANNO_STRIMZI_IO_LOG_MESSAGE_FORMAT_VERSION).removeFromAnnotations(KafkaCluster.ANNO_STRIMZI_IO_INTER_BROKER_PROTOCOL_VERSION).endMetadata().endTemplate().endSpec().build();
client.apps().statefulSets().inNamespace(NAMESPACE).withName(CLUSTER_NAME + "-kafka").createOrReplace(modifiedSts);
for (int i = 0; i < 3; i++) {
Pod pod = client.pods().inNamespace(NAMESPACE).withName(CLUSTER_NAME + "-kafka-" + i).get();
Pod modifiedPod = new PodBuilder(pod).editMetadata().removeFromAnnotations(KafkaCluster.ANNO_STRIMZI_IO_KAFKA_VERSION).removeFromAnnotations(KafkaCluster.ANNO_STRIMZI_IO_LOG_MESSAGE_FORMAT_VERSION).removeFromAnnotations(KafkaCluster.ANNO_STRIMZI_IO_INTER_BROKER_PROTOCOL_VERSION).endMetadata().build();
client.pods().inNamespace(NAMESPACE).withName(CLUSTER_NAME + "-kafka-" + i).createOrReplace(modifiedPod);
}
return Future.succeededFuture();
}).compose(v -> operator.createOrUpdate(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, NAMESPACE, CLUSTER_NAME), updatedKafka)).onComplete(context.failing(v -> context.verify(() -> {
assertThat(v.getMessage(), stringContainsInOrder("Kafka Pods or StatefulSet exist, but do not contain the strimzi.io/kafka-version annotation to detect their version. Kafka upgrade cannot be detected."));
reconciliation.flag();
})));
}
use of io.fabric8.kubernetes.api.model.apps.StatefulSetBuilder in project strimzi-kafka-operator by strimzi.
the class KafkaUpgradeDowngradeMockTest method testDowngradeWithNoMessageAndProtocolVersionsOnPodsFails.
// Test downgrade with message and protocol versions defined to correct version in the CR, but not on the broker pods.
@Test
public void testDowngradeWithNoMessageAndProtocolVersionsOnPodsFails(VertxTestContext context) {
Kafka initialKafka = kafkaWithVersions(KafkaVersionTestUtils.LATEST_KAFKA_VERSION);
Kafka updatedKafka = kafkaWithVersions(KafkaVersionTestUtils.PREVIOUS_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.LATEST_KAFKA_VERSION, KafkaVersionTestUtils.LATEST_FORMAT_VERSION, KafkaVersionTestUtils.LATEST_PROTOCOL_VERSION, KafkaVersionTestUtils.LATEST_KAFKA_IMAGE);
});
})).compose(v -> {
StatefulSet sts = client.apps().statefulSets().inNamespace(NAMESPACE).withName(CLUSTER_NAME + "-kafka").get();
StatefulSet modifiedSts = new StatefulSetBuilder(sts).editSpec().editTemplate().editMetadata().removeFromAnnotations(KafkaCluster.ANNO_STRIMZI_IO_LOG_MESSAGE_FORMAT_VERSION).removeFromAnnotations(KafkaCluster.ANNO_STRIMZI_IO_INTER_BROKER_PROTOCOL_VERSION).endMetadata().endTemplate().endSpec().build();
client.apps().statefulSets().inNamespace(NAMESPACE).withName(CLUSTER_NAME + "-kafka").createOrReplace(modifiedSts);
for (int i = 0; i < 3; i++) {
Pod pod = client.pods().inNamespace(NAMESPACE).withName(CLUSTER_NAME + "-kafka-" + i).get();
Pod modifiedPod = new PodBuilder(pod).editMetadata().removeFromAnnotations(KafkaCluster.ANNO_STRIMZI_IO_LOG_MESSAGE_FORMAT_VERSION).removeFromAnnotations(KafkaCluster.ANNO_STRIMZI_IO_INTER_BROKER_PROTOCOL_VERSION).endMetadata().build();
client.pods().inNamespace(NAMESPACE).withName(CLUSTER_NAME + "-kafka-" + i).createOrReplace(modifiedPod);
}
return Future.succeededFuture();
}).compose(v -> operator.createOrUpdate(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, NAMESPACE, CLUSTER_NAME), updatedKafka)).onComplete(context.failing(v -> context.verify(() -> {
assertThat(v.getMessage(), stringContainsInOrder("log.message.format.version (null) and inter.broker.protocol.version (null) used by the brokers have to be set and be lower or equal to the Kafka broker version we downgrade to"));
reconciliation.flag();
})));
}
use of io.fabric8.kubernetes.api.model.apps.StatefulSetBuilder in project strimzi-kafka-operator 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(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