Merge "Add volume mount for storing k8s robot logs to the host"
[policy/docker.git] / csit / get-cluster-info.sh
1 #!/bin/bash
2 # ============LICENSE_START=======================================================
3 #  Copyright (C) 2023 Nordix Foundation. All rights reserved.
4 # ================================================================================
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #      http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #
17 # SPDX-License-Identifier: Apache-2.0
18 # ============LICENSE_END=========================================================
19
20 # This script will be used to gather cluster information
21 # for JMeter to work towards the installed cluster
22
23 # EXPLICITLY ASSIGN PORTS FOR TESTING PURPOSES
24 export APEX_PORT=30001
25 export API_PORT=30002
26 export PAP_PORT=30003
27 export XACML_PORT=30004
28 export DROOLS_PORT=30005
29 export DIST_PORT=30006
30 export ACM_PORT=30007
31 export POLICY_PARTICIPANT_PORT=30008
32 export DMAAP_PORT=30904
33
34 # Retrieve pod names
35 function get_pod_names() {
36   export APEX_POD=$(get_pod_name apex)
37   export PAP_POD=$(get_pod_name pap)
38   export API_POD=$(get_pod_name api)
39   export DMAAP_POD=$(get_pod_name message-router)
40   export XACML_POD=$(get_pod_name xacml)
41   export DROOLS_POD=$(get_pod_name drools-pdp)
42   export DIST_POD=$(get_pod_name distribution)
43   export ACM_POD=$(get_pod_name acm-runtime)
44   export POLICY_PPNT_POD=$(get_pod_name policy-ppnt)
45 }
46
47 # Retrieve service names
48 function get_svc_names() {
49   export APEX_SVC=$(get_svc_name policy-apex)
50   export PAP_SVC=$(get_svc_name policy-pap)
51   export API_SVC=$(get_svc_name policy-api)
52   export DMAAP_SVC=$(get_svc_name message-router)
53   export DROOLS_SVC=$(get_svc_name drools-pdp)
54   export XACML_SVC=$(get_svc_name xacml)
55   export DIST_SVC=$(get_svc_name distribution)
56   export ACM_SVC=$(get_svc_name acm-runtime)
57   export POLICY_PPNT_SVC=$(get_svc_name policy-ppnt)
58 }
59
60 # Expose services in order to perform tests from JMeter
61 function expose_services() {
62     expose_service $APEX_SVC
63     expose_service $PAP_SVC
64     expose_service $API_SVC
65     expose_service $XACML_SVC
66     expose_service $DROOLS_SVC
67     expose_service $DIST_SVC
68     expose_service $ACM_SVC
69     export_service $POLICY_PPNT_SVC
70
71     setup_message_router_svc
72     sleep 2
73     patch_ports
74 }
75
76 function get_pod_name() {
77   microk8s kubectl get pods --no-headers -o custom-columns=':metadata.name' | grep $1
78 }
79
80 function get_svc_name() {
81   microk8s kubectl get svc --no-headers -o custom-columns=':metadata.name' | grep $1
82 }
83
84 function expose_service() {
85   microk8s kubectl expose service $1 --name $1"-svc" --type NodePort --protocol TCP --port 6969 --target-port 6969
86 }
87
88 function patch_port() {
89   microk8s kubectl patch service "$1-svc" --namespace=default --type='json' --patch='[{"op": "replace", "path": "/spec/ports/0/nodePort", "value":'"$2"'}]'
90 }
91
92 # Assign set port values
93 function patch_ports() {
94   patch_port "$APEX_SVC" $APEX_PORT
95   patch_port "$API_SVC" $API_PORT
96   patch_port "$PAP_SVC" $PAP_PORT
97   patch_port "$ACM_SVC" $ACM_PORT
98   patch_port "$POLICY_PPNT_SVC" $POLICY_PARTICIPANT_PORT
99   patch_port "$DIST_SVC" $DIST_PORT
100   patch_port "$DROOLS_SVC" $DROOLS_PORT
101   patch_port "$XACML_SVC" $XACML_PORT
102 }
103
104 function setup_message_router_svc() {
105   microk8s kubectl expose service message-router --name message-router-svc --type NodePort --protocol TCP --port 3904 --target-port 3904
106   microk8s kubectl patch service message-router-svc --namespace=default --type='json' --patch='[{"op": "replace", "path": "/spec/ports/0/nodePort", "value":'"$DMAAP_PORT"'}]'
107 }
108
109 ####MAIN###
110 get_pod_names
111 get_svc_names
112 expose_services