From f9d57234272973e42143ba3b0b9a1916100ed9be Mon Sep 17 00:00:00 2001 From: Zain Date: Thu, 16 Nov 2023 18:00:22 -0500 Subject: [PATCH 1/3] added ignoreNotFound flag --- .../extended/kubectl/KubectlDelete.java | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) 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..563b74e13b 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,19 @@ 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 +41,23 @@ 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) { + System.out.println("Ignoring resource not found."); + 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) { + System.out.println("Ignoring resource not found."); + return null; + } else { + throw new KubectlException(e); + } } } } @@ -60,4 +76,4 @@ private void verifyArguments() throws KubectlException { throw new KubectlException("missing name argument"); } } -} +} \ No newline at end of file From 653f954102af64f07f5e13a031b31ee81b6c4fa6 Mon Sep 17 00:00:00 2001 From: Zain Date: Thu, 16 Nov 2023 18:16:48 -0500 Subject: [PATCH 2/3] removed print --- .../io/kubernetes/client/extended/kubectl/KubectlDelete.java | 2 -- 1 file changed, 2 deletions(-) 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 563b74e13b..ff4145ad9a 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 @@ -42,7 +42,6 @@ public ApiType execute() throws KubectlException { return getGenericApi().delete(namespace, name).throwsApiException().getObject(); } catch (ApiException e) { if (ignoreNotFound && e.getCode() == 404) { - System.out.println("Ignoring resource not found."); return null; } else { throw new KubectlException(e); @@ -53,7 +52,6 @@ public ApiType execute() throws KubectlException { return getGenericApi().delete(name).throwsApiException().getObject(); } catch (ApiException e) { if (ignoreNotFound && e.getCode() == 404) { - System.out.println("Ignoring resource not found."); return null; } else { throw new KubectlException(e); From 95e572d628d6646d458c905a8136f7426f47a688 Mon Sep 17 00:00:00 2001 From: Zain Date: Thu, 16 Nov 2023 19:49:20 -0500 Subject: [PATCH 3/3] added new lines at end and after method --- .../io/kubernetes/client/extended/kubectl/KubectlDelete.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 ff4145ad9a..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 @@ -32,6 +32,7 @@ public KubectlDelete ignoreNotFound(boolean ignore) { this.ignoreNotFound = ignore; return this; } + @Override public ApiType execute() throws KubectlException { verifyArguments(); @@ -74,4 +75,4 @@ private void verifyArguments() throws KubectlException { throw new KubectlException("missing name argument"); } } -} \ No newline at end of file +}