sigs.k8s.io/kubebuilder/v3@v3.14.0/test/e2e/setup.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  # Copyright 2019 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  build_kb
    18  fetch_tools
    19  install_kind
    20  
    21  # Creates a named kind cluster given a k8s version.
    22  # The KIND_CLUSTER variable defines the cluster name and
    23  # is expected to be defined in the calling environment.
    24  #
    25  # Usage:
    26  #
    27  #   export KIND_CLUSTER=<kind cluster name>
    28  #   create_cluster <k8s version>
    29  function create_cluster {
    30    KIND_VERSION=$1
    31    : ${KIND_CLUSTER:?"KIND_CLUSTER must be set"}
    32    : ${1:?"k8s version must be set as arg 1"}
    33    if ! kind get clusters | grep -q $KIND_CLUSTER ; then
    34      version_prefix="${KIND_VERSION%.*}"
    35      kind_config=$(dirname "$0")/kind-config.yaml
    36      if test -f $(dirname "$0")/kind-config-${version_prefix}.yaml; then
    37        kind_config=$(dirname "$0")/kind-config-${version_prefix}.yaml
    38      fi
    39      kind create cluster -v 4 --name $KIND_CLUSTER --retain --wait=1m --config ${kind_config} --image=kindest/node:$1
    40    fi
    41  }
    42  
    43  # Deletes a kind cluster by cluster name.
    44  # The KIND_CLUSTER variable defines the cluster name and
    45  # is expected to be defined in the calling environment.
    46  #
    47  # Usage:
    48  #
    49  #   export KIND_CLUSTER=<kind cluster name>
    50  #   delete_cluster
    51  function delete_cluster {
    52    : ${KIND_CLUSTER:?"KIND_CLUSTER must be set"}
    53    kind delete cluster --name $KIND_CLUSTER
    54  }
    55  
    56  function test_cluster {
    57    local flags="$@"
    58  
    59    docker pull memcached:1.6.23-alpine
    60    kind load docker-image --name $KIND_CLUSTER memcached:1.6.23-alpine
    61  
    62    docker pull busybox:1.36.1
    63    kind load docker-image --name $KIND_CLUSTER busybox:1.36.1
    64  
    65    go test $(dirname "$0")/grafana $flags -timeout 30m
    66    go test $(dirname "$0")/deployimage $flags -timeout 30m
    67    go test $(dirname "$0")/v4 $flags -timeout 30m
    68    go test $(dirname "$0")/externalplugin $flags -timeout 30m
    69    go test $(dirname "$0")/alphagenerate $flags -timeout 30m
    70  }
    71  
    72  function build_sample_external_plugin {
    73    if [ "$(uname -s)" == "Darwin" ]; then
    74      EXTERNAL_PLUGIN_DESTINATION_PREFIX="${HOME}/Library/Application Support/kubebuilder/plugins"
    75    else
    76      XDG_CONFIG_HOME="${HOME}/.config"
    77      EXTERNAL_PLUGIN_DESTINATION_PREFIX="$XDG_CONFIG_HOME/kubebuilder/plugins"
    78    fi
    79  
    80    PLUGIN_NAME="sampleexternalplugin"
    81    PLUGIN_VERSION="v1"
    82    EXTERNAL_PLUGIN_DESTINATION="${EXTERNAL_PLUGIN_DESTINATION_PREFIX}/${PLUGIN_NAME}/${PLUGIN_VERSION}"
    83    EXTERNAL_PLUGIN_PATH="${EXTERNAL_PLUGIN_DESTINATION}/${PLUGIN_NAME}"
    84  
    85    if [ -d "$EXTERNAL_PLUGIN_DESTINATION" ]; then
    86      echo "$EXTERNAL_PLUGIN_DESTINATION does exist."
    87      if [ -e "$EXTERNAL_PLUGIN_PATH" ]; then
    88        echo "clean up old binary..."
    89        rm "$EXTERNAL_PLUGIN_PATH"
    90      fi
    91    else
    92        mkdir -p "$EXTERNAL_PLUGIN_DESTINATION"
    93    fi
    94  
    95    REPO_ROOT_DIR="$(git rev-parse --show-toplevel)"
    96    SOURCE_DIR="${REPO_ROOT_DIR}/docs/book/src/simple-external-plugin-tutorial/testdata/sampleexternalplugin/v1"
    97  
    98    cd $SOURCE_DIR && go build -o $PLUGIN_NAME && mv $PLUGIN_NAME "$EXTERNAL_PLUGIN_PATH"
    99  
   100    cd $REPO_ROOT_DIR
   101  }