Search in sources :

Example 6 with MockKube2

use of io.strimzi.test.mockkube2.MockKube2 in project strimzi by strimzi.

the class PartialRollingUpdateMockTest method beforeEach.

@BeforeEach
public void beforeEach(VertxTestContext context) throws InterruptedException, ExecutionException, TimeoutException {
    this.cluster = new KafkaBuilder().withMetadata(new ObjectMetaBuilder().withName(CLUSTER_NAME).withNamespace(NAMESPACE).build()).withNewSpec().withNewKafka().withReplicas(5).withListeners(new GenericKafkaListenerBuilder().withName("plain").withPort(9092).withType(KafkaListenerType.INTERNAL).withTls(false).build(), new GenericKafkaListenerBuilder().withName("tls").withPort(9093).withType(KafkaListenerType.INTERNAL).withTls(true).build()).withNewPersistentClaimStorage().withSize("123").withStorageClass("foo").withDeleteClaim(true).endPersistentClaimStorage().endKafka().withNewZookeeper().withReplicas(3).withNewPersistentClaimStorage().withSize("123").withStorageClass("foo").withDeleteClaim(true).endPersistentClaimStorage().endZookeeper().endSpec().build();
    // Configure the Kubernetes Mock
    mockKube = new MockKube2.MockKube2Builder(client).withKafkaCrd().withInitialKafkas(cluster).withStrimziPodSetCrd().withDeploymentController().withPodController().withStatefulSetController().withServiceController().build();
    mockKube.start();
    ResourceOperatorSupplier supplier = supplier(client);
    kco = new KafkaAssemblyOperator(vertx, new PlatformFeaturesAvailability(false, KubernetesVersion.V1_16), new MockCertManager(), new PasswordGenerator(10, "a", "a"), supplier, ResourceUtils.dummyClusterOperatorConfig(VERSIONS, 2_000));
    LOGGER.info("Initial reconciliation");
    CountDownLatch createAsync = new CountDownLatch(1);
    kco.reconcile(new Reconciliation("initialization", Kafka.RESOURCE_KIND, NAMESPACE, CLUSTER_NAME)).onComplete(ar -> {
        context.verify(() -> assertThat(ar.succeeded(), is(true)));
        createAsync.countDown();
    });
    if (!createAsync.await(60, TimeUnit.SECONDS)) {
        context.failNow(new Throwable("Test timeout"));
    }
    LOGGER.info("Initial reconciliation complete");
    context.completeNow();
}
Also used : KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) CountDownLatch(java.util.concurrent.CountDownLatch) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) MockCertManager(io.strimzi.operator.common.operator.MockCertManager) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) MockKube2(io.strimzi.test.mockkube2.MockKube2) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) PasswordGenerator(io.strimzi.operator.common.PasswordGenerator) Reconciliation(io.strimzi.operator.common.Reconciliation) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 7 with MockKube2

use of io.strimzi.test.mockkube2.MockKube2 in project strimzi by strimzi.

the class StrimziPodSetControllerMockTest method beforeEach.

@BeforeEach
public void beforeEach() {
    // Configure the Kubernetes Mock
    mockKube = new MockKube2.MockKube2Builder(client).withKafkaCrd().withStrimziPodSetCrd().withPodController().build();
    mockKube.start();
    vertx = Vertx.vertx();
    kafkaOperator = new CrdOperator<>(vertx, client, Kafka.class, KafkaList.class, Kafka.RESOURCE_KIND);
    podSetOperator = new StrimziPodSetOperator(vertx, client, 10_000L);
    podOperator = new PodOperator(vertx, client);
    kafkaOp().inNamespace(NAMESPACE).create(kafka(KAFKA_NAME, MATCHING_LABELS));
    kafkaOp().inNamespace(NAMESPACE).create(kafka(OTHER_KAFKA_NAME, OTHER_LABELS));
    startController();
}
Also used : StrimziPodSetOperator(io.strimzi.operator.common.operator.resource.StrimziPodSetOperator) MockKube2(io.strimzi.test.mockkube2.MockKube2) PodOperator(io.strimzi.operator.common.operator.resource.PodOperator) Kafka(io.strimzi.api.kafka.model.Kafka) KafkaList(io.strimzi.api.kafka.KafkaList) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 8 with MockKube2

use of io.strimzi.test.mockkube2.MockKube2 in project strimzi-kafka-operator by strimzi.

the class KafkaRebalanceAssemblyOperatorTest method beforeEach.

@BeforeEach
public void beforeEach(Vertx vertx) {
    ccServer.reset();
    // Configure the Kubernetes Mock
    mockKube = new MockKube2.MockKube2Builder(client).withKafkaRebalanceCrd().build();
    mockKube.start();
    ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(false);
    // Override to inject mocked cruise control address so real cruise control not required
    kcrao = new KafkaRebalanceAssemblyOperator(vertx, supplier, ResourceUtils.dummyClusterOperatorConfig()) {

        @Override
        public String cruiseControlHost(String clusterName, String clusterNamespace) {
            return HOST;
        }

        @Override
        public CruiseControlApi cruiseControlClientProvider(Secret ccSecret, Secret ccApiSecret, boolean apiAuthEnabled, boolean apiSslEnabled) {
            return new CruiseControlApiImpl(vertx, 1, ccSecret, ccApiSecret, true, true);
        }
    };
    mockRebalanceOps = supplier.kafkaRebalanceOperator;
    mockKafkaOps = supplier.kafkaOperator;
    mockCmOps = supplier.configMapOperations;
    mockSecretOps = supplier.secretOperations;
}
Also used : Secret(io.fabric8.kubernetes.api.model.Secret) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) MockKube2(io.strimzi.test.mockkube2.MockKube2) CruiseControlApi(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlApi) CruiseControlApiImpl(io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlApiImpl) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 9 with MockKube2

use of io.strimzi.test.mockkube2.MockKube2 in project strimzi-kafka-operator by strimzi.

the class KafkaAssemblyOperatorCustomCertMockTest method setup.

@BeforeEach
public void setup() {
    kafka = createKafka();
    // Configure the Kubernetes Mock
    mockKube = new MockKube2.MockKube2Builder(client).withKafkaCrd().withInitialKafkas(kafka).withStrimziPodSetCrd().withPodController().withStatefulSetController().build();
    mockKube.start();
    client.secrets().inNamespace(namespace).create(getTlsSecret());
    client.secrets().inNamespace(namespace).create(getExternalSecret());
    Secret secret = new SecretBuilder().withNewMetadata().withNamespace(namespace).withName("testkafka-cluster-operator-certs").endMetadata().addToData("foo", "bar").build();
    client.secrets().inNamespace(namespace).create(secret);
    ResourceOperatorSupplier supplier = new ResourceOperatorSupplier(vertx, client, mock(ZookeeperLeaderFinder.class), mock(AdminClientProvider.class), mock(ZookeeperScalerProvider.class), mock(MetricsProvider.class), new PlatformFeaturesAvailability(false, KubernetesVersion.V1_20), 10000);
    operator = new MockKafkaAssemblyOperator(vertx, new PlatformFeaturesAvailability(false, kubernetesVersion), certManager, passwordGenerator, supplier, config);
}
Also used : Secret(io.fabric8.kubernetes.api.model.Secret) SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) MockKube2(io.strimzi.test.mockkube2.MockKube2) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) ZookeeperScalerProvider(io.strimzi.operator.cluster.operator.resource.ZookeeperScalerProvider) ZookeeperLeaderFinder(io.strimzi.operator.cluster.operator.resource.ZookeeperLeaderFinder) AdminClientProvider(io.strimzi.operator.common.AdminClientProvider) MetricsProvider(io.strimzi.operator.common.MetricsProvider) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 10 with MockKube2

use of io.strimzi.test.mockkube2.MockKube2 in project strimzi-kafka-operator by strimzi.

the class PartialRollingUpdateMockTest method beforeEach.

@BeforeEach
public void beforeEach(VertxTestContext context) throws InterruptedException, ExecutionException, TimeoutException {
    this.cluster = new KafkaBuilder().withMetadata(new ObjectMetaBuilder().withName(CLUSTER_NAME).withNamespace(NAMESPACE).build()).withNewSpec().withNewKafka().withReplicas(5).withListeners(new GenericKafkaListenerBuilder().withName("plain").withPort(9092).withType(KafkaListenerType.INTERNAL).withTls(false).build(), new GenericKafkaListenerBuilder().withName("tls").withPort(9093).withType(KafkaListenerType.INTERNAL).withTls(true).build()).withNewPersistentClaimStorage().withSize("123").withStorageClass("foo").withDeleteClaim(true).endPersistentClaimStorage().endKafka().withNewZookeeper().withReplicas(3).withNewPersistentClaimStorage().withSize("123").withStorageClass("foo").withDeleteClaim(true).endPersistentClaimStorage().endZookeeper().endSpec().build();
    // Configure the Kubernetes Mock
    mockKube = new MockKube2.MockKube2Builder(client).withKafkaCrd().withInitialKafkas(cluster).withStrimziPodSetCrd().withDeploymentController().withPodController().withStatefulSetController().withServiceController().build();
    mockKube.start();
    ResourceOperatorSupplier supplier = supplier(client);
    kco = new KafkaAssemblyOperator(vertx, new PlatformFeaturesAvailability(false, KubernetesVersion.V1_16), new MockCertManager(), new PasswordGenerator(10, "a", "a"), supplier, ResourceUtils.dummyClusterOperatorConfig(VERSIONS, 2_000));
    LOGGER.info("Initial reconciliation");
    CountDownLatch createAsync = new CountDownLatch(1);
    kco.reconcile(new Reconciliation("initialization", Kafka.RESOURCE_KIND, NAMESPACE, CLUSTER_NAME)).onComplete(ar -> {
        context.verify(() -> assertThat(ar.succeeded(), is(true)));
        createAsync.countDown();
    });
    if (!createAsync.await(60, TimeUnit.SECONDS)) {
        context.failNow(new Throwable("Test timeout"));
    }
    LOGGER.info("Initial reconciliation complete");
    context.completeNow();
}
Also used : KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) CountDownLatch(java.util.concurrent.CountDownLatch) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) MockCertManager(io.strimzi.operator.common.operator.MockCertManager) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) MockKube2(io.strimzi.test.mockkube2.MockKube2) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) PasswordGenerator(io.strimzi.operator.common.PasswordGenerator) Reconciliation(io.strimzi.operator.common.Reconciliation) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

MockKube2 (io.strimzi.test.mockkube2.MockKube2)24 ResourceOperatorSupplier (io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier)20 BeforeEach (org.junit.jupiter.api.BeforeEach)20 PlatformFeaturesAvailability (io.strimzi.operator.PlatformFeaturesAvailability)16 ClusterOperatorConfig (io.strimzi.operator.cluster.ClusterOperatorConfig)12 Reconciliation (io.strimzi.operator.common.Reconciliation)12 ZookeeperLeaderFinder (io.strimzi.operator.cluster.operator.resource.ZookeeperLeaderFinder)10 MetricsProvider (io.strimzi.operator.common.MetricsProvider)10 LabelSelector (io.fabric8.kubernetes.api.model.LabelSelector)8 CustomResource (io.fabric8.kubernetes.client.CustomResource)8 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)8 Watch (io.fabric8.kubernetes.client.Watch)8 Resource (io.fabric8.kubernetes.client.dsl.Resource)8 EnableKubernetesMockClient (io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient)8 Gauge (io.micrometer.core.instrument.Gauge)8 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)8 Tags (io.micrometer.core.instrument.Tags)8 ConnectTimeoutException (io.netty.channel.ConnectTimeoutException)8 Crds (io.strimzi.api.kafka.Crds)8 KafkaConnect (io.strimzi.api.kafka.model.KafkaConnect)8