Skip to content

Commit a6548e3

Browse files
authored
OWLS-89535 - scalingAction.sh script fails if multiple domains are running in the same namespace (#2388)
* fix bug scalingAction.sh with more than one domain * add test cases where returning json contains 2 clusters for same domain
1 parent 562dd03 commit a6548e3

File tree

6 files changed

+229
-116
lines changed

6 files changed

+229
-116
lines changed

operator/scripts/scaling/scalingAction.sh

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ function get_custom_resource_domain() {
148148
-v \
149149
--cacert /var/run/secrets/kubernetes.io/serviceaccount/ca.crt \
150150
-H "Authorization: Bearer $(cat /var/run/secrets/kubernetes.io/serviceaccount/token)" \
151-
$kubernetes_master/apis/weblogic.oracle/$domain_api_version/namespaces/$wls_domain_namespace/domains/$domain_uid)
151+
$kubernetes_master/apis/weblogic.oracle/$domain_api_version/namespaces/$wls_domain_namespace/domains/$wls_domain_uid)
152152
if [ $? -ne 0 ]; then
153153
trace "Failed to retrieve WebLogic Domain Custom Resource Definition"
154154
exit 1
@@ -164,7 +164,7 @@ function is_defined_in_clusters() {
164164
local in_cluster_startup="False"
165165

166166
if jq_available; then
167-
local inClusterStartupCmd="(.items[].spec.clusters[] | select (.clusterName == \"${wls_cluster_name}\"))"
167+
local inClusterStartupCmd="(.spec.clusters[] | select (.clusterName == \"${wls_cluster_name}\"))"
168168
local clusterDefinedInCRD=$(echo "${DOMAIN}" | jq "${inClusterStartupCmd}" 2>> ${log_file_name})
169169
if [ "${clusterDefinedInCRD}" != "" ]; then
170170
in_cluster_startup="True"
@@ -173,13 +173,11 @@ function is_defined_in_clusters() {
173173
cat > cmds-$$.py << INPUT
174174
import sys, json
175175
outer_loop_must_break = False
176-
for i in json.load(sys.stdin)["items"]:
177-
j = i["spec"]["clusters"]
178-
for index, cs in enumerate(j):
179-
if j[index]["clusterName"] == "$wls_cluster_name":
180-
outer_loop_must_break = True
181-
print (True)
182-
break
176+
for j in json.load(sys.stdin)["spec"]["clusters"]:
177+
if j["clusterName"] == "$wls_cluster_name":
178+
outer_loop_must_break = True
179+
print (True)
180+
break
183181
if outer_loop_must_break == False:
184182
print (False)
185183
INPUT
@@ -195,16 +193,14 @@ function get_num_ms_in_cluster() {
195193
local DOMAIN="$1"
196194
local num_ms
197195
if jq_available; then
198-
local numManagedServersCmd="(.items[].spec.clusters[] | select (.clusterName == \"${wls_cluster_name}\") | .replicas)"
196+
local numManagedServersCmd="(.spec.clusters[] | select (.clusterName == \"${wls_cluster_name}\") | .replicas)"
199197
num_ms=$(echo "${DOMAIN}" | jq "${numManagedServersCmd}" 2>> ${log_file_name})
200198
else
201199
cat > cmds-$$.py << INPUT
202200
import sys, json
203-
for i in json.load(sys.stdin)["items"]:
204-
j = i["spec"]["clusters"]
205-
for index, cs in enumerate(j):
206-
if j[index]["clusterName"] == "$wls_cluster_name":
207-
print (j[index]["replicas"])
201+
for j in json.load(sys.stdin)["spec"]["clusters"]:
202+
if j["clusterName"] == "$wls_cluster_name":
203+
print (j["replicas"])
208204
INPUT
209205
num_ms=`echo ${DOMAIN} | python cmds-$$.py 2>> ${log_file_name}`
210206
fi
@@ -223,12 +219,11 @@ function get_num_ms_domain_scope() {
223219
local DOMAIN="$1"
224220
local num_ms
225221
if jq_available; then
226-
num_ms=$(echo "${DOMAIN}" | jq -r '.items[].spec.replicas' 2>> ${log_file_name})
222+
num_ms=$(echo "${DOMAIN}" | jq -r '.spec.replicas' 2>> ${log_file_name})
227223
else
228224
cat > cmds-$$.py << INPUT
229225
import sys, json
230-
for i in json.load(sys.stdin)["items"]:
231-
print (i["spec"]["replicas"])
226+
print (json.load(sys.stdin)["spec"]["replicas"])
232227
INPUT
233228
num_ms=`echo ${DOMAIN} | python cmds-$$.py 2>> ${log_file_name}`
234229
fi
@@ -254,17 +249,15 @@ function get_min_replicas {
254249

255250
eval $__result=0
256251
if jq_available; then
257-
minReplicaCmd="(.items[].status.clusters[] | select (.clusterName == \"${clusterName}\")) \
252+
minReplicaCmd="(.status.clusters[] | select (.clusterName == \"${clusterName}\")) \
258253
| .minimumReplicas"
259254
minReplicas=$(echo ${domainJson} | jq "${minReplicaCmd}" 2>> ${log_file_name})
260255
else
261256
cat > cmds-$$.py << INPUT
262257
import sys, json
263-
for i in json.load(sys.stdin)["items"]:
264-
j = i["status"]["clusters"]
265-
for index, cs in enumerate(j):
266-
if j[index]["clusterName"] == "$clusterName":
267-
print (j[index]["minimumReplicas"])
258+
for j in json.load(sys.stdin)["status"]["clusters"]:
259+
if j["clusterName"] == "$clusterName":
260+
print (j["minimumReplicas"])
268261
INPUT
269262
minReplicas=`echo ${DOMAIN} | python cmds-$$.py 2>> ${log_file_name}`
270263
fi
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"apiVersion": "weblogic.oracle/v8",
3+
"kind": "Domain",
4+
"spec": {
5+
"clusters": [
6+
{
7+
"clusterName": "cluster-1",
8+
"replicas": 1,
9+
"serverStartState": "RUNNING"
10+
},
11+
{
12+
"clusterName": "cluster-2",
13+
"replicas": 2,
14+
"serverStartState": "RUNNING"
15+
}
16+
],
17+
"dataHome": "",
18+
"domainHome": "/shared/domains/domain1",
19+
"domainHomeSourceType": "PersistentVolume",
20+
"httpAccessLogInLogHome": true,
21+
"image": "container-registry.oracle.com/middleware/weblogic:12.2.1.4",
22+
"imagePullPolicy": "IfNotPresent",
23+
"includeServerOutInPodLog": false,
24+
"logHome": "/shared/logs/domain1",
25+
"logHomeEnabled": true,
26+
"replicas": 2
27+
},
28+
"status": {
29+
"clusters": [
30+
{
31+
"clusterName": "cluster-1",
32+
"minimumReplicas": 1
33+
},
34+
{
35+
"clusterName": "cluster-2",
36+
"minimumReplicas": 2
37+
}
38+
]
39+
}
40+
}
Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,31 @@
11
{
2-
"apiVersion":"weblogic.oracle/v8",
3-
"items":[
4-
{
5-
"apiVersion": "weblogic.oracle/v8",
6-
"kind": "Domain",
7-
"spec": {
8-
"clusters": [
9-
{
10-
"clusterName": "cluster-1",
11-
"replicas": 1,
12-
"serverStartState": "RUNNING"
13-
}
14-
],
15-
"dataHome": "",
16-
"domainHome": "/shared/domains/domain1",
17-
"domainHomeSourceType": "PersistentVolume",
18-
"httpAccessLogInLogHome": true,
19-
"image": "container-registry.oracle.com/middleware/weblogic:12.2.1.4",
20-
"imagePullPolicy": "IfNotPresent",
21-
"includeServerOutInPodLog": false,
22-
"logHome": "/shared/logs/domain1",
23-
"logHomeEnabled": true,
24-
"replicas": 2
25-
},
26-
"status": {
27-
"clusters": [
28-
{
29-
"clusterName": "cluster-1",
30-
"minimumReplicas": 1
31-
}
32-
]
33-
}
34-
}
35-
]
2+
"apiVersion": "weblogic.oracle/v8",
3+
"kind": "Domain",
4+
"spec": {
5+
"clusters": [
6+
{
7+
"clusterName": "cluster-1",
8+
"replicas": 1,
9+
"serverStartState": "RUNNING"
10+
}
11+
],
12+
"dataHome": "",
13+
"domainHome": "/shared/domains/domain1",
14+
"domainHomeSourceType": "PersistentVolume",
15+
"httpAccessLogInLogHome": true,
16+
"image": "container-registry.oracle.com/middleware/weblogic:12.2.1.4",
17+
"imagePullPolicy": "IfNotPresent",
18+
"includeServerOutInPodLog": false,
19+
"logHome": "/shared/logs/domain1",
20+
"logHomeEnabled": true,
21+
"replicas": 2
22+
},
23+
"status": {
24+
"clusters": [
25+
{
26+
"clusterName": "cluster-1",
27+
"minimumReplicas": 1
28+
}
29+
]
30+
}
3631
}
Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,31 @@
11
{
2-
"apiVersion":"weblogic.oracle/v8",
3-
"items":[
4-
{
5-
"apiVersion": "weblogic.oracle/v8",
6-
"kind": "Domain",
7-
"spec": {
8-
"clusters": [
9-
{
10-
"clusterName": "cluster-1",
11-
"replicas": 1,
12-
"serverStartState": "RUNNING"
13-
}
14-
],
15-
"dataHome": "",
16-
"domainHome": "/shared/domains/domain1",
17-
"domainHomeSourceType": "PersistentVolume",
18-
"httpAccessLogInLogHome": true,
19-
"image": "container-registry.oracle.com/middleware/weblogic:12.2.1.4",
20-
"imagePullPolicy": "IfNotPresent",
21-
"includeServerOutInPodLog": false,
22-
"logHome": "/shared/logs/domain1",
23-
"logHomeEnabled": true,
24-
"replicas": 2
25-
},
26-
"status": {
27-
"clusters": [
28-
{
29-
"clusterName": "cluster-1",
30-
"minimumReplicas": 3
31-
}
32-
]
33-
}
34-
}
35-
]
2+
"apiVersion": "weblogic.oracle/v8",
3+
"kind": "Domain",
4+
"spec": {
5+
"clusters": [
6+
{
7+
"clusterName": "cluster-1",
8+
"replicas": 1,
9+
"serverStartState": "RUNNING"
10+
}
11+
],
12+
"dataHome": "",
13+
"domainHome": "/shared/domains/domain1",
14+
"domainHomeSourceType": "PersistentVolume",
15+
"httpAccessLogInLogHome": true,
16+
"image": "container-registry.oracle.com/middleware/weblogic:12.2.1.4",
17+
"imagePullPolicy": "IfNotPresent",
18+
"includeServerOutInPodLog": false,
19+
"logHome": "/shared/logs/domain1",
20+
"logHomeEnabled": true,
21+
"replicas": 2
22+
},
23+
"status": {
24+
"clusters": [
25+
{
26+
"clusterName": "cluster-1",
27+
"minimumReplicas": 3
28+
}
29+
]
30+
}
3631
}
Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
11
{
2-
"apiVersion":"weblogic.oracle/v8",
3-
"items":[
4-
{
5-
"apiVersion": "weblogic.oracle/v8",
6-
"kind": "Domain",
7-
"spec": {
8-
"clusters": [
9-
{
10-
"clusterName": "cluster-1",
11-
"serverStartState": "RUNNING"
12-
}
13-
],
14-
"dataHome": "",
15-
"domainHome": "/shared/domains/domain1",
16-
"domainHomeSourceType": "PersistentVolume",
17-
"httpAccessLogInLogHome": true,
18-
"image": "container-registry.oracle.com/middleware/weblogic:12.2.1.4",
19-
"imagePullPolicy": "IfNotPresent",
20-
"includeServerOutInPodLog": false,
21-
"logHome": "/shared/logs/domain1",
22-
"logHomeEnabled": true
23-
}
24-
}
25-
]
2+
"apiVersion": "weblogic.oracle/v8",
3+
"kind": "Domain",
4+
"spec": {
5+
"clusters": [
6+
{
7+
"clusterName": "cluster-1",
8+
"serverStartState": "RUNNING"
9+
}
10+
],
11+
"dataHome": "",
12+
"domainHome": "/shared/domains/domain1",
13+
"domainHomeSourceType": "PersistentVolume",
14+
"httpAccessLogInLogHome": true,
15+
"image": "container-registry.oracle.com/middleware/weblogic:12.2.1.4",
16+
"imagePullPolicy": "IfNotPresent",
17+
"includeServerOutInPodLog": false,
18+
"logHome": "/shared/logs/domain1",
19+
"logHomeEnabled": true
20+
}
2621
}

0 commit comments

Comments
 (0)