Skip to content

Commit 6a19717

Browse files
committed
Backport OWLS-82320 namespace error
1 parent 1f8ba6a commit 6a19717

File tree

3 files changed

+66
-10
lines changed

3 files changed

+66
-10
lines changed

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

Lines changed: 64 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.util.Collection;
1313
import java.util.Collections;
1414
import java.util.HashSet;
15+
import java.util.List;
1516
import java.util.Map;
1617
import java.util.Optional;
1718
import java.util.Properties;
@@ -208,11 +209,12 @@ private static void begin() {
208209

209210
Step strategy = Step.chain(
210211
new InitializeNamespacesSecurityStep(targetNamespaces),
211-
new NamespaceRulesReviewStep(),
212-
CrdHelper.createDomainCrdStep(version,
213-
new StartNamespacesStep(targetNamespaces, false)));
212+
new NamespaceRulesReviewStep());
214213
if (!isDedicated()) {
215-
strategy = Step.chain(strategy, readExistingNamespaces());
214+
strategy = Step.chain(strategy, readExistingNamespaces(targetNamespaces));
215+
} else {
216+
strategy = Step.chain(strategy, CrdHelper.createDomainCrdStep(version,
217+
new StartNamespacesStep(targetNamespaces, false)));
216218
}
217219
runSteps(
218220
strategy,
@@ -360,8 +362,8 @@ private static Step readExistingPods(String ns) {
360362
.listPodAsync(ns, new PodListStep(ns));
361363
}
362364

363-
private static Step readExistingNamespaces() {
364-
return new CallBuilder().listNamespaceAsync(new NamespaceListStep());
365+
private static Step readExistingNamespaces(Collection<String> targetNamespaces) {
366+
return new CallBuilder().listNamespaceAsync(new NamespaceListStep(targetNamespaces));
365367
}
366368

367369
private static ConfigMapAfterStep createConfigMapStep(String ns) {
@@ -865,6 +867,12 @@ private String getInitialResourceVersion(V1PodList result) {
865867
}
866868

867869
private static class NamespaceListStep extends ResponseStep<V1NamespaceList> {
870+
private final Collection<String> targetNamespaces;
871+
872+
NamespaceListStep(Collection<String> targetNamespaces) {
873+
this.targetNamespaces = targetNamespaces;
874+
}
875+
868876
@Override
869877
public NextAction onFailure(Packet packet, CallResponse<V1NamespaceList> callResponse) {
870878
return callResponse.getStatusCode() == CallBuilder.NOT_FOUND
@@ -875,23 +883,69 @@ public NextAction onFailure(Packet packet, CallResponse<V1NamespaceList> callRes
875883
@Override
876884
protected NextAction onFailureNoRetry(Packet packet, CallResponse<V1NamespaceList> callResponse) {
877885
return isNotAuthorizedOrForbidden(callResponse)
878-
? doNext(packet) : super.onFailureNoRetry(packet, callResponse);
886+
? doNext(createDomainCrdAndStartNamespaces(targetNamespaces), packet) :
887+
super.onFailureNoRetry(packet, callResponse);
879888
}
880889

881890
@Override
882891
public NextAction onSuccess(Packet packet, CallResponse<V1NamespaceList> callResponse) {
883892
V1NamespaceList result = callResponse.getResult();
884893
// don't bother processing pre-existing events
894+
String intialResourceVersion = getInitialResourceVersion(result);
895+
List<String> nsList = getExistingNamespaces(result);
885896

886-
if (namespaceWatcher == null) {
887-
namespaceWatcher = createNamespaceWatcher(getInitialResourceVersion(result));
897+
Set<String> namespacesToStart = new TreeSet<>(targetNamespaces);
898+
for (String ns : targetNamespaces) {
899+
if (!nsList.contains(ns)) {
900+
LOGGER.warning(MessageKeys.NAMESPACE_IS_MISSING, ns);
901+
namespacesToStart.remove(ns);
902+
}
888903
}
889-
return doNext(packet);
904+
Step strategy = null;
905+
if (!namespacesToStart.isEmpty()) {
906+
strategy = Step.chain(createDomainCrdAndStartNamespaces(namespacesToStart),
907+
new CreateNamespaceWatcherStep(intialResourceVersion));
908+
} else {
909+
strategy = CrdHelper.createDomainCrdStep(version,
910+
new CreateNamespaceWatcherStep(intialResourceVersion));
911+
}
912+
return doNext(strategy, packet);
913+
}
914+
915+
private Step createDomainCrdAndStartNamespaces(Collection<String> namespacesToStart) {
916+
return CrdHelper.createDomainCrdStep(version,
917+
new StartNamespacesStep(namespacesToStart, false));
890918
}
891919

892920
private String getInitialResourceVersion(V1NamespaceList result) {
893921
return result != null ? result.getMetadata().getResourceVersion() : "";
894922
}
923+
924+
private List<String> getExistingNamespaces(V1NamespaceList result) {
925+
List<String> namespaces = new ArrayList<>();
926+
if (result != null) {
927+
for (V1Namespace ns:result.getItems()) {
928+
namespaces.add(ns.getMetadata().getName());
929+
}
930+
}
931+
return namespaces;
932+
}
933+
}
934+
935+
private static class CreateNamespaceWatcherStep extends Step {
936+
private final String initialResourceVersion;
937+
938+
CreateNamespaceWatcherStep(String initialResourceVersion) {
939+
this.initialResourceVersion = initialResourceVersion;
940+
}
941+
942+
@Override
943+
public NextAction apply(Packet packet) {
944+
if (namespaceWatcher == null) {
945+
namespaceWatcher = createNamespaceWatcher(initialResourceVersion);
946+
}
947+
return doNext(packet);
948+
}
895949
}
896950

897951
private static class NullCompletionCallback implements CompletionCallback {

operator/src/main/java/oracle/kubernetes/operator/logging/MessageKeys.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ public class MessageKeys {
127127
public static final String CALL_FAILED = "WLSKO-0168";
128128
public static final String JOB_CREATION_TIMESTAMP_MESSAGE = "WLSKO-0169";
129129
public static final String HTTP_REQUEST_TIMED_OUT = "WLSKO-0170";
130+
public static final String NAMESPACE_IS_MISSING = "WLSKO-0171";
130131

131132
// domain status messages
132133
public static final String DUPLICATE_SERVER_NAME_FOUND = "WLSDO-0001";

operator/src/main/resources/Operator.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ WLSKO-0167=with {0}
171171
WLSKO-0168={0}: {1}
172172
WLSKO-0169=Job {0} is created at {1}
173173
WLSKO-0170=HTTP timeout: exception {0}.
174+
WLSKO-0171=Namespace {0} is in operator's target namespaces list but doesn't exist
174175

175176
# Domain status messages
176177

0 commit comments

Comments
 (0)