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
10 # http://www.apache.org/licenses/LICENSE-2.0
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=================================================
20 # Script to obtain the ip/host-name of kubernetes control plance
23 kube_get_controlplane_host() {
24 __current_context=$(kubectl config current-context)
26 echo "Cannot list kubernetes current context"
29 __cluster_name=$(kubectl config view -o "jsonpath={.contexts[?(@.name=='"$__current_context"')].context.cluster}")
31 echo "Cannot find the cluster name in kubernetes current context"
34 __cluster_server=$(kubectl config view -o "jsonpath={.clusters[?(@.name=='"$__cluster_name"')].cluster.server}")
36 echo "Cannot find the server name in kubernetes current context"
39 __cluster_host=$(echo $__cluster_server | awk -F[/:] '{print $4}')
41 echo "Cannot host from kubernetes current context"