Search in sources :

Example 1 with ManagedKafkaSpecBuilder

use of org.bf2.operator.resources.v1alpha1.ManagedKafkaSpecBuilder in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class IngressControllerManagerTest method testGetManagedKafkaRoutesFor.

@Test
public void testGetManagedKafkaRoutesFor() {
    final String mkName = "my-managedkafka";
    ManagedKafka mk = new ManagedKafkaBuilder().withNewMetadata().withName(mkName).withNamespace(mkName).endMetadata().withSpec(new ManagedKafkaSpecBuilder().withNewEndpoint().withBootstrapServerHost("bs.bf2.example.tld").endEndpoint().build()).build();
    final Function<? super String, ? extends Route> makeRoute = broker -> new RouteBuilder().editOrNewMetadata().withName(mkName + "-" + broker.replace("broker", "kafka")).withNamespace(mkName).addNewOwnerReference().withApiVersion(Kafka.V1BETA2).withKind(Kafka.RESOURCE_KIND).withName(AbstractKafkaCluster.kafkaClusterName(mk)).endOwnerReference().endMetadata().editOrNewSpec().withHost(broker + "-bs.bf2.example.tld").withTo(new RouteTargetReferenceBuilder().withKind("Service").withName(mkName + "-" + broker).withWeight(100).build()).endSpec().build();
    final Function<? super String, ? extends Service> suffixToService = suffix -> new ServiceBuilder().editOrNewMetadata().withName(mkName + "-" + suffix).withNamespace(mkName).endMetadata().editOrNewSpec().withSelector(Map.of("dummy-label", mkName + "-" + suffix)).endSpec().build();
    final Function<? super String, ? extends Pod> suffixToPod = suffix -> new PodBuilder().editOrNewMetadata().withName(mkName + "-" + suffix).withNamespace(mkName).addToLabels(Map.of("dummy-label", mkName + "-" + suffix, "app.kubernetes.io/name", "kafka", OperandUtils.MANAGED_BY_LABEL, OperandUtils.STRIMZI_OPERATOR_NAME)).endMetadata().editOrNewSpec().withNodeName("zone" + "-" + suffix).endSpec().build();
    final Function<? super String, ? extends Node> suffixToNode = suffix -> new NodeBuilder().editOrNewMetadata().withName("zone" + "-" + suffix).withLabels(Map.of(IngressControllerManager.TOPOLOGY_KEY, "zone" + "-" + suffix, IngressControllerManager.WORKER_NODE_LABEL, "true")).endMetadata().build();
    List<String> suffixes = List.of("broker-0", "broker-1", "broker-2");
    suffixes.stream().map(makeRoute).forEach(route -> openShiftClient.routes().inNamespace(mkName).createOrReplace(route));
    suffixes.stream().map(suffixToService).forEach(svc -> openShiftClient.services().inNamespace(mkName).createOrReplace(svc));
    suffixes.stream().map(suffixToPod).forEach(pod -> openShiftClient.pods().inNamespace(mkName).createOrReplace(pod));
    suffixes.stream().map(suffixToNode).forEach(node -> openShiftClient.nodes().createOrReplace(node));
    ingressControllerManager.reconcileIngressControllers();
    List<ManagedKafkaRoute> managedKafkaRoutes = ingressControllerManager.getManagedKafkaRoutesFor(mk);
    assertEquals(5, managedKafkaRoutes.size());
    assertEquals(managedKafkaRoutes.stream().sorted(Comparator.comparing(ManagedKafkaRoute::getName)).collect(Collectors.toList()), managedKafkaRoutes, "Expected list of ManagedKafkaRoutes to be sorted by name");
    assertEquals("admin-server", managedKafkaRoutes.get(0).getName());
    assertEquals("admin-server", managedKafkaRoutes.get(0).getPrefix());
    assertEquals("ingresscontroller.kas.testing.domain.tld", managedKafkaRoutes.get(0).getRouter());
    assertEquals("bootstrap", managedKafkaRoutes.get(1).getName());
    assertEquals("", managedKafkaRoutes.get(1).getPrefix());
    assertEquals("ingresscontroller.kas.testing.domain.tld", managedKafkaRoutes.get(1).getRouter());
    assertEquals("broker-0", managedKafkaRoutes.get(2).getName());
    assertEquals("broker-0", managedKafkaRoutes.get(2).getPrefix());
    assertEquals("ingresscontroller.kas-zone-broker-0.testing.domain.tld", managedKafkaRoutes.get(2).getRouter());
    assertEquals("broker-1", managedKafkaRoutes.get(3).getName());
    assertEquals("broker-1", managedKafkaRoutes.get(3).getPrefix());
    assertEquals("ingresscontroller.kas-zone-broker-1.testing.domain.tld", managedKafkaRoutes.get(3).getRouter());
    assertEquals("broker-2", managedKafkaRoutes.get(4).getName());
    assertEquals("broker-2", managedKafkaRoutes.get(4).getPrefix());
    assertEquals("ingresscontroller.kas-zone-broker-2.testing.domain.tld", managedKafkaRoutes.get(4).getRouter());
}
Also used : Quantity(io.fabric8.kubernetes.api.model.Quantity) IntStream(java.util.stream.IntStream) BeforeEach(org.junit.jupiter.api.BeforeEach) KubernetesServerTestResource(io.quarkus.test.kubernetes.client.KubernetesServerTestResource) QuarkusMock(io.quarkus.test.junit.QuarkusMock) KubernetesCrudDispatcher(io.fabric8.kubernetes.client.server.mock.KubernetesCrudDispatcher) ManagedKafkaRoute(org.bf2.operator.resources.v1alpha1.ManagedKafkaRoute) Function(java.util.function.Function) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Inject(javax.inject.Inject) Route(io.fabric8.openshift.api.model.Route) NodeBuilder(io.fabric8.kubernetes.api.model.NodeBuilder) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) Map(java.util.Map) AbstractKafkaCluster(org.bf2.operator.operands.AbstractKafkaCluster) Service(io.fabric8.kubernetes.api.model.Service) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Node(io.fabric8.kubernetes.api.model.Node) ServiceBuilder(io.fabric8.kubernetes.api.model.ServiceBuilder) LongSummaryStatistics(java.util.LongSummaryStatistics) QuarkusTestResource(io.quarkus.test.common.QuarkusTestResource) KubernetesServer(io.fabric8.kubernetes.client.server.mock.KubernetesServer) OperandUtils(org.bf2.common.OperandUtils) RouteBuilder(io.fabric8.openshift.api.model.RouteBuilder) ManagedKafkaSpecBuilder(org.bf2.operator.resources.v1alpha1.ManagedKafkaSpecBuilder) Pod(io.fabric8.kubernetes.api.model.Pod) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) AfterEach(org.junit.jupiter.api.AfterEach) List(java.util.List) KafkaCluster(org.bf2.operator.operands.KafkaCluster) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) KubernetesTestServer(io.quarkus.test.kubernetes.client.KubernetesTestServer) Kafka(io.strimzi.api.kafka.model.Kafka) Comparator(java.util.Comparator) RouteTargetReferenceBuilder(io.fabric8.openshift.api.model.RouteTargetReferenceBuilder) IngressController(io.fabric8.openshift.api.model.operator.v1.IngressController) ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) Collections(java.util.Collections) ManagedKafkaBuilder(org.bf2.operator.resources.v1alpha1.ManagedKafkaBuilder) RouteBuilder(io.fabric8.openshift.api.model.RouteBuilder) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) ManagedKafkaBuilder(org.bf2.operator.resources.v1alpha1.ManagedKafkaBuilder) NodeBuilder(io.fabric8.kubernetes.api.model.NodeBuilder) ServiceBuilder(io.fabric8.kubernetes.api.model.ServiceBuilder) ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) ManagedKafkaRoute(org.bf2.operator.resources.v1alpha1.ManagedKafkaRoute) ManagedKafkaSpecBuilder(org.bf2.operator.resources.v1alpha1.ManagedKafkaSpecBuilder) RouteTargetReferenceBuilder(io.fabric8.openshift.api.model.RouteTargetReferenceBuilder) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 2 with ManagedKafkaSpecBuilder

use of org.bf2.operator.resources.v1alpha1.ManagedKafkaSpecBuilder in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class ConditionUtilsTest method testFindManagedKafkaCondition.

@Test
void testFindManagedKafkaCondition() {
    ManagedKafka mk = new ManagedKafkaBuilder().withMetadata(new ObjectMetaBuilder().withNamespace("test").withName("my-managed-kafka").build()).withSpec(new ManagedKafkaSpecBuilder().withNewVersions().withKafka("2.6.0").withStrimzi("0.21.1").endVersions().build()).withStatus(new ManagedKafkaStatusBuilder().addNewCondition().withStatus(Status.True.name()).withType(ManagedKafkaCondition.Type.Ready.name()).endCondition().build()).build();
    assertNotNull(ConditionUtils.findManagedKafkaCondition(mk.getStatus().getConditions(), ManagedKafkaCondition.Type.Ready).get());
}
Also used : ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) ManagedKafkaStatusBuilder(org.bf2.operator.resources.v1alpha1.ManagedKafkaStatusBuilder) ManagedKafkaSpecBuilder(org.bf2.operator.resources.v1alpha1.ManagedKafkaSpecBuilder) ManagedKafkaBuilder(org.bf2.operator.resources.v1alpha1.ManagedKafkaBuilder) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with ManagedKafkaSpecBuilder

use of org.bf2.operator.resources.v1alpha1.ManagedKafkaSpecBuilder in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class CanaryTest method createCanaryService.

@Test
void createCanaryService() throws Exception {
    ManagedKafka mk = new ManagedKafkaBuilder().withNewMetadata().withNamespace("test").withName("test-mk").endMetadata().withSpec(new ManagedKafkaSpecBuilder().withNewVersions().withKafka("2.6.0").endVersions().withNewEndpoint().withBootstrapServerHost("test-mk-kafka-bootstrap").endEndpoint().build()).build();
    Service canaryService = canary.serviceFrom(mk, null);
    server.getClient().services().create(canaryService);
    assertNotNull(server.getClient().services().inNamespace(canaryService.getMetadata().getNamespace()).withName(canaryService.getMetadata().getName()).get());
    KafkaClusterTest.diffToExpected(canaryService, "/expected/canary-service.yml");
}
Also used : ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) ManagedKafkaSpecBuilder(org.bf2.operator.resources.v1alpha1.ManagedKafkaSpecBuilder) Service(io.fabric8.kubernetes.api.model.Service) ManagedKafkaBuilder(org.bf2.operator.resources.v1alpha1.ManagedKafkaBuilder) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with ManagedKafkaSpecBuilder

use of org.bf2.operator.resources.v1alpha1.ManagedKafkaSpecBuilder in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class CanaryTest method createCanaryDeployment.

@ParameterizedTest(name = "createCanaryDeployment: {0}")
@CsvSource({ "shouldHaveNoDiffByDefault, test-mk-kafka-bootstrap, '[]'", "shouldNotHaveInitContainersIfDevCluster, bootstrap.kas.testing.domain.tld, '[{\"op\":\"remove\",\"path\":\"/spec/template/spec/initContainers\"},{\"op\":\"replace\",\"path\":\"/spec/template/spec/containers/0/env/0/value\",\"value\":\"bootstrap.kas.testing.domain.tld:443\"}]'" })
void createCanaryDeployment(String name, String bootstrapServerHost, String expectedDiff) throws Exception {
    ManagedKafka mk = new ManagedKafkaBuilder().withNewMetadata().withNamespace("test").withName("test-mk").endMetadata().withSpec(new ManagedKafkaSpecBuilder().withNewVersions().withKafka("2.6.0").endVersions().withNewEndpoint().withBootstrapServerHost(bootstrapServerHost).endEndpoint().build()).build();
    Deployment canaryDeployment = canary.deploymentFrom(mk, null);
    KafkaClusterTest.diffToExpected(canaryDeployment, "/expected/canary.yml", expectedDiff);
}
Also used : ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) ManagedKafkaSpecBuilder(org.bf2.operator.resources.v1alpha1.ManagedKafkaSpecBuilder) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) ManagedKafkaBuilder(org.bf2.operator.resources.v1alpha1.ManagedKafkaBuilder) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with ManagedKafkaSpecBuilder

use of org.bf2.operator.resources.v1alpha1.ManagedKafkaSpecBuilder in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class ManagedKafkaSpecTest method testIngressEgressBackwardsCompatibility.

@Test
public void testIngressEgressBackwardsCompatibility() {
    ManagedKafkaSpec spec = new ManagedKafkaSpecBuilder().withNewCapacity().withNewIngressEgressThroughputPerSec("30Mi").endCapacity().build();
    assertEquals(spec.getCapacity().getIngressEgressThroughputPerSec(), spec.getCapacity().getIngressPerSec());
    assertEquals(spec.getCapacity().getIngressEgressThroughputPerSec(), spec.getCapacity().getEgressPerSec());
}
Also used : ManagedKafkaSpecBuilder(org.bf2.operator.resources.v1alpha1.ManagedKafkaSpecBuilder) ManagedKafkaSpec(org.bf2.operator.resources.v1alpha1.ManagedKafkaSpec) Test(org.junit.jupiter.api.Test)

Aggregations

ManagedKafkaSpecBuilder (org.bf2.operator.resources.v1alpha1.ManagedKafkaSpecBuilder)6 ManagedKafka (org.bf2.operator.resources.v1alpha1.ManagedKafka)5 ManagedKafkaBuilder (org.bf2.operator.resources.v1alpha1.ManagedKafkaBuilder)5 Test (org.junit.jupiter.api.Test)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 Service (io.fabric8.kubernetes.api.model.Service)2 QuarkusTest (io.quarkus.test.junit.QuarkusTest)2 Node (io.fabric8.kubernetes.api.model.Node)1 NodeBuilder (io.fabric8.kubernetes.api.model.NodeBuilder)1 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)1 Pod (io.fabric8.kubernetes.api.model.Pod)1 PodBuilder (io.fabric8.kubernetes.api.model.PodBuilder)1 Quantity (io.fabric8.kubernetes.api.model.Quantity)1 ServiceBuilder (io.fabric8.kubernetes.api.model.ServiceBuilder)1 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)1 KubernetesCrudDispatcher (io.fabric8.kubernetes.client.server.mock.KubernetesCrudDispatcher)1 KubernetesServer (io.fabric8.kubernetes.client.server.mock.KubernetesServer)1 Route (io.fabric8.openshift.api.model.Route)1 RouteBuilder (io.fabric8.openshift.api.model.RouteBuilder)1 RouteTargetReferenceBuilder (io.fabric8.openshift.api.model.RouteTargetReferenceBuilder)1