Skip to content

Response from pod delete REST call can be Pod or Status #2038

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

Merged
merged 4 commits into from
Nov 6, 2020
Merged
Show file tree
Hide file tree
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 @@ -139,7 +139,7 @@ private String getDomainUid(V1Pod pod) {
}
}

static class ForcedDeleteResponseStep extends DefaultResponseStep<V1Pod> {
static class ForcedDeleteResponseStep extends DefaultResponseStep<Object> {

private final String name;
private final String namespace;
Expand All @@ -150,7 +150,7 @@ public ForcedDeleteResponseStep(String name, String namespace) {
}

@Override
public NextAction onSuccess(Packet packet, CallResponse<V1Pod> callResponse) {
public NextAction onSuccess(Packet packet, CallResponse<Object> callResponse) {
LOGGER.info(POD_FORCE_DELETED, name, namespace);
return super.onSuccess(packet, callResponse);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,22 @@
package oracle.kubernetes.operator.helpers;

import java.io.IOException;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Consumer;
import javax.annotation.Nonnull;

import com.google.common.base.Strings;
import com.google.gson.reflect.TypeToken;
import io.kubernetes.client.custom.V1Patch;
import io.kubernetes.client.openapi.ApiCallback;
import io.kubernetes.client.openapi.ApiClient;
import io.kubernetes.client.openapi.ApiException;
import io.kubernetes.client.openapi.Pair;
import io.kubernetes.client.openapi.apis.ApiextensionsV1Api;
import io.kubernetes.client.openapi.apis.ApiextensionsV1beta1Api;
import io.kubernetes.client.openapi.apis.AuthenticationV1Api;
Expand Down Expand Up @@ -69,7 +76,6 @@
/** Simplifies synchronous and asynchronous call patterns to the Kubernetes API Server. */
@SuppressWarnings({"WeakerAccess", "UnusedReturnValue"})
public class CallBuilder {

/** HTTP status code for "Not Found". */
public static final int NOT_FOUND = 404;

Expand Down Expand Up @@ -317,7 +323,7 @@ public <T> T execute(
requestParams.namespace,
(V1DeleteOptions) requestParams.body,
callback));
private final CallFactory<V1Pod> deletePod =
private final CallFactory<Object> deletePod =
(requestParams, usage, cont, callback) ->
wrap(
deletePodAsync(
Expand Down Expand Up @@ -1182,19 +1188,19 @@ private Call deletePodAsync(
String name,
String namespace,
V1DeleteOptions deleteOptions,
ApiCallback<V1Pod> callback)
ApiCallback<Object> callback)
throws ApiException {
return new CoreV1Api(client)
.deleteNamespacedPodAsync(
name,
namespace,
pretty,
dryRun,
gracePeriodSeconds,
orphanDependents,
propagationPolicy,
deleteOptions,
callback);
return deleteNamespacedPodAsync(
client,
name,
namespace,
pretty,
dryRun,
gracePeriodSeconds,
orphanDependents,
propagationPolicy,
deleteOptions,
callback);
}

/**
Expand All @@ -1212,12 +1218,85 @@ public Step deletePodAsync(
String namespace,
String domainUid,
V1DeleteOptions deleteOptions,
ResponseStep<V1Pod> responseStep) {
ResponseStep<Object> responseStep) {
return createRequestAsync(
responseStep, new RequestParams("deletePod", namespace, name, deleteOptions, domainUid),
responseStep, new RequestParams("deletePod", namespace, name, deleteOptions, domainUid),
deletePod, retryStrategy);
}

private Call deleteNamespacedPodAsync(ApiClient client, String name, String namespace, String pretty, String dryRun,
Integer gracePeriodSeconds, Boolean orphanDependents, String propagationPolicy,
V1DeleteOptions body, ApiCallback<Object> callback) throws ApiException {
Call localVarCall = this.deleteNamespacedPodValidateBeforeCall(client, name, namespace, pretty, dryRun,
gracePeriodSeconds, orphanDependents, propagationPolicy, body, callback);
Type localVarReturnType = (new TypeToken<Object>() {
}).getType();
client.executeAsync(localVarCall, localVarReturnType, callback);
return localVarCall;
}

private Call deleteNamespacedPodValidateBeforeCall(ApiClient client, String name, String namespace, String pretty,
String dryRun, Integer gracePeriodSeconds,
Boolean orphanDependents, String propagationPolicy,
V1DeleteOptions body, ApiCallback callback) throws ApiException {
if (name == null) {
throw new ApiException("Missing the required parameter 'name' when calling deleteNamespacedPod(Async)");
} else if (namespace == null) {
throw new ApiException("Missing the required parameter 'namespace' when calling deleteNamespacedPod(Async)");
} else {
Call localVarCall = this.deleteNamespacedPodCall(client, name, namespace, pretty, dryRun, gracePeriodSeconds,
orphanDependents, propagationPolicy, body, callback);
return localVarCall;
}
}

private Call deleteNamespacedPodCall(ApiClient client, String name, String namespace, String pretty, String dryRun,
Integer gracePeriodSeconds, Boolean orphanDependents, String propagationPolicy,
V1DeleteOptions body, ApiCallback callback) throws ApiException {
String localVarPath = "/api/v1/namespaces/{namespace}/pods/{name}".replaceAll("\\{name\\}",
client.escapeString(name.toString())).replaceAll("\\{namespace\\}",
client.escapeString(namespace.toString()));
List<Pair> localVarQueryParams = new ArrayList();
List<Pair> localVarCollectionQueryParams = new ArrayList();
if (pretty != null) {
localVarQueryParams.addAll(client.parameterToPair("pretty", pretty));
}

if (dryRun != null) {
localVarQueryParams.addAll(client.parameterToPair("dryRun", dryRun));
}

if (gracePeriodSeconds != null) {
localVarQueryParams.addAll(client.parameterToPair("gracePeriodSeconds", gracePeriodSeconds));
}

if (orphanDependents != null) {
localVarQueryParams.addAll(client.parameterToPair("orphanDependents", orphanDependents));
}

if (propagationPolicy != null) {
localVarQueryParams.addAll(client.parameterToPair("propagationPolicy", propagationPolicy));
}

Map<String, String> localVarHeaderParams = new HashMap();
Map<String, String> localVarCookieParams = new HashMap();
Map<String, Object> localVarFormParams = new HashMap();
String[] localVarAccepts = new String[]{
"application/json", "application/yaml", "application/vnd.kubernetes.protobuf"
};
String localVarAccept = client.selectHeaderAccept(localVarAccepts);
if (localVarAccept != null) {
localVarHeaderParams.put("Accept", localVarAccept);
}

String[] localVarContentTypes = new String[0];
String localVarContentType = client.selectHeaderContentType(localVarContentTypes);
localVarHeaderParams.put("Content-Type", localVarContentType);
String[] localVarAuthNames = new String[]{"BearerToken"};
return client.buildCall(localVarPath, "DELETE", localVarQueryParams, localVarCollectionQueryParams, body,
localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAuthNames, callback);
}

private Call patchPodAsync(
ApiClient client, String name, String namespace, V1Patch patch, ApiCallback<V1Pod> callback)
throws ApiException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,11 @@ Step createNewPod(Step next) {
}

@Override
Step replaceCurrentPod(Step next) {
Step replaceCurrentPod(V1Pod pod, Step next) {
if (MakeRightDomainOperation.isInspectionRequired(packet)) {
return createProgressingStep(MakeRightDomainOperation.createStepsToRerunWithIntrospection(packet));
} else {
return createProgressingStep(createCyclePodStep(next));
return createProgressingStep(createCyclePodStep(pod, next));
}
}

Expand Down Expand Up @@ -409,8 +409,8 @@ String getServerName() {

@Override
// let the pod rolling step update the pod
Step replaceCurrentPod(Step next) {
return deferProcessing(createCyclePodStep(next));
Step replaceCurrentPod(V1Pod pod, Step next) {
return deferProcessing(createCyclePodStep(pod, next));
}

private Step deferProcessing(Step deferredStep) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,13 @@ Step verifyPod(Step next) {
/**
* Deletes the specified pod.
*
* @param pod the existing pod
* @param next the next step to perform after the pod deletion is complete.
* @return a step to be scheduled.
*/
private Step deletePod(Step next) {
private Step deletePod(V1Pod pod, Step next) {
return new CallBuilder()
.deletePodAsync(getPodName(), getNamespace(), getDomainUid(), new V1DeleteOptions(), deleteResponse(next));
.deletePodAsync(getPodName(), getNamespace(), getDomainUid(), new V1DeleteOptions(), deleteResponse(pod, next));
}

/**
Expand Down Expand Up @@ -331,10 +332,11 @@ private Step createPodAsync(ResponseStep<V1Pod> response) {
/**
* Creates the specified replacement pod and performs any additional needed processing.
*
* @param pod the existing pod
* @param next the next step to perform after the pod creation is complete.
* @return a step to be scheduled.
*/
abstract Step replaceCurrentPod(Step next);
abstract Step replaceCurrentPod(V1Pod pod, Step next);

/**
* Creates the specified replacement pod and records it.
Expand Down Expand Up @@ -412,8 +414,8 @@ private void logPodReplaced() {

abstract String getPodReplacedMessageKey();

Step createCyclePodStep(Step next) {
return new CyclePodStep(next);
Step createCyclePodStep(V1Pod pod, Step next) {
return new CyclePodStep(pod, next);
}

private boolean mustPatchPod(V1Pod currentPod) {
Expand Down Expand Up @@ -443,8 +445,8 @@ private ResponseStep<V1Pod> createResponse(Step next) {
return new CreateResponseStep(next);
}

private ResponseStep<V1Pod> deleteResponse(Step next) {
return new DeleteResponseStep(next);
private ResponseStep<Object> deleteResponse(V1Pod pod, Step next) {
return new DeleteResponseStep(pod, next);
}

private ResponseStep<V1Pod> replaceResponse(Step next) {
Expand Down Expand Up @@ -822,15 +824,17 @@ private Step getConflictStep() {
}

private class CyclePodStep extends BaseStep {
private final V1Pod pod;

CyclePodStep(Step next) {
CyclePodStep(V1Pod pod, Step next) {
super(next);
this.pod = pod;
}

@Override
public NextAction apply(Packet packet) {
markBeingDeleted();
return doNext(deletePod(getNext()), packet);
return doNext(deletePod(pod, getNext()), packet);
}
}

Expand Down Expand Up @@ -858,7 +862,7 @@ public NextAction apply(Packet packet) {
MessageKeys.CYCLING_POD,
Objects.requireNonNull(currentPod.getMetadata()).getName(),
getReasonToRecycle(currentPod));
return doNext(replaceCurrentPod(getNext()), packet);
return doNext(replaceCurrentPod(currentPod, getNext()), packet);
} else if (mustPatchPod(currentPod)) {
return doNext(patchCurrentPod(currentPod, getNext()), packet);
} else {
Expand Down Expand Up @@ -916,27 +920,30 @@ public NextAction onSuccess(Packet packet, CallResponse<V1Pod> callResponse) {
}
}

private class DeleteResponseStep extends ResponseStep<V1Pod> {
DeleteResponseStep(Step next) {
private class DeleteResponseStep extends ResponseStep<Object> {
private final V1Pod pod;

DeleteResponseStep(V1Pod pod, Step next) {
super(next);
this.pod = pod;
}

protected String getDetail() {
return getServerName();
}

@Override
public NextAction onFailure(Packet packet, CallResponse<V1Pod> callResponses) {
public NextAction onFailure(Packet packet, CallResponse<Object> callResponses) {
if (callResponses.getStatusCode() == CallBuilder.NOT_FOUND) {
return onSuccess(packet, callResponses);
}
return super.onFailure(getConflictStep(), packet, callResponses);
}

@Override
public NextAction onSuccess(Packet packet, CallResponse<V1Pod> callResponses) {
public NextAction onSuccess(Packet packet, CallResponse<Object> callResponses) {
PodAwaiterStepFactory pw = packet.getSpi(PodAwaiterStepFactory.class);
return doNext(pw.waitForDelete(callResponses.getResult(), replacePod(getNext())), packet);
return doNext(pw.waitForDelete(pod, replacePod(getNext())), packet);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ public void afterDeletePod_podsInDifferentNamespacesStillExist() {
V1Pod pod3 = createPod("ns3", "another");
testSupport.defineResources(pod1, pod2, pod3);

TestResponseStep<V1Pod> responseStep = new TestResponseStep<>();
TestResponseStep<Object> responseStep = new TestResponseStep<>();
testSupport.runSteps(new CallBuilder().deletePodAsync("mycrd", "ns2", "", null, responseStep));

assertThat(testSupport.getResources(POD), containsInAnyOrder(pod1, pod3));
Expand All @@ -383,7 +383,7 @@ public void afterDeletePod_podsInDifferentNamespacesStillExist() {
public void whenHttpErrorAssociatedWithResource_callResponseIsError() {
testSupport.failOnResource(POD, "pod1", "ns2", HTTP_BAD_REQUEST);

TestResponseStep<V1Pod> responseStep = new TestResponseStep<>();
TestResponseStep<Object> responseStep = new TestResponseStep<>();
testSupport.runSteps(new CallBuilder().deletePodAsync("pod1", "ns2", "", null, responseStep));

testSupport.verifyCompletionThrowable(FailureStatusSourceException.class);
Expand All @@ -394,7 +394,7 @@ public void whenHttpErrorAssociatedWithResource_callResponseIsError() {
public void whenHttpErrorNotAssociatedWithResource_ignoreIt() {
testSupport.failOnResource(POD, "pod1", "ns2", HTTP_BAD_REQUEST);

TestResponseStep<V1Pod> responseStep = new TestResponseStep<>();
TestResponseStep<Object> responseStep = new TestResponseStep<>();
testSupport.runSteps(new CallBuilder().deletePodAsync("pod2", "ns2", "", null, responseStep));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,10 @@ private Step.StepAndPacket createRollingStepAndPacket(String serverName) {
return new Step.StepAndPacket(DomainStatusUpdater.createProgressingStep(
DomainStatusUpdater.MANAGED_SERVERS_STARTING_PROGRESS_REASON,
false,
new ManagedPodStepContext(terminalStep, packet).createCyclePodStep(null)), packet);
new ManagedPodStepContext(terminalStep, packet).createCyclePodStep(
testSupport.getResourceWithName(
KubernetesTestSupport.POD,
LegalNames.toPodName(UID, serverName)), null)), packet);
}

private void initializeExistingPods() {
Expand Down