use of io.strimzi.api.kafka.model.StrimziPodSet in project strimzi by strimzi.
the class StrimziPodSetControllerIT method testPodUpdates.
/**
* Tests updates to pods in the StrimziPodSet:
* - StrimziPodSetController should not roll the pods => the dedicated rollers do it
* - The pod should not be marked as current when it is updated
*
* @param context Test context
*/
@Test
public void testPodUpdates(VertxTestContext context) {
String podSetName = "pod-updates";
String podName = podSetName + "-0";
try {
Pod originalPod = pod(podName, KAFKA_NAME, podSetName);
podSetOp().inNamespace(NAMESPACE).create(podSet(podSetName, KAFKA_NAME, originalPod));
// 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!"));
// 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 resource version to double check the pod was not deleted
Pod initialPod = client.pods().inNamespace(NAMESPACE).withName(podName).get();
String resourceVersion = initialPod.getMetadata().getResourceVersion();
// Update the pod with a new revision and
Pod updatedPod = pod(podName, KAFKA_NAME, podSetName);
updatedPod.getMetadata().getAnnotations().put(PodRevision.STRIMZI_REVISION_ANNOTATION, "new-revision");
updatedPod.getSpec().setTerminationGracePeriodSeconds(1L);
podSetOp().inNamespace(NAMESPACE).withName(podSetName).patch(podSet(podSetName, KAFKA_NAME, updatedPod));
// 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() == 0 && podSet.getStatus().getReadyPods() == 1 && podSet.getStatus().getPods() == 1;
}, () -> context.failNow("Pod stats do not match"));
// Check the pod was not changed
Pod actualPod = client.pods().inNamespace(NAMESPACE).withName(podName).get();
assertThat(actualPod.getMetadata().getResourceVersion(), is(resourceVersion));
assertThat(actualPod.getMetadata().getAnnotations().get(PodRevision.STRIMZI_REVISION_ANNOTATION), is(originalPod.getMetadata().getAnnotations().get(PodRevision.STRIMZI_REVISION_ANNOTATION)));
assertThat(actualPod.getSpec().getTerminationGracePeriodSeconds(), is(0L));
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 testPodCreationDeletionAndRecreation.
/*
* Tests
*/
/**
* Tests the basic operations:
* - Creation of StrimziPodSet and the managed pod
* - Re-creation of the managed pod when it is deleted
* - Deletion of the StrimziPodSet and the managed pod
*
* @param context Test context
*/
@Test
public void testPodCreationDeletionAndRecreation(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);
// We keep the resource version for pod re-creation test
String resourceVersion = actualPod.getMetadata().getResourceVersion();
// 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"));
// Delete the pod and test that it is recreated
client.pods().inNamespace(NAMESPACE).withName(podName).delete();
// Check that pod is created
TestUtils.waitFor("Wait for Pod to be recreated", 100, 10_000, () -> {
Pod p = client.pods().inNamespace(NAMESPACE).withName(podName).get();
return p != null && !resourceVersion.equals(p.getMetadata().getResourceVersion());
}, () -> context.failNow("Test timed out waiting for pod recreation!"));
// Delete the PodSet
podSetOp().inNamespace(NAMESPACE).withName(podSetName).delete();
// Check that pod is deleted after pod set deletion
TestUtils.waitFor("Wait for Pod to be deleted", 100, 10_000, () -> client.pods().inNamespace(NAMESPACE).withName(podName).get() == null, () -> context.failNow("Test timed out waiting for pod deletion!"));
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 testCrSelector.
/**
* Tests that the controller will ignore pods or node sets when the Kafka cluster they belong to doesn't match the
* custom resource selector
*
* @param context Test context
*/
@Test
public void testCrSelector(VertxTestContext context) {
String podSetName = "matching-podset";
String otherPodSetName = "other-podset";
String podName = podSetName + "-0";
String preExistingPodName = podSetName + "-1";
String otherPodName = otherPodSetName + "-0";
String otherPreExistingPodName = otherPodSetName + "-1";
try {
// Create the pod set which should be reconciled
Pod pod = pod(podName, KAFKA_NAME, podSetName);
Pod preExistingPod = pod(preExistingPodName, KAFKA_NAME, podSetName);
client.pods().inNamespace(NAMESPACE).create(preExistingPod);
podSetOp().inNamespace(NAMESPACE).create(podSet(podSetName, KAFKA_NAME, pod));
// Create the pod set which should be ignored
Pod otherPod = pod(otherPodName, OTHER_KAFKA_NAME, otherPodSetName);
Pod otherPreExistingPod = pod(otherPreExistingPodName, OTHER_KAFKA_NAME, otherPodSetName);
client.pods().inNamespace(NAMESPACE).create(otherPreExistingPod);
podSetOp().inNamespace(NAMESPACE).create(podSet(otherPodSetName, OTHER_KAFKA_NAME, otherPod));
// Check that the pre-existing pod for matching pod set is deleted
TestUtils.waitFor("Wait for the pre-existing Pod to be deleted", 100, 10_000, () -> client.pods().inNamespace(NAMESPACE).withName(preExistingPodName).get() == null, () -> context.failNow("Test timed out waiting for pod deletion!"));
// Check that the pod for matching pod set 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!"));
// Check status of the matching pod set which should be updated
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"));
// Check that the non-matching pod set was ignored
assertThat(client.pods().inNamespace(NAMESPACE).withName(otherPodName).get(), is(nullValue()));
assertThat(podSetOp().inNamespace(NAMESPACE).withName(otherPodSetName).get().getStatus(), is(nullValue()));
assertThat(client.pods().inNamespace(NAMESPACE).withName(otherPreExistingPodName).get(), is(notNullValue()));
context.completeNow();
} finally {
podSetOp().inNamespace(NAMESPACE).withName(podSetName).delete();
podSetOp().inNamespace(NAMESPACE).withName(otherPodSetName).delete();
client.pods().inNamespace(NAMESPACE).withName(otherPreExistingPodName).delete();
client.pods().inNamespace(NAMESPACE).withName(preExistingPodName).delete();
}
}
use of io.strimzi.api.kafka.model.StrimziPodSet in project strimzi by strimzi.
the class StrimziPodSetControllerMockTest method testPodUpdates.
/**
* Tests updates pods in the StrimziPodSet:
* - StrimziPodSetController should not roll the pods => the dedicated rollers do it
* - The pod should not be marked as current when it is updated
*
* @param context Test context
*/
@Test
public void testPodUpdates(VertxTestContext context) {
String podSetName = "pod-updates";
String podName = podSetName + "-0";
try {
Pod originalPod = pod(podName, KAFKA_NAME, podSetName);
podSetOp().inNamespace(NAMESPACE).create(podSet(podSetName, KAFKA_NAME, originalPod));
// 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!"));
// 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 resource version to double-check the pod was not deleted
Pod initialPod = client.pods().inNamespace(NAMESPACE).withName(podName).get();
String resourceVersion = initialPod.getMetadata().getResourceVersion();
// Update the pod with a new revision and
Pod updatedPod = pod(podName, KAFKA_NAME, podSetName);
updatedPod.getMetadata().getAnnotations().put(PodRevision.STRIMZI_REVISION_ANNOTATION, "new-revision");
updatedPod.getSpec().setTerminationGracePeriodSeconds(1L);
podSetOp().inNamespace(NAMESPACE).withName(podSetName).patch(podSet(podSetName, KAFKA_NAME, updatedPod));
// 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() == 0 && podSet.getStatus().getReadyPods() == 1 && podSet.getStatus().getPods() == 1;
}, () -> context.failNow("Pod stats do not match"));
// Check the pod was not changed
Pod actualPod = client.pods().inNamespace(NAMESPACE).withName(podName).get();
assertThat(actualPod.getMetadata().getResourceVersion(), is(resourceVersion));
assertThat(actualPod.getMetadata().getAnnotations().get(PodRevision.STRIMZI_REVISION_ANNOTATION), is(originalPod.getMetadata().getAnnotations().get(PodRevision.STRIMZI_REVISION_ANNOTATION)));
assertThat(actualPod.getSpec().getTerminationGracePeriodSeconds(), is(0L));
context.completeNow();
} finally {
podSetOp().inNamespace(NAMESPACE).withName(podSetName).delete();
}
}
use of io.strimzi.api.kafka.model.StrimziPodSet in project strimzi by strimzi.
the class StrimziPodSetOperator method isReady.
/**
* Check if the PodSet is in the Ready state. The PodSet is ready when all the following conditions are fulfilled:
* - All pods are created
* - All pods are up-to-date
* - All pods are ready
*
* @param namespace The namespace
* @param name The name of the StrimziPodSet
*
* @return True when the StrimziPodSet is ready. False otherwise.
*/
public boolean isReady(String namespace, String name) {
StrimziPodSet podSet = operation().inNamespace(namespace).withName(name).get();
int replicas = podSet.getSpec().getPods().size();
return podSet.getStatus() != null && replicas == podSet.getStatus().getPods() && replicas == podSet.getStatus().getReadyPods();
}
Aggregations