Skip to content

Commit 25bc01e

Browse files
committed
Merge branch 'develop' of https://github.com/oracle/weblogic-kubernetes-operator into develop-acao
pull
2 parents 5a0fade + 0256d80 commit 25bc01e

File tree

11 files changed

+177
-115
lines changed

11 files changed

+177
-115
lines changed

operator/src/main/java/oracle/kubernetes/operator/DomainProcessorImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,14 @@ public void dispatchPodWatch(Watch.Response<V1Pod> item) {
147147
if (info != null) {
148148
switch (item.type) {
149149
case "ADDED":
150+
info.setServerPodBeingDeleted(serverName, Boolean.FALSE);
151+
// fall through
150152
case "MODIFIED":
151153
info.setServerPodFromEvent(serverName, pod);
152154
break;
153155
case "DELETED":
154156
boolean removed = info.deleteServerPodFromEvent(serverName, pod);
155-
if (removed && info.isNotDeleting()) {
157+
if (removed && info.isNotDeleting() && !info.isServerPodBeingDeleted(serverName)) {
156158
LOGGER.info(
157159
MessageKeys.POD_DELETED, domainUID, metadata.getNamespace(), serverName);
158160
makeRightDomainPresence(info, true, false, true);

operator/src/main/java/oracle/kubernetes/operator/PodWatcher.java

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
import io.kubernetes.client.models.V1ObjectMeta;
99
import io.kubernetes.client.models.V1Pod;
1010
import io.kubernetes.client.util.Watch;
11+
import java.util.ArrayList;
12+
import java.util.Collection;
13+
import java.util.HashMap;
1114
import java.util.List;
1215
import java.util.Map;
13-
import java.util.concurrent.ConcurrentHashMap;
14-
import java.util.concurrent.ConcurrentMap;
1516
import java.util.concurrent.ThreadFactory;
1617
import java.util.concurrent.atomic.AtomicBoolean;
1718
import oracle.kubernetes.operator.TuningParameters.WatchTuning;
@@ -39,8 +40,24 @@ public class PodWatcher extends Watcher<V1Pod>
3940
private final WatchListener<V1Pod> listener;
4041

4142
// Map of Pod name to OnReady
42-
private final ConcurrentMap<String, OnReady> readyCallbackRegistrations =
43-
new ConcurrentHashMap<>();
43+
private final Map<String, Collection<OnReady>> readyCallbackRegistrations = new HashMap<>();
44+
45+
private void registerOnReady(String podName, OnReady onReady) {
46+
synchronized (readyCallbackRegistrations) {
47+
Collection<OnReady> col = readyCallbackRegistrations.get(podName);
48+
if (col == null) {
49+
col = new ArrayList<>();
50+
readyCallbackRegistrations.put(podName, col);
51+
}
52+
col.add(onReady);
53+
}
54+
}
55+
56+
private Collection<OnReady> retrieveOnReady(String podName) {
57+
synchronized (readyCallbackRegistrations) {
58+
return readyCallbackRegistrations.remove(podName);
59+
}
60+
}
4461

4562
/**
4663
* Factory for PodWatcher.
@@ -96,9 +113,11 @@ public void receivedResponse(Watch.Response<V1Pod> item) {
96113
Boolean isReady = !PodHelper.isDeleting(pod) && PodHelper.isReady(pod);
97114
String podName = pod.getMetadata().getName();
98115
if (isReady) {
99-
OnReady ready = readyCallbackRegistrations.remove(podName);
100-
if (ready != null) {
101-
ready.onReady();
116+
Collection<OnReady> col = retrieveOnReady(podName);
117+
if (col != null) {
118+
for (OnReady ready : col) {
119+
ready.onReady();
120+
}
102121
}
103122
}
104123
break;
@@ -148,7 +167,7 @@ public NextAction apply(Packet packet) {
148167
fiber.resume(packet);
149168
}
150169
};
151-
readyCallbackRegistrations.put(metadata.getName(), ready);
170+
registerOnReady(metadata.getName(), ready);
152171

153172
// Timing window -- pod may have come ready before registration for callback
154173
CallBuilderFactory factory =

operator/src/main/java/oracle/kubernetes/operator/Watcher.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ private void watchForEvents() {
143143
new WatchBuilder()
144144
.withResourceVersion(resourceVersion.toString())
145145
.withTimeoutSeconds(tuning.watchLifetime))) {
146-
while (watch.hasNext()) {
146+
while (hasNext(watch)) {
147147
Watch.Response<T> item = watch.next();
148148

149149
if (isStopping()) {
@@ -164,6 +164,15 @@ private void watchForEvents() {
164164
}
165165
}
166166

167+
private boolean hasNext(WatchI<T> watch) {
168+
try {
169+
return watch.hasNext();
170+
} catch (Throwable ex) {
171+
// no-op on exception during hasNext
172+
}
173+
return false;
174+
}
175+
167176
/**
168177
* Initiates a watch by using the watch builder to request any updates for the specified watcher.
169178
*

operator/src/main/java/oracle/kubernetes/operator/calls/AsyncRequestStep.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public void onSuccess(
190190
try {
191191
cc.cancel();
192192
} finally {
193-
LOGGER.info(
193+
LOGGER.fine(
194194
MessageKeys.ASYNC_TIMEOUT,
195195
requestParams.call,
196196
requestParams.namespace,

operator/src/main/java/oracle/kubernetes/operator/helpers/DomainPresenceInfo.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,18 @@ private V1Pod getPod(ServerKubernetesObjects sko) {
122122
return sko.getPod().get();
123123
}
124124

125+
private Boolean getPodIsBeingDeleted(ServerKubernetesObjects sko) {
126+
return sko.isPodBeingDeleted().get();
127+
}
128+
129+
public Boolean isServerPodBeingDeleted(String serverName) {
130+
return getPodIsBeingDeleted(getSko(serverName));
131+
}
132+
133+
public void setServerPodBeingDeleted(String serverName, Boolean isBeingDeleted) {
134+
getSko(serverName).isPodBeingDeleted().set(isBeingDeleted);
135+
}
136+
125137
/**
126138
* Returns a collection of all servers defined.
127139
*

operator/src/main/java/oracle/kubernetes/operator/helpers/PodStepContext.java

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,21 @@ private Step getConflictStep() {
103103

104104
abstract Map<String, String> getPodAnnotations();
105105

106-
private class ConflictStep extends Step {
106+
private abstract class BaseStep extends Step {
107+
BaseStep() {
108+
this(null);
109+
}
110+
111+
BaseStep(Step next) {
112+
super(next);
113+
}
114+
115+
protected String getDetail() {
116+
return getServerName();
117+
}
118+
}
119+
120+
private class ConflictStep extends BaseStep {
107121

108122
@Override
109123
public NextAction apply(Packet packet) {
@@ -225,8 +239,12 @@ private List<V1ContainerPort> getContainerPorts() {
225239
// ----------------------- step methods ------------------------------
226240

227241
// Prevent the watcher from recreating pod with old spec
228-
private void clearRecord() {
229-
setRecordedPod(null);
242+
private void markBeingDeleted() {
243+
info.setServerPodBeingDeleted(getServerName(), Boolean.TRUE);
244+
}
245+
246+
private void clearBeingDeleted() {
247+
info.setServerPodBeingDeleted(getServerName(), Boolean.FALSE);
230248
}
231249

232250
private void setRecordedPod(V1Pod pod) {
@@ -269,6 +287,7 @@ private Step deletePod(Step next) {
269287
* @return a step to be scheduled.
270288
*/
271289
Step createPod(Step next) {
290+
clearBeingDeleted();
272291
return createPodAsync(createResponse(next));
273292
}
274293

@@ -337,15 +356,15 @@ Step createCyclePodStep(Step next) {
337356
return new CyclePodStep(next);
338357
}
339358

340-
private class CyclePodStep extends Step {
359+
private class CyclePodStep extends BaseStep {
341360

342361
CyclePodStep(Step next) {
343362
super(next);
344363
}
345364

346365
@Override
347366
public NextAction apply(Packet packet) {
348-
clearRecord();
367+
markBeingDeleted();
349368
return doNext(deletePod(getNext()), packet);
350369
}
351370
}
@@ -373,7 +392,7 @@ private String getReasonToRecycle(V1Pod currentPod) {
373392
return compatibility.getIncompatibility();
374393
}
375394

376-
private class VerifyPodStep extends Step {
395+
private class VerifyPodStep extends BaseStep {
377396

378397
VerifyPodStep(Step next) {
379398
super(next);
@@ -399,11 +418,21 @@ public NextAction apply(Packet packet) {
399418
}
400419
}
401420

421+
private abstract class BaseResponseStep extends ResponseStep<V1Pod> {
422+
BaseResponseStep(Step next) {
423+
super(next);
424+
}
425+
426+
protected String getDetail() {
427+
return getServerName();
428+
}
429+
}
430+
402431
private ResponseStep<V1Pod> createResponse(Step next) {
403432
return new CreateResponseStep(next);
404433
}
405434

406-
private class CreateResponseStep extends ResponseStep<V1Pod> {
435+
private class CreateResponseStep extends BaseResponseStep {
407436
CreateResponseStep(Step next) {
408437
super(next);
409438
}
@@ -433,6 +462,10 @@ private class DeleteResponseStep extends ResponseStep<V1Status> {
433462
super(next);
434463
}
435464

465+
protected String getDetail() {
466+
return getServerName();
467+
}
468+
436469
@Override
437470
public NextAction onFailure(Packet packet, CallResponse<V1Status> callResponses) {
438471
if (callResponses.getStatusCode() == CallBuilder.NOT_FOUND) {
@@ -451,12 +484,10 @@ private ResponseStep<V1Pod> replaceResponse(Step next) {
451484
return new ReplacePodResponseStep(next);
452485
}
453486

454-
private class ReplacePodResponseStep extends ResponseStep<V1Pod> {
455-
private final Step next;
487+
private class ReplacePodResponseStep extends BaseResponseStep {
456488

457489
ReplacePodResponseStep(Step next) {
458490
super(next);
459-
this.next = next;
460491
}
461492

462493
@Override
@@ -473,15 +504,16 @@ public NextAction onSuccess(Packet packet, CallResponse<V1Pod> callResponse) {
473504
setRecordedPod(newPod);
474505
}
475506

476-
return doNext(next, packet);
507+
PodAwaiterStepFactory pw = packet.getSPI(PodAwaiterStepFactory.class);
508+
return doNext(pw.waitForReady(newPod, getNext()), packet);
477509
}
478510
}
479511

480512
private ResponseStep<V1Pod> patchResponse(Step next) {
481513
return new PatchPodResponseStep(next);
482514
}
483515

484-
private class PatchPodResponseStep extends ResponseStep<V1Pod> {
516+
private class PatchPodResponseStep extends BaseResponseStep {
485517
private final Step next;
486518

487519
PatchPodResponseStep(Step next) {

0 commit comments

Comments
 (0)