Skip to content

Commit df093f4

Browse files
committed
Address review comments
1 parent 21719b5 commit df093f4

File tree

5 files changed

+62
-21
lines changed

5 files changed

+62
-21
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved.
1+
// Copyright 2018, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
22
// Licensed under the Universal Permissive License v 1.0 as shown at
33
// http://oss.oracle.com/licenses/upl.
44

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,61 @@
1010
import oracle.kubernetes.operator.work.FiberGate;
1111
import oracle.kubernetes.operator.work.Step;
1212

13+
/** A set of underlying services required during domain processing. */
1314
public interface DomainProcessorDelegate {
15+
/**
16+
* Returns the namespace associated with the operator itself.
17+
*
18+
* @return a namespace string
19+
*/
1420
String getOperatorNamespace();
1521

22+
/**
23+
* Returns a factory that creates a step to wait for a pod in the specified namespace to be ready.
24+
*
25+
* @param namespace the namespace for the pod
26+
* @return a step-creating factory
27+
*/
1628
PodAwaiterStepFactory getPodAwaiterStepFactory(String namespace);
1729

30+
/**
31+
* Returns true if the namespace is running.
32+
*
33+
* @param namespace the namespace to check
34+
* @return the 'running' state of the namespace
35+
*/
1836
boolean isNamespaceRunning(String namespace);
1937

38+
/**
39+
* Returns the version of the Kubernetes environment in which the operator is running
40+
*
41+
* @return an object that represents the Kubernetes version
42+
*/
2043
KubernetesVersion getVersion();
2144

45+
/**
46+
* Creates a new FiberGate.
47+
*
48+
* @return the created instance
49+
*/
2250
FiberGate createFiberGate();
2351

52+
/**
53+
* Runs a chain of steps
54+
*
55+
* @param firstStep the first step to run
56+
*/
2457
void runSteps(Step firstStep);
2558

59+
/**
60+
* Schedules the specified command to run periodically.
61+
*
62+
* @param command the command to run
63+
* @param initialDelay the number of time units to wait before running the command the first time
64+
* @param delay the number of time units to delay between successive runs
65+
* @param unit the time unit for the above delays
66+
* @return a future which indicates completion of the command
67+
*/
2668
ScheduledFuture<?> scheduleWithFixedDelay(
2769
Runnable command, long initialDelay, long delay, TimeUnit unit);
2870
}

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

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,10 @@ public void dispatchPodWatch(Watch.Response<V1Pod> item) {
141141
String domainUID = metadata.getLabels().get(LabelConstants.DOMAINUID_LABEL);
142142
String serverName = metadata.getLabels().get(LabelConstants.SERVERNAME_LABEL);
143143
if (domainUID != null && serverName != null) {
144-
DomainPresenceInfo existing =
145-
getExistingDomainPresenceInfo(metadata.getNamespace(), domainUID);
146-
if (existing != null) {
144+
DomainPresenceInfo info = getExistingDomainPresenceInfo(metadata.getNamespace(), domainUID);
145+
if (info != null) {
147146
ServerKubernetesObjects sko =
148-
existing.getServers().computeIfAbsent(serverName, k -> new ServerKubernetesObjects());
147+
info.getServers().computeIfAbsent(serverName, k -> new ServerKubernetesObjects());
149148
switch (item.type) {
150149
case "ADDED":
151150
sko.getPod()
@@ -194,11 +193,11 @@ public void dispatchPodWatch(Watch.Response<V1Pod> item) {
194193
}
195194
return current;
196195
});
197-
if (oldPod != null && !existing.isDeleting()) {
196+
if (oldPod != null && info.isNotDeleting()) {
198197
// Pod was deleted, but sko still contained a non-null entry
199198
LOGGER.info(
200199
MessageKeys.POD_DELETED, domainUID, metadata.getNamespace(), serverName);
201-
makeRightDomainPresence(existing, true, false, true);
200+
makeRightDomainPresence(info, true, false, true);
202201
}
203202
break;
204203

@@ -215,19 +214,18 @@ public void dispatchServiceWatch(Watch.Response<V1Service> item) {
215214
String domainUID = ServiceHelper.getServiceDomainUID(service);
216215
if (domainUID == null) return;
217216

218-
DomainPresenceInfo domainPresenceInfo =
217+
DomainPresenceInfo info =
219218
getExistingDomainPresenceInfo(service.getMetadata().getNamespace(), domainUID);
220-
if (domainPresenceInfo == null) return;
219+
if (info == null) return;
221220

222221
switch (item.type) {
223222
case "ADDED":
224223
case "MODIFIED":
225-
ServiceHelper.updatePresenceFromEvent(domainPresenceInfo, item.object);
224+
ServiceHelper.updatePresenceFromEvent(info, item.object);
226225
break;
227226
case "DELETED":
228-
boolean removed = ServiceHelper.deleteFromEvent(domainPresenceInfo, item.object);
229-
if (removed && !domainPresenceInfo.isDeleting())
230-
makeRightDomainPresence(domainPresenceInfo, true, false, true);
227+
boolean removed = ServiceHelper.deleteFromEvent(info, item.object);
228+
if (removed && info.isNotDeleting()) makeRightDomainPresence(info, true, false, true);
231229
break;
232230
default:
233231
}
@@ -483,7 +481,7 @@ private class StartPlanStep extends Step {
483481
public NextAction apply(Packet packet) {
484482
registerDomainPresenceInfo(info);
485483
Step strategy = getNext();
486-
if (!info.isPopulated() && !info.isDeleting()) {
484+
if (!info.isPopulated() && info.isNotDeleting()) {
487485
strategy = Step.chain(readExistingPods(info), readExistingServices(info), strategy);
488486
}
489487
return doNext(strategy, packet);

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved.
1+
// Copyright 2018, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
22
// Licensed under the Universal Permissive License v 1.0 as shown at
33
// http://oss.oracle.com/licenses/upl.
44

@@ -18,6 +18,7 @@
1818
import java.util.concurrent.ThreadFactory;
1919
import java.util.concurrent.atomic.AtomicBoolean;
2020
import java.util.function.Function;
21+
import javax.annotation.Nonnull;
2122
import oracle.kubernetes.operator.TuningParameters.WatchTuning;
2223
import oracle.kubernetes.operator.builders.WatchBuilder;
2324
import oracle.kubernetes.operator.builders.WatchI;
@@ -45,16 +46,16 @@ public class JobWatcher extends Watcher<V1Job> implements WatchListener<V1Job> {
4546
new ConcurrentHashMap<>();
4647

4748
/**
48-
* If a JobWatcher has already been created, returns it.
49+
* Returns a cached JobWatcher, if present; otherwise, creates a new one.
4950
*
5051
* @param domain the domain for which the job watcher is to be returned
51-
* @return a cached jobwatcher, or null.
52+
* @return a cached jobwatcher.
5253
*/
53-
public static JobWatcher getOrCreateFor(Domain domain) {
54+
public static @Nonnull JobWatcher getOrCreateFor(Domain domain) {
5455
return JOB_WATCHERS.computeIfAbsent(getNamespace(domain), n -> factory.createFor(domain));
5556
}
5657

57-
static String getNamespace(Domain domain) {
58+
private static String getNamespace(Domain domain) {
5859
return domain.getMetadata().getNamespace();
5960
}
6061

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ boolean deleteExternalServiceFromEvent(String serverName, V1Service event) {
174174
return deletedService != null;
175175
}
176176

177-
public boolean isDeleting() {
178-
return isDeleting.get();
177+
public boolean isNotDeleting() {
178+
return !isDeleting.get();
179179
}
180180

181181
public void setDeleting(boolean deleting) {

0 commit comments

Comments
 (0)