Skip to content

Commit

Permalink
Split driver install/uninstall out to functions; Introduce make clust…
Browse files Browse the repository at this point in the history
…er/(un)install

Signed-off-by: Connor Catlett <conncatl@amazon.com>
  • Loading branch information
ConnorJC3 committed Jul 2, 2024
1 parent 7061742 commit 78c1cc4
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 47 deletions.
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
43 changes: 43 additions & 0 deletions hack/e2e/install.sh
Original file line number Diff line number Diff line change
@@ -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 [ -n "${PROW_JOB_ID:-}" ]; 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}"
41 changes: 3 additions & 38 deletions hack/e2e/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions hack/e2e/uninstall.sh
Original file line number Diff line number Diff line change
@@ -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}"
43 changes: 36 additions & 7 deletions hack/e2e/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 78c1cc4

Please sign in to comment.