use of io.strimzi.api.kafka.model.status.Condition in project strimzi-kafka-operator by strimzi.
the class KafkaConnectAssemblyOperatorMockTest method testPauseReconcileUnpause.
@Test
public void testPauseReconcileUnpause(VertxTestContext context) {
setConnectResource(new KafkaConnectBuilder().withMetadata(new ObjectMetaBuilder().withName(CLUSTER_NAME).withNamespace(NAMESPACE).withLabels(TestUtils.map("foo", "bar")).withAnnotations(singletonMap("strimzi.io/pause-reconciliation", "true")).build()).withNewSpec().withReplicas(replicas).endSpec().build());
KafkaConnectApi mock = mock(KafkaConnectApi.class);
when(mock.list(anyString(), anyInt())).thenReturn(Future.succeededFuture(emptyList()));
when(mock.listConnectorPlugins(any(), anyString(), anyInt())).thenReturn(Future.succeededFuture(emptyList()));
Checkpoint async = context.checkpoint();
createConnectCluster(context, mock, true).onComplete(context.succeeding()).compose(v -> {
LOGGER.info("Reconciling again -> update");
return kco.reconcile(new Reconciliation("test-trigger", KafkaConnect.RESOURCE_KIND, NAMESPACE, CLUSTER_NAME));
}).onComplete(context.succeeding(v -> context.verify(() -> {
Resource<KafkaConnect> resource = Crds.kafkaConnectOperation(client).inNamespace(NAMESPACE).withName(CLUSTER_NAME);
if (resource.get().getStatus() == null) {
fail();
}
List<Condition> conditions = resource.get().getStatus().getConditions();
boolean conditionFound = false;
if (conditions != null && !conditions.isEmpty()) {
for (Condition condition : conditions) {
if ("ReconciliationPaused".equals(condition.getType())) {
conditionFound = true;
break;
}
}
}
assertTrue(conditionFound);
async.flag();
}))).compose(v -> {
setConnectResource(new KafkaConnectBuilder().withMetadata(new ObjectMetaBuilder().withName(CLUSTER_NAME).withNamespace(NAMESPACE).withLabels(TestUtils.map("foo", "bar")).withAnnotations(singletonMap("strimzi.io/pause-reconciliation", "false")).build()).withNewSpec().withReplicas(replicas).endSpec().build());
LOGGER.info("Reconciling again -> update");
return kco.reconcile(new Reconciliation("test-trigger", KafkaConnect.RESOURCE_KIND, NAMESPACE, CLUSTER_NAME));
}).onComplete(context.succeeding(v -> context.verify(() -> {
Resource<KafkaConnect> resource = Crds.kafkaConnectOperation(client).inNamespace(NAMESPACE).withName(CLUSTER_NAME);
if (resource.get().getStatus() == null) {
fail();
}
List<Condition> conditions = resource.get().getStatus().getConditions();
boolean conditionFound = false;
if (conditions != null && !conditions.isEmpty()) {
for (Condition condition : conditions) {
if ("ReconciliationPaused".equals(condition.getType())) {
conditionFound = true;
break;
}
}
}
assertFalse(conditionFound);
async.flag();
})));
}
use of io.strimzi.api.kafka.model.status.Condition in project strimzi-kafka-operator by strimzi.
the class KafkaMirrorMaker2AssemblyOperatorMockTest method testPauseReconcile.
@Test
public void testPauseReconcile(VertxTestContext context) {
setMirrorMaker2Resource(new KafkaMirrorMaker2Builder().withMetadata(new ObjectMetaBuilder().withName(CLUSTER_NAME).withNamespace(NAMESPACE).withLabels(TestUtils.map("foo", "bar")).withAnnotations(singletonMap("strimzi.io/pause-reconciliation", "true")).build()).withNewSpec().withReplicas(replicas).endSpec().build());
KafkaConnectApi mock = mock(KafkaConnectApi.class);
when(mock.list(anyString(), anyInt())).thenReturn(Future.succeededFuture(emptyList()));
when(mock.updateConnectLoggers(any(), anyString(), anyInt(), anyString(), any(OrderedProperties.class))).thenReturn(Future.succeededFuture());
Checkpoint async = context.checkpoint();
createMirrorMaker2Cluster(context, mock, true).onComplete(context.succeeding(v -> {
LOGGER.info("Reconciling again -> update");
kco.reconcile(new Reconciliation("test-trigger", KafkaMirrorMaker2.RESOURCE_KIND, NAMESPACE, CLUSTER_NAME));
})).onComplete(context.succeeding(v -> context.verify(() -> {
Resource<KafkaMirrorMaker2> resource = Crds.kafkaMirrorMaker2Operation(client).inNamespace(NAMESPACE).withName(CLUSTER_NAME);
if (resource.get().getStatus() == null) {
fail();
}
List<Condition> conditions = resource.get().getStatus().getConditions();
boolean conditionFound = false;
if (conditions != null && !conditions.isEmpty()) {
for (Condition condition : conditions) {
if ("ReconciliationPaused".equals(condition.getType())) {
conditionFound = true;
break;
}
}
}
assertTrue(conditionFound);
async.flag();
})));
}
use of io.strimzi.api.kafka.model.status.Condition in project strimzi-kafka-operator by strimzi.
the class KafkaRebalanceAssemblyOperatorTest method assertState.
private void assertState(VertxTestContext context, KubernetesClient kubernetesClient, String namespace, String resource, KafkaRebalanceState state) {
context.verify(() -> {
KafkaRebalance kafkaRebalance = Crds.kafkaRebalanceOperation(kubernetesClient).inNamespace(namespace).withName(resource).get();
assertThat(kafkaRebalance, StateMatchers.hasState());
Condition condition = kcrao.rebalanceStateCondition(kafkaRebalance.getStatus());
assertThat(Collections.singletonList(condition), StateMatchers.hasStateInConditions(state));
});
}
use of io.strimzi.api.kafka.model.status.Condition in project strimzi-kafka-operator by strimzi.
the class KafkaRebalanceAssemblyOperatorTest method krNewWithMissingHardGoalsAndRefresh.
private void krNewWithMissingHardGoalsAndRefresh(VertxTestContext context, int pendingCalls, CruiseControlEndpoints endpoint, KafkaRebalance kr) throws IOException, URISyntaxException {
// Setup the rebalance endpoint to get error about hard goals
MockCruiseControl.setupCCRebalanceBadGoalsError(ccServer, endpoint);
Crds.kafkaRebalanceOperation(client).inNamespace(CLUSTER_NAMESPACE).create(kr);
// the Kafka cluster isn't deployed in the namespace
when(mockKafkaOps.getAsync(CLUSTER_NAMESPACE, CLUSTER_NAME)).thenReturn(Future.succeededFuture(kafka));
mockSecretResources();
mockRebalanceOperator(mockRebalanceOps, mockCmOps, CLUSTER_NAMESPACE, kr.getMetadata().getName(), client);
Checkpoint checkpoint = context.checkpoint();
kcrao.reconcileRebalance(new Reconciliation("test-trigger", KafkaRebalance.RESOURCE_KIND, CLUSTER_NAMESPACE, kr.getMetadata().getName()), kr).onComplete(context.succeeding(v -> context.verify(() -> {
// the resource moved from New to NotReady due to the error
KafkaRebalance kr1 = Crds.kafkaRebalanceOperation(client).inNamespace(CLUSTER_NAMESPACE).withName(kr.getMetadata().getName()).get();
assertThat(kr1, StateMatchers.hasState());
Condition condition = kcrao.rebalanceStateCondition(kr1.getStatus());
assertThat(condition, StateMatchers.hasStateInCondition(KafkaRebalanceState.NotReady, CruiseControlRestException.class, "Error processing POST request '/rebalance' due to: " + "'java.lang.IllegalArgumentException: Missing hard goals [NetworkInboundCapacityGoal, DiskCapacityGoal, RackAwareGoal, NetworkOutboundCapacityGoal, CpuCapacityGoal, ReplicaCapacityGoal] " + "in the provided goals: [RackAwareGoal, ReplicaCapacityGoal]. " + "Add skip_hard_goal_check=true parameter to ignore this sanity check.'."));
}))).compose(v -> {
ccServer.reset();
try {
// Setup the rebalance endpoint with the number of pending calls before a response is received.
MockCruiseControl.setupCCRebalanceResponse(ccServer, pendingCalls, endpoint);
} catch (IOException | URISyntaxException e) {
context.failNow(e);
}
// set the skip hard goals check flag
KafkaRebalance kr2 = Crds.kafkaRebalanceOperation(client).inNamespace(CLUSTER_NAMESPACE).withName(kr.getMetadata().getName()).get();
KafkaRebalance patchedKr = new KafkaRebalanceBuilder(kr2).editSpec().withSkipHardGoalCheck(true).endSpec().build();
Crds.kafkaRebalanceOperation(client).inNamespace(CLUSTER_NAMESPACE).withName(kr.getMetadata().getName()).patch(patchedKr);
// apply the "refresh" annotation to the resource in the NotReady state
patchedKr = annotate(client, CLUSTER_NAMESPACE, kr.getMetadata().getName(), KafkaRebalanceAnnotation.refresh);
// trigger another reconcile to process the NotReady state
return kcrao.reconcileRebalance(new Reconciliation("test-trigger", KafkaRebalance.RESOURCE_KIND, CLUSTER_NAMESPACE, kr.getMetadata().getName()), patchedKr);
}).onComplete(context.succeeding(v -> {
// the resource transitioned from 'NotReady' to 'ProposalReady'
assertState(context, client, CLUSTER_NAMESPACE, kr.getMetadata().getName(), KafkaRebalanceState.ProposalReady);
checkpoint.flag();
}));
}
use of io.strimzi.api.kafka.model.status.Condition in project strimzi-kafka-operator by strimzi.
the class KafkaRebalanceAssemblyOperatorTest method testUnknownPropertyInSpec.
@Test
public void testUnknownPropertyInSpec(VertxTestContext context) throws IOException, URISyntaxException {
MockCruiseControl.setupCCRebalanceResponse(ccServer, 2, CruiseControlEndpoints.REBALANCE);
String yaml = "apiVersion: kafka.strimzi.io/v1beta2\n" + "kind: KafkaRebalance\n" + "metadata:\n" + " name: " + RESOURCE_NAME + "\n" + " namespace: " + CLUSTER_NAMESPACE + "\n" + " labels:\n" + " strimzi.io/cluster: " + CLUSTER_NAME + "\n" + "spec:\n" + " unknown: \"property\"\n" + " goals:\n" + " - CpuCapacityGoal\n" + " - NetworkInboundCapacityGoal\n" + " - DiskCapacityGoal\n" + " - RackAwareGoal\n" + " - NetworkOutboundCapacityGoal\n" + " - ReplicaCapacityGoal\n";
KafkaRebalance kr = TestUtils.fromYamlString(yaml, KafkaRebalance.class);
Crds.kafkaRebalanceOperation(client).inNamespace(CLUSTER_NAMESPACE).create(kr);
// the Kafka cluster isn't deployed in the namespace
when(mockKafkaOps.getAsync(CLUSTER_NAMESPACE, CLUSTER_NAME)).thenReturn(Future.succeededFuture(kafka));
mockSecretResources();
mockRebalanceOperator(mockRebalanceOps, mockCmOps, CLUSTER_NAMESPACE, RESOURCE_NAME, client);
Checkpoint checkpoint = context.checkpoint();
kcrao.reconcileRebalance(new Reconciliation("test-trigger", KafkaRebalance.RESOURCE_KIND, CLUSTER_NAMESPACE, RESOURCE_NAME), kr).onComplete(context.succeeding(v -> context.verify(() -> {
KafkaRebalance kr1 = Crds.kafkaRebalanceOperation(client).inNamespace(CLUSTER_NAMESPACE).withName(RESOURCE_NAME).get();
assertThat(kr1, StateMatchers.hasState());
Optional<Condition> condition = kr1.getStatus().getConditions().stream().filter(cond -> "UnknownFields".equals(cond.getReason())).findFirst();
assertTrue(condition.isPresent());
assertThat(condition.get().getStatus(), is("True"));
assertThat(condition.get().getMessage(), is("Contains object at path spec with an unknown property: unknown"));
assertThat(condition.get().getType(), is("Warning"));
checkpoint.flag();
})));
}
Aggregations