19
19
import org .apache .commons .lang3 .StringUtils ;
20
20
21
21
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 ;
24
26
25
27
KubectlDelete (Class <ApiType > apiTypeClass ) {
26
28
super (apiTypeClass );
27
29
}
28
30
31
+ public KubectlDelete <ApiType > ignoreNotFound (boolean ignore ) {
32
+ this .ignoreNotFound = ignore ;
33
+ return this ;
34
+ }
29
35
@ Override
30
36
public ApiType execute () throws KubectlException {
31
37
verifyArguments ();
@@ -35,13 +41,23 @@ public ApiType execute() throws KubectlException {
35
41
try {
36
42
return getGenericApi ().delete (namespace , name ).throwsApiException ().getObject ();
37
43
} 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
+ }
39
50
}
40
51
} else {
41
52
try {
42
53
return getGenericApi ().delete (name ).throwsApiException ().getObject ();
43
54
} 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
+ }
45
61
}
46
62
}
47
63
}
@@ -60,4 +76,4 @@ private void verifyArguments() throws KubectlException {
60
76
throw new KubectlException ("missing name argument" );
61
77
}
62
78
}
63
- }
79
+ }
0 commit comments