Search in sources :

Example 6 with Kafka

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

the class EntityUserOperatorTest method testFromCrdCaValidityAndRenewal.

@ParallelTest
public void testFromCrdCaValidityAndRenewal() {
    EntityUserOperatorSpec entityUserOperatorSpec = new EntityUserOperatorSpecBuilder().build();
    EntityOperatorSpec entityOperatorSpec = new EntityOperatorSpecBuilder().withUserOperator(entityUserOperatorSpec).build();
    CertificateAuthority ca = new CertificateAuthority();
    ca.setValidityDays(42);
    ca.setRenewalDays(69);
    Kafka customValues = new KafkaBuilder(ResourceUtils.createKafka(namespace, cluster, replicas, image, healthDelay, healthTimeout)).editSpec().withEntityOperator(entityOperatorSpec).withClientsCa(ca).endSpec().build();
    EntityUserOperator entityUserOperator = EntityUserOperator.fromCrd(new Reconciliation("test", resource.getKind(), resource.getMetadata().getNamespace(), resource.getMetadata().getName()), customValues);
    Kafka defaultValues = new KafkaBuilder(ResourceUtils.createKafka(namespace, cluster, replicas, image, healthDelay, healthTimeout)).editSpec().withEntityOperator(entityOperatorSpec).endSpec().build();
    EntityUserOperator entityUserOperator2 = EntityUserOperator.fromCrd(new Reconciliation("test", resource.getKind(), resource.getMetadata().getNamespace(), resource.getMetadata().getName()), defaultValues);
    assertThat(entityUserOperator.getClientsCaValidityDays(), is(42L));
    assertThat(entityUserOperator.getClientsCaRenewalDays(), is(69L));
    assertThat(entityUserOperator2.getClientsCaValidityDays(), is(Long.valueOf(CertificateAuthority.DEFAULT_CERTS_VALIDITY_DAYS)));
    assertThat(entityUserOperator2.getClientsCaRenewalDays(), is(Long.valueOf(CertificateAuthority.DEFAULT_CERTS_RENEWAL_DAYS)));
}
Also used : EntityOperatorSpec(io.strimzi.api.kafka.model.EntityOperatorSpec) EntityUserOperatorSpec(io.strimzi.api.kafka.model.EntityUserOperatorSpec) Reconciliation(io.strimzi.operator.common.Reconciliation) Kafka(io.strimzi.api.kafka.model.Kafka) CertificateAuthority(io.strimzi.api.kafka.model.CertificateAuthority) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) EntityUserOperatorSpecBuilder(io.strimzi.api.kafka.model.EntityUserOperatorSpecBuilder) EntityOperatorSpecBuilder(io.strimzi.api.kafka.model.EntityOperatorSpecBuilder) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 7 with Kafka

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

the class EntityUserOperatorTest method testAclsAdminApiSupported.

private void testAclsAdminApiSupported(KafkaAuthorization authorizer) {
    Kafka kafkaAssembly = new KafkaBuilder(ResourceUtils.createKafka(namespace, cluster, replicas, image, healthDelay, healthTimeout, jmxMetricsConfig, singletonMap("foo", "bar"), emptyMap())).editSpec().editKafka().withAuthorization(authorizer).endKafka().withNewEntityOperator().withNewUserOperator().endUserOperator().endEntityOperator().endSpec().build();
    EntityUserOperator f = EntityUserOperator.fromCrd(new Reconciliation("test", resource.getKind(), resource.getMetadata().getNamespace(), resource.getMetadata().getName()), kafkaAssembly);
    assertThat(f.getEnvVars().stream().filter(a -> a.getName().equals(EntityUserOperator.ENV_VAR_ACLS_ADMIN_API_SUPPORTED)).findFirst().orElseThrow().getValue(), is(String.valueOf(authorizer.supportsAdminApi())));
}
Also used : Reconciliation(io.strimzi.operator.common.Reconciliation) Kafka(io.strimzi.api.kafka.model.Kafka) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder)

Example 8 with Kafka

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

the class EntityUserOperatorTest method testFromCrdDefault.

@ParallelTest
public void testFromCrdDefault() {
    EntityUserOperatorSpec entityUserOperatorSpec = new EntityUserOperatorSpecBuilder().build();
    EntityOperatorSpec entityOperatorSpec = new EntityOperatorSpecBuilder().withUserOperator(entityUserOperatorSpec).build();
    Kafka resource = new KafkaBuilder(ResourceUtils.createKafka(namespace, cluster, replicas, image, healthDelay, healthTimeout)).editSpec().withEntityOperator(entityOperatorSpec).endSpec().build();
    EntityUserOperator entityUserOperator = EntityUserOperator.fromCrd(new Reconciliation("test", resource.getKind(), resource.getMetadata().getNamespace(), resource.getMetadata().getName()), resource);
    assertThat(entityUserOperator.getWatchedNamespace(), is(namespace));
    assertThat(entityUserOperator.getImage(), is("quay.io/strimzi/operator:latest"));
    assertThat(entityUserOperator.getReconciliationIntervalMs(), is(EntityUserOperatorSpec.DEFAULT_FULL_RECONCILIATION_INTERVAL_SECONDS * 1000));
    assertThat(entityUserOperator.readinessProbeOptions.getInitialDelaySeconds(), is(EntityUserOperatorSpec.DEFAULT_HEALTHCHECK_DELAY));
    assertThat(entityUserOperator.readinessProbeOptions.getTimeoutSeconds(), is(EntityUserOperatorSpec.DEFAULT_HEALTHCHECK_TIMEOUT));
    assertThat(entityUserOperator.livenessProbeOptions.getInitialDelaySeconds(), is(EntityUserOperatorSpec.DEFAULT_HEALTHCHECK_DELAY));
    assertThat(entityUserOperator.livenessProbeOptions.getTimeoutSeconds(), is(EntityUserOperatorSpec.DEFAULT_HEALTHCHECK_TIMEOUT));
    assertThat(entityUserOperator.getKafkaBootstrapServers(), is(EntityUserOperator.defaultBootstrapServers(cluster)));
    assertThat(entityUserOperator.getLogging(), is(nullValue()));
    assertThat(entityUserOperator.getSecretPrefix(), is(EntityUserOperatorSpec.DEFAULT_SECRET_PREFIX));
}
Also used : EntityOperatorSpec(io.strimzi.api.kafka.model.EntityOperatorSpec) EntityUserOperatorSpec(io.strimzi.api.kafka.model.EntityUserOperatorSpec) Reconciliation(io.strimzi.operator.common.Reconciliation) Kafka(io.strimzi.api.kafka.model.Kafka) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) EntityUserOperatorSpecBuilder(io.strimzi.api.kafka.model.EntityUserOperatorSpecBuilder) EntityOperatorSpecBuilder(io.strimzi.api.kafka.model.EntityOperatorSpecBuilder) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 9 with Kafka

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

the class KafkaAssemblyOperatorCustomCertTest method testPodToRestartTrueWhenCustomCertExternalListenerThumbprintAnnotationsNotMatchingThumbprint.

@Test
public void testPodToRestartTrueWhenCustomCertExternalListenerThumbprintAnnotationsNotMatchingThumbprint(VertxTestContext context) {
    Checkpoint async = context.checkpoint();
    operator.createOrUpdate(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, namespace, clusterName), kafka).onComplete(context.succeeding(v -> context.verify(() -> {
        StatefulSet reconcileSts = client.apps().statefulSets().inNamespace(namespace).withName(KafkaResources.kafkaStatefulSetName(clusterName)).get();
        assertThat(reconcileSts.getSpec().getTemplate().getMetadata().getAnnotations(), hasEntry(KafkaCluster.ANNO_STRIMZI_CUSTOM_LISTENER_CERT_THUMBPRINTS, getTlsThumbprint()));
        assertThat(functionArgumentCaptor, hasSize(1));
        Function<Pod, List<String>> isPodToRestart = functionArgumentCaptor.get(0);
        Pod pod = getPod(reconcileSts);
        assertThat("There are no changes in broker config, the restart should not be needed", isPodToRestart.apply(pod), empty());
        pod.getMetadata().getAnnotations().put(KafkaCluster.ANNO_STRIMZI_CUSTOM_LISTENER_CERT_THUMBPRINTS, Base64.getEncoder().encodeToString("Not the right one!".getBytes()));
        assertThat(isPodToRestart.apply(pod).get(0), equalTo("custom certificate one or more listeners changed"));
        async.flag();
    })));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Matchers.not(org.hamcrest.Matchers.not) Matchers.hasKey(org.hamcrest.Matchers.hasKey) MockKube(io.strimzi.test.mockkube.MockKube) AfterAll(org.junit.jupiter.api.AfterAll) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) KafkaResources(io.strimzi.api.kafka.model.KafkaResources) BeforeAll(org.junit.jupiter.api.BeforeAll) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) ResourceUtils(io.strimzi.operator.cluster.ResourceUtils) KafkaVersion(io.strimzi.operator.cluster.model.KafkaVersion) MetricsProvider(io.strimzi.operator.common.MetricsProvider) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) VertxExtension(io.vertx.junit5.VertxExtension) Future(io.vertx.core.Future) Test(org.junit.jupiter.api.Test) Base64(java.util.Base64) List(java.util.List) StrimziPodSet(io.strimzi.api.kafka.model.StrimziPodSet) PasswordGenerator(io.strimzi.operator.common.PasswordGenerator) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Secret(io.fabric8.kubernetes.api.model.Secret) AdminClientProvider(io.strimzi.operator.common.AdminClientProvider) Checkpoint(io.vertx.junit5.Checkpoint) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) MockCertManager(io.strimzi.operator.common.operator.MockCertManager) Mockito.mock(org.mockito.Mockito.mock) VertxTestContext(io.vertx.junit5.VertxTestContext) KafkaList(io.strimzi.api.kafka.KafkaList) CertManager(io.strimzi.certs.CertManager) Crds(io.strimzi.api.kafka.Crds) Function(java.util.function.Function) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) FeatureGates(io.strimzi.operator.cluster.FeatureGates) ArrayList(java.util.ArrayList) KafkaCluster(io.strimzi.operator.cluster.model.KafkaCluster) KafkaVersionTestUtils(io.strimzi.operator.cluster.KafkaVersionTestUtils) ZookeeperLeaderFinder(io.strimzi.operator.cluster.operator.resource.ZookeeperLeaderFinder) ZookeeperScalerProvider(io.strimzi.operator.cluster.operator.resource.ZookeeperScalerProvider) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Matchers.hasEntry(org.hamcrest.Matchers.hasEntry) Matchers.empty(org.hamcrest.Matchers.empty) StrimziPodSetList(io.strimzi.api.kafka.StrimziPodSetList) KubernetesVersion(io.strimzi.operator.KubernetesVersion) Vertx(io.vertx.core.Vertx) Pod(io.fabric8.kubernetes.api.model.Pod) StatefulSet(io.fabric8.kubernetes.api.model.apps.StatefulSet) Reconciliation(io.strimzi.operator.common.Reconciliation) KafkaListenerType(io.strimzi.api.kafka.model.listener.arraylistener.KafkaListenerType) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) Kafka(io.strimzi.api.kafka.model.Kafka) Checkpoint(io.vertx.junit5.Checkpoint) Pod(io.fabric8.kubernetes.api.model.Pod) Reconciliation(io.strimzi.operator.common.Reconciliation) List(java.util.List) KafkaList(io.strimzi.api.kafka.KafkaList) ArrayList(java.util.ArrayList) StrimziPodSetList(io.strimzi.api.kafka.StrimziPodSetList) StatefulSet(io.fabric8.kubernetes.api.model.apps.StatefulSet) Test(org.junit.jupiter.api.Test)

Example 10 with Kafka

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

the class KafkaAssemblyOperatorCustomCertTest method setup.

@BeforeEach
public void setup() {
    kafka = createKafka();
    client = new MockKube().withCustomResourceDefinition(Crds.kafka(), Kafka.class, KafkaList.class).end().withCustomResourceDefinition(Crds.strimziPodSet(), StrimziPodSet.class, StrimziPodSetList.class).end().build();
    Crds.kafkaOperation(client).inNamespace(namespace).create(kafka);
    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), FeatureGates.NONE, 10000);
    operator = new MockKafkaAssemblyOperator(vertx, new PlatformFeaturesAvailability(false, kubernetesVersion), certManager, passwordGenerator, supplier, config);
}
Also used : StrimziPodSet(io.strimzi.api.kafka.model.StrimziPodSet) Kafka(io.strimzi.api.kafka.model.Kafka) ZookeeperScalerProvider(io.strimzi.operator.cluster.operator.resource.ZookeeperScalerProvider) AdminClientProvider(io.strimzi.operator.common.AdminClientProvider) StrimziPodSetList(io.strimzi.api.kafka.StrimziPodSetList) KafkaList(io.strimzi.api.kafka.KafkaList) Secret(io.fabric8.kubernetes.api.model.Secret) SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) MockKube(io.strimzi.test.mockkube.MockKube) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) ZookeeperLeaderFinder(io.strimzi.operator.cluster.operator.resource.ZookeeperLeaderFinder) MetricsProvider(io.strimzi.operator.common.MetricsProvider) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

Kafka (io.strimzi.api.kafka.model.Kafka)749 KafkaBuilder (io.strimzi.api.kafka.model.KafkaBuilder)589 ParallelTest (io.strimzi.test.annotations.ParallelTest)412 Reconciliation (io.strimzi.operator.common.Reconciliation)352 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)268 Test (org.junit.jupiter.api.Test)256 GenericKafkaListenerBuilder (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder)252 ResourceUtils (io.strimzi.operator.cluster.ResourceUtils)244 KafkaVersionTestUtils (io.strimzi.operator.cluster.KafkaVersionTestUtils)242 ResourceOperatorSupplier (io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier)222 PlatformFeaturesAvailability (io.strimzi.operator.PlatformFeaturesAvailability)220 Map (java.util.Map)216 CoreMatchers.is (org.hamcrest.CoreMatchers.is)214 Checkpoint (io.vertx.junit5.Checkpoint)200 AfterAll (org.junit.jupiter.api.AfterAll)194 StatefulSet (io.fabric8.kubernetes.api.model.apps.StatefulSet)192 Labels (io.strimzi.operator.common.model.Labels)190 Vertx (io.vertx.core.Vertx)190 KubernetesVersion (io.strimzi.operator.KubernetesVersion)186 Collections (java.util.Collections)184