github.com/verrazzano/verrazzano@v1.7.0/platform-operator/config/scripts/run.sh (about)

     1  #!/usr/bin/env bash
     2  #
     3  # Copyright (c) 2020, 2023, Oracle and/or its affiliates.
     4  # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
     5  #
     6  
     7  vpo="verrazzano-platform-operator"
     8  namespace="verrazzano-install"
     9  
    10  function create-kubeconfig {
    11    # Get the version of the Kubernetes server
    12    version=$(kubectl version -o json | jq -rj '.serverVersion|.major,".",.minor')
    13  
    14    # Secret does not exist for a serviceAccount starting with Kubernetes 1.24 so we create one.
    15    # The secret contains a certificate and token we need for accessing the cluster.
    16    if [[ "$version" > "1.23" ]]
    17    then
    18      kubectl apply -f /verrazzano/platform-operator/scripts/install/vpo-secret.yaml > /dev/null
    19      secret=$vpo
    20    else
    21      # Get the name of secret from the serviceAccount.
    22      secret=$(kubectl get serviceAccount $vpo -n $namespace -o=jsonpath='{.secrets[0].name}')
    23    fi
    24  
    25    # Get the certificate for accessing the kubernetes cluster
    26    ca=$(kubectl get secret $secret -n $namespace -o=jsonpath='{.data.ca\.crt}')
    27  
    28    # Get the user token
    29    token=$(kubectl get secret $secret -n $namespace -o=jsonpath='{.data.token}' | base64 --decode)
    30  
    31    # Get the endpoint for the kubernetes API server
    32    # The sed command is to strip out color escape sequences
    33    server=$(kubectl cluster-info | grep "control plane" | awk '{ print $7 }' | sed $'s/\e\\[[0-9;:]*[a-zA-Z]//g' )
    34  
    35    # Create a kubeconfig file for the pod.
    36    cp /verrazzano/config/kubeconfig-template $VERRAZZANO_KUBECONFIG
    37    sed -i -e "s|CA|$ca|g" -e "s|SERVER|$server|g" -e "s|TOKEN|$token|g" $VERRAZZANO_KUBECONFIG
    38    export KUBECONFIG=$VERRAZZANO_KUBECONFIG
    39    chmod 600 ${KUBECONFIG}
    40  }
    41  
    42  if [ -n "${VERRAZZANO_KUBECONFIG}" ]; then
    43    # If VERRAZZANO_KUBECONFIG is set, set up a valid Kubeconfig for tools that require them at the requested location
    44    create-kubeconfig
    45  fi
    46  
    47  # Run the operator
    48  /usr/local/bin/verrazzano-platform-operator $*