Skip to content

Commit

Permalink
Merge pull request #2898 from awesominat/add-ignore-not-found-flag-to…
Browse files Browse the repository at this point in the history
…-kubectldelete-2876

Add ignoreNotFound flag to KubectlDelete.java
  • Loading branch information
k8s-ci-robot authored Nov 20, 2023
2 parents 867755a + 95e572d commit 592d2a1
Showing 1 changed file with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,20 @@
import org.apache.commons.lang3.StringUtils;

public class KubectlDelete<ApiType extends KubernetesObject>
extends Kubectl.ResourceBuilder<ApiType, KubectlDelete<ApiType>>
implements Kubectl.Executable<ApiType> {
extends Kubectl.ResourceBuilder<ApiType, KubectlDelete<ApiType>>
implements Kubectl.Executable<ApiType> {

private boolean ignoreNotFound = false;

KubectlDelete(Class<ApiType> apiTypeClass) {
super(apiTypeClass);
}

public KubectlDelete<ApiType> ignoreNotFound(boolean ignore) {
this.ignoreNotFound = ignore;
return this;
}

@Override
public ApiType execute() throws KubectlException {
verifyArguments();
Expand All @@ -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);
}
}
}
}
Expand Down

0 comments on commit 592d2a1

Please sign in to comment.