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));
}
}
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));
}
}
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();
}
}
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();
}
}
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();
}
}
Aggregations