use of io.strimzi.operator.cluster.model.KafkaVersion in project strimzi by strimzi.
the class KafkaAssemblyOperatorMockTest method reconcileZkVersionChange.
/**
* Test the ZK version change functions
*/
private void reconcileZkVersionChange(VertxTestContext context, String initialKafkaVersion, String changedKafkaVersion, String changedImage) {
// We set the versions in the initial cluster to allow downgrades / upgrades
KafkaVersion lowerVersion = KafkaVersion.compareDottedVersions(initialKafkaVersion, changedKafkaVersion) > 0 ? VERSIONS.version(changedKafkaVersion) : VERSIONS.version(initialKafkaVersion);
Map<String, Object> config = new HashMap<>(2);
config.put(KafkaConfiguration.LOG_MESSAGE_FORMAT_VERSION, lowerVersion.messageVersion());
config.put(KafkaConfiguration.INTERBROKER_PROTOCOL_VERSION, lowerVersion.protocolVersion());
cluster.getSpec().getKafka().setConfig(config);
cluster.getSpec().getKafka().setVersion(initialKafkaVersion);
// We prepare updated Kafka with new version
Kafka updatedKafka = new KafkaBuilder(cluster).editSpec().editKafka().withVersion(changedKafkaVersion).endKafka().endSpec().build();
KafkaAssemblyOperator.ReconciliationState initialState = operator.new ReconciliationState(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, NAMESPACE, CLUSTER_NAME), updatedKafka);
Checkpoint async = context.checkpoint();
initialReconcile(context).onComplete(context.succeeding()).compose(v -> initialState.getKafkaClusterDescription()).compose(v -> initialState.prepareVersionChange()).compose(v -> initialState.getZookeeperDescription()).compose(state -> state.zkVersionChange()).onComplete(context.succeeding(state -> context.verify(() -> {
assertThat(state.zkCluster.getImage(), is(changedImage));
async.flag();
})));
}
use of io.strimzi.operator.cluster.model.KafkaVersion in project strimzi 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.strimzi.operator.cluster.model.KafkaVersion in project strimzi-kafka-operator by strimzi.
the class KafkaRoller method restartPlan.
/**
* Determine whether the pod should be restarted, or the broker reconfigured.
*/
private RestartPlan restartPlan(int podId, Pod pod, RestartContext restartContext) throws ForceableProblem, InterruptedException, FatalProblem {
List<String> reasonToRestartPod = Objects.requireNonNull(podNeedsRestart.apply(pod));
boolean podStuck = pod != null && pod.getStatus() != null && "Pending".equals(pod.getStatus().getPhase()) && pod.getStatus().getConditions().stream().anyMatch(ps -> "PodScheduled".equals(ps.getType()) && "Unschedulable".equals(ps.getReason()) && "False".equals(ps.getStatus()));
if (podStuck && // "Pod has old generation" is used with StatefulSets
!reasonToRestartPod.contains("Pod has old generation") && !reasonToRestartPod.contains("Pod has old revision")) {
// and deleting a different pod in the meantime will likely result in another unschedulable pod.
throw new FatalProblem("Pod is unschedulable");
}
// Unless the annotation is present, check the pod is at least ready.
boolean needsRestart = !reasonToRestartPod.isEmpty();
KafkaBrokerConfigurationDiff diff = null;
KafkaBrokerLoggingConfigurationDiff loggingDiff = null;
boolean needsReconfig = false;
// connect to the broker and that it's capable of responding.
if (!initAdminClient()) {
return new RestartPlan(true);
}
Config brokerConfig;
try {
brokerConfig = brokerConfig(podId);
} catch (ForceableProblem e) {
if (restartContext.backOff.done()) {
needsRestart = true;
brokerConfig = null;
} else {
throw e;
}
}
if (!needsRestart && allowReconfiguration) {
LOGGER.traceCr(reconciliation, "Broker {}: description {}", podId, brokerConfig);
diff = new KafkaBrokerConfigurationDiff(reconciliation, brokerConfig, kafkaConfig, kafkaVersion, podId);
loggingDiff = logging(podId);
if (diff.getDiffSize() > 0) {
if (diff.canBeUpdatedDynamically()) {
LOGGER.debugCr(reconciliation, "Pod {} needs to be reconfigured.", podId);
needsReconfig = true;
} else {
LOGGER.debugCr(reconciliation, "Pod {} needs to be restarted, because reconfiguration cannot be done dynamically", podId);
needsRestart = true;
}
}
if (loggingDiff.getDiffSize() > 0) {
LOGGER.debugCr(reconciliation, "Pod {} logging needs to be reconfigured.", podId);
needsReconfig = true;
}
} else if (needsRestart) {
LOGGER.infoCr(reconciliation, "Pod {} needs to be restarted. Reason: {}", podId, reasonToRestartPod);
}
return new RestartPlan(needsRestart, needsReconfig, podStuck, diff, loggingDiff);
}
use of io.strimzi.operator.cluster.model.KafkaVersion in project strimzi-kafka-operator by strimzi.
the class KafkaAssemblyOperatorMockTest method reconcileZkVersionChange.
/**
* Test the ZK version change functions
*/
private void reconcileZkVersionChange(VertxTestContext context, String initialKafkaVersion, String changedKafkaVersion, String changedImage) {
// We set the versions in the initial cluster to allow downgrades / upgrades
KafkaVersion lowerVersion = KafkaVersion.compareDottedVersions(initialKafkaVersion, changedKafkaVersion) > 0 ? VERSIONS.version(changedKafkaVersion) : VERSIONS.version(initialKafkaVersion);
Map<String, Object> config = new HashMap<>(2);
config.put(KafkaConfiguration.LOG_MESSAGE_FORMAT_VERSION, lowerVersion.messageVersion());
config.put(KafkaConfiguration.INTERBROKER_PROTOCOL_VERSION, lowerVersion.protocolVersion());
cluster.getSpec().getKafka().setConfig(config);
cluster.getSpec().getKafka().setVersion(initialKafkaVersion);
// We prepare updated Kafka with new version
Kafka updatedKafka = new KafkaBuilder(cluster).editSpec().editKafka().withVersion(changedKafkaVersion).endKafka().endSpec().build();
KafkaAssemblyOperator.ReconciliationState initialState = operator.new ReconciliationState(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, NAMESPACE, CLUSTER_NAME), updatedKafka);
Checkpoint async = context.checkpoint();
initialReconcile(context).onComplete(context.succeeding()).compose(v -> initialState.getKafkaClusterDescription()).compose(v -> initialState.prepareVersionChange()).compose(v -> initialState.getZookeeperDescription()).compose(state -> state.zkVersionChange()).onComplete(context.succeeding(state -> context.verify(() -> {
assertThat(state.zkCluster.getImage(), is(changedImage));
async.flag();
})));
}
use of io.strimzi.operator.cluster.model.KafkaVersion 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();
})));
}
Aggregations