use of org.apache.skywalking.oap.query.graphql.type.PodContainers in project skywalking by apache.
the class OndemandLogQuery method listContainers.
public PodContainers listContainers(final String namespace, final String podName) throws IOException {
try {
if (Strings.isNullOrEmpty(namespace) || Strings.isNullOrEmpty(podName)) {
return new PodContainers().setErrorReason("namespace and podName can't be null or empty");
}
final V1Pod pod = kApi().readNamespacedPod(podName, namespace, null);
final V1PodSpec spec = pod.getSpec();
if (isNull(spec)) {
return new PodContainers().setErrorReason("No pod spec can be found");
}
final List<String> containers = spec.getContainers().stream().map(V1Container::getName).collect(Collectors.toList());
if (nonNull(spec.getInitContainers())) {
final List<String> init = spec.getInitContainers().stream().map(V1Container::getName).collect(Collectors.toList());
containers.addAll(init);
}
return new PodContainers().setContainers(containers);
} catch (ApiException e) {
log.error("Failed to list containers from Kubernetes, {}", e.getResponseBody(), e);
if (!Strings.isNullOrEmpty(e.getResponseBody())) {
Map<String, Object> responseBody = gson.fromJson(e.getResponseBody(), responseType);
String message = responseBody.getOrDefault("message", e.getCode()).toString();
return new PodContainers().setErrorReason(message);
}
return new PodContainers().setErrorReason(e.getMessage() + ": " + e.getCode());
}
}
Aggregations