Search in sources :

Example 51 with Condition

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();
    })));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) AfterAll(org.junit.jupiter.api.AfterAll) Resource(io.fabric8.kubernetes.client.dsl.Resource) DefaultAdminClientProvider(io.strimzi.operator.common.DefaultAdminClientProvider) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) EnableKubernetesMockClient(io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient) BeforeAll(org.junit.jupiter.api.BeforeAll) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) ResourceUtils(io.strimzi.operator.cluster.ResourceUtils) MockKube2(io.strimzi.test.mockkube2.MockKube2) KafkaConnect(io.strimzi.api.kafka.model.KafkaConnect) Collections.emptyList(java.util.Collections.emptyList) KafkaVersion(io.strimzi.operator.cluster.model.KafkaVersion) KafkaConnectBuilder(io.strimzi.api.kafka.model.KafkaConnectBuilder) VertxExtension(io.vertx.junit5.VertxExtension) Future(io.vertx.core.Future) Test(org.junit.jupiter.api.Test) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Checkpoint(io.vertx.junit5.Checkpoint) Condition(io.strimzi.api.kafka.model.status.Condition) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) Mockito.mock(org.mockito.Mockito.mock) VertxTestContext(io.vertx.junit5.VertxTestContext) Assertions.fail(org.junit.jupiter.api.Assertions.fail) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BackOff(io.strimzi.operator.common.BackOff) Crds(io.strimzi.api.kafka.Crds) KafkaVersionTestUtils(io.strimzi.operator.cluster.KafkaVersionTestUtils) ZookeeperLeaderFinder(io.strimzi.operator.cluster.operator.resource.ZookeeperLeaderFinder) TestUtils(io.strimzi.test.TestUtils) Collections.singletonMap(java.util.Collections.singletonMap) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) Promise(io.vertx.core.Promise) KubernetesVersion(io.strimzi.operator.KubernetesVersion) Vertx(io.vertx.core.Vertx) Mockito.when(org.mockito.Mockito.when) Reconciliation(io.strimzi.operator.common.Reconciliation) AfterEach(org.junit.jupiter.api.AfterEach) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultZookeeperScalerProvider(io.strimzi.operator.cluster.operator.resource.DefaultZookeeperScalerProvider) LogManager(org.apache.logging.log4j.LogManager) KafkaConnectResources(io.strimzi.api.kafka.model.KafkaConnectResources) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Condition(io.strimzi.api.kafka.model.status.Condition) KafkaConnectBuilder(io.strimzi.api.kafka.model.KafkaConnectBuilder) Checkpoint(io.vertx.junit5.Checkpoint) Reconciliation(io.strimzi.operator.common.Reconciliation) KafkaConnect(io.strimzi.api.kafka.model.KafkaConnect) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) Test(org.junit.jupiter.api.Test)

Example 52 with Condition

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();
    })));
}
Also used : KafkaMirrorMaker2Builder(io.strimzi.api.kafka.model.KafkaMirrorMaker2Builder) CoreMatchers.is(org.hamcrest.CoreMatchers.is) OrderedProperties(io.strimzi.operator.common.model.OrderedProperties) KafkaMirrorMaker2Builder(io.strimzi.api.kafka.model.KafkaMirrorMaker2Builder) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) AfterAll(org.junit.jupiter.api.AfterAll) Resource(io.fabric8.kubernetes.client.dsl.Resource) DefaultAdminClientProvider(io.strimzi.operator.common.DefaultAdminClientProvider) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) EnableKubernetesMockClient(io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient) BeforeAll(org.junit.jupiter.api.BeforeAll) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) ResourceUtils(io.strimzi.operator.cluster.ResourceUtils) MockKube2(io.strimzi.test.mockkube2.MockKube2) Collections.emptyList(java.util.Collections.emptyList) KafkaVersion(io.strimzi.operator.cluster.model.KafkaVersion) VertxExtension(io.vertx.junit5.VertxExtension) Future(io.vertx.core.Future) KafkaMirrorMaker2Resources(io.strimzi.api.kafka.model.KafkaMirrorMaker2Resources) Test(org.junit.jupiter.api.Test) KafkaMirrorMaker2(io.strimzi.api.kafka.model.KafkaMirrorMaker2) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Checkpoint(io.vertx.junit5.Checkpoint) Condition(io.strimzi.api.kafka.model.status.Condition) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) Mockito.mock(org.mockito.Mockito.mock) VertxTestContext(io.vertx.junit5.VertxTestContext) Assertions.fail(org.junit.jupiter.api.Assertions.fail) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BackOff(io.strimzi.operator.common.BackOff) Crds(io.strimzi.api.kafka.Crds) KafkaVersionTestUtils(io.strimzi.operator.cluster.KafkaVersionTestUtils) ZookeeperLeaderFinder(io.strimzi.operator.cluster.operator.resource.ZookeeperLeaderFinder) TestUtils(io.strimzi.test.TestUtils) Collections.singletonMap(java.util.Collections.singletonMap) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) Promise(io.vertx.core.Promise) KubernetesVersion(io.strimzi.operator.KubernetesVersion) Vertx(io.vertx.core.Vertx) Mockito.when(org.mockito.Mockito.when) Reconciliation(io.strimzi.operator.common.Reconciliation) AfterEach(org.junit.jupiter.api.AfterEach) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultZookeeperScalerProvider(io.strimzi.operator.cluster.operator.resource.DefaultZookeeperScalerProvider) LogManager(org.apache.logging.log4j.LogManager) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Condition(io.strimzi.api.kafka.model.status.Condition) Checkpoint(io.vertx.junit5.Checkpoint) Reconciliation(io.strimzi.operator.common.Reconciliation) OrderedProperties(io.strimzi.operator.common.model.OrderedProperties) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) KafkaMirrorMaker2(io.strimzi.api.kafka.model.KafkaMirrorMaker2) Test(org.junit.jupiter.api.Test)

Example 53 with Condition

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));
    });
}
Also used : Condition(io.strimzi.api.kafka.model.status.Condition) KafkaRebalance(io.strimzi.api.kafka.model.KafkaRebalance)

Example 54 with Condition

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();
    }));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) URISyntaxException(java.net.URISyntaxException) Annotations(io.strimzi.operator.common.Annotations) KafkaRebalanceSpecBuilder(io.strimzi.api.kafka.model.KafkaRebalanceSpecBuilder) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) AfterAll(org.junit.jupiter.api.AfterAll) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Collections.singleton(java.util.Collections.singleton) EnableKubernetesMockClient(io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient) BeforeAll(org.junit.jupiter.api.BeforeAll) Map(java.util.Map) Matchers.nullValue(org.hamcrest.Matchers.nullValue) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) ResourceUtils(io.strimzi.operator.cluster.ResourceUtils) MockKube2(io.strimzi.test.mockkube2.MockKube2) KafkaRebalance(io.strimzi.api.kafka.model.KafkaRebalance) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) SecretOperator(io.strimzi.operator.common.operator.resource.SecretOperator) VertxExtension(io.vertx.junit5.VertxExtension) KafkaRebalanceList(io.strimzi.api.kafka.KafkaRebalanceList) KafkaRebalanceAnnotation(io.strimzi.api.kafka.model.balancing.KafkaRebalanceAnnotation) Future(io.vertx.core.Future) NoSuchResourceException(io.strimzi.operator.cluster.model.NoSuchResourceException) ClientAndServer(org.mockserver.integration.ClientAndServer) CruiseControlResources(io.strimzi.api.kafka.model.CruiseControlResources) Test(org.junit.jupiter.api.Test) Labels(io.strimzi.operator.common.model.Labels) CruiseControlApi(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlApi) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Secret(io.fabric8.kubernetes.api.model.Secret) Optional(java.util.Optional) Checkpoint(io.vertx.junit5.Checkpoint) Matchers.is(org.hamcrest.Matchers.is) Condition(io.strimzi.api.kafka.model.status.Condition) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) VertxTestContext(io.vertx.junit5.VertxTestContext) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) KafkaList(io.strimzi.api.kafka.KafkaList) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) KafkaRebalanceState(io.strimzi.api.kafka.model.balancing.KafkaRebalanceState) KafkaRebalanceBuilder(io.strimzi.api.kafka.model.KafkaRebalanceBuilder) CruiseControlApiImpl(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlApiImpl) Crds(io.strimzi.api.kafka.Crds) KafkaRebalanceSpec(io.strimzi.api.kafka.model.KafkaRebalanceSpec) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) KafkaRebalanceMode(io.strimzi.api.kafka.model.balancing.KafkaRebalanceMode) CruiseControlEndpoints(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlEndpoints) KafkaVersionTestUtils(io.strimzi.operator.cluster.KafkaVersionTestUtils) ConfigMapOperator(io.strimzi.operator.common.operator.resource.ConfigMapOperator) CrdOperator(io.strimzi.operator.common.operator.resource.CrdOperator) TestUtils(io.strimzi.test.TestUtils) ReconcileResult(io.strimzi.operator.common.operator.resource.ReconcileResult) ConnectException(java.net.ConnectException) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) NoStackTraceTimeoutException(io.strimzi.operator.common.operator.resource.NoStackTraceTimeoutException) CruiseControl(io.strimzi.operator.cluster.model.CruiseControl) InvalidResourceException(io.strimzi.operator.cluster.model.InvalidResourceException) Vertx(io.vertx.core.Vertx) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) KafkaRebalanceStatus(io.strimzi.api.kafka.model.status.KafkaRebalanceStatus) Reconciliation(io.strimzi.operator.common.Reconciliation) AfterEach(org.junit.jupiter.api.AfterEach) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Kafka(io.strimzi.api.kafka.model.Kafka) CruiseControlRestException(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlRestException) MockCruiseControl(io.strimzi.operator.cluster.operator.resource.cruisecontrol.MockCruiseControl) Collections(java.util.Collections) Condition(io.strimzi.api.kafka.model.status.Condition) Checkpoint(io.vertx.junit5.Checkpoint) Reconciliation(io.strimzi.operator.common.Reconciliation) KafkaRebalanceBuilder(io.strimzi.api.kafka.model.KafkaRebalanceBuilder) KafkaRebalance(io.strimzi.api.kafka.model.KafkaRebalance) CruiseControlRestException(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlRestException)

Example 55 with Condition

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();
    })));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) URISyntaxException(java.net.URISyntaxException) Annotations(io.strimzi.operator.common.Annotations) KafkaRebalanceSpecBuilder(io.strimzi.api.kafka.model.KafkaRebalanceSpecBuilder) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) AfterAll(org.junit.jupiter.api.AfterAll) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Collections.singleton(java.util.Collections.singleton) EnableKubernetesMockClient(io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient) BeforeAll(org.junit.jupiter.api.BeforeAll) Map(java.util.Map) Matchers.nullValue(org.hamcrest.Matchers.nullValue) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) ResourceUtils(io.strimzi.operator.cluster.ResourceUtils) MockKube2(io.strimzi.test.mockkube2.MockKube2) KafkaRebalance(io.strimzi.api.kafka.model.KafkaRebalance) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) SecretOperator(io.strimzi.operator.common.operator.resource.SecretOperator) VertxExtension(io.vertx.junit5.VertxExtension) KafkaRebalanceList(io.strimzi.api.kafka.KafkaRebalanceList) KafkaRebalanceAnnotation(io.strimzi.api.kafka.model.balancing.KafkaRebalanceAnnotation) Future(io.vertx.core.Future) NoSuchResourceException(io.strimzi.operator.cluster.model.NoSuchResourceException) ClientAndServer(org.mockserver.integration.ClientAndServer) CruiseControlResources(io.strimzi.api.kafka.model.CruiseControlResources) Test(org.junit.jupiter.api.Test) Labels(io.strimzi.operator.common.model.Labels) CruiseControlApi(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlApi) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Secret(io.fabric8.kubernetes.api.model.Secret) Optional(java.util.Optional) Checkpoint(io.vertx.junit5.Checkpoint) Matchers.is(org.hamcrest.Matchers.is) Condition(io.strimzi.api.kafka.model.status.Condition) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) VertxTestContext(io.vertx.junit5.VertxTestContext) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) KafkaList(io.strimzi.api.kafka.KafkaList) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) KafkaRebalanceState(io.strimzi.api.kafka.model.balancing.KafkaRebalanceState) KafkaRebalanceBuilder(io.strimzi.api.kafka.model.KafkaRebalanceBuilder) CruiseControlApiImpl(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlApiImpl) Crds(io.strimzi.api.kafka.Crds) KafkaRebalanceSpec(io.strimzi.api.kafka.model.KafkaRebalanceSpec) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) KafkaRebalanceMode(io.strimzi.api.kafka.model.balancing.KafkaRebalanceMode) CruiseControlEndpoints(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlEndpoints) KafkaVersionTestUtils(io.strimzi.operator.cluster.KafkaVersionTestUtils) ConfigMapOperator(io.strimzi.operator.common.operator.resource.ConfigMapOperator) CrdOperator(io.strimzi.operator.common.operator.resource.CrdOperator) TestUtils(io.strimzi.test.TestUtils) ReconcileResult(io.strimzi.operator.common.operator.resource.ReconcileResult) ConnectException(java.net.ConnectException) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) NoStackTraceTimeoutException(io.strimzi.operator.common.operator.resource.NoStackTraceTimeoutException) CruiseControl(io.strimzi.operator.cluster.model.CruiseControl) InvalidResourceException(io.strimzi.operator.cluster.model.InvalidResourceException) Vertx(io.vertx.core.Vertx) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) KafkaRebalanceStatus(io.strimzi.api.kafka.model.status.KafkaRebalanceStatus) Reconciliation(io.strimzi.operator.common.Reconciliation) AfterEach(org.junit.jupiter.api.AfterEach) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Kafka(io.strimzi.api.kafka.model.Kafka) CruiseControlRestException(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlRestException) MockCruiseControl(io.strimzi.operator.cluster.operator.resource.cruisecontrol.MockCruiseControl) Collections(java.util.Collections) Condition(io.strimzi.api.kafka.model.status.Condition) Checkpoint(io.vertx.junit5.Checkpoint) Reconciliation(io.strimzi.operator.common.Reconciliation) KafkaRebalance(io.strimzi.api.kafka.model.KafkaRebalance) Test(org.junit.jupiter.api.Test)

Aggregations

Condition (io.strimzi.api.kafka.model.status.Condition)150 Test (org.junit.jupiter.api.Test)70 Kafka (io.strimzi.api.kafka.model.Kafka)61 HashMap (java.util.HashMap)49 EphemeralStorage (io.strimzi.api.kafka.model.storage.EphemeralStorage)42 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)38 Collections (java.util.Collections)37 Vertx (io.vertx.core.Vertx)36 Map (java.util.Map)36 KafkaBuilder (io.strimzi.api.kafka.model.KafkaBuilder)34 Labels (io.strimzi.operator.common.model.Labels)34 Future (io.vertx.core.Future)34 BeforeAll (org.junit.jupiter.api.BeforeAll)32 Reconciliation (io.strimzi.operator.common.Reconciliation)26 Checkpoint (io.vertx.junit5.Checkpoint)26 VertxExtension (io.vertx.junit5.VertxExtension)26 VertxTestContext (io.vertx.junit5.VertxTestContext)26 AfterAll (org.junit.jupiter.api.AfterAll)26 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)26 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)25