...

Text file src/k8s.io/kubernetes/cluster/kubectl.sh

Documentation: k8s.io/kubernetes/cluster

     1#!/usr/bin/env bash
     2
     3# Copyright 2014 The Kubernetes Authors.
     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
    17set -o errexit
    18set -o nounset
    19set -o pipefail
    20
    21# Stop the bleeding, turn off the warning until we fix token gen.
    22# echo "-=-=-=-=-=-=-=-=-=-="
    23# echo "NOTE:"
    24# echo "kubectl.sh is deprecated and will be removed soon."
    25# echo "please replace all usage with calls to the kubectl"
    26# echo "binary and ensure that it is in your PATH."
    27# echo ""
    28# echo "Please see 'kubectl help config' for more details"
    29# echo "about configuring kubectl for your cluster."
    30# echo "-=-=-=-=-=-=-=-=-=-="
    31
    32
    33KUBE_ROOT=${KUBE_ROOT:-$(dirname "${BASH_SOURCE[0]}")/..}
    34source "${KUBE_ROOT}/cluster/kube-util.sh"
    35source "${KUBE_ROOT}/hack/lib/util.sh"
    36source "${KUBE_ROOT}/hack/lib/logging.sh"
    37
    38# If KUBECTL_PATH isn't set, gather up the list of likely places and use ls
    39# to find the latest one.
    40if [[ -z "${KUBECTL_PATH:-}" ]]; then
    41  kubectl=$( kube::util::find-binary "kubectl" )
    42
    43  if [[ ! -x "$kubectl" ]]; then
    44    {
    45      echo "It looks as if you don't have a compiled kubectl binary"
    46      echo
    47      echo "If you are running from a clone of the git repo, please run"
    48      echo "'./build/run.sh make cross'. Note that this requires having"
    49      echo "Docker installed."
    50      echo
    51      echo "If you are running from a binary release tarball, something is wrong. "
    52      echo "Look at http://kubernetes.io/ for information on how to contact the "
    53      echo "development team for help."
    54    } >&2
    55    exit 1
    56  fi
    57elif [[ ! -x "${KUBECTL_PATH}" ]]; then
    58  {
    59    echo "KUBECTL_PATH environment variable set to '${KUBECTL_PATH}', but "
    60    echo "this doesn't seem to be a valid executable."
    61  } >&2
    62  exit 1
    63fi
    64kubectl="${KUBECTL_PATH:-${kubectl}}"
    65
    66if [[ "$KUBERNETES_PROVIDER" == "gke" ]]; then
    67  detect-project &> /dev/null
    68elif [[ "$KUBERNETES_PROVIDER" == "ubuntu" ]]; then
    69  detect-master > /dev/null
    70  config=(
    71    "--server=http://${KUBE_MASTER_IP}:8080"
    72  )
    73fi
    74
    75
    76if false; then
    77  # disable these debugging messages by default
    78  echo "current-context: \"$(${kubectl} "${config[@]:+${config[@]}}" config view -o template --template='{{index . "current-context"}}')\"" >&2
    79  echo "Running:" "${kubectl}" "${config[@]:+${config[@]}}" "${@+$@}" >&2
    80fi
    81
    82if [[ "${1:-}" =~ ^(path)$ ]]; then
    83  echo "${kubectl}"
    84  exit 0
    85fi
    86
    87"${kubectl}" "${config[@]:+${config[@]}}" "${@+$@}"
    88

View as plain text