Search in sources :

Example 1 with KafkaBridge

use of io.strimzi.api.kafka.model.KafkaBridge in project strimzi by strimzi.

the class KafkaBridgeAssemblyOperatorTest method testCreateOrUpdateWithNoDiffCausesNoChanges.

@Test
public void testCreateOrUpdateWithNoDiffCausesNoChanges(VertxTestContext context) {
    ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(true);
    var mockBridgeOps = supplier.kafkaBridgeOperator;
    DeploymentOperator mockDcOps = supplier.deploymentOperations;
    PodDisruptionBudgetOperator mockPdbOps = supplier.podDisruptionBudgetOperator;
    ConfigMapOperator mockCmOps = supplier.configMapOperations;
    ServiceOperator mockServiceOps = supplier.serviceOperations;
    String kbName = "foo";
    String kbNamespace = "test";
    KafkaBridge kb = ResourceUtils.createKafkaBridge(kbNamespace, kbName, image, 1, BOOTSTRAP_SERVERS, KAFKA_BRIDGE_PRODUCER_SPEC, KAFKA_BRIDGE_CONSUMER_SPEC, KAFKA_BRIDGE_HTTP_SPEC, true);
    KafkaBridgeCluster bridge = KafkaBridgeCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kb, VERSIONS);
    when(mockBridgeOps.get(kbNamespace, kbName)).thenReturn(kb);
    when(mockBridgeOps.getAsync(anyString(), anyString())).thenReturn(Future.succeededFuture(kb));
    when(mockBridgeOps.updateStatusAsync(any(), any(KafkaBridge.class))).thenReturn(Future.succeededFuture());
    when(mockServiceOps.get(kbNamespace, bridge.getName())).thenReturn(bridge.generateService());
    when(mockDcOps.get(kbNamespace, bridge.getName())).thenReturn(bridge.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());
    ArgumentCaptor<String> serviceNameCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<Service> serviceCaptor = ArgumentCaptor.forClass(Service.class);
    when(mockServiceOps.reconcile(any(), eq(kbNamespace), serviceNameCaptor.capture(), serviceCaptor.capture())).thenReturn(Future.succeededFuture());
    ArgumentCaptor<String> dcNameCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<Deployment> dcCaptor = ArgumentCaptor.forClass(Deployment.class);
    when(mockDcOps.reconcile(any(), eq(kbNamespace), dcNameCaptor.capture(), dcCaptor.capture())).thenReturn(Future.succeededFuture());
    ArgumentCaptor<String> dcScaleUpNameCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<Integer> dcScaleUpReplicasCaptor = ArgumentCaptor.forClass(Integer.class);
    when(mockDcOps.scaleUp(any(), eq(kbNamespace), dcScaleUpNameCaptor.capture(), dcScaleUpReplicasCaptor.capture())).thenReturn(Future.succeededFuture());
    ArgumentCaptor<String> dcScaleDownNameCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<Integer> dcScaleDownReplicasCaptor = ArgumentCaptor.forClass(Integer.class);
    when(mockDcOps.scaleDown(any(), eq(kbNamespace), dcScaleDownNameCaptor.capture(), dcScaleDownReplicasCaptor.capture())).thenReturn(Future.succeededFuture());
    ArgumentCaptor<PodDisruptionBudget> pdbCaptor = ArgumentCaptor.forClass(PodDisruptionBudget.class);
    when(mockPdbOps.reconcile(any(), anyString(), any(), pdbCaptor.capture())).thenReturn(Future.succeededFuture());
    when(mockCmOps.reconcile(any(), anyString(), any(), any())).thenReturn(Future.succeededFuture(ReconcileResult.created(new ConfigMap())));
    KafkaBridgeAssemblyOperator ops = new KafkaBridgeAssemblyOperator(vertx, new PlatformFeaturesAvailability(true, kubernetesVersion), new MockCertManager(), new PasswordGenerator(10, "a", "a"), supplier, ResourceUtils.dummyClusterOperatorConfig(VERSIONS));
    Checkpoint async = context.checkpoint();
    ops.createOrUpdate(new Reconciliation("test-trigger", KafkaBridge.RESOURCE_KIND, kbNamespace, kbName), kb).onComplete(context.succeeding(v -> context.verify(() -> {
        // Verify service
        List<Service> capturedServices = serviceCaptor.getAllValues();
        assertThat(capturedServices, hasSize(1));
        // Verify Deployment Config
        List<Deployment> capturedDc = dcCaptor.getAllValues();
        assertThat(capturedDc, hasSize(1));
        // Verify PodDisruptionBudget
        List<PodDisruptionBudget> capturedPdb = pdbCaptor.getAllValues();
        assertThat(capturedPdb, hasSize(1));
        PodDisruptionBudget pdb = capturedPdb.get(0);
        assertThat(pdb.getMetadata().getName(), is(bridge.getName()));
        assertThat(pdb, is(bridge.generatePodDisruptionBudget()));
        // Verify scaleDown / scaleUp were not called
        assertThat(dcScaleDownNameCaptor.getAllValues(), hasSize(1));
        assertThat(dcScaleUpNameCaptor.getAllValues(), hasSize(1));
        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) PodDisruptionBudget(io.fabric8.kubernetes.api.model.policy.v1.PodDisruptionBudget) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ServiceOperator(io.strimzi.operator.common.operator.resource.ServiceOperator) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) PasswordGenerator(io.strimzi.operator.common.PasswordGenerator) Reconciliation(io.strimzi.operator.common.Reconciliation) DeploymentOperator(io.strimzi.operator.common.operator.resource.DeploymentOperator) KafkaBridgeCluster(io.strimzi.operator.cluster.model.KafkaBridgeCluster) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) KafkaBridge(io.strimzi.api.kafka.model.KafkaBridge) PodDisruptionBudgetOperator(io.strimzi.operator.common.operator.resource.PodDisruptionBudgetOperator) Service(io.fabric8.kubernetes.api.model.Service) Checkpoint(io.vertx.junit5.Checkpoint) MockCertManager(io.strimzi.operator.common.operator.MockCertManager) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) ConfigMapOperator(io.strimzi.operator.common.operator.resource.ConfigMapOperator) Test(org.junit.jupiter.api.Test)

Example 2 with KafkaBridge

use of io.strimzi.api.kafka.model.KafkaBridge in project strimzi by strimzi.

the class KafkaBridgeTemplates method kafkaBridgeWithCors.

public static KafkaBridgeBuilder kafkaBridgeWithCors(String name, String clusterName, String bootstrap, int kafkaBridgeReplicas, String allowedCorsOrigin, String allowedCorsMethods) {
    KafkaBridge kafkaBridge = getKafkaBridgeFromYaml(Constants.PATH_TO_KAFKA_BRIDGE_CONFIG);
    KafkaBridgeBuilder kafkaBridgeBuilder = defaultKafkaBridge(kafkaBridge, name, clusterName, bootstrap, kafkaBridgeReplicas);
    kafkaBridgeBuilder.editSpec().editHttp().withNewCors().withAllowedOrigins(allowedCorsOrigin).withAllowedMethods(allowedCorsMethods != null ? allowedCorsMethods : "GET,POST,PUT,DELETE,OPTIONS,PATCH").endCors().endHttp().endSpec();
    return kafkaBridgeBuilder;
}
Also used : KafkaBridge(io.strimzi.api.kafka.model.KafkaBridge) KafkaBridgeBuilder(io.strimzi.api.kafka.model.KafkaBridgeBuilder)

Example 3 with KafkaBridge

use of io.strimzi.api.kafka.model.KafkaBridge in project strimzi by strimzi.

the class HttpBridgeIsolatedST method testCustomBridgeLabelsAreProperlySet.

@ParallelTest
void testCustomBridgeLabelsAreProperlySet(ExtensionContext extensionContext) {
    final String bridgeName = "bridge-" + mapWithClusterNames.get(extensionContext.getDisplayName());
    resourceManager.createResource(extensionContext, KafkaBridgeTemplates.kafkaBridge(bridgeName, KafkaResources.plainBootstrapAddress(httpBridgeClusterName), 1).editMetadata().withNamespace(INFRA_NAMESPACE).endMetadata().build());
    // get service with custom labels
    final Service kafkaBridgeService = kubeClient(INFRA_NAMESPACE).getService(INFRA_NAMESPACE, KafkaBridgeResources.serviceName(bridgeName));
    // filter only app-bar service
    final Map<String, String> filteredActualKafkaBridgeCustomLabels = kafkaBridgeService.getMetadata().getLabels().entrySet().stream().filter(item -> item.getKey().equals("app") && item.getValue().equals("bar")).collect(Collectors.toMap(item -> item.getKey(), item -> item.getValue()));
    final Map<String, String> filteredActualKafkaBridgeCustomAnnotations = kafkaBridgeService.getMetadata().getAnnotations().entrySet().stream().filter(item -> item.getKey().equals("bar") && item.getValue().equals("app")).collect(Collectors.toMap(item -> item.getKey(), item -> item.getValue()));
    // verify phase: that inside KafkaBridge we can find 'exceptedKafkaBridgeCustomLabels' and 'exceptedKafkaBridgeCustomAnnotations' previously defined
    assertThat(filteredActualKafkaBridgeCustomLabels.size(), is(Collections.singletonMap("app", "bar").size()));
    assertThat(filteredActualKafkaBridgeCustomAnnotations.size(), is(Collections.singletonMap("bar", "app").size()));
    assertThat(filteredActualKafkaBridgeCustomLabels, is(Collections.singletonMap("app", "bar")));
    assertThat(filteredActualKafkaBridgeCustomAnnotations, is(Collections.singletonMap("bar", "app")));
}
Also used : ParallelTest(io.strimzi.systemtest.annotations.ParallelTest) CoreMatchers.is(org.hamcrest.CoreMatchers.is) Arrays(java.util.Arrays) KubeClusterResource.cmdKubeClient(io.strimzi.test.k8s.KubeClusterResource.cmdKubeClient) Random(java.util.Random) INFRA_NAMESPACE(io.strimzi.systemtest.Constants.INFRA_NAMESPACE) KafkaBridge(io.strimzi.api.kafka.model.KafkaBridge) KafkaResources(io.strimzi.api.kafka.model.KafkaResources) BeforeAll(org.junit.jupiter.api.BeforeAll) Map(java.util.Map) Tag(org.junit.jupiter.api.Tag) StUtils(io.strimzi.systemtest.utils.StUtils) BeforeAllOnce(io.strimzi.systemtest.BeforeAllOnce) IsolatedSuite(io.strimzi.systemtest.annotations.IsolatedSuite) ConsumerConfig(org.apache.kafka.clients.consumer.ConsumerConfig) INTERNAL_CLIENTS_USED(io.strimzi.systemtest.Constants.INTERNAL_CLIENTS_USED) EnvVarBuilder(io.fabric8.kubernetes.api.model.EnvVarBuilder) Collectors(java.util.stream.Collectors) ClientUtils(io.strimzi.systemtest.utils.ClientUtils) List(java.util.List) Labels(io.strimzi.operator.common.model.Labels) KafkaBridgeResource(io.strimzi.systemtest.resources.crd.KafkaBridgeResource) Logger(org.apache.logging.log4j.Logger) KafkaTopicTemplates(io.strimzi.systemtest.templates.crd.KafkaTopicTemplates) BRIDGE(io.strimzi.systemtest.Constants.BRIDGE) BridgeClients(io.strimzi.systemtest.kafkaclients.internalClients.BridgeClients) BridgeClientsBuilder(io.strimzi.systemtest.kafkaclients.internalClients.BridgeClientsBuilder) Matchers.containsString(org.hamcrest.Matchers.containsString) AbstractST(io.strimzi.systemtest.AbstractST) Environment(io.strimzi.systemtest.Environment) KafkaClientsTemplates(io.strimzi.systemtest.templates.crd.KafkaClientsTemplates) CoreMatchers.not(org.hamcrest.CoreMatchers.not) HashMap(java.util.HashMap) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) LinkedHashMap(java.util.LinkedHashMap) PodUtils(io.strimzi.systemtest.utils.kubeUtils.objects.PodUtils) DeploymentStrategy(io.strimzi.api.kafka.model.template.DeploymentStrategy) Service(io.fabric8.kubernetes.api.model.Service) KafkaBridgeUtils(io.strimzi.systemtest.utils.kafkaUtils.KafkaBridgeUtils) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) KafkaBridgeResources(io.strimzi.api.kafka.model.KafkaBridgeResources) KafkaTemplates(io.strimzi.systemtest.templates.crd.KafkaTemplates) Ready(io.strimzi.systemtest.enums.CustomResourceStatus.Ready) InternalKafkaClient(io.strimzi.systemtest.kafkaclients.clients.InternalKafkaClient) Constants(io.strimzi.systemtest.Constants) SetupClusterOperator(io.strimzi.systemtest.resources.operator.SetupClusterOperator) KubeClusterResource.kubeClient(io.strimzi.test.k8s.KubeClusterResource.kubeClient) KafkaBridgeStatus(io.strimzi.api.kafka.model.status.KafkaBridgeStatus) JsonArray(io.vertx.core.json.JsonArray) DeploymentUtils(io.strimzi.systemtest.utils.kubeUtils.controllers.DeploymentUtils) KafkaBridgeTemplates(io.strimzi.systemtest.templates.crd.KafkaBridgeTemplates) LogManager(org.apache.logging.log4j.LogManager) Collections(java.util.Collections) REGRESSION(io.strimzi.systemtest.Constants.REGRESSION) Service(io.fabric8.kubernetes.api.model.Service) Matchers.containsString(org.hamcrest.Matchers.containsString) ParallelTest(io.strimzi.systemtest.annotations.ParallelTest)

Example 4 with KafkaBridge

use of io.strimzi.api.kafka.model.KafkaBridge in project strimzi 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)

Example 5 with KafkaBridge

use of io.strimzi.api.kafka.model.KafkaBridge in project strimzi by strimzi.

the class KafkaBridgeClusterTest method testCorsConfiguration.

@ParallelTest
public void testCorsConfiguration() {
    KafkaBridge resource = new KafkaBridgeBuilder(this.resource).editSpec().editHttp().withNewCors().withAllowedOrigins("https://strimzi.io", "https://cncf.io").withAllowedMethods("GET", "POST", "PUT", "DELETE", "PATCH").endCors().endHttp().endSpec().build();
    KafkaBridgeCluster kb = KafkaBridgeCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, resource, VERSIONS);
    Deployment deployment = kb.generateDeployment(new HashMap<>(), true, null, null);
    Container container = deployment.getSpec().getTemplate().getSpec().getContainers().get(0);
    assertThat(AbstractModel.containerEnvVars(container).get(KafkaBridgeCluster.ENV_VAR_KAFKA_BRIDGE_CORS_ENABLED), is("true"));
    assertThat(AbstractModel.containerEnvVars(container).get(KafkaBridgeCluster.ENV_VAR_KAFKA_BRIDGE_CORS_ALLOWED_ORIGINS), is("https://strimzi.io,https://cncf.io"));
    assertThat(AbstractModel.containerEnvVars(container).get(KafkaBridgeCluster.ENV_VAR_KAFKA_BRIDGE_CORS_ALLOWED_METHODS), is("GET,POST,PUT,DELETE,PATCH"));
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) KafkaBridge(io.strimzi.api.kafka.model.KafkaBridge) KafkaBridgeBuilder(io.strimzi.api.kafka.model.KafkaBridgeBuilder) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Aggregations

KafkaBridge (io.strimzi.api.kafka.model.KafkaBridge)88 KafkaBridgeBuilder (io.strimzi.api.kafka.model.KafkaBridgeBuilder)82 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)70 ParallelTest (io.strimzi.test.annotations.ParallelTest)62 Service (io.fabric8.kubernetes.api.model.Service)38 PodDisruptionBudget (io.fabric8.kubernetes.api.model.policy.v1.PodDisruptionBudget)38 HashMap (java.util.HashMap)38 KafkaBridgeResources (io.strimzi.api.kafka.model.KafkaBridgeResources)36 Collections (java.util.Collections)36 List (java.util.List)36 Container (io.fabric8.kubernetes.api.model.Container)34 Reconciliation (io.strimzi.operator.common.Reconciliation)34 Labels (io.strimzi.operator.common.model.Labels)34 Map (java.util.Map)34 CoreMatchers.is (org.hamcrest.CoreMatchers.is)34 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)34 KafkaBridgeHttpConfig (io.strimzi.api.kafka.model.KafkaBridgeHttpConfig)32 KafkaVersionTestUtils (io.strimzi.operator.cluster.KafkaVersionTestUtils)32 ResourceUtils (io.strimzi.operator.cluster.ResourceUtils)32 TestUtils (io.strimzi.test.TestUtils)32