Helm charts and apps for pm-setup
[nonrtric/plt/ranpm.git] / install / scripts / kube_get_controlplane_host.sh
1 #!/bin/bash
2
3 #  ============LICENSE_START===============================================
4 #  Copyright (C) 2023 Nordix Foundation. All rights reserved.
5 #  ========================================================================
6 #  Licensed under the Apache License, Version 2.0 (the "License");
7 #  you may not use this file except in compliance with the License.
8 #  You may obtain a copy of the License at
9 #
10 #       http://www.apache.org/licenses/LICENSE-2.0
11 #
12 #  Unless required by applicable law or agreed to in writing, software
13 #  distributed under the License is distributed on an "AS IS" BASIS,
14 #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 #  See the License for the specific language governing permissions and
16 #  limitations under the License.
17 #  ============LICENSE_END=================================================
18 #
19
20 # Script to obtain the ip/host-name of kubernetes control plance
21 # args: -
22
23 kube_get_controlplane_host() {
24     __current_context=$(kubectl config current-context)
25     if [ $? -ne 0 ]; then
26         echo "Cannot list kubernetes current context"
27         return 1
28     fi
29     __cluster_name=$(kubectl config view -o "jsonpath={.contexts[?(@.name=='"$__current_context"')].context.cluster}")
30     if [ $? -ne 0 ]; then
31         echo "Cannot find the cluster name in kubernetes current context"
32         return 1
33     fi
34     __cluster_server=$(kubectl config view -o "jsonpath={.clusters[?(@.name=='"$__cluster_name"')].cluster.server}")
35     if [ $? -ne 0 ]; then
36         echo "Cannot find the server name in kubernetes current context"
37         return 1
38     fi
39     __cluster_host=$(echo $__cluster_server | awk -F[/:] '{print $4}')
40     if [ $? -ne 0 ]; then
41         echo "Cannot host from kubernetes current context"
42         return 1
43     fi
44     echo $__cluster_host
45     return 0
46 }