Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ignoreNotFound flag to KubectlDelete.java #2898

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
awesominat marked this conversation as resolved.
Show resolved Hide resolved

@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
Loading