diff --git a/extended/src/main/java/io/kubernetes/client/extended/kubectl/KubectlDelete.java b/extended/src/main/java/io/kubernetes/client/extended/kubectl/KubectlDelete.java index 599b87c8e2..1d320c060f 100644 --- a/extended/src/main/java/io/kubernetes/client/extended/kubectl/KubectlDelete.java +++ b/extended/src/main/java/io/kubernetes/client/extended/kubectl/KubectlDelete.java @@ -19,13 +19,20 @@ import org.apache.commons.lang3.StringUtils; public class KubectlDelete - extends Kubectl.ResourceBuilder> - implements Kubectl.Executable { + extends Kubectl.ResourceBuilder> + implements Kubectl.Executable { + + private boolean ignoreNotFound = false; KubectlDelete(Class apiTypeClass) { super(apiTypeClass); } + public KubectlDelete ignoreNotFound(boolean ignore) { + this.ignoreNotFound = ignore; + return this; + } + @Override public ApiType execute() throws KubectlException { verifyArguments(); @@ -35,13 +42,21 @@ public ApiType execute() throws KubectlException { try { return getGenericApi().delete(namespace, name).throwsApiException().getObject(); } catch (ApiException e) { - throw new KubectlException(e); + if (ignoreNotFound && e.getCode() == 404) { + return null; + } else { + throw new KubectlException(e); + } } } else { try { return getGenericApi().delete(name).throwsApiException().getObject(); } catch (ApiException e) { - throw new KubectlException(e); + if (ignoreNotFound && e.getCode() == 404) { + return null; + } else { + throw new KubectlException(e); + } } } }