Skip to content

Commit 592d2a1

Browse files
authored
Merge pull request #2898 from awesominat/add-ignore-not-found-flag-to-kubectldelete-2876
Add ignoreNotFound flag to KubectlDelete.java
2 parents 867755a + 95e572d commit 592d2a1

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

extended/src/main/java/io/kubernetes/client/extended/kubectl/KubectlDelete.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,20 @@
1919
import org.apache.commons.lang3.StringUtils;
2020

2121
public class KubectlDelete<ApiType extends KubernetesObject>
22-
extends Kubectl.ResourceBuilder<ApiType, KubectlDelete<ApiType>>
23-
implements Kubectl.Executable<ApiType> {
22+
extends Kubectl.ResourceBuilder<ApiType, KubectlDelete<ApiType>>
23+
implements Kubectl.Executable<ApiType> {
24+
25+
private boolean ignoreNotFound = false;
2426

2527
KubectlDelete(Class<ApiType> apiTypeClass) {
2628
super(apiTypeClass);
2729
}
2830

31+
public KubectlDelete<ApiType> ignoreNotFound(boolean ignore) {
32+
this.ignoreNotFound = ignore;
33+
return this;
34+
}
35+
2936
@Override
3037
public ApiType execute() throws KubectlException {
3138
verifyArguments();
@@ -35,13 +42,21 @@ public ApiType execute() throws KubectlException {
3542
try {
3643
return getGenericApi().delete(namespace, name).throwsApiException().getObject();
3744
} catch (ApiException e) {
38-
throw new KubectlException(e);
45+
if (ignoreNotFound && e.getCode() == 404) {
46+
return null;
47+
} else {
48+
throw new KubectlException(e);
49+
}
3950
}
4051
} else {
4152
try {
4253
return getGenericApi().delete(name).throwsApiException().getObject();
4354
} catch (ApiException e) {
44-
throw new KubectlException(e);
55+
if (ignoreNotFound && e.getCode() == 404) {
56+
return null;
57+
} else {
58+
throw new KubectlException(e);
59+
}
4560
}
4661
}
4762
}

0 commit comments

Comments
 (0)