Skip to content

Commit

Permalink
Changes to check if the cached pod is not found on read then execute …
Browse files Browse the repository at this point in the history
…make-right domain.
  • Loading branch information
ankedia committed Jun 12, 2021
1 parent 70eab49 commit 4dbbe1c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 5 deletions.
Expand Up @@ -25,7 +25,9 @@
import io.kubernetes.client.util.Watchable;
import oracle.kubernetes.operator.TuningParameters.WatchTuning;
import oracle.kubernetes.operator.builders.WatchBuilder;
import oracle.kubernetes.operator.calls.CallResponse;
import oracle.kubernetes.operator.helpers.CallBuilder;
import oracle.kubernetes.operator.helpers.DomainPresenceInfo;
import oracle.kubernetes.operator.helpers.KubernetesUtils;
import oracle.kubernetes.operator.helpers.ResponseStep;
import oracle.kubernetes.operator.logging.LoggingFacade;
Expand Down Expand Up @@ -243,6 +245,11 @@ boolean isReady(V1Job job) {
return isComplete(job) || isFailed(job);
}

@Override
boolean onReadNotFoundForCachedPod(CallResponse callResponse, DomainPresenceInfo info, String serverName) {
return false;
}

// Ignore modified callbacks from different jobs (identified by having different creation times) or those
// where the job is not yet ready.
@Override
Expand Down
18 changes: 18 additions & 0 deletions operator/src/main/java/oracle/kubernetes/operator/PodWatcher.java
Expand Up @@ -28,7 +28,9 @@
import io.kubernetes.client.util.Watchable;
import oracle.kubernetes.operator.TuningParameters.WatchTuning;
import oracle.kubernetes.operator.builders.WatchBuilder;
import oracle.kubernetes.operator.calls.CallResponse;
import oracle.kubernetes.operator.helpers.CallBuilder;
import oracle.kubernetes.operator.helpers.DomainPresenceInfo;
import oracle.kubernetes.operator.helpers.KubernetesUtils;
import oracle.kubernetes.operator.helpers.LegalNames;
import oracle.kubernetes.operator.helpers.PodHelper;
Expand Down Expand Up @@ -360,13 +362,29 @@ protected void removeCallback(String podName, Consumer<V1Pod> callback) {
protected void logWaiting(String name) {
LOGGER.fine(MessageKeys.WAITING_FOR_POD_READY, name);
}

@Override
protected boolean onReadNotFoundForCachedPod(CallResponse callResponse,
DomainPresenceInfo info, String serverName) {
if ((info.getServerPod(serverName) != null) && callResponse.getResult() == null) {
// Initial resource is not null but live info is null.
return true;
}
return false;
}

}

private class WaitForPodDeleteStep extends WaitForPodStatusStep {
private WaitForPodDeleteStep(V1Pod pod, Step next) {
super(pod, next);
}

@Override
protected boolean onReadNotFoundForCachedPod(CallResponse callResponse, DomainPresenceInfo info, String name) {
return false;
}

// A pod is considered deleted when reading its value from Kubernetes returns null.
@Override
protected boolean isReady(V1Pod result) {
Expand Down
Expand Up @@ -23,6 +23,7 @@
import oracle.kubernetes.weblogic.domain.model.Domain;

import static oracle.kubernetes.operator.ProcessingConstants.MAKE_RIGHT_DOMAIN_OPERATION;
import static oracle.kubernetes.operator.ProcessingConstants.SERVER_NAME;
import static oracle.kubernetes.operator.helpers.KubernetesUtils.getDomainUidLabel;

/**
Expand Down Expand Up @@ -73,6 +74,8 @@ static int getWatchBackstopRecheckCount() {
*/
abstract boolean isReady(T resource);

abstract boolean onReadNotFoundForCachedPod(CallResponse callResponse, DomainPresenceInfo info, String serverName);

/**
* Returns true if the callback for this resource should be processed. This is typically used to exclude
* resources which have changed but are not yet ready, or else different instances with the same name.
Expand Down Expand Up @@ -209,12 +212,19 @@ private DefaultResponseStep<T> resumeIfReady(Callback callback) {
return new DefaultResponseStep<>(null) {
@Override
public NextAction onSuccess(Packet packet, CallResponse<T> callResponse) {

DomainPresenceInfo info = packet.getSpi(DomainPresenceInfo.class);
if ((callResponse != null) && (callResponse.getResult() instanceof V1Pod)) {
V1Pod pod = (V1Pod) callResponse.getResult();
Optional.ofNullable(info)
.ifPresent(i -> i.setServerPodFromEvent(getPodLabel(pod, LabelConstants.SERVERNAME_LABEL), pod));
if (callResponse != null) {
if (callResponse.getResult() instanceof V1Pod) {
Optional.ofNullable(info)
.ifPresent(i -> i.setServerPodFromEvent(getPodLabel((V1Pod) callResponse.getResult(),
LabelConstants.SERVERNAME_LABEL), (V1Pod) callResponse.getResult()));
}
if (isMakeRightNeeded(callResponse, info, (String)packet.get(SERVER_NAME)))
return doNext(new CallBuilder().readDomainAsync(info.getDomainUid(),
info.getNamespace(), new MakeRightDomainStep(callback, null)), packet);
}

if (isReady(callResponse.getResult()) || callback.didResume.get()) {
callback.proceedFromWait(callResponse.getResult());
Optional.ofNullable(info).ifPresent(i -> i.resetWatchBackstopRecheckCount());
Expand All @@ -231,6 +241,14 @@ public NextAction onSuccess(Packet packet, CallResponse<T> callResponse) {
}
}

private boolean isMakeRightNeeded(CallResponse<T> callResponse,
DomainPresenceInfo info, String name) {
if ((info != null) && onReadNotFoundForCachedPod(callResponse, info, name)) {
return true;
}
return false;
}

private boolean shouldWait(CallResponse<T> callResponse, DomainPresenceInfo info) {
return ((callResponse != null) && (callResponse.getResult() instanceof V1Job))
|| (info == null)
Expand Down Expand Up @@ -276,11 +294,13 @@ private class MakeRightDomainStep extends DefaultResponseStep {

@Override
public NextAction onSuccess(Packet packet, CallResponse callResponse) {
String name = initialResource == null ? resourceName : getMetadata(initialResource).getName();
MakeRightDomainOperation makeRightDomainOperation =
(MakeRightDomainOperation)packet.get(MAKE_RIGHT_DOMAIN_OPERATION);
makeRightDomainOperation.setLiveInfo(new DomainPresenceInfo((Domain)callResponse.getResult()));
callback.fiber.terminate(null, packet);
makeRightDomainOperation.withExplicitRecheck().interrupt().execute();
removeCallback(name, callback);
callback.fiber.terminate(null, packet);
return super.onSuccess(packet, callResponse);
}
}
Expand Down

0 comments on commit 4dbbe1c

Please sign in to comment.