Search in sources :

Example 66 with StrimziPodSet

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

the class ZookeeperPodSetTest method testPodSet.

@ParallelTest
public void testPodSet() {
    ZookeeperCluster zc = ZookeeperCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, KAFKA, VERSIONS);
    StrimziPodSet ps = zc.generatePodSet(3, true, null, null, Map.of());
    assertThat(ps.getMetadata().getName(), is(KafkaResources.zookeeperStatefulSetName(CLUSTER)));
    assertThat(ps.getMetadata().getLabels().entrySet().containsAll(zc.getLabelsWithStrimziName(zc.getName(), null).toMap().entrySet()), is(true));
    assertThat(ps.getMetadata().getAnnotations().get(AbstractModel.ANNO_STRIMZI_IO_STORAGE), is(ModelUtils.encodeStorageToJson(new PersistentClaimStorageBuilder().withSize("100Gi").withDeleteClaim(false).build())));
    assertThat(ps.getMetadata().getOwnerReferences().size(), is(1));
    assertThat(ps.getMetadata().getOwnerReferences().get(0), is(zc.createOwnerReference()));
    assertThat(ps.getSpec().getSelector().getMatchLabels(), is(zc.getSelectorLabels().toMap()));
    assertThat(ps.getSpec().getPods().size(), is(3));
    // We need to loop through the pods to make sure they have the right values
    List<Pod> pods = PodSetUtils.mapsToPods(ps.getSpec().getPods());
    for (Pod pod : pods) {
        assertThat(pod.getMetadata().getLabels().entrySet().containsAll(zc.getLabelsWithStrimziNameAndPodName(zc.getName(), pod.getMetadata().getName(), null).withStatefulSetPod(pod.getMetadata().getName()).withStrimziPodSetController(zc.getName()).toMap().entrySet()), is(true));
        assertThat(pod.getMetadata().getAnnotations().size(), is(1));
        assertThat(pod.getMetadata().getAnnotations().get(PodRevision.STRIMZI_REVISION_ANNOTATION), is(notNullValue()));
        assertThat(pod.getSpec().getHostname(), is(pod.getMetadata().getName()));
        assertThat(pod.getSpec().getSubdomain(), is(zc.getHeadlessServiceName()));
        assertThat(pod.getSpec().getRestartPolicy(), is("Always"));
        assertThat(pod.getSpec().getTerminationGracePeriodSeconds(), is(30L));
        assertThat(pod.getSpec().getVolumes().stream().filter(volume -> volume.getName().equalsIgnoreCase("strimzi-tmp")).findFirst().orElse(null).getEmptyDir().getSizeLimit(), is(new Quantity(AbstractModel.STRIMZI_TMP_DIRECTORY_DEFAULT_SIZE)));
        assertThat(pod.getSpec().getContainers().size(), is(1));
        assertThat(pod.getSpec().getContainers().get(0).getLivenessProbe().getTimeoutSeconds(), is(5));
        assertThat(pod.getSpec().getContainers().get(0).getLivenessProbe().getInitialDelaySeconds(), is(15));
        assertThat(pod.getSpec().getContainers().get(0).getReadinessProbe().getTimeoutSeconds(), is(5));
        assertThat(pod.getSpec().getContainers().get(0).getReadinessProbe().getInitialDelaySeconds(), is(15));
        assertThat(AbstractModel.containerEnvVars(pod.getSpec().getContainers().get(0)).get(ZookeeperCluster.ENV_VAR_STRIMZI_KAFKA_GC_LOG_ENABLED), is(Boolean.toString(AbstractModel.DEFAULT_JVM_GC_LOGGING_ENABLED)));
        assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(0).getName(), is(AbstractModel.STRIMZI_TMP_DIRECTORY_DEFAULT_VOLUME_NAME));
        assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(0).getMountPath(), is(AbstractModel.STRIMZI_TMP_DIRECTORY_DEFAULT_MOUNT_PATH));
        assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(1).getName(), is(AbstractModel.VOLUME_NAME));
        assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(1).getMountPath(), is("/var/lib/zookeeper"));
        assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(2).getName(), is("zookeeper-metrics-and-logging"));
        assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(2).getMountPath(), is("/opt/kafka/custom-config/"));
        assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(3).getName(), is(ZookeeperCluster.ZOOKEEPER_NODE_CERTIFICATES_VOLUME_NAME));
        assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(3).getMountPath(), is(ZookeeperCluster.ZOOKEEPER_NODE_CERTIFICATES_VOLUME_MOUNT));
        assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(4).getName(), is(ZookeeperCluster.ZOOKEEPER_CLUSTER_CA_VOLUME_NAME));
        assertThat(pod.getSpec().getContainers().get(0).getVolumeMounts().get(4).getMountPath(), is(ZookeeperCluster.ZOOKEEPER_CLUSTER_CA_VOLUME_MOUNT));
        // Config
        OrderedProperties expectedConfig = new OrderedProperties().addMapPairs(ZookeeperConfiguration.DEFAULTS);
        OrderedProperties actual = new OrderedProperties().addStringPairs(AbstractModel.containerEnvVars(pod.getSpec().getContainers().get(0)).get(ZookeeperCluster.ENV_VAR_ZOOKEEPER_CONFIGURATION));
        assertThat(actual, is(expectedConfig));
    }
}
Also used : Quantity(io.fabric8.kubernetes.api.model.Quantity) CoreMatchers.is(org.hamcrest.CoreMatchers.is) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) OrderedProperties(io.strimzi.operator.common.model.OrderedProperties) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) ParallelSuite(io.strimzi.test.annotations.ParallelSuite) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) SecurityContextBuilder(io.fabric8.kubernetes.api.model.SecurityContextBuilder) LocalObjectReference(io.fabric8.kubernetes.api.model.LocalObjectReference) PodDisruptionBudget(io.fabric8.kubernetes.api.model.policy.v1.PodDisruptionBudget) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) HostAlias(io.fabric8.kubernetes.api.model.HostAlias) PersistentClaimStorageBuilder(io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder) SecurityContext(io.fabric8.kubernetes.api.model.SecurityContext) KafkaResources(io.strimzi.api.kafka.model.KafkaResources) KafkaVersionTestUtils(io.strimzi.operator.cluster.KafkaVersionTestUtils) Map(java.util.Map) TestUtils(io.strimzi.test.TestUtils) CoreMatchers.allOf(org.hamcrest.CoreMatchers.allOf) Collections.singletonMap(java.util.Collections.singletonMap) ContainerEnvVar(io.strimzi.api.kafka.model.ContainerEnvVar) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) PodRevision(io.strimzi.operator.cluster.operator.resource.PodRevision) Affinity(io.fabric8.kubernetes.api.model.Affinity) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) Probe(io.strimzi.api.kafka.model.Probe) TopologySpreadConstraint(io.fabric8.kubernetes.api.model.TopologySpreadConstraint) LabelSelectorBuilder(io.fabric8.kubernetes.api.model.LabelSelectorBuilder) ParallelTest(io.strimzi.test.annotations.ParallelTest) Pod(io.fabric8.kubernetes.api.model.Pod) Toleration(io.fabric8.kubernetes.api.model.Toleration) TolerationBuilder(io.fabric8.kubernetes.api.model.TolerationBuilder) AffinityBuilder(io.fabric8.kubernetes.api.model.AffinityBuilder) Reconciliation(io.strimzi.operator.common.Reconciliation) NodeSelectorTermBuilder(io.fabric8.kubernetes.api.model.NodeSelectorTermBuilder) List(java.util.List) StrimziPodSet(io.strimzi.api.kafka.model.StrimziPodSet) PodSecurityContextBuilder(io.fabric8.kubernetes.api.model.PodSecurityContextBuilder) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) HostAliasBuilder(io.fabric8.kubernetes.api.model.HostAliasBuilder) TopologySpreadConstraintBuilder(io.fabric8.kubernetes.api.model.TopologySpreadConstraintBuilder) Kafka(io.strimzi.api.kafka.model.Kafka) StrimziPodSet(io.strimzi.api.kafka.model.StrimziPodSet) Pod(io.fabric8.kubernetes.api.model.Pod) PersistentClaimStorageBuilder(io.strimzi.api.kafka.model.storage.PersistentClaimStorageBuilder) Quantity(io.fabric8.kubernetes.api.model.Quantity) OrderedProperties(io.strimzi.operator.common.model.OrderedProperties) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 67 with StrimziPodSet

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

the class ZookeeperPodSetTest method testImagePullSecretsFromBoth.

@ParallelTest
public void testImagePullSecretsFromBoth() {
    // CR configuration has priority -> CO configuration is ignored if both are set
    LocalObjectReference secret1 = new LocalObjectReference("some-pull-secret");
    LocalObjectReference secret2 = new LocalObjectReference("some-other-pull-secret");
    Kafka kafka = new KafkaBuilder(KAFKA).editSpec().editZookeeper().withNewTemplate().withNewPod().withImagePullSecrets(secret2).endPod().endTemplate().endZookeeper().endSpec().build();
    ZookeeperCluster zc = ZookeeperCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafka, VERSIONS);
    StrimziPodSet ps = zc.generatePodSet(3, true, null, List.of(secret1), Map.of());
    // We need to loop through the pods to make sure they have the right values
    List<Pod> pods = PodSetUtils.mapsToPods(ps.getSpec().getPods());
    for (Pod pod : pods) {
        assertThat(pod.getSpec().getImagePullSecrets().size(), is(1));
        assertThat(pod.getSpec().getImagePullSecrets().contains(secret1), is(false));
        assertThat(pod.getSpec().getImagePullSecrets().contains(secret2), is(true));
    }
}
Also used : StrimziPodSet(io.strimzi.api.kafka.model.StrimziPodSet) Pod(io.fabric8.kubernetes.api.model.Pod) LocalObjectReference(io.fabric8.kubernetes.api.model.LocalObjectReference) Kafka(io.strimzi.api.kafka.model.Kafka) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 68 with StrimziPodSet

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

the class StrimziPodSetControllerIT method testScaleUpScaleDown.

/**
 * Tests scaling up and down of the StrimziPodSet and updates of the StrimziPodSet status.
 *
 * @param context   Test context
 */
@Test
public void testScaleUpScaleDown(VertxTestContext context) {
    String podSetName = "scale-up-down";
    String pod1Name = podSetName + "-0";
    String pod2Name = podSetName + "-1";
    try {
        Pod pod1 = pod(pod1Name, KAFKA_NAME, podSetName);
        podSetOp().inNamespace(NAMESPACE).create(podSet(podSetName, KAFKA_NAME, pod1));
        // Wait until the pod is ready
        TestUtils.waitFor("Wait for Pod to be ready", 100, 10_000, () -> client.pods().inNamespace(NAMESPACE).withName(pod1Name).isReady(), () -> context.failNow("Test timed out waiting for pod readiness!"));
        // Check status of the PodSet
        TestUtils.waitFor("Wait for StrimziPodSetStatus", 100, 10_000, () -> {
            StrimziPodSet podSet = podSetOp().inNamespace(NAMESPACE).withName(podSetName).get();
            return podSet.getStatus().getCurrentPods() == 1 && podSet.getStatus().getReadyPods() == 1 && podSet.getStatus().getPods() == 1;
        }, () -> context.failNow("Pod stats do not match"));
        // Scale-up the pod-set
        Pod pod2 = pod(pod2Name, KAFKA_NAME, podSetName);
        podSetOp().inNamespace(NAMESPACE).withName(podSetName).patch(podSet(podSetName, KAFKA_NAME, pod1, pod2));
        // Wait until the new pod is ready
        TestUtils.waitFor("Wait for second Pod to be ready", 100, 10_000, () -> client.pods().inNamespace(NAMESPACE).withName(pod2Name).isReady(), () -> context.failNow("Test timed out waiting for second pod readiness!"));
        // Check status of the PodSet
        TestUtils.waitFor("Wait for StrimziPodSetStatus", 100, 10_000, () -> {
            StrimziPodSet podSet = podSetOp().inNamespace(NAMESPACE).withName(podSetName).get();
            return podSet.getStatus().getCurrentPods() == 2 && podSet.getStatus().getReadyPods() == 2 && podSet.getStatus().getPods() == 2;
        }, () -> context.failNow("Pod stats do not match"));
        // Scale-down the pod-set
        podSetOp().inNamespace(NAMESPACE).withName(podSetName).patch(podSet(podSetName, KAFKA_NAME, pod1));
        // Wait until the pod is ready
        TestUtils.waitFor("Wait for second Pod to be deleted", 100, 10_000, () -> client.pods().inNamespace(NAMESPACE).withName(pod2Name).get() == null, () -> context.failNow("Test timed out waiting for second pod to be deleted!"));
        // Check status of the PodSet
        TestUtils.waitFor("Wait for StrimziPodSetStatus", 100, 10_000, () -> {
            StrimziPodSet podSet = podSetOp().inNamespace(NAMESPACE).withName(podSetName).get();
            return podSet.getStatus().getCurrentPods() == 1 && podSet.getStatus().getReadyPods() == 1 && podSet.getStatus().getPods() == 1;
        }, () -> context.failNow("Pod stats do not match"));
        context.completeNow();
    } finally {
        podSetOp().inNamespace(NAMESPACE).withName(podSetName).delete();
    }
}
Also used : StrimziPodSet(io.strimzi.api.kafka.model.StrimziPodSet) Pod(io.fabric8.kubernetes.api.model.Pod) Test(org.junit.jupiter.api.Test)

Example 69 with StrimziPodSet

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

the class StrimziPodSetControllerIT method testOwnerReferencePatching.

/**
 * Tests patching of the owner reference in pre-existing pods
 *
 * @param context   Test context
 */
@Test
public void testOwnerReferencePatching(VertxTestContext context) {
    String podSetName = "owner-reference";
    String podName = podSetName + "-0";
    try {
        Pod pod = pod(podName, KAFKA_NAME, podSetName);
        client.pods().inNamespace(NAMESPACE).create(pod);
        // Wait until the pod is ready
        TestUtils.waitFor("Wait for Pod to be ready", 100, 10_000, () -> client.pods().inNamespace(NAMESPACE).withName(podName).isReady(), () -> context.failNow("Test timed out waiting for pod readiness!"));
        podSetOp().inNamespace(NAMESPACE).create(podSet(podSetName, KAFKA_NAME, pod));
        // Check status of the PodSet
        TestUtils.waitFor("Wait for StrimziPodSetStatus", 100, 10_000, () -> {
            StrimziPodSet podSet = podSetOp().inNamespace(NAMESPACE).withName(podSetName).get();
            return podSet.getStatus().getCurrentPods() == 1 && podSet.getStatus().getReadyPods() == 1 && podSet.getStatus().getPods() == 1;
        }, () -> context.failNow("Pod stats do not match"));
        // Get the pod and check that the owner reference was set
        Pod actualPod = client.pods().inNamespace(NAMESPACE).withName(podName).get();
        checkOwnerReference(actualPod, podSetName);
        context.completeNow();
    } finally {
        podSetOp().inNamespace(NAMESPACE).withName(podSetName).delete();
    }
}
Also used : StrimziPodSet(io.strimzi.api.kafka.model.StrimziPodSet) Pod(io.fabric8.kubernetes.api.model.Pod) Test(org.junit.jupiter.api.Test)

Example 70 with StrimziPodSet

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

the class StrimziPodSetControllerIT method testNonCascadingDeletion.

/**
 * Tests the non-cascading delete of the PodSet:
 *   - Creation of StrimziPodSet and the managed pod
 *   - Non-cascading deletion of the pod set
 *   - Check the pod is still there
 *
 * @param context   Test context
 */
@Test
public void testNonCascadingDeletion(VertxTestContext context) {
    String podSetName = "basic-test";
    String podName = podSetName + "-0";
    try {
        Pod pod = pod(podName, KAFKA_NAME, podSetName);
        podSetOp().inNamespace(NAMESPACE).create(podSet(podSetName, KAFKA_NAME, pod));
        // Check that pod is created
        TestUtils.waitFor("Wait for Pod to be created", 100, 10_000, () -> client.pods().inNamespace(NAMESPACE).withName(podName).get() != null, () -> context.failNow("Test timed out waiting for pod creation!"));
        // Wait until the pod is ready
        TestUtils.waitFor("Wait for Pod to be ready", 100, 10_000, () -> client.pods().inNamespace(NAMESPACE).withName(podName).isReady(), () -> context.failNow("Test timed out waiting for pod readiness!"));
        Pod actualPod = client.pods().inNamespace(NAMESPACE).withName(podName).get();
        // Check OwnerReference was added
        checkOwnerReference(actualPod, podSetName);
        // Delete the PodSet in non-cascading way
        podSetOp().inNamespace(NAMESPACE).withName(podSetName).withPropagationPolicy(DeletionPropagation.ORPHAN).delete();
        // Check that the PodSet is deleted
        TestUtils.waitFor("Wait for StrimziPodSet deletion", 100, 10_000, () -> {
            StrimziPodSet podSet = podSetOp().inNamespace(NAMESPACE).withName(podSetName).get();
            return podSet == null;
        }, () -> context.failNow("PodSet was not deleted"));
        // Check that the pod still exists without owner reference
        actualPod = client.pods().inNamespace(NAMESPACE).withName(podName).get();
        assertThat(actualPod, is(notNullValue()));
        assertThat(actualPod.getMetadata().getOwnerReferences().size(), is(0));
        context.completeNow();
    } finally {
        podSetOp().inNamespace(NAMESPACE).withName(podSetName).delete();
        client.pods().inNamespace(NAMESPACE).withName(podName).delete();
    }
}
Also used : StrimziPodSet(io.strimzi.api.kafka.model.StrimziPodSet) Pod(io.fabric8.kubernetes.api.model.Pod) Test(org.junit.jupiter.api.Test)

Aggregations

StrimziPodSet (io.strimzi.api.kafka.model.StrimziPodSet)106 Pod (io.fabric8.kubernetes.api.model.Pod)84 Test (org.junit.jupiter.api.Test)62 Reconciliation (io.strimzi.operator.common.Reconciliation)58 Kafka (io.strimzi.api.kafka.model.Kafka)54 KafkaBuilder (io.strimzi.api.kafka.model.KafkaBuilder)50 ResourceOperatorSupplier (io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier)44 StatefulSetOperator (io.strimzi.operator.cluster.operator.resource.StatefulSetOperator)44 Labels (io.strimzi.operator.common.model.Labels)44 PodOperator (io.strimzi.operator.common.operator.resource.PodOperator)44 Checkpoint (io.vertx.junit5.Checkpoint)44 CoreMatchers.is (org.hamcrest.CoreMatchers.is)44 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)44 GenericKafkaListenerBuilder (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder)42 Map (java.util.Map)42 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)40 PlatformFeaturesAvailability (io.strimzi.operator.PlatformFeaturesAvailability)38 KafkaVersionTestUtils (io.strimzi.operator.cluster.KafkaVersionTestUtils)38 KafkaCluster (io.strimzi.operator.cluster.model.KafkaCluster)38 ArrayList (java.util.ArrayList)38