8000 OWLS-87753 - Fix to start all managed server pods when watch event notifications not received in jumbo k8s cluster by ankedia · Pull Request #2188 · oracle/weblogic-kubernetes-operator · GitHub
[go: up one dir, main page]

Skip to content

OWLS-87753 - Fix to start all managed server pods when watch event notifications not received in jumbo k8s cluster #2188

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
Feb 11, 2021
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 @@ -16,6 +16,15 @@ public interface PodAwaiterStepFactory {
*/
Step waitForReady(V1Pod pod, Step next);

/**
* Waits until the Pod with given name is Ready.
*
* @param podName Name of the Pod to watch
* @param next Next processing step once Pod is ready
* @return Asynchronous step
*/
Step waitForReady(String podName, Step next);

/**
* Waits until the Pod is deleted.
*
Expand Down
19 changes: 19 additions & 0 deletions operator/src/main/java/oracle/kubernetes/operator/PodWatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,17 @@ public Step waitForReady(V1Pod pod, Step next) {
return new WaitForPodReadyStep(pod, next);
}

/**
* Waits until the Pod with given name is Ready.
*
* @param podName Name of the Pod to watch
* @param next Next processing step once Pod is ready
* @return Asynchronous step
*/
public Step waitForReady(String podName, Step next) {
return new WaitForPodReadyStep(podName, next);
}

/**
* Waits until the Pod is deleted.
*
Expand All @@ -295,6 +306,10 @@ private WaitForPodStatusStep(V1Pod pod, Step next) {
super(pod, next);
}

private WaitForPodStatusStep(String podName, Step next) {
super(podName, null, next);
}

@Override
V1ObjectMeta getMetadata(V1Pod pod) {
return pod.getMetadata();
Expand All @@ -312,6 +327,10 @@ private WaitForPodReadyStep(V1Pod pod, Step next) {
super(pod, next);
}

private WaitForPodReadyStep(String podName, Step next) {
super(podName, next);
}

// A pod is ready if it is not being deleted and has the ready status.
@Override
protected boolean isReady(V1Pod result) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import java.util.function.Consumer;

import io.kubernetes.client.openapi.models.V1ObjectMeta;
import io.kubernetes.client.openapi.models.V1Pod;
import oracle.kubernetes.operator.calls.CallResponse;
import oracle.kubernetes.operator.helpers.DomainPresenceInfo;
import oracle.kubernetes.operator.helpers.ResponseStep;
import oracle.kubernetes.operator.steps.DefaultResponseStep;
import oracle.kubernetes.operator.work.AsyncFiber;
Expand All @@ -35,15 +37,21 @@ static int getWatchBackstopRecheckDelaySeconds() {
}

private final T initialResource;
private final String resourceName;

/**
* Creates a step which will only proceed once the specified resource is ready.
* @param resource the resource to watch
* @param next the step to run once it the resource is ready
*/
WaitForReadyStep(T resource, Step next) {
this(null, resource, next);
}

WaitForReadyStep(String resourceName, T resource, Step next) {
super(next);
this.initialResource = resource;
this.resourceName = resourceName;
}

/**
Expand Down Expand Up @@ -166,7 +174,11 @@ private void checkUpdatedResource(Packet packet, AsyncFiber fiber, Callback call
}

private Step createReadAndIfReadyCheckStep(Callback callback) {
return createReadAsyncStep(getName(), getNamespace(), getDomainUid(), resumeIfReady(callback));
if (initialResource != null) {
return createReadAsyncStep(getName(), getNamespace(), getDomainUid(), resumeIfReady(callback));
} else {
return new ReadAndIfReadyCheckStep(getName(), callback, getNext());
}
}

private String getNamespace() {
Expand All @@ -178,23 +190,55 @@ private String getDomainUid() {
}

public String getName() {
return getMetadata(initialResource).getName();
return initialResource != null ? getMetadata(initialResource).getName() : resourceName;
}

private DefaultResponseStep<T> resumeIfReady(Callback callback) {
return new DefaultResponseStep<>(null) {
@Override
public NextAction onSuccess(Packet packet, CallResponse<T> callResponse) {
if ((callResponse != null) && (callResponse.getResult() instanceof V1Pod)) {
V1Pod pod = (V1Pod) callResponse.getResult();
Optional.ofNullable(packet.getSpi(DomainPresenceInfo.class))
.ifPresent(i -> i.setServerPodFromEvent(getPodLabel(pod, LabelConstants.SERVERNAME_LABEL), pod));
}
if (isReady(callResponse.getResult())) {
callback.proceedFromWait(callResponse.getResult());
return doNext(packet);
}
return doDelay(createReadAndIfReadyCheckStep(callback), packet,
getWatchBackstopRecheckDelaySeconds(), TimeUnit.SECONDS);
}

private String getPodLabel(V1Pod pod, String labelName) {
return Optional.ofNullable(pod)
.map(V1Pod::getMetadata)
.map(V1ObjectMeta::getLabels)
.map(m -> m.get(labelName))
.orElse(null);
}
};
}

private class ReadAndIfReadyCheckStep extends Step {
private final Callback callback;
private final String resourceName;

ReadAndIfReadyCheckStep(String resourceName, Callback callback, Step next) {
super(next);
this.callback = callback;
this.resourceName = resourceName;
}

@Override
public NextAction apply(Packet packet) {
DomainPresenceInfo info = packet.getSpi(DomainPresenceInfo.class);
return doNext(createReadAsyncStep(resourceName, info.getNamespace(),
info.getDomainUid(), resumeIfReady(callback)), packet);
}

}

private class Callback implements Consumer<T> {
private final AsyncFiber fiber;
private final Packet packet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Queue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
Expand All @@ -17,9 +18,11 @@
import java.util.stream.Collectors;

import oracle.kubernetes.operator.DomainStatusUpdater;
import oracle.kubernetes.operator.PodAwaiterStepFactory;
import oracle.kubernetes.operator.ProcessingConstants;
import oracle.kubernetes.operator.helpers.DomainPresenceInfo;
import oracle.kubernetes.operator.helpers.DomainPresenceInfo.ServerStartupInfo;
import oracle.kubernetes.operator.helpers.LegalNames;
import oracle.kubernetes.operator.helpers.PodHelper;
import oracle.kubernetes.operator.helpers.ServiceHelper;
import oracle.kubernetes.operator.logging.LoggingFacade;
Expand Down Expand Up @@ -93,6 +96,11 @@ public NextAction apply(Packet packet) {
entry.getValue().getServerStartsStepAndPackets(), null), packet.clone()));
}

Collection<StepAndPacket> startupWaiters =
startupInfos.stream()
.map(ssi -> createManagedServerUpWaiters(packet, ssi)).collect(Collectors.toList());
work.addAll(startupWaiters);

if (!work.isEmpty()) {
return doForkJoin(DomainStatusUpdater.createStatusUpdateStep(
new ManagedServerUpAfterStep(getNext())), packet, work);
Expand All @@ -115,6 +123,17 @@ private StepAndPacket createManagedServerUpDetails(Packet packet, ServerStartupI
createPacketForServer(packet, ssi));
}

private StepAndPacket createManagedServerUpWaiters(Packet packet, ServerStartupInfo ssi) {
String podName = getPodName(packet.getSpi(DomainPresenceInfo.class), ssi.getServerName());
return new StepAndPacket(Optional.ofNullable(packet.getSpi(PodAwaiterStepFactory.class))
.map(p -> p.waitForReady(podName, null)).orElse(null),
createPacketForServer(pac 23D3 ket, ssi));
}

String getPodName(DomainPresenceInfo info, String serverName) {
return LegalNames.toPodName(info.getDomainUid(), serverName);
}

private Packet createPacketForServer(Packet packet, ServerStartupInfo ssi) {
Packet p = packet.clone();
p.put(ProcessingConstants.CLUSTER_NAME, ssi.getClusterName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ public Step waitForReady(V1Pod pod, Step next) {
return next;
}

@Override
public Step waitForReady(String podName, Step next) {
return next;
}

@Override
public Step waitForDelete(V1Pod pod, Step next) {
return next;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ public Step waitForReady(V1Pod pod, Step next) {
return null;
}

@Override
public Step waitForReady(String podName, Step next) {
return null;
}

@Override
public Step waitForDelete(V1Pod pod, Step next) {
return null;
Expand Down
Original file line number Diff line number Diff line change
8093 Expand Up @@ -1466,6 +1466,11 @@ public Step waitForReady(V1Pod pod, Step next) {
return next;
}

@Override
public Step waitForReady(String podName, Step next) {
return next;
}

@Override
public Step waitForDelete(V1Pod pod, Step next) {
return next;
Expand All @@ -1484,6 +1489,11 @@ public Step waitForReady(V1Pod pod, Step next) {
return new DelayStep(next, delaySeconds);
}

@Override
public Step waitForReady(String podName, Step next) {
return new DelayStep(next, delaySeconds);
}

@Override
public Step waitForDelete(V1Pod pod, Step next) {
return new DelayStep(next, delaySeconds);
Expand Down
0