diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/base/BaseOperation.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/base/BaseOperation.java index 7e548d0535..e860e0b0f4 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/base/BaseOperation.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/base/BaseOperation.java @@ -57,6 +57,7 @@ import io.fabric8.kubernetes.client.utils.URLUtils; import io.fabric8.kubernetes.client.utils.Utils; import io.fabric8.kubernetes.client.utils.WatcherToggle; + import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -75,6 +76,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.function.Predicate; + import okhttp3.HttpUrl; import okhttp3.Request; @@ -83,7 +85,7 @@ public class BaseOperation, - Resource { + Resource { private static final Logger LOG = LoggerFactory.getLogger(BaseOperation.class); @@ -134,8 +136,8 @@ protected BaseOperation(OperationContext ctx) { * @param item The item. * @param name The name to check. * @param - * @return - */ + * @return + */ private static String name(T item, String name) { if (name != null && !name.isEmpty()) { return name; @@ -147,7 +149,7 @@ private static String name(T item, String name) { } - public BaseOperation newInstance(OperationContext context) { + public BaseOperation newInstance(OperationContext context) { return new BaseOperation(context); } @@ -178,7 +180,7 @@ protected URL fetchListUrl(URL url, ListOptions listOptions) throws MalformedURL } private void addQueryStringParam(HttpUrl.Builder requestUrlBuilder, String name, String value) { - if(Utils.isNotNullOrEmpty(value)) { + if (Utils.isNotNullOrEmpty(value)) { requestUrlBuilder.addQueryParameter(name, value); } } @@ -236,12 +238,12 @@ public T getMandatory() { } catch (KubernetesClientException e) { throw KubernetesClientException.launderThrowable(forOperationType("get"), e); //if (e.getCode() != HttpURLConnection.HTTP_NOT_FOUND) { - // throw e; + // throw e; //} else { // String resourceType = type != null ? type.getSimpleName() : "Resource"; // String msg = resourceType + " with name: [" + getName() + "] not found in namespace: [" + (Utils.isNotNullOrEmpty(getNamespace()) ? getName() : getConfig().getNamespace()) + "]"; - // throw new KubernetesClientException(msg, HttpURLConnection.HTTP_NOT_FOUND, new StatusBuilder().withCode(HttpURLConnection.HTTP_NOT_FOUND).withMessage(msg).build()); - // } + // throw new KubernetesClientException(msg, HttpURLConnection.HTTP_NOT_FOUND, new StatusBuilder().withCode(HttpURLConnection.HTTP_NOT_FOUND).withMessage(msg).build()); + // } } catch (InterruptedException | ExecutionException | IOException e) { throw KubernetesClientException.launderThrowable(forOperationType("get"), e); } @@ -577,9 +579,9 @@ public String getLabelQueryParam() { } Map.Entry entry = iter.next(); if (entry.getValue() != null) { - sb.append(entry.getKey()).append("=").append(entry.getValue()); + sb.append(entry.getKey()).append("=").append(entry.getValue()); } else { - sb.append(entry.getKey()); + sb.append(entry.getKey()); } } } @@ -598,7 +600,7 @@ public String getLabelQueryParam() { sb.append(entry.getKey()).append("!=").append(entry.getValue()[i]); } } else { - sb.append('!').append(entry.getKey()); + sb.append('!').append(entry.getKey()); } } } @@ -709,6 +711,9 @@ public Boolean delete(List items) { boolean deleted = true; if (items != null) { for (T item : items) { + if (item == null) { + continue; + } updateApiVersionResource(item); try { @@ -717,7 +722,7 @@ public Boolean delete(List items) { if (item instanceof HasMetadata && ((HasMetadata) item).getMetadata() != null && ((HasMetadata) item).getMetadata().getName() != null - && !((HasMetadata) item).getMetadata().getName().isEmpty()) { + && !((HasMetadata) item).getMetadata().getName().isEmpty()) { op = (R) inNamespace(checkNamespace(item)).withName(((HasMetadata) item).getMetadata().getName()); } else { op = (R) withItem(item); @@ -744,7 +749,7 @@ public T updateStatus(T item) { } } - public BaseOperation withItem(T item) { + public BaseOperation withItem(T item) { return newInstance(context.withItem(item)); } @@ -805,7 +810,7 @@ public Watch watch(ListOptions options, final Watcher watcher) { } catch (KubernetesClientException ke) { if (ke.getCode() != 200) { - if(watch != null){ + if (watch != null) { //release the watch watch.close(); } @@ -813,7 +818,7 @@ public Watch watch(ListOptions options, final Watcher watcher) { throw ke; } - if(watch != null){ + if (watch != null) { //release the watch after disabling the watcher (to avoid premature call to onClose) watcherToggle.disable(); watch.close(); @@ -1010,14 +1015,12 @@ public OperationInfo forOperationType(String type) { } @Override - public FilterWatchListDeletable> withGracePeriod(long gracePeriodSeconds) - { + public FilterWatchListDeletable> withGracePeriod(long gracePeriodSeconds) { return newInstance(context.withGracePeriodSeconds(gracePeriodSeconds)); } @Override - public EditReplacePatchDeletable withPropagationPolicy(DeletionPropagation propagationPolicy) - { + public EditReplacePatchDeletable withPropagationPolicy(DeletionPropagation propagationPolicy) { return newInstance(context.withPropagationPolicy(propagationPolicy)); } @@ -1100,7 +1103,7 @@ public boolean isApiGroup() { @Override public Boolean isReady() { T i = get(); - return i instanceof HasMetadata && Readiness.isReady((HasMetadata)i); + return i instanceof HasMetadata && Readiness.isReady((HasMetadata) i); } @Override @@ -1127,8 +1130,8 @@ private T waitUntilConditionWithRetries(Predicate condition, long timeoutNano WaitForConditionWatcher watcher = new WaitForConditionWatcher<>(condition); Watch watch = item == null ? watch(new ListOptionsBuilder() - .withResourceVersion(null) - .build(), watcher) + .withResourceVersion(null) + .build(), watcher) : watch(item.getMetadata().getResourceVersion(), watcher); try {