Skip to content

Commit

Permalink
defend against NPE's
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Barker <[email protected]>

rh-pre-commit.version: 2.0.1
rh-pre-commit.check-secrets: ENABLED
  • Loading branch information
SamBarker committed Nov 8, 2023
1 parent ef11a60 commit 060f31b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,17 @@ private <T extends HasMetadata> ResourceType<T> findResourceType(T resource) {

TestUtils.waitFor(String.format("%s: %s#%s will have desired state 'Ready'", kind, namespace, name),
Constants.POLL_INTERVAL_FOR_RESOURCE_READINESS_MILLIS, resourceTimeoutMs,
() -> operation.inNamespace(namespace)
.withName(name)
.get().getStatus().getConditions().stream()
.anyMatch(condition -> condition.getType().equals("Ready") && condition.getStatus().equals(conditionStatus.toString())));
() -> {
final Status status = operation.inNamespace(namespace)
.withName(name)
.get()
.getStatus();
if (status != null) {
return status.getConditions().stream()
.anyMatch(condition -> condition.getType().equals("Ready") && condition.getStatus().equals(conditionStatus.toString()));
}
return false;
});

LOGGER.info("{}: {}/{} is in desired state 'Ready'", kind, namespace, name);
return true;
Expand All @@ -260,4 +267,4 @@ private <T extends HasMetadata> ResourceType<T> findResourceType(T resource) {
long resourceTimeout = ResourceOperation.getTimeoutForResourceReadiness(resource.getKind());
return waitForResourceStatusReady(operation, resource, resourceTimeout);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -180,18 +180,30 @@ private static InputStream replaceStringInResourceFile(String resourceTemplateFi
*/
public static boolean restartBroker(String deployNamespace, String clusterName) {
String podName = "";
String podUid = "";
List<Pod> kafkaPods = kubeClient().listPods(Constants.KROXY_DEFAULT_NAMESPACE);
for (Pod pod : kafkaPods) {
String tmpName = pod.getMetadata().getName();
if (tmpName.startsWith(clusterName) && tmpName.endsWith("0")) {
podName = pod.getMetadata().getName();
podUid = pod.getMetadata().getUid();
break;
}
}
String podUid = kubeClient().getPod(deployNamespace, podName).getMetadata().getUid();
kubeClient().getClient().pods().inNamespace(deployNamespace).withName(podName).withGracePeriod(0).delete();
kubeClient().getClient().pods().inNamespace(deployNamespace).withName(podName).waitUntilCondition(Objects::isNull, 60, TimeUnit.SECONDS);
String finalPodName = podName;
await().atMost(Duration.ofMinutes(1)).until(() -> kubeClient().getClient().pods().inNamespace(deployNamespace).withName(finalPodName) != null);
return !Objects.equals(podUid, kubeClient().getPod(deployNamespace, podName).getMetadata().getUid());
return !Objects.equals(podUid, getPodUid(deployNamespace, podName));
}
}

private static String getPodUid(String deployNamespace, String podName) {
final Pod pod = kubeClient().getPod(deployNamespace, podName);
if (pod != null) {
return pod.getMetadata().getUid();
}
else {
return "";
}
}
}

0 comments on commit 060f31b

Please sign in to comment.