Skip to content

Commit c264422

Browse files
committed
Change domainsNamespaces to an array of Strings
1 parent 82aa557 commit c264422

File tree

7 files changed

+87
-37
lines changed

7 files changed

+87
-37
lines changed

kubernetes/charts/weblogic-operator/templates/_domains-namespaces.tpl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33

44
{{- define "operator.domainsNamespaces" }}
55
{{- $scope := . -}}
6-
{{- $domainsNamespaces := merge (dict) .domainsNamespaces -}}
6+
{{- $args := merge (dict) $scope -}}
7+
{{- $domainsNamespaces := .domainsNamespaces -}}
78
{{- $len := len $domainsNamespaces -}}
89
{{- if eq $len 0 -}}
9-
{{- $ignore := set $domainsNamespaces "default" (dict) -}}
10+
{{- $ignore := set $args "domainsNamespacesList" (list "default") -}}
11+
{{- else -}}
12+
{{- $ignore := set $args "domainsNamespacesList" $domainsNamespaces -}}
1013
{{- end -}}
11-
{{- range $key, $element := $domainsNamespaces -}}
12-
{{- $args := merge (dict) $element $scope -}}
14+
{{- range $key := $args.domainsNamespacesList -}}
1315
{{- $ignore := set $args "domainsNamespace" $key -}}
14-
{{- /* include "operator.domainConfigMap" $args currently the GA operator runtime does this */ -}}
16+
{{/*- include "operator.domainConfigMap" $args currently the GA operator runtime does this -*/}}
1517
{{- include "operator.operatorRoleBinding" $args -}}
1618
{{- end }}
1719
{{- end }}

kubernetes/charts/weblogic-operator/templates/_inputs-utils.tpl

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,37 @@ Verify that an input value of a specific kind has been specified.
3939
{{- end -}}
4040
{{- end -}}
4141

42+
{{/*
43+
Verify that a list input value has been specified
44+
*/}}
45+
{{- define "operator.verifyListInput" -}}
46+
{{- $requiredKind := index . 0 -}}
47+
{{- $scope := index . 1 -}}
48+
{{- $parent := index . 2 -}}
49+
{{- $name := index . 3 -}}
50+
{{- $args := . -}}
51+
{{- if include "operator.verifyInputKind" (list "slice" $scope $parent $name) -}}
52+
{{- $status := dict -}}
53+
{{- if hasKey $parent $name -}}
54+
{{- $list := index $parent $name -}}
55+
{{- range $value := $list -}}
56+
{{- $actualKind := kindOf $value -}}
57+
{{- if not (eq $requiredKind $actualKind) -}}
58+
{{- $errorMsg := cat "The list property" $name "has a" $actualKind "element. It must only contain" $requiredKind "elements." -}}
59+
{{- include "operator.recordValidationError" (list $scope $errorMsg) -}}
60+
{{- $ignore := set $status "error" true -}}
61+
{{- end -}}
62+
{{- end -}}
63+
{{- end -}}
64+
{{- if not (hasKey $status "error") -}}
65+
true
66+
{{- end -}}
67+
{{- else -}}
68+
{{- $errorMsg := cat "The" $requiredKind "property" $name "must be specified." -}}
69+
{{- include "operator.recordValidationError" (list $scope $errorMsg) -}}
70+
{{- end -}}
71+
{{- end -}}
72+
4273
{{/*
4374
Verify that a string input value has been specified
4475
*/}}
@@ -62,9 +93,9 @@ Verify that an integer input value has been specified
6293
{{- end -}}
6394

6495
{{/*
65-
Verify that an object input value has been specified
96+
Verify that a dictionary input value has been specified
6697
*/}}
67-
{{- define "operator.verifyObjectInput" -}}
98+
{{- define "operator.verifyDictInput" -}}
6899
{{- include "operator.verifyInputKind" (prepend . "map") -}}
69100
{{- end -}}
70101

@@ -87,6 +118,20 @@ Verify that an enum string input value has been specified
87118
{{- end -}}
88119
{{- end -}}
89120

121+
{{/*
122+
Verify that a list of strings input value has been specified
123+
*/}}
124+
{{- define "operator.verifyStringListInput" -}}
125+
{{- include "operator.verifyListInput" (prepend . "string") -}}
126+
{{- end -}}
127+
128+
{{/*
129+
Verify that a list of dictionaries input value has been specified
130+
*/}}
131+
{{- define "operator.verifyDictListInput" -}}
132+
{{- include "operator.verifyListInput" (prepend . "map") -}}
133+
{{- end -}}
134+
90135
{{/*
91136
Report the validation errors that have been found then kill the helm chart install
92137
*/}}

kubernetes/charts/weblogic-operator/templates/_operator-cm.tpl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@ data:
1010
externalOperatorCert: {{ .externalOperatorCert | quote }}
1111
{{- end }}
1212
serviceaccount: {{ .operatorServiceAccount | quote }}
13-
{{- $domainsNamespaces := merge (dict) .domainsNamespaces -}}
13+
{{- $scope := . -}}
14+
{{- $args := merge (dict) $scope -}}
15+
{{- $domainsNamespaces := .domainsNamespaces -}}
1416
{{- $len := len $domainsNamespaces -}}
1517
{{- if eq $len 0 -}}
16-
{{- $ignore := set $domainsNamespaces "default" (dict) -}}
18+
{{- $ignore := set $args "domainsNamespacesList" (list "default") -}}
19+
{{- else -}}
20+
{{- $ignore := set $args "domainsNamespacesList" $domainsNamespaces -}}
1721
{{- end }}
18-
targetNamespaces: {{ keys $domainsNamespaces | sortAlpha | join "," }}
22+
targetNamespaces: {{ $domainsNamespaces | uniq | sortAlpha | join "," | quote }}
1923
kind: "ConfigMap"
2024
metadata:
2125
labels:

kubernetes/charts/weblogic-operator/templates/_validate-inputs.tpl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,9 @@
4949
{{- $ignore := include "operator.verifyIntegerInput" (list $scope $scope "externalDebugHttpPort") -}}
5050
{{- end -}}
5151
{{- end -}}
52-
{{- if include "operator.verifyObjectInput" (list $scope $scope "domainsNamespaces") -}}
53-
{{- $domainsNamespaces := $scope.domainsNamespaces -}}
54-
{{- range $key, $element := $domainsNamespaces -}}
55-
{{- $ignore := include "operator.verifyObjectInput" (list $scope $domainsNamespaces $key) -}}
56-
{{- end -}}
57-
{{- end -}}
52+
{{- $ignore := include "operator.verifyStringListInput" (list $scope $scope "domainsNamespaces") -}}
5853
{{- end -}}
5954
{{- end -}}
55+
{{- $ignore := include "operator.verifyDictListInput" (list $scope $scope "extraResources") -}}
6056
{{- include "operator.reportValidationErrors" $scope -}}
6157
{{- end -}}

kubernetes/charts/weblogic-operator/values.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ operatorNamespace: "weblogic-operator"
1919
# The name must be lowercase
2020
operatorServiceAccount: "weblogic-operator"
2121

22-
# domainsNamespaces specifies a dictionary of WebLogic Domain namespaces which the operator manages (same as targetNamespaces but in dictionary format)
23-
# The names must be lowercase. The values must be empty dictionaries.
22+
# domainsNamespaces specifies list of WebLogic Domain namespaces which the operator manages
23+
# The names must be lowercase.
2424
# The customer is responsible for creating these namespaces.
2525
#
2626
# Example : In the configuration below, the helm installation will manage namespace1 and namespace2.
2727
#
2828
# createDomainsNamespace: true
2929
# domainsNamespaces:
30-
# namespace1: {}
31-
# namespace2: {}
30+
# - namespace1
31+
# - namespace2
3232
domainsNamespaces: {}
3333

3434
# operatorImage specifies the docker image containing the operator code.
@@ -59,7 +59,7 @@ operatorImagePullPolicy: "IfNotPresent"
5959
externalRestOption: NONE
6060

6161
# externalRestHttpsPort specifies the node port that should be allocated for the external operator REST https interface.
62-
# This parameter is required if 'externalRestEnabled' is 'true'.
62+
# This parameter is required if 'externalRestOption' is not 'NONE'.
6363
# Otherwise, it is ignored.
6464
externalRestHttpsPort: 31001
6565

@@ -105,7 +105,7 @@ internalRestOption: SELF_SIGNED_CERT
105105
# DNS:internal-weblogic-operator-service.OPERATOR_NAMESPACE
106106
# DNS:internal-weblogic-operator-service.OPERATOR_NAMESPACE.svc
107107
# DNS:internal-weblogic-operator-service.OPERATOR_NAMESPACE.svc.cluster.local"
108-
# where OPERTOR_NAMESPACE is the name of the operator's namespace.
108+
# where OPERATOR_NAMESPACE is the name of the operator's namespace.
109109
#internalOperatorCert:
110110

111111
# The customer supplied private key to use for the internal operator REST
@@ -157,4 +157,4 @@ elkIntegrationEnabled: false
157157
# metadata: ...
158158
# spec: ...
159159
#
160-
extraResources: {}
160+
extraResources: []

kubernetes/src/test/java/oracle/kubernetes/operator/helm/HelmOperatorValues.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
import static oracle.kubernetes.operator.helm.MapUtils.loadFromMap;
1111
import static oracle.kubernetes.operator.helm.MapUtils.loadIntegerFromMap;
1212

13+
import java.util.ArrayList;
1314
import java.util.Arrays;
1415
import java.util.HashMap;
16+
import java.util.List;
1517
import java.util.Map;
1618
import oracle.kubernetes.operator.utils.OperatorValues;
1719
import org.apache.commons.codec.binary.Base64;
@@ -51,9 +53,9 @@ private void setElkIntegrationEnabled(Boolean enabled) {
5153

5254
@SuppressWarnings("unchecked")
5355
private void loadDomainsNamespacesFromMap(Map<String, Object> map) {
54-
Map<String, ?> domainsNamespaces = (Map<String, ?>) map.get("domainsNamespaces");
56+
List<String> domainsNamespaces = (List<String>) map.get("domainsNamespaces");
5557
if (domainsNamespaces != null) {
56-
String[] namespaces = domainsNamespaces.keySet().toArray(new String[0]);
58+
String[] namespaces = domainsNamespaces.toArray(new String[0]);
5759
Arrays.sort(namespaces);
5860
setTargetNamespaces(String.join(",", namespaces));
5961
}
@@ -90,11 +92,11 @@ Map<String, Object> createMap() {
9092
private void addDomainsNamespaces(HashMap<String, Object> map) {
9193
String targetNamespaces = getTargetNamespaces();
9294
if (targetNamespaces.length() > 0) {
93-
Map<String, Map> namespaceEntries = new HashMap<>();
95+
List<String> namespaces = new ArrayList<>();
9496
for (String namespace : targetNamespaces.split(",")) {
95-
namespaceEntries.put(namespace, new HashMap());
97+
namespaces.add(namespace);
9698
}
97-
map.put("domainsNamespaces", namespaceEntries);
99+
map.put("domainsNamespaces", namespaces);
98100
}
99101
}
100102

kubernetes/src/test/java/oracle/kubernetes/operator/helm/HelmOperatorValuesTest.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@
88
import static org.hamcrest.Matchers.both;
99
import static org.hamcrest.Matchers.equalTo;
1010
import static org.hamcrest.Matchers.hasEntry;
11+
import static org.hamcrest.Matchers.hasItem;
12+
import static org.hamcrest.Matchers.hasItems;
1113
import static org.hamcrest.Matchers.hasKey;
1214
import static org.hamcrest.Matchers.not;
1315
import static org.junit.Assert.assertThat;
1416

17+
import com.google.common.collect.ImmutableList;
1518
import com.google.common.collect.ImmutableMap;
16-
import java.util.Map;
19+
import java.util.List;
1720
import org.junit.Test;
1821

1922
public class HelmOperatorValuesTest {
@@ -374,19 +377,19 @@ public void whenTargetNamespacesNotDefined_createdMapLacksValue() {
374377
public void whenSingleTargetNamespaceDefined_createdMapContainsValue() {
375378
operatorValues.targetNamespaces(stringValue);
376379

377-
assertThat(getDomainsNamespaces(), hasKey(stringValue));
380+
assertThat(getDomainsNamespaces(), hasItem(stringValue));
378381
}
379382

380383
@SuppressWarnings("unchecked")
381-
private Map<String, Map> getDomainsNamespaces() {
382-
return (Map<String, Map>) operatorValues.createMap().get("domainsNamespaces");
384+
private List<String> getDomainsNamespaces() {
385+
return (List<String>) operatorValues.createMap().get("domainsNamespaces");
383386
}
384387

385388
@Test
386389
public void whenMultipleTargetNamespaceDefined_createdMapContainsValue() {
387390
operatorValues.targetNamespaces("aaa,bbb");
388391

389-
assertThat(getDomainsNamespaces(), both(hasKey("aaa")).and(hasKey("bbb")));
392+
assertThat(getDomainsNamespaces(), hasItems("aaa", "bbb"));
390393
}
391394

392395
@Test
@@ -400,7 +403,7 @@ public void whenCreatedFromMapWithoutDomainsNamespaces_hasEmptyString() {
400403
public void whenCreatedFromMapWithSingleNamespace_hasSpecifiedValue() {
401404
HelmOperatorValues values =
402405
new HelmOperatorValues(
403-
ImmutableMap.of("domainsNamespaces", ImmutableMap.of("namespace1", ImmutableMap.of())));
406+
ImmutableMap.of("domainsNamespaces", ImmutableList.of("namespace1")));
404407

405408
assertThat(values.getTargetNamespaces(), equalTo("namespace1"));
406409
}
@@ -409,9 +412,7 @@ public void whenCreatedFromMapWithSingleNamespace_hasSpecifiedValue() {
409412
public void whenCreatedFromMapWithMultipleNamespaces_hasSpecifiedValue() {
410413
HelmOperatorValues values =
411414
new HelmOperatorValues(
412-
ImmutableMap.of(
413-
"domainsNamespaces",
414-
ImmutableMap.of("namespace1", ImmutableMap.of(), "namespace2", ImmutableMap.of())));
415+
ImmutableMap.of("domainsNamespaces", ImmutableList.of("namespace1", "namespace2")));
415416

416417
assertThat(values.getTargetNamespaces(), equalTo("namespace1,namespace2"));
417418
}

0 commit comments

Comments
 (0)