Skip to content

Commit 5efcac0

Browse files
authored
Merge pull request #186 from oracle/fix-domain-cm-labels
Replace the domainUID="" label on the per-domain operator config map with an operatorName="<operatornamespace>" label
2 parents 7abfb77 + e4bcb56 commit 5efcac0

File tree

3 files changed

+33
-29
lines changed

3 files changed

+33
-29
lines changed

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

+11-6
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,7 @@ public static void main(String[] args) {
169169

170170
private static void begin() {
171171
// read the operator configuration
172-
String namespace = System.getenv("OPERATOR_NAMESPACE");
173-
if (namespace == null) {
174-
namespace = "default";
175-
}
172+
String namespace = getOperatorNamespace();
176173

177174
Collection<String> targetNamespaces = getTargetNamespaces(namespace);
178175

@@ -245,7 +242,7 @@ public NextAction onSuccess(Packet packet, DomainList result, int statusCode,
245242
}
246243
});
247244

248-
Step initialize = ConfigMapHelper.createScriptConfigMapStep(ns,
245+
Step initialize = ConfigMapHelper.createScriptConfigMapStep(namespace, ns,
249246
new ConfigMapAfterStep(ns, callBuilderFactory.create().with($ -> {
250247
$.labelSelector = LabelConstants.DOMAINUID_LABEL + "," + LabelConstants.CREATEDBYOPERATOR_LABEL;
251248
}).listPodAsync(ns, new ResponseStep<V1PodList>(callBuilderFactory.create().with($ -> {
@@ -1791,7 +1788,7 @@ private static void dispatchConfigMapWatch(Watch.Response<V1ConfigMap> item) {
17911788
switch (item.type) {
17921789
case "MODIFIED":
17931790
case "DELETED":
1794-
engine.createFiber().start(ConfigMapHelper.createScriptConfigMapStep(c.getMetadata().getNamespace(), null),
1791+
engine.createFiber().start(ConfigMapHelper.createScriptConfigMapStep(getOperatorNamespace(), c.getMetadata().getNamespace(), null),
17951792
new Packet(), new CompletionCallback() {
17961793
@Override
17971794
public void onCompletion(Packet packet) {
@@ -1919,4 +1916,12 @@ public static Collection<NetworkAccessPoint> adminChannelsToCreate(WlsDomainConf
19191916
LOGGER.exiting();
19201917
return validatedChannels;
19211918
}
1919+
1920+
private static String getOperatorNamespace() {
1921+
String namespace = System.getenv("OPERATOR_NAMESPACE");
1922+
if (namespace == null) {
1923+
namespace = "default";
1924+
}
1925+
return namespace;
1926+
}
19221927
}

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

+17-19
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,31 @@ private ConfigMapHelper() {}
2929

3030
/**
3131
* Factory for {@link Step} that creates config map containing scripts
32-
* @param namespace Namespace
32+
* @param operatorNamespace the operator's namespace
33+
* @param domainNamespace the domain's namespace
3334
* @param next Next processing step
3435
* @return Step for creating config map containing scripts
3536
*/
36-
public static Step createScriptConfigMapStep(String namespace, Step next) {
37-
return new ScriptConfigMapStep(namespace, next);
37+
public static Step createScriptConfigMapStep(String operatorNamespace, String domainNamespace, Step next) {
38+
return new ScriptConfigMapStep(operatorNamespace, domainNamespace, next);
3839
}
3940

4041
// Make this public so that it can be unit tested
4142
public static class ScriptConfigMapStep extends Step {
42-
private final String namespace;
43+
private final String operatorNamespace;
44+
private final String domainNamespace;
4345

44-
public ScriptConfigMapStep(String namespace, Step next) {
46+
public ScriptConfigMapStep(String operatorNamespace, String domainNamespace, Step next) {
4547
super(next);
46-
this.namespace = namespace;
48+
this.operatorNamespace = operatorNamespace;
49+
this.domainNamespace = domainNamespace;
4750
}
4851

4952
@Override
5053
public NextAction apply(Packet packet) {
5154
V1ConfigMap cm = computeDomainConfigMap();
5255
CallBuilderFactory factory = ContainerResolver.getInstance().getContainer().getSPI(CallBuilderFactory.class);
53-
Step read = factory.create().readConfigMapAsync(cm.getMetadata().getName(), namespace, new ResponseStep<V1ConfigMap>(next) {
56+
Step read = factory.create().readConfigMapAsync(cm.getMetadata().getName(), domainNamespace, new ResponseStep<V1ConfigMap>(next) {
5457
@Override
5558
public NextAction onFailure(Packet packet, ApiException e, int statusCode,
5659
Map<String, List<String>> responseHeaders) {
@@ -64,7 +67,7 @@ public NextAction onFailure(Packet packet, ApiException e, int statusCode,
6467
public NextAction onSuccess(Packet packet, V1ConfigMap result, int statusCode,
6568
Map<String, List<String>> responseHeaders) {
6669
if (result == null) {
67-
Step create = factory.create().createConfigMapAsync(namespace, cm, new ResponseStep<V1ConfigMap>(next) {
70+
Step create = factory.create().createConfigMapAsync(domainNamespace, cm, new ResponseStep<V1ConfigMap>(next) {
6871
@Override
6972
public NextAction onFailure(Packet packet, ApiException e, int statusCode,
7073
Map<String, List<String>> responseHeaders) {
@@ -75,23 +78,23 @@ public NextAction onFailure(Packet packet, ApiException e, int statusCode,
7578
public NextAction onSuccess(Packet packet, V1ConfigMap result, int statusCode,
7679
Map<String, List<String>> responseHeaders) {
7780

78-
LOGGER.info(MessageKeys.CM_CREATED, namespace);
81+
LOGGER.info(MessageKeys.CM_CREATED, domainNamespace);
7982
packet.put(ProcessingConstants.SCRIPT_CONFIG_MAP, result);
8083
return doNext(packet);
8184
}
8285
});
8386
return doNext(create, packet);
8487
} else if (AnnotationHelper.checkFormatAnnotation(result.getMetadata()) && result.getData().entrySet().containsAll(cm.getData().entrySet())) {
8588
// existing config map has correct data
86-
LOGGER.fine(MessageKeys.CM_EXISTS, namespace);
89+
LOGGER.fine(MessageKeys.CM_EXISTS, domainNamespace);
8790
packet.put(ProcessingConstants.SCRIPT_CONFIG_MAP, result);
8891
return doNext(packet);
8992
} else {
9093
// we need to update the config map
9194
Map<String, String> updated = result.getData();
9295
updated.putAll(cm.getData());
9396
cm.setData(updated);
94-
Step replace = factory.create().replaceConfigMapAsync(cm.getMetadata().getName(), namespace, cm, new ResponseStep<V1ConfigMap>(next) {
97+
Step replace = factory.create().replaceConfigMapAsync(cm.getMetadata().getName(), domainNamespace, cm, new ResponseStep<V1ConfigMap>(next) {
9598
@Override
9699
public NextAction onFailure(Packet packet, ApiException e, int statusCode,
97100
Map<String, List<String>> responseHeaders) {
@@ -101,7 +104,7 @@ public NextAction onFailure(Packet packet, ApiException e, int statusCode,
101104
@Override
102105
public NextAction onSuccess(Packet packet, V1ConfigMap result, int statusCode,
103106
Map<String, List<String>> responseHeaders) {
104-
LOGGER.info(MessageKeys.CM_REPLACED, namespace);
107+
LOGGER.info(MessageKeys.CM_REPLACED, domainNamespace);
105108
packet.put(ProcessingConstants.SCRIPT_CONFIG_MAP, result);
106109
return doNext(packet);
107110
}
@@ -123,17 +126,12 @@ protected V1ConfigMap computeDomainConfigMap() {
123126

124127
V1ObjectMeta metadata = new V1ObjectMeta();
125128
metadata.setName(name);
126-
metadata.setNamespace(namespace);
129+
metadata.setNamespace(domainNamespace);
127130

128131
AnnotationHelper.annotateWithFormat(metadata);
129132

130133
Map<String, String> labels = new HashMap<>();
131-
// This config map is a singleton that is shared by all the domains
132-
// We need to add a domain uid label so that it can be located as
133-
// related to the operator. However, we don't have a specific domain uid
134-
// to set as the value. So, just set it to an empty string. That way,
135-
// someone seleting on just the weblogic.domainUID label will find it.
136-
labels.put(LabelConstants.DOMAINUID_LABEL, "");
134+
labels.put(LabelConstants.OPERATORNAME_LABEL, operatorNamespace);
137135
labels.put(LabelConstants.CREATEDBYOPERATOR_LABEL, "true");
138136
metadata.setLabels(labels);
139137

src/test/java/oracle/kubernetes/operator/create/ConfigMapHelperConfigTest.java renamed to operator/src/test/java/oracle/kubernetes/operator/create/ConfigMapHelperConfigTest.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
*/
2020
public class ConfigMapHelperConfigTest {
2121

22-
private static final String NAMESPACE = "test-namespace";
22+
private static final String OPERATOR_NAMESPACE = "test-operator-namespace";
23+
private static final String DOMAIN_NAMESPACE = "test-domain-namespace";
2324
private static final String PROPERTY_LIVENESS_PROBE_SH = "livenessProbe.sh";
2425
private static final String PROPERTY_READINESS_PROBE_SH = "readinessProbe.sh";
2526
private static final String PROPERTY_READ_STATE_SH = "readState.sh";
@@ -45,8 +46,8 @@ private V1ConfigMap getDesiredDomainConfigMap() {
4546
newConfigMap()
4647
.metadata(newObjectMeta()
4748
.name(DOMAIN_CONFIG_MAP_NAME)
48-
.namespace(NAMESPACE)
49-
.putLabelsItem(DOMAINUID_LABEL, "")
49+
.namespace(DOMAIN_NAMESPACE)
50+
.putLabelsItem(OPERATORNAME_LABEL, OPERATOR_NAMESPACE)
5051
.putLabelsItem(CREATEDBYOPERATOR_LABEL, "true")
5152
.putAnnotationsItem(FORMAT_ANNOTATION, FORMAT_VERSION))
5253
.putDataItem(PROPERTY_LIVENESS_PROBE_SH, "")
@@ -60,7 +61,7 @@ private V1ConfigMap getActualDomainConfigMap() throws Exception {
6061

6162
private static class TestScriptConfigMapStep extends ConfigMapHelper.ScriptConfigMapStep {
6263
public TestScriptConfigMapStep() {
63-
super(NAMESPACE, null);
64+
super(OPERATOR_NAMESPACE, DOMAIN_NAMESPACE, null);
6465
}
6566
@Override public V1ConfigMap computeDomainConfigMap() {
6667
return super.computeDomainConfigMap();

0 commit comments

Comments
 (0)