use of io.strimzi.api.kafka.model.storage.EphemeralStorage in project strimzi by strimzi.
the class KafkaAssemblyOperatorMockTest method testReconcileUpdatesKafkaStorageType.
@ParameterizedTest
@MethodSource("data")
public void testReconcileUpdatesKafkaStorageType(Params params, VertxTestContext context) {
init(params);
AtomicReference<List<PersistentVolumeClaim>> originalPVCs = new AtomicReference<>();
AtomicReference<List<Volume>> originalVolumes = new AtomicReference<>();
AtomicReference<List<Container>> originalInitContainers = new AtomicReference<>();
Checkpoint async = context.checkpoint();
initialReconcile(context).onComplete(context.succeeding(v -> context.verify(() -> {
originalPVCs.set(Optional.ofNullable(client.apps().statefulSets().inNamespace(NAMESPACE).withName(KafkaCluster.kafkaClusterName(CLUSTER_NAME)).get()).map(StatefulSet::getSpec).map(StatefulSetSpec::getVolumeClaimTemplates).orElse(new ArrayList<>()));
originalVolumes.set(Optional.ofNullable(client.apps().statefulSets().inNamespace(NAMESPACE).withName(KafkaCluster.kafkaClusterName(CLUSTER_NAME)).get()).map(StatefulSet::getSpec).map(StatefulSetSpec::getTemplate).map(PodTemplateSpec::getSpec).map(PodSpec::getVolumes).orElse(new ArrayList<>()));
originalInitContainers.set(Optional.ofNullable(client.apps().statefulSets().inNamespace(NAMESPACE).withName(KafkaCluster.kafkaClusterName(CLUSTER_NAME)).get()).map(StatefulSet::getSpec).map(StatefulSetSpec::getTemplate).map(PodTemplateSpec::getSpec).map(PodSpec::getInitContainers).orElse(new ArrayList<>()));
// Update the storage type
// ephemeral -> persistent
// or
// persistent -> ephemeral
Kafka updatedStorageKafka = null;
if (kafkaStorage instanceof EphemeralStorage) {
updatedStorageKafka = new KafkaBuilder(cluster).editSpec().editKafka().withNewPersistentClaimStorage().withSize("123").endPersistentClaimStorage().endKafka().endSpec().build();
} else if (kafkaStorage instanceof PersistentClaimStorage) {
updatedStorageKafka = new KafkaBuilder(cluster).editSpec().editKafka().withNewEphemeralStorage().endEphemeralStorage().endKafka().endSpec().build();
} else {
context.failNow(new Exception("If storage is not ephemeral or persistent something has gone wrong"));
}
kafkaAssembly(NAMESPACE, CLUSTER_NAME).patch(updatedStorageKafka);
LOGGER.info("Updating with changed storage type");
}))).compose(v -> operator.reconcile(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, NAMESPACE, CLUSTER_NAME))).onComplete(context.succeeding(v -> context.verify(() -> {
// Check the Volumes and PVCs were not changed
assertPVCs(context, KafkaCluster.kafkaClusterName(CLUSTER_NAME), originalPVCs.get());
assertVolumes(context, KafkaCluster.kafkaClusterName(CLUSTER_NAME), originalVolumes.get());
assertInitContainers(context, KafkaCluster.kafkaClusterName(CLUSTER_NAME), originalInitContainers.get());
async.flag();
})));
}
use of io.strimzi.api.kafka.model.storage.EphemeralStorage in project strimzi by strimzi.
the class KafkaSpecCheckerTest method checkZookeeperReplicas.
@Test
public void checkZookeeperReplicas() {
Map<String, Object> kafkaOptions = new HashMap<>();
kafkaOptions.put(KafkaConfiguration.DEFAULT_REPLICATION_FACTOR, 2);
kafkaOptions.put(KafkaConfiguration.MIN_INSYNC_REPLICAS, 1);
Kafka kafka = ResourceUtils.createKafka(NAMESPACE, NAME, 2, IMAGE, HEALTH_DELAY, HEALTH_TIMEOUT, null, kafkaOptions, emptyMap(), new EphemeralStorage(), new EphemeralStorage(), null, null, null, null);
KafkaSpecChecker checker = generateChecker(kafka);
List<Condition> warnings = checker.run();
assertThat(warnings, hasSize(1));
Condition warning = warnings.get(0);
assertThat(warning.getReason(), is("ZooKeeperReplicas"));
assertThat(warning.getStatus(), is("True"));
assertThat(warning.getMessage(), is("Running ZooKeeper with two nodes is not advisable as both replicas will be needed to avoid downtime. It is recommended that a minimum of three replicas are used."));
}
use of io.strimzi.api.kafka.model.storage.EphemeralStorage in project strimzi by strimzi.
the class KafkaSpecCheckerTest method checkInterBrokerProtocolWithCorrectVersion.
@Test
public void checkInterBrokerProtocolWithCorrectVersion() {
Map<String, Object> kafkaOptions = new HashMap<>();
kafkaOptions.put(KafkaConfiguration.INTERBROKER_PROTOCOL_VERSION, KafkaVersionTestUtils.LATEST_PROTOCOL_VERSION);
kafkaOptions.put(KafkaConfiguration.DEFAULT_REPLICATION_FACTOR, 3);
kafkaOptions.put(KafkaConfiguration.MIN_INSYNC_REPLICAS, 2);
Kafka kafka = ResourceUtils.createKafka(NAMESPACE, NAME, 3, IMAGE, HEALTH_DELAY, HEALTH_TIMEOUT, null, kafkaOptions, emptyMap(), new EphemeralStorage(), new EphemeralStorage(), null, null, null, null);
KafkaSpecChecker checker = generateChecker(kafka);
List<Condition> warnings = checker.run();
assertThat(warnings, hasSize(0));
}
use of io.strimzi.api.kafka.model.storage.EphemeralStorage in project strimzi by strimzi.
the class KafkaSpecCheckerTest method checkEmptyWarnings.
@Test
public void checkEmptyWarnings() {
Map<String, Object> kafkaOptions = new HashMap<>();
kafkaOptions.put(KafkaConfiguration.DEFAULT_REPLICATION_FACTOR, 3);
kafkaOptions.put(KafkaConfiguration.MIN_INSYNC_REPLICAS, 2);
Kafka kafka = ResourceUtils.createKafka(NAMESPACE, NAME, 3, IMAGE, HEALTH_DELAY, HEALTH_TIMEOUT, null, kafkaOptions, emptyMap(), new EphemeralStorage(), new EphemeralStorage(), null, null, null, null);
KafkaSpecChecker checker = generateChecker(kafka);
assertThat(checker.run(), empty());
}
use of io.strimzi.api.kafka.model.storage.EphemeralStorage in project strimzi by strimzi.
the class KafkaSpecCheckerTest method checkKafkaJbodStorage.
@Test
public void checkKafkaJbodStorage() {
Kafka kafka = new KafkaBuilder(ResourceUtils.createKafka(NAMESPACE, NAME, 1, IMAGE, HEALTH_DELAY, HEALTH_TIMEOUT, null, emptyMap(), emptyMap(), new JbodStorageBuilder().withVolumes(new EphemeralStorageBuilder().withId(1).build(), new EphemeralStorageBuilder().withId(2).build()).build(), new EphemeralStorage(), null, null, null, null)).editSpec().editZookeeper().withReplicas(3).endZookeeper().endSpec().build();
KafkaSpecChecker checker = generateChecker(kafka);
List<Condition> warnings = checker.run();
assertThat(warnings, hasSize(1));
Condition warning = warnings.get(0);
assertThat(warning.getReason(), is("KafkaStorage"));
assertThat(warning.getStatus(), is("True"));
assertThat(warning.getMessage(), is("A Kafka cluster with a single replica and ephemeral storage will lose topic messages after any restart or rolling update."));
}
Aggregations