Skip to content

Commit f9d5723

Browse files
committed
added ignoreNotFound flag
1 parent 7a53684 commit f9d5723

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

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

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,19 @@
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+
}
2935
@Override
3036
public ApiType execute() throws KubectlException {
3137
verifyArguments();
@@ -35,13 +41,23 @@ public ApiType execute() throws KubectlException {
3541
try {
3642
return getGenericApi().delete(namespace, name).throwsApiException().getObject();
3743
} catch (ApiException e) {
38-
throw new KubectlException(e);
44+
if (ignoreNotFound && e.getCode() == 404) {
45+
System.out.println("Ignoring resource not found.");
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+
System.out.println("Ignoring resource not found.");
57+
return null;
58+
} else {
59+
throw new KubectlException(e);
60+
}
4561
}
4662
}
4763
}
@@ -60,4 +76,4 @@ private void verifyArguments() throws KubectlException {
6076
throw new KubectlException("missing name argument");
6177
}
6278
}
63-
}
79+
}

0 commit comments

Comments
 (0)