github.com/verrazzano/verrazzano-monitoring-operator@v0.0.30/scripts/get-externalIP.sh (about)

     1  # Copyright (C) 2020, Oracle and/or its affiliates.
     2  # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
     3  #!/bin/bash
     4  
     5  if [ -z "$1" ]; then
     6      echo "[error] Missing path to the kubeconfig file to use for CLI requests"
     7      echo
     8  	echo "Usage: scripts/get-externalIP.sh <KUBECONFIG>"
     9  	exit 0
    10  fi
    11  
    12  
    13  for n in $(kubectl --kubeconfig=$1 get nodes --selector node-role.kubernetes.io/node="" -o 'jsonpath={.items[*].metadata.name}')
    14  do
    15  	status=$(kubectl get node $n -o jsonpath='{ range .status.conditions[?(@.type == "Ready")].status }{ @ }{ end }')
    16  	if [[ "$status" == "True" ]]; then
    17  	    unschedulable=$(kubectl --kubeconfig=$1 get node $n -o jsonpath='{.spec.unschedulable}')
    18  	    if [[ ("$unschedulable" == "") || ("$unschedulable" == "false") ]]; then
    19  	        externalIP=$(kubectl --kubeconfig=$1 get node $n -o jsonpath='{.status.addresses[?(@.type=="ExternalIP")].address}')
    20  	        break
    21  	    fi
    22  	fi
    23  done
    24  if [ -n "$externalIP" ]; then
    25    echo $externalIP
    26  else
    27    echo "Could not determine external IP to use"
    28    exit 1
    29  fi