...

Text file src/sigs.k8s.io/gateway-api/hack/kube-env.sh

Documentation: sigs.k8s.io/gateway-api/hack

     1#!/bin/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
    17# Some useful colors.
    18if [[ -z "${color_start-}" ]]; then
    19  declare -r color_start="\033["
    20  declare -r color_red="${color_start}0;31m"
    21  declare -r color_yellow="${color_start}0;33m"
    22  declare -r color_green="${color_start}0;32m"
    23  declare -r color_norm="${color_start}0m"
    24fi
    25
    26# Returns the server version as MMmmpp, with MM as the major
    27# component, mm the minor component, and pp as the patch
    28# revision. e.g. 0.7.1 is echoed as 701, and 1.0.11 would be
    29# 10011. (This makes for easy integer comparison in bash.)
    30function kube_server_version() {
    31  local server_version
    32  local major
    33  local minor
    34  local patch
    35
    36  # This sed expression is the POSIX BRE to match strings like:
    37  # Server Version: &version.Info{Major:"0", Minor:"7+", GitVersion:"v0.7.0-dirty", GitCommit:"ad44234f7152e9c66bc2853575445c7071335e57", GitTreeState:"dirty"}
    38  # and capture the GitVersion portion (which has the patch level)
    39  server_version=$(${KUBECTL} --match-server-version=false version | grep "Server Version:")
    40  read major minor patch < <(
    41    echo ${server_version} | \
    42      sed "s/.*GitVersion:\"v\([0-9]\{1,\}\)\.\([0-9]\{1,\}\)\.\([0-9]\{1,\}\).*/\1 \2 \3/")
    43  printf "%02d%02d%02d" ${major} ${minor} ${patch} | sed 's/^0*//'
    44}

View as plain text