use of io.strimzi.api.kafka.model.Kafka in project strimzi by strimzi.
the class KafkaUpgradeDowngradeMockTest method testDowngradeWithWrongMessageAndProtocolVersionsFails.
// Test downgrade with message and protocol versions defined to newer version than we downgrade to (this fails before
// reaching downgrade since this is invalid Kafka CR).
@Test
public void testDowngradeWithWrongMessageAndProtocolVersionsFails(VertxTestContext context) {
Kafka initialKafka = kafkaWithVersions(KafkaVersionTestUtils.LATEST_KAFKA_VERSION, KafkaVersionTestUtils.LATEST_FORMAT_VERSION, KafkaVersionTestUtils.LATEST_PROTOCOL_VERSION);
Kafka updatedKafka = kafkaWithVersions(KafkaVersionTestUtils.PREVIOUS_KAFKA_VERSION, KafkaVersionTestUtils.LATEST_FORMAT_VERSION, KafkaVersionTestUtils.LATEST_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 -> operator.createOrUpdate(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, NAMESPACE, CLUSTER_NAME), updatedKafka)).onComplete(context.failing(v -> context.verify(() -> {
assertThat(v.getMessage(), stringContainsInOrder("does not match the required pattern"));
reconciliation.flag();
})));
}
use of io.strimzi.api.kafka.model.Kafka in project strimzi by strimzi.
the class KafkaUpgradeDowngradeMockTest method testNoopUpgrade.
/*
* NOOP tests
*/
// Tests regular reconciliation without any upgrades
@Test
public void testNoopUpgrade(VertxTestContext context) {
Kafka initialKafka = kafkaWithVersions(KafkaVersionTestUtils.LATEST_KAFKA_VERSION, KafkaVersionTestUtils.LATEST_FORMAT_VERSION, KafkaVersionTestUtils.LATEST_PROTOCOL_VERSION);
Kafka updatedKafka = kafkaWithVersions(KafkaVersionTestUtils.LATEST_KAFKA_VERSION, KafkaVersionTestUtils.LATEST_FORMAT_VERSION, KafkaVersionTestUtils.LATEST_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 -> 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.LATEST_FORMAT_VERSION, KafkaVersionTestUtils.LATEST_PROTOCOL_VERSION, KafkaVersionTestUtils.LATEST_KAFKA_IMAGE);
reconciliation.flag();
})));
}
use of io.strimzi.api.kafka.model.Kafka in project strimzi by strimzi.
the class KafkaRebalanceAssemblyOperatorTest method testNoKafkaClusterInKafkaRebalanceLabel.
/**
* Tests the transition from 'New' to 'NotReady' due to missing Kafka cluster label in the resource
*
* 1. A new KafkaRebalance resource is created; it is in the 'New' state
* 2. The operator checks that the resource is missing the label to specify the Kafka cluster
* 4. The KafkaRebalance resource moves to 'NotReady' state
*/
@Test
public void testNoKafkaClusterInKafkaRebalanceLabel(VertxTestContext context) {
KafkaRebalance kr = createKafkaRebalance(CLUSTER_NAMESPACE, null, RESOURCE_NAME, new KafkaRebalanceSpecBuilder().build());
Crds.kafkaRebalanceOperation(kubernetesClient).inNamespace(CLUSTER_NAMESPACE).create(kr);
when(mockKafkaOps.getAsync(CLUSTER_NAMESPACE, CLUSTER_NAME)).thenReturn(Future.succeededFuture(kafka));
mockRebalanceOperator(mockRebalanceOps, mockCmOps, CLUSTER_NAMESPACE, RESOURCE_NAME, kubernetesClient);
Checkpoint checkpoint = context.checkpoint();
kcrao.reconcileRebalance(new Reconciliation("test-trigger", KafkaRebalance.RESOURCE_KIND, CLUSTER_NAMESPACE, RESOURCE_NAME), kr).onComplete(context.succeeding(v -> context.verify(() -> {
// the resource moved from New to NotReady due to the error
assertState(context, kubernetesClient, CLUSTER_NAMESPACE, RESOURCE_NAME, KafkaRebalanceState.NotReady, InvalidResourceException.class, "Resource lacks label '" + Labels.STRIMZI_CLUSTER_LABEL + "': No cluster related to a possible rebalance.");
checkpoint.flag();
})));
}
use of io.strimzi.api.kafka.model.Kafka in project strimzi by strimzi.
the class KafkaRebalanceAssemblyOperatorTest method testNewToPendingProposalToStoppedAndRefreshRebalance.
/**
* Tests the transition from 'New' to 'PendingProposal' to 'Stopped' (via annotation)
* The resource is refreshed and transitions to 'PendingProposal' again and finally to 'ProposalReady'
*
* 1. A new KafkaRebalance resource is created; it is in the 'New' state
* 2. The operator requests a rebalance proposal through the Cruise Control REST API
* 3. The rebalance proposal is not ready yet; the operator starts polling the Cruise Control REST API
* 4. The KafkaRebalance resource transitions to the 'PendingProposal' state
* 6. While the operator is waiting for the proposal, the KafkaRebalance resource is annotated with 'strimzi.io/rebalance=stop'
* 7. The operator stops polling the Cruise Control REST API
* 8. The KafkaRebalance resource moves to the 'Stopped' state
* 9. The KafkaRebalance resource is annotated with 'strimzi.io/rebalance=refresh'
* 10. The operator requests a rebalance proposal through the Cruise Control REST API
* 11. The rebalance proposal is not ready yet; the operator starts polling the Cruise Control REST API
* 12. The KafkaRebalance resource moves to PendingProposal state
* 13. The rebalance proposal is ready after the specified pending calls
* 14. The KafkaRebalance resource moves to ProposalReady state
*/
@Test
public void testNewToPendingProposalToStoppedAndRefreshRebalance(VertxTestContext context) throws IOException, URISyntaxException {
// Setup the rebalance endpoint with the number of pending calls before a response is received.
MockCruiseControl.setupCCRebalanceResponse(ccServer, 2);
KafkaRebalance kr = createKafkaRebalance(CLUSTER_NAMESPACE, CLUSTER_NAME, RESOURCE_NAME, new KafkaRebalanceSpecBuilder().build());
Crds.kafkaRebalanceOperation(kubernetesClient).inNamespace(CLUSTER_NAMESPACE).create(kr);
when(mockKafkaOps.getAsync(CLUSTER_NAMESPACE, CLUSTER_NAME)).thenReturn(Future.succeededFuture(kafka));
mockSecretResources();
mockRebalanceOperator(mockRebalanceOps, mockCmOps, CLUSTER_NAMESPACE, RESOURCE_NAME, kubernetesClient, new Runnable() {
int count = 0;
@Override
public void run() {
if (++count == 4) {
// after a while, apply the "stop" annotation to the resource in the PendingProposal state
annotate(kubernetesClient, CLUSTER_NAMESPACE, RESOURCE_NAME, KafkaRebalanceAnnotation.stop);
}
return;
}
});
Checkpoint checkpoint = context.checkpoint();
kcrao.reconcileRebalance(new Reconciliation("test-trigger", KafkaRebalance.RESOURCE_KIND, CLUSTER_NAMESPACE, RESOURCE_NAME), kr).onComplete(context.succeeding(v -> assertState(context, kubernetesClient, CLUSTER_NAMESPACE, RESOURCE_NAME, KafkaRebalanceState.PendingProposal))).compose(v -> {
// trigger another reconcile to process the PendingProposal state
KafkaRebalance kr1 = Crds.kafkaRebalanceOperation(kubernetesClient).inNamespace(CLUSTER_NAMESPACE).withName(RESOURCE_NAME).get();
return kcrao.reconcileRebalance(new Reconciliation("test-trigger", KafkaRebalance.RESOURCE_KIND, CLUSTER_NAMESPACE, RESOURCE_NAME), kr1);
}).onComplete(context.succeeding(v -> assertState(context, kubernetesClient, CLUSTER_NAMESPACE, RESOURCE_NAME, KafkaRebalanceState.Stopped))).compose(v -> {
// apply the "refresh" annotation to the resource in the Stopped state
KafkaRebalance refreshedKr = annotate(kubernetesClient, CLUSTER_NAMESPACE, RESOURCE_NAME, KafkaRebalanceAnnotation.refresh);
// trigger another reconcile to process the Stopped state
return kcrao.reconcileRebalance(new Reconciliation("test-trigger", KafkaRebalance.RESOURCE_KIND, CLUSTER_NAMESPACE, RESOURCE_NAME), refreshedKr);
}).onComplete(context.succeeding(v -> assertState(context, kubernetesClient, CLUSTER_NAMESPACE, RESOURCE_NAME, KafkaRebalanceState.PendingProposal))).compose(v -> {
// trigger another reconcile to process the PendingProposal state
KafkaRebalance kr6 = Crds.kafkaRebalanceOperation(kubernetesClient).inNamespace(CLUSTER_NAMESPACE).withName(RESOURCE_NAME).get();
return kcrao.reconcileRebalance(new Reconciliation("test-trigger", KafkaRebalance.RESOURCE_KIND, CLUSTER_NAMESPACE, RESOURCE_NAME), kr6);
}).onComplete(context.succeeding(v -> {
// the resource moved from PendingProposal to ProposalReady
assertState(context, kubernetesClient, CLUSTER_NAMESPACE, RESOURCE_NAME, KafkaRebalanceState.ProposalReady);
checkpoint.flag();
}));
}
use of io.strimzi.api.kafka.model.Kafka in project strimzi by strimzi.
the class KafkaRebalanceAssemblyOperatorTest method testNewToProposalReadyToRebalancingToReadyRebalance.
/**
* Tests the transition from 'New' to to 'ProposalReady'
* The rebalance proposal is approved and the resource moves to 'Rebalancing' and finally to 'Ready'
*
* 1. A new KafkaRebalance resource is created; it is in the 'New' state
* 2. The operator requests a rebalance proposal through the Cruise Control REST API
* 3. The rebalance proposal is ready on the first call
* 4. The KafkaRebalance resource transitions to the 'ProposalReady' state
* 9. The KafkaRebalance resource is annotated with 'strimzi.io/rebalance=approve'
* 10. The operator requests the rebalance operation through the Cruise Control REST API
* 11. The rebalance operation is not done immediately; the operator starts polling the Cruise Control REST API
* 12. The KafkaRebalance resource moves to the 'Rebalancing' state
* 13. The rebalance operation is done
* 14. The KafkaRebalance resource moves to the 'Ready' state
*/
@Test
public void testNewToProposalReadyToRebalancingToReadyRebalance(VertxTestContext context) throws IOException, URISyntaxException {
// Setup the rebalance and user tasks endpoints with the number of pending calls before a response is received.
MockCruiseControl.setupCCRebalanceResponse(ccServer, 0);
MockCruiseControl.setupCCUserTasksResponseNoGoals(ccServer, 0, 0);
KafkaRebalance kr = createKafkaRebalance(CLUSTER_NAMESPACE, CLUSTER_NAME, RESOURCE_NAME, new KafkaRebalanceSpecBuilder().build());
Crds.kafkaRebalanceOperation(kubernetesClient).inNamespace(CLUSTER_NAMESPACE).create(kr);
when(mockKafkaOps.getAsync(CLUSTER_NAMESPACE, CLUSTER_NAME)).thenReturn(Future.succeededFuture(kafka));
mockSecretResources();
mockRebalanceOperator(mockRebalanceOps, mockCmOps, CLUSTER_NAMESPACE, RESOURCE_NAME, kubernetesClient);
Checkpoint checkpoint = context.checkpoint();
kcrao.reconcileRebalance(new Reconciliation("test-trigger", KafkaRebalance.RESOURCE_KIND, CLUSTER_NAMESPACE, RESOURCE_NAME), kr).onComplete(context.succeeding(v -> assertState(context, kubernetesClient, CLUSTER_NAMESPACE, RESOURCE_NAME, KafkaRebalanceState.ProposalReady))).compose(v -> {
// apply the "approve" annotation to the resource in the ProposalReady state
KafkaRebalance approvedKr = annotate(kubernetesClient, CLUSTER_NAMESPACE, RESOURCE_NAME, KafkaRebalanceAnnotation.approve);
return kcrao.reconcileRebalance(new Reconciliation("test-trigger", KafkaRebalance.RESOURCE_KIND, CLUSTER_NAMESPACE, RESOURCE_NAME), approvedKr);
}).onComplete(context.succeeding(v -> {
// the resource moved from ProposalReady to Rebalancing on approval
assertState(context, kubernetesClient, CLUSTER_NAMESPACE, RESOURCE_NAME, KafkaRebalanceState.Rebalancing);
})).compose(v -> {
// trigger another reconcile to process the Rebalancing state
KafkaRebalance kr4 = Crds.kafkaRebalanceOperation(kubernetesClient).inNamespace(CLUSTER_NAMESPACE).withName(RESOURCE_NAME).get();
return kcrao.reconcileRebalance(new Reconciliation("test-trigger", KafkaRebalance.RESOURCE_KIND, CLUSTER_NAMESPACE, RESOURCE_NAME), kr4);
}).onComplete(context.succeeding(v -> {
// the resource moved from Rebalancing to Ready
assertState(context, kubernetesClient, CLUSTER_NAMESPACE, RESOURCE_NAME, KafkaRebalanceState.Ready);
checkpoint.flag();
}));
}
Aggregations