diff --git a/Makefile b/Makefile index 6efc0238d3..9b902a50ca 100644 --- a/Makefile +++ b/Makefile @@ -96,8 +96,6 @@ update: update/gofmt update/kustomize update/mockgen update/gomod update/shfmt u verify: verify/govet verify/golangci-lint verify/update @echo "All verifications passed!" - - .PHONY: cluster/create cluster/create: bin/kops bin/eksctl bin/aws bin/gomplate ./hack/e2e/create-cluster.sh @@ -114,6 +112,14 @@ cluster/image: bin/aws cluster/delete: bin/kops bin/eksctl ./hack/e2e/delete-cluster.sh +.PHONY: cluster/install +cluster/install: bin/helm bin/aws + ./hack/e2e/install.sh + +.PHONY: cluster/uninstall +cluster/uninstall: bin/helm bin/aws + ./hack/e2e/uninstall.sh + ## E2E targets # Targets to run e2e tests diff --git a/hack/e2e/install.sh b/hack/e2e/install.sh new file mode 100755 index 0000000000..216eb3d26d --- /dev/null +++ b/hack/e2e/install.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +# Copyright 2024 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This script deletes a cluster that was created by `create-cluster.sh` +# CLUSTER_NAME and CLUSTER_TYPE are expected to be specified by the caller +# All other environment variables have default values (see config.sh) but +# many can be overridden on demand if needed + +set -euo pipefail + +BASE_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]}")")" +BIN="${BASE_DIR}/../../bin" + +source "${BASE_DIR}/config.sh" +source "${BASE_DIR}/util.sh" + +if [ -z "${HELM_VALUES_FILE:-}" ]; then + if [[ "${CLUSTER_TYPE}" == "kops" ]]; then + HELM_VALUES_FILE="${BASE_DIR}/kops/values.yaml" + elif [[ "${CLUSTER_TYPE}" == "eksctl" ]]; then + HELM_VALUES_FILE="${BASE_DIR}/eksctl/values.yaml" + else + echo "Cluster type ${CLUSTER_TYPE} is invalid, must be kops or eksctl" >&2 + exit 1 + fi +fi + +loudecho "Installing driver via ${DEPLOY_METHOD}" +install_driver +loudecho "Sucessfully installed driver via ${DEPLOY_METHOD}" diff --git a/hack/e2e/run.sh b/hack/e2e/run.sh index 86cff248d2..909ad7879c 100755 --- a/hack/e2e/run.sh +++ b/hack/e2e/run.sh @@ -60,37 +60,9 @@ fi if [[ "${HELM_CT_TEST}" != true ]]; then startSec=$(date +'%s') - - if [[ ${DEPLOY_METHOD} == "helm" ]]; then - HELM_ARGS=(upgrade --install "aws-ebs-csi-driver" - --namespace kube-system - --set image.repository="${IMAGE_NAME}" - --set image.tag="${IMAGE_TAG}" - --set node.enableWindows="${WINDOWS}" - --set node.windowsHostProcess="${WINDOWS_HOSTPROCESS}" - --set=controller.k8sTagClusterId="${CLUSTER_NAME}" - --timeout 10m0s - --wait - --kubeconfig "${KUBECONFIG}" - ./charts/aws-ebs-csi-driver) - if [[ -f "$HELM_VALUES_FILE" ]]; then - HELM_ARGS+=(-f "${HELM_VALUES_FILE}") - fi - eval "EXPANDED_HELM_EXTRA_FLAGS=$HELM_EXTRA_FLAGS" - if [[ -n "$EXPANDED_HELM_EXTRA_FLAGS" ]]; then - HELM_ARGS+=("${EXPANDED_HELM_EXTRA_FLAGS}") - fi - set -x - "${BIN}/helm" "${HELM_ARGS[@]}" - set +x - elif [[ ${DEPLOY_METHOD} == "kustomize" ]]; then - set -x - kubectl --kubeconfig "${KUBECONFIG}" apply -k "./deploy/kubernetes/overlays/stable" - kubectl --kubeconfig "${KUBECONFIG}" --namespace kube-system wait --timeout 10m0s --for "condition=ready" pod -l "app.kubernetes.io/name=aws-ebs-csi-driver" - set +x - fi - + install_driver endSec=$(date +'%s') + deployTimeSeconds=$(((endSec - startSec) / 1)) loudecho "Driver deployment complete, time used: $deployTimeSeconds seconds" fi @@ -199,14 +171,7 @@ fi ## Cleanup if [[ "${HELM_CT_TEST}" != true ]]; then - loudecho "Removing driver via ${DEPLOY_METHOD}" - if [[ ${DEPLOY_METHOD} == "helm" ]]; then - ${BIN}/helm del "aws-ebs-csi-driver" \ - --namespace kube-system \ - --kubeconfig "${KUBECONFIG}" - elif [[ ${DEPLOY_METHOD} == "kustomize" ]]; then - kubectl --kubeconfig "${KUBECONFIG}" delete -k "${BASE_DIR}/../../deploy/kubernetes/overlays/stable" - fi + uninstall_driver fi if [[ "${EBS_INSTALL_SNAPSHOT}" == true ]]; then diff --git a/hack/e2e/uninstall.sh b/hack/e2e/uninstall.sh new file mode 100755 index 0000000000..e55945c593 --- /dev/null +++ b/hack/e2e/uninstall.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# Copyright 2024 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This script deletes a cluster that was created by `create-cluster.sh` +# CLUSTER_NAME and CLUSTER_TYPE are expected to be specified by the caller +# All other environment variables have default values (see config.sh) but +# many can be overridden on demand if needed + +BASE_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]}")")" +BIN="${BASE_DIR}/../../bin" + +source "${BASE_DIR}/config.sh" +source "${BASE_DIR}/util.sh" + +loudecho "Uninstalling driver via ${DEPLOY_METHOD}" +uninstall_driver +loudecho "Sucessfully uninstalled driver via ${DEPLOY_METHOD}" diff --git a/hack/e2e/util.sh b/hack/e2e/util.sh index 7515711ccb..1910e175bd 100644 --- a/hack/e2e/util.sh +++ b/hack/e2e/util.sh @@ -22,12 +22,41 @@ function loudecho() { echo "#" } -function generate_ssh_key() { - SSH_KEY_PATH=${1} - if [[ ! -e ${SSH_KEY_PATH} ]]; then - loudecho "Generating SSH key $SSH_KEY_PATH" - ssh-keygen -P csi-e2e -f "${SSH_KEY_PATH}" - else - loudecho "Reusing SSH key $SSH_KEY_PATH" +function install_driver() { + if [[ ${DEPLOY_METHOD} == "helm" ]]; then + HELM_ARGS=(upgrade --install aws-ebs-csi-driver + "${BASE_DIR}/../../charts/aws-ebs-csi-driver" + --namespace kube-system + --set image.repository="${IMAGE_NAME}" + --set image.tag="${IMAGE_TAG}" + --set node.enableWindows="${WINDOWS}" + --set node.windowsHostProcess="${WINDOWS_HOSTPROCESS}" + --set=controller.k8sTagClusterId="${CLUSTER_NAME}" + --timeout 10m0s + --wait + --kubeconfig "${KUBECONFIG}") + if [ -n "${HELM_VALUES_FILE:-}" ]; then + HELM_ARGS+=(-f "${HELM_VALUES_FILE}") + fi + eval "EXPANDED_HELM_EXTRA_FLAGS=$HELM_EXTRA_FLAGS" + if [[ -n "$EXPANDED_HELM_EXTRA_FLAGS" ]]; then + HELM_ARGS+=("${EXPANDED_HELM_EXTRA_FLAGS}") + fi + set -x + "${BIN}/helm" "${HELM_ARGS[@]}" + set +x + elif [[ ${DEPLOY_METHOD} == "kustomize" ]]; then + set -x + kubectl --kubeconfig "${KUBECONFIG}" apply -k "${BASE_DIR}/../../deploy/kubernetes/overlays/stable" + kubectl --kubeconfig "${KUBECONFIG}" --namespace kube-system wait --timeout 10m0s --for "condition=ready" pod -l "app.kubernetes.io/name=aws-ebs-csi-driver" + set +x + fi +} + +function uninstall_driver() { + if [[ ${DEPLOY_METHOD} == "helm" ]]; then + ${BIN}/helm uninstall "aws-ebs-csi-driver" --namespace kube-system --kubeconfig "${KUBECONFIG}" + elif [[ ${DEPLOY_METHOD} == "kustomize" ]]; then + kubectl --kubeconfig "${KUBECONFIG}" delete -k "${BASE_DIR}/../../deploy/kubernetes/overlays/stable" fi }