Search in sources :

Example 6 with KafkaBridgeStatus

use of io.strimzi.api.kafka.model.status.KafkaBridgeStatus in project strimzi by strimzi.

the class KafkaBridgeAssemblyOperatorTest method testReconcileCallsCreateOrUpdate.

@Test
@SuppressWarnings("unchecked")
public void testReconcileCallsCreateOrUpdate(VertxTestContext context) {
    // Must create all checkpoints before flagging any to avoid premature test success
    Checkpoint async = context.checkpoint();
    // Should be called twice, once for foo and once for bar
    Checkpoint asyncCreatedOrUpdated = context.checkpoint(2);
    ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(true);
    var mockBridgeOps = supplier.kafkaBridgeOperator;
    DeploymentOperator mockDcOps = supplier.deploymentOperations;
    SecretOperator mockSecretOps = supplier.secretOperations;
    String kbNamespace = "test";
    KafkaBridge foo = ResourceUtils.createKafkaBridge(kbNamespace, "foo", image, 1, BOOTSTRAP_SERVERS, KAFKA_BRIDGE_PRODUCER_SPEC, KAFKA_BRIDGE_CONSUMER_SPEC, KAFKA_BRIDGE_HTTP_SPEC, true);
    KafkaBridge bar = ResourceUtils.createKafkaBridge(kbNamespace, "bar", image, 1, BOOTSTRAP_SERVERS, KAFKA_BRIDGE_PRODUCER_SPEC, KAFKA_BRIDGE_CONSUMER_SPEC, KAFKA_BRIDGE_HTTP_SPEC, true);
    when(mockBridgeOps.listAsync(eq(kbNamespace), any(Optional.class))).thenReturn(Future.succeededFuture(asList(foo, bar)));
    when(mockBridgeOps.getAsync(anyString(), anyString())).thenReturn(Future.succeededFuture(bar));
    when(mockBridgeOps.updateStatusAsync(any(), any(KafkaBridge.class))).thenReturn(Future.succeededFuture());
    // when requested ConfigMap for a specific Kafka Bridge cluster
    when(mockBridgeOps.get(eq(kbNamespace), eq("foo"))).thenReturn(foo);
    when(mockBridgeOps.get(eq(kbNamespace), eq("bar"))).thenReturn(bar);
    // providing the list of ALL Deployments for all the Kafka Bridge clusters
    Labels newLabels = Labels.forStrimziKind(KafkaBridge.RESOURCE_KIND);
    when(mockDcOps.list(eq(kbNamespace), eq(newLabels))).thenReturn(List.of(KafkaBridgeCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, bar, VERSIONS).generateDeployment(Map.of(), true, null, null)));
    when(mockDcOps.readiness(any(), anyString(), anyString(), anyLong(), anyLong())).thenReturn(Future.succeededFuture());
    when(mockDcOps.waitForObserved(any(), anyString(), anyString(), anyLong(), anyLong())).thenReturn(Future.succeededFuture());
    // providing the list Deployments for already "existing" Kafka Bridge clusters
    Labels barLabels = Labels.forStrimziCluster("bar");
    when(mockDcOps.list(eq(kbNamespace), eq(barLabels))).thenReturn(List.of(KafkaBridgeCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, bar, VERSIONS).generateDeployment(Map.of(), true, null, null)));
    when(mockSecretOps.reconcile(any(), eq(kbNamespace), any(), any())).thenReturn(Future.succeededFuture());
    Set<String> createdOrUpdated = new CopyOnWriteArraySet<>();
    KafkaBridgeAssemblyOperator ops = new KafkaBridgeAssemblyOperator(vertx, new PlatformFeaturesAvailability(true, kubernetesVersion), new MockCertManager(), new PasswordGenerator(10, "a", "a"), supplier, ResourceUtils.dummyClusterOperatorConfig(VERSIONS)) {

        @Override
        public Future<KafkaBridgeStatus> createOrUpdate(Reconciliation reconciliation, KafkaBridge kafkaBridgeAssembly) {
            createdOrUpdated.add(kafkaBridgeAssembly.getMetadata().getName());
            asyncCreatedOrUpdated.flag();
            return Future.succeededFuture();
        }
    };
    Promise<Void> reconciled = Promise.promise();
    // Now try to reconcile all the Kafka Bridge clusters
    ops.reconcileAll("test", kbNamespace, v -> reconciled.complete());
    reconciled.future().onComplete(context.succeeding(v -> context.verify(() -> {
        assertThat(createdOrUpdated, is(Set.of("foo", "bar")));
        async.flag();
    })));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Annotations(io.strimzi.operator.common.Annotations) PodDisruptionBudget(io.fabric8.kubernetes.api.model.policy.v1.PodDisruptionBudget) AfterAll(org.junit.jupiter.api.AfterAll) KafkaBridge(io.strimzi.api.kafka.model.KafkaBridge) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) BeforeAll(org.junit.jupiter.api.BeforeAll) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Mockito.doAnswer(org.mockito.Mockito.doAnswer) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) ResourceUtils(io.strimzi.operator.cluster.ResourceUtils) KafkaBridgeConsumerSpec(io.strimzi.api.kafka.model.KafkaBridgeConsumerSpec) AbstractModel(io.strimzi.operator.cluster.model.AbstractModel) KafkaBridgeProducerSpec(io.strimzi.api.kafka.model.KafkaBridgeProducerSpec) DeploymentOperator(io.strimzi.operator.common.operator.resource.DeploymentOperator) KafkaVersion(io.strimzi.operator.cluster.model.KafkaVersion) SecretOperator(io.strimzi.operator.common.operator.resource.SecretOperator) Set(java.util.Set) VertxExtension(io.vertx.junit5.VertxExtension) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) Future(io.vertx.core.Future) KafkaBridgeHttpConfig(io.strimzi.api.kafka.model.KafkaBridgeHttpConfig) Test(org.junit.jupiter.api.Test) List(java.util.List) Labels(io.strimzi.operator.common.model.Labels) PasswordGenerator(io.strimzi.operator.common.PasswordGenerator) Optional(java.util.Optional) Checkpoint(io.vertx.junit5.Checkpoint) PodDisruptionBudgetOperator(io.strimzi.operator.common.operator.resource.PodDisruptionBudgetOperator) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) MockCertManager(io.strimzi.operator.common.operator.MockCertManager) VertxTestContext(io.vertx.junit5.VertxTestContext) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) HashMap(java.util.HashMap) ServiceOperator(io.strimzi.operator.common.operator.resource.ServiceOperator) ArgumentCaptor(org.mockito.ArgumentCaptor) KafkaVersionTestUtils(io.strimzi.operator.cluster.KafkaVersionTestUtils) ConfigMapOperator(io.strimzi.operator.common.operator.resource.ConfigMapOperator) TestUtils(io.strimzi.test.TestUtils) KafkaBridgeBuilder(io.strimzi.api.kafka.model.KafkaBridgeBuilder) Matchers.hasSize(org.hamcrest.Matchers.hasSize) ReconcileResult(io.strimzi.operator.common.operator.resource.ReconcileResult) Service(io.fabric8.kubernetes.api.model.Service) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) KafkaBridgeResources(io.strimzi.api.kafka.model.KafkaBridgeResources) Promise(io.vertx.core.Promise) KubernetesVersion(io.strimzi.operator.KubernetesVersion) Vertx(io.vertx.core.Vertx) Mockito.when(org.mockito.Mockito.when) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) KafkaBridgeCluster(io.strimzi.operator.cluster.model.KafkaBridgeCluster) Mockito.verify(org.mockito.Mockito.verify) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) KafkaBridgeStatus(io.strimzi.api.kafka.model.status.KafkaBridgeStatus) Reconciliation(io.strimzi.operator.common.Reconciliation) Mockito.never(org.mockito.Mockito.never) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) Collections(java.util.Collections) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Optional(java.util.Optional) KafkaBridge(io.strimzi.api.kafka.model.KafkaBridge) Labels(io.strimzi.operator.common.model.Labels) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) KafkaBridgeStatus(io.strimzi.api.kafka.model.status.KafkaBridgeStatus) SecretOperator(io.strimzi.operator.common.operator.resource.SecretOperator) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) Checkpoint(io.vertx.junit5.Checkpoint) MockCertManager(io.strimzi.operator.common.operator.MockCertManager) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) PasswordGenerator(io.strimzi.operator.common.PasswordGenerator) Reconciliation(io.strimzi.operator.common.Reconciliation) DeploymentOperator(io.strimzi.operator.common.operator.resource.DeploymentOperator) Test(org.junit.jupiter.api.Test)

Example 7 with KafkaBridgeStatus

use of io.strimzi.api.kafka.model.status.KafkaBridgeStatus in project strimzi-kafka-operator by strimzi.

the class CustomResourceStatusIsolatedST method assertKafkaBridgeStatus.

void assertKafkaBridgeStatus(long expectedObservedGeneration, String bridgeAddress) {
    KafkaBridgeStatus kafkaBridgeStatus = KafkaBridgeResource.kafkaBridgeClient().inNamespace(Constants.INFRA_NAMESPACE).withName(CUSTOM_RESOURCE_STATUS_CLUSTER_NAME).get().getStatus();
    assertThat("Kafka Bridge cluster status has incorrect Observed Generation", kafkaBridgeStatus.getObservedGeneration(), is(expectedObservedGeneration));
    assertThat("Kafka Bridge cluster status has incorrect URL", kafkaBridgeStatus.getUrl(), is(bridgeAddress));
}
Also used : KafkaBridgeStatus(io.strimzi.api.kafka.model.status.KafkaBridgeStatus)

Example 8 with KafkaBridgeStatus

use of io.strimzi.api.kafka.model.status.KafkaBridgeStatus in project strimzi-kafka-operator by strimzi.

the class KafkaBridgeAssemblyOperator method createOrUpdate.

@Override
protected Future<KafkaBridgeStatus> createOrUpdate(Reconciliation reconciliation, KafkaBridge assemblyResource) {
    KafkaBridgeStatus kafkaBridgeStatus = new KafkaBridgeStatus();
    String namespace = reconciliation.namespace();
    KafkaBridgeCluster bridge;
    try {
        bridge = KafkaBridgeCluster.fromCrd(reconciliation, assemblyResource, versions);
    } catch (Exception e) {
        LOGGER.warnCr(reconciliation, e);
        StatusUtils.setStatusConditionAndObservedGeneration(assemblyResource, kafkaBridgeStatus, Future.failedFuture(e));
        return Future.failedFuture(new ReconciliationException(kafkaBridgeStatus, e));
    }
    KafkaClientAuthentication auth = assemblyResource.getSpec().getAuthentication();
    List<CertSecretSource> trustedCertificates = assemblyResource.getSpec().getTls() == null ? Collections.emptyList() : assemblyResource.getSpec().getTls().getTrustedCertificates();
    Promise<KafkaBridgeStatus> createOrUpdatePromise = Promise.promise();
    boolean bridgeHasZeroReplicas = bridge.getReplicas() == 0;
    LOGGER.debugCr(reconciliation, "Updating Kafka Bridge cluster");
    kafkaBridgeServiceAccount(reconciliation, namespace, bridge).compose(i -> deploymentOperations.scaleDown(reconciliation, namespace, bridge.getName(), bridge.getReplicas())).compose(scale -> serviceOperations.reconcile(reconciliation, namespace, bridge.getServiceName(), bridge.generateService())).compose(i -> Util.metricsAndLogging(reconciliation, configMapOperations, namespace, bridge.getLogging(), null)).compose(metricsAndLogging -> configMapOperations.reconcile(reconciliation, namespace, bridge.getAncillaryConfigMapName(), bridge.generateMetricsAndLogConfigMap(metricsAndLogging))).compose(i -> pfa.hasPodDisruptionBudgetV1() ? podDisruptionBudgetOperator.reconcile(reconciliation, namespace, bridge.getName(), bridge.generatePodDisruptionBudget()) : Future.succeededFuture()).compose(i -> !pfa.hasPodDisruptionBudgetV1() ? podDisruptionBudgetV1Beta1Operator.reconcile(reconciliation, namespace, bridge.getName(), bridge.generatePodDisruptionBudgetV1Beta1()) : Future.succeededFuture()).compose(i -> Util.authTlsHash(secretOperations, namespace, auth, trustedCertificates)).compose(hash -> deploymentOperations.reconcile(reconciliation, namespace, bridge.getName(), bridge.generateDeployment(Collections.singletonMap(Annotations.ANNO_STRIMZI_AUTH_HASH, Integer.toString(hash)), pfa.isOpenshift(), imagePullPolicy, imagePullSecrets))).compose(i -> deploymentOperations.scaleUp(reconciliation, namespace, bridge.getName(), bridge.getReplicas())).compose(i -> deploymentOperations.waitForObserved(reconciliation, namespace, bridge.getName(), 1_000, operationTimeoutMs)).compose(i -> bridgeHasZeroReplicas ? Future.succeededFuture() : deploymentOperations.readiness(reconciliation, namespace, bridge.getName(), 1_000, operationTimeoutMs)).onComplete(reconciliationResult -> {
        StatusUtils.setStatusConditionAndObservedGeneration(assemblyResource, kafkaBridgeStatus, reconciliationResult.mapEmpty());
        if (!bridgeHasZeroReplicas) {
            int port = KafkaBridgeCluster.DEFAULT_REST_API_PORT;
            if (bridge.getHttp() != null) {
                port = bridge.getHttp().getPort();
            }
            kafkaBridgeStatus.setUrl(KafkaBridgeResources.url(bridge.getCluster(), namespace, port));
        }
        kafkaBridgeStatus.setReplicas(bridge.getReplicas());
        kafkaBridgeStatus.setLabelSelector(bridge.getSelectorLabels().toSelectorString());
        if (reconciliationResult.succeeded()) {
            createOrUpdatePromise.complete(kafkaBridgeStatus);
        } else {
            createOrUpdatePromise.fail(new ReconciliationException(kafkaBridgeStatus, reconciliationResult.cause()));
        }
    });
    return createOrUpdatePromise.future();
}
Also used : KafkaBridgeCluster(io.strimzi.operator.cluster.model.KafkaBridgeCluster) ReconciliationException(io.strimzi.operator.common.ReconciliationException) KafkaClientAuthentication(io.strimzi.api.kafka.model.authentication.KafkaClientAuthentication) CertManager(io.strimzi.certs.CertManager) Annotations(io.strimzi.operator.common.Annotations) Resource(io.fabric8.kubernetes.client.dsl.Resource) KafkaBridge(io.strimzi.api.kafka.model.KafkaBridge) ConfigMapOperator(io.strimzi.operator.common.operator.resource.ConfigMapOperator) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) ReconciliationException(io.strimzi.operator.common.ReconciliationException) ReconcileResult(io.strimzi.operator.common.operator.resource.ReconcileResult) KafkaBridgeResources(io.strimzi.api.kafka.model.KafkaBridgeResources) StatusUtils(io.strimzi.operator.common.operator.resource.StatusUtils) ReconciliationLogger(io.strimzi.operator.common.ReconciliationLogger) ExternalLogging(io.strimzi.api.kafka.model.ExternalLogging) CertSecretSource(io.strimzi.api.kafka.model.CertSecretSource) DeploymentOperator(io.strimzi.operator.common.operator.resource.DeploymentOperator) Promise(io.vertx.core.Promise) KafkaVersion(io.strimzi.operator.cluster.model.KafkaVersion) Vertx(io.vertx.core.Vertx) KafkaBridgeSpec(io.strimzi.api.kafka.model.KafkaBridgeSpec) KafkaBridgeList(io.strimzi.api.kafka.KafkaBridgeList) Future(io.vertx.core.Future) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) KafkaBridgeCluster(io.strimzi.operator.cluster.model.KafkaBridgeCluster) KafkaBridgeStatus(io.strimzi.api.kafka.model.status.KafkaBridgeStatus) Reconciliation(io.strimzi.operator.common.Reconciliation) List(java.util.List) Util(io.strimzi.operator.common.Util) PasswordGenerator(io.strimzi.operator.common.PasswordGenerator) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) ServiceAccount(io.fabric8.kubernetes.api.model.ServiceAccount) KafkaClientAuthentication(io.strimzi.api.kafka.model.authentication.KafkaClientAuthentication) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) Collections(java.util.Collections) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) CertSecretSource(io.strimzi.api.kafka.model.CertSecretSource) ReconciliationException(io.strimzi.operator.common.ReconciliationException) KafkaBridgeStatus(io.strimzi.api.kafka.model.status.KafkaBridgeStatus)

Aggregations

KafkaBridgeStatus (io.strimzi.api.kafka.model.status.KafkaBridgeStatus)8 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)4 KafkaBridge (io.strimzi.api.kafka.model.KafkaBridge)4 KafkaBridgeResources (io.strimzi.api.kafka.model.KafkaBridgeResources)4 PlatformFeaturesAvailability (io.strimzi.operator.PlatformFeaturesAvailability)4 KafkaBridgeCluster (io.strimzi.operator.cluster.model.KafkaBridgeCluster)4 KafkaVersion (io.strimzi.operator.cluster.model.KafkaVersion)4 ResourceOperatorSupplier (io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier)4 Annotations (io.strimzi.operator.common.Annotations)4 PasswordGenerator (io.strimzi.operator.common.PasswordGenerator)4 Reconciliation (io.strimzi.operator.common.Reconciliation)4 ConfigMapOperator (io.strimzi.operator.common.operator.resource.ConfigMapOperator)4 DeploymentOperator (io.strimzi.operator.common.operator.resource.DeploymentOperator)4 ReconcileResult (io.strimzi.operator.common.operator.resource.ReconcileResult)4 Future (io.vertx.core.Future)4 Promise (io.vertx.core.Promise)4 Vertx (io.vertx.core.Vertx)4 Collections (java.util.Collections)4 List (java.util.List)4 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)2