Skip to content

Commit

Permalink
Enable shellcheck errors. (kubernetes-sigs#2763)
Browse files Browse the repository at this point in the history
* Enable SC2269 shellcheck.

* Enable SC1091 shellcheck.

* Enable SC2155 shellcheck.

* Enable SC2034 shellcheck.

* Enable SC2046 shellcheck.

* Enable SC2086 shellcheck.
  • Loading branch information
mbobrovskyi authored Aug 5, 2024
1 parent 9517c85 commit 97cc53b
Show file tree
Hide file tree
Showing 15 changed files with 180 additions and 192 deletions.
28 changes: 0 additions & 28 deletions .shellcheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,3 @@
# we need this because we specify one file at a time in order to trivially
# detect which files are failing
external-sources=true

# Currently disabled these errors will take care of them later

# Not following: (error message here)
# This variable is assigned to itself, so the assignment does nothing.
# https://github.com/koalaman/shellcheck/wiki/SC2269
disable=SC2269
# Reasons include: file not found, no permissions, not included on the command line, not allowing shellcheck to follow files with -x, etc.
# https://github.com/koalaman/shellcheck/wiki/SC1091
disable=SC1091
# Since you double quoted this, it will not word split, and the loop will only run once
# https://github.com/koalaman/shellcheck/wiki/SC2066
disable=SC2066
# Double quote to prevent globbing and word splitting
# https://github.com/koalaman/shellcheck/wiki/SC2086
disable=SC2086
# foo appears unused. Verify it or export it
# https://github.com/koalaman/shellcheck/wiki/SC2034
disable=SC2034
# This {/} is literal. Check if ; is missing or quote the expression.
# https://github.com/koalaman/shellcheck/wiki/SC1083
disable=SC1083
# Declare and assign separately to avoid masking return values
# https://github.com/koalaman/shellcheck/wiki/SC2155
disable=SC2155
# Quote this to prevent word splitting
# https://github.com/koalaman/shellcheck/wiki/SC2046
disable=SC2046
12 changes: 7 additions & 5 deletions cmd/experimental/kjobctl/hack/update-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,23 @@ set -o nounset
set -o pipefail

GO_CMD=${1:-go}
KJOBCTL_ROOT=$(realpath $(dirname ${BASH_SOURCE[0]})/..)
CURRENT_DIR=$(dirname "${BASH_SOURCE[0]}")
KJOBCTL_ROOT=$(realpath "$CURRENT_DIR/..")
KJOBCTL_PKG="sigs.k8s.io/kueue/cmd/experimental/kjobctl"
CODEGEN_PKG=$(cd $TOOLS_DIR && go mod download && $GO_CMD list -m -f "{{.Dir}}" k8s.io/code-generator)
CODEGEN_PKG=$(cd "$TOOLS_DIR" && go mod download && $GO_CMD list -m -f "{{.Dir}}" k8s.io/code-generator)

cd $(dirname ${BASH_SOURCE[0]})/..
cd "$CURRENT_DIR/.."

# shellcheck source=/dev/null
source "${CODEGEN_PKG}/kube_codegen.sh"

# Generating conversion and defaults functions
kube::codegen::gen_helpers \
--boilerplate ${KJOBCTL_ROOT}/hack/boilerplate.go.txt \
--boilerplate "${KJOBCTL_ROOT}/hack/boilerplate.go.txt" \
"${KJOBCTL_ROOT}"

kube::codegen::gen_client \
--boilerplate ${KJOBCTL_ROOT}/hack/boilerplate.go.txt \
--boilerplate "${KJOBCTL_ROOT}/hack/boilerplate.go.txt" \
--output-dir "${KJOBCTL_ROOT}/client-go" \
--output-pkg "${KJOBCTL_PKG}/client-go" \
"${KJOBCTL_ROOT}"
Expand Down
36 changes: 18 additions & 18 deletions cmd/experimental/podtaintstolerations/hack/e2e-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,54 +25,54 @@ export GINKGO="$ROOT_DIR"/bin/ginkgo
export KIND="$ROOT_DIR"/bin/kind

function cleanup {
if [ $CREATE_KIND_CLUSTER == 'true' ]; then
if [ "$CREATE_KIND_CLUSTER" == 'true' ]; then
if [ ! -d "$ARTIFACTS" ]; then
mkdir -p "$ARTIFACTS"
fi
kubectl logs -n kube-system kube-scheduler-kind-control-plane >$ARTIFACTS/kube-scheduler.log || true
kubectl logs -n kube-system kube-controller-manager-kind-control-plane >$ARTIFACTS/kube-controller-manager.log || true
kubectl logs -n kueue-system deployment/kueue-controller-manager >$ARTIFACTS/kueue-controller-manager.log || true
kubectl logs -n kueue-system deployment/kueue-podtaintstolerations >$ARTIFACTS/kueue-controller-manager.log || true
kubectl describe pods -n kueue-system >$ARTIFACTS/kueue-system-pods.log || true
$KIND delete cluster --name $KIND_CLUSTER_NAME
kubectl logs -n kube-system kube-scheduler-kind-control-plane > "$ARTIFACTS/kube-scheduler.log" || true
kubectl logs -n kube-system kube-controller-manager-kind-control-plane > "$ARTIFACTS/kube-controller-manager.log" || true
kubectl logs -n kueue-system deployment/kueue-controller-manager > "$ARTIFACTS/kueue-controller-manager.log" || true
kubectl logs -n kueue-system deployment/kueue-podtaintstolerations > "$ARTIFACTS/kueue-controller-manager.log" || true
kubectl describe pods -n kueue-system > "$ARTIFACTS/kueue-system-pods.log" || true
$KIND delete cluster --name "$KIND_CLUSTER_NAME"
fi
(cd test/e2e/config && $KUSTOMIZE edit set image controller=controller)
}

function startup {
if [ $CREATE_KIND_CLUSTER == 'true' ]; then
if [ "$CREATE_KIND_CLUSTER" == 'true' ]; then
if [ ! -d "$ARTIFACTS" ]; then
mkdir -p "$ARTIFACTS"
fi
$KIND create cluster --name "$KIND_CLUSTER_NAME" --image "$E2E_KIND_VERSION" --config "$SOURCE_DIR/kind-cluster.yaml" --wait 15m -v 5 >"$ARTIFACTS"/kind-create.log 2>&1 ||
{
echo "unable to start the kind cluster "
cat $ARTIFACTS/kind-create.log
cat "$ARTIFACTS/kind-create.log"
}
kubectl get nodes >$ARTIFACTS/kind-nodes.log || true
kubectl describe pods -n kube-system >$ARTIFACTS/kube-system-pods.log || true
kubectl get nodes > "$ARTIFACTS/kind-nodes.log" || true
kubectl describe pods -n kube-system > "$ARTIFACTS/kube-system-pods.log" || true
fi
}

function kind_load {
$KIND load docker-image $CONTROLLER_IMAGE --name $KIND_CLUSTER_NAME
$KIND load docker-image "$CONTROLLER_IMAGE" --name "$KIND_CLUSTER_NAME"
}

function kueue_deploy {
kubectl apply -f https://github.com/kubernetes-sigs/kueue/releases/download/v0.4.1/manifests.yaml
}

function controller_deploy {
(cd test/e2e/config && $KUSTOMIZE edit set image controller=$CONTROLLER_IMAGE)
(cd test/e2e/config && $KUSTOMIZE edit set image controller="$CONTROLLER_IMAGE")
kubectl apply --server-side -k test/e2e/config
}

function taint_nodes {
kubectl taint nodes $KIND_CLUSTER_NAME-worker2 --overwrite tier=spot:NoSchedule
kubectl taint nodes $KIND_CLUSTER_NAME-worker2 --overwrite company.com/kueue-admission:NoSchedule
kubectl taint nodes "$KIND_CLUSTER_NAME-worker2" --overwrite tier=spot:NoSchedule
kubectl taint nodes "$KIND_CLUSTER_NAME-worker2" --overwrite company.com/kueue-admission:NoSchedule

kubectl taint nodes $KIND_CLUSTER_NAME-worker3 --overwrite tier=regular:NoSchedule
kubectl taint nodes $KIND_CLUSTER_NAME-worker3 --overwrite company.com/kueue-admission:NoSchedule
kubectl taint nodes "$KIND_CLUSTER_NAME-worker3" --overwrite tier=regular:NoSchedule
kubectl taint nodes "$KIND_CLUSTER_NAME-worker3" --overwrite company.com/kueue-admission:NoSchedule
}

trap cleanup EXIT
Expand All @@ -81,4 +81,4 @@ taint_nodes
kind_load
kueue_deploy
controller_deploy
$GINKGO --junit-report=junit.xml --output-dir=$ARTIFACTS -v ./test/e2e/...
$GINKGO --junit-report=junit.xml --output-dir="$ARTIFACTS" -v ./test/e2e/...
6 changes: 3 additions & 3 deletions hack/dump_cache.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ NAMESPACE=${NAMESPACE:-kueue-system}
LEASE_NAME=${LEASE_NAME:-c1f6bfd2.kueue.x-k8s.io}
DEBUG_IMAGE=${DEBUG_IMAGE:-us-central1-docker.pkg.dev/k8s-staging-images/kueue/debug:main}

leader=$(kubectl get lease -n ${NAMESPACE} ${LEASE_NAME} -o jsonpath='{.spec.holderIdentity}' | cut -d '_' -f 1)
leader=$(kubectl get lease -n "${NAMESPACE}" "${LEASE_NAME}" -o jsonpath='{.spec.holderIdentity}' | cut -d '_' -f 1)

# When the FOLLOW environment variable is set, output the logs.
if [ -v FOLLOW ]; then
kubectl logs -n ${NAMESPACE} ${leader} -f --tail=1 &
kubectl logs -n "${NAMESPACE}" "${leader}" -f --tail=1 &
fi

kubectl debug -n ${NAMESPACE} ${leader} --image=${DEBUG_IMAGE} --target=manager --profile=restricted --image-pull-policy=IfNotPresent -- sh -c 'kill -USR2 1'
kubectl debug -n "${NAMESPACE}" "${leader}" --image="${DEBUG_IMAGE}" --target=manager --profile=restricted --image-pull-policy=IfNotPresent -- sh -c 'kill -USR2 1'
45 changes: 23 additions & 22 deletions hack/e2e-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,57 +30,58 @@ export KUBEFLOW_CRDS=${ROOT_DIR}/dep-crds/training-operator/

# $1 - cluster name
function cluster_cleanup {
kubectl config use-context kind-$1
$KIND export logs $ARTIFACTS --name $1 || true
kubectl describe pods -n kueue-system > $ARTIFACTS/$1-kueue-system-pods.log || true
kubectl describe pods > $ARTIFACTS/$1-default-pods.log || true
$KIND delete cluster --name $1
kubectl config use-context "kind-$1"
$KIND export logs "$ARTIFACTS" --name "$1" || true
kubectl describe pods -n kueue-system > "$ARTIFACTS/$1-kueue-system-pods.log" || true
kubectl describe pods > "$ARTIFACTS/$1-default-pods.log" || true
$KIND delete cluster --name "$1"
}

# $1 cluster name
# $2 cluster kind config
function cluster_create {
$KIND create cluster --name $1 --image $E2E_KIND_VERSION --config $2 --wait 1m -v 5 > $ARTIFACTS/$1-create.log 2>&1 \
|| { echo "unable to start the $1 cluster "; cat $ARTIFACTS/$1-create.log ; }
kubectl config use-context kind-$1
kubectl get nodes > $ARTIFACTS/$1-nodes.log || true
kubectl describe pods -n kube-system > $ARTIFACTS/$1-system-pods.log || true
$KIND create cluster --name "$1" --image "$E2E_KIND_VERSION" --config "$2" --wait 1m -v 5 > "$ARTIFACTS/$1-create.log" 2>&1 \
|| { echo "unable to start the $1 cluster "; cat "$ARTIFACTS/$1-create.log" ; }
kubectl config use-context "kind-$1"
kubectl get nodes > "$ARTIFACTS/$1-nodes.log" || true
kubectl describe pods -n kube-system > "$ARTIFACTS/$1-system-pods.log" || true
}

# $1 cluster
function cluster_kind_load {
cluster_kind_load_image $1 $E2E_TEST_IMAGE
cluster_kind_load_image $1 $IMAGE_TAG
cluster_kind_load_image "$1" "$E2E_TEST_IMAGE"
cluster_kind_load_image "$1" "$IMAGE_TAG"
}

# $1 cluster
# $2 image
function cluster_kind_load_image {
$KIND load docker-image $2 --name $1
$KIND load docker-image "$2" --name "$1"
}

# $1 cluster
function cluster_kueue_deploy {
kubectl config use-context kind-${1}
kubectl config use-context "kind-${1}"
kubectl apply --server-side -k test/e2e/config
}

#$1 - cluster name
function install_jobset {
cluster_kind_load_image ${1} ${JOBSET_IMAGE}
kubectl config use-context kind-${1}
kubectl apply --server-side -f ${JOBSET_MANIFEST}
cluster_kind_load_image "${1}" "${JOBSET_IMAGE}"
kubectl config use-context "kind-${1}"
kubectl apply --server-side -f "${JOBSET_MANIFEST}"
}

#$1 - cluster name
function install_kubeflow {
cluster_kind_load_image ${1} ${KUBEFLOW_IMAGE}
kubectl config use-context kind-${1}
kubectl apply -k ${KUBEFLOW_MANIFEST}
cluster_kind_load_image "${1}" ${KUBEFLOW_IMAGE}
kubectl config use-context "kind-${1}"
kubectl apply -k "${KUBEFLOW_MANIFEST}"
}

export INITIAL_IMAGE=$($YQ '.images[] | select(.name == "controller") | [.newName, .newTag] | join(":")' config/components/manager/kustomization.yaml)
INITIAL_IMAGE=$($YQ '.images[] | select(.name == "controller") | [.newName, .newTag] | join(":")' config/components/manager/kustomization.yaml)
export INITIAL_IMAGE

function restore_managers_image {
(cd config/components/manager && $KUSTOMIZE edit set image controller=$INITIAL_IMAGE)
(cd config/components/manager && $KUSTOMIZE edit set image controller="$INITIAL_IMAGE")
}
24 changes: 13 additions & 11 deletions hack/e2e-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,23 @@ SOURCE_DIR="$(cd "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
ROOT_DIR="$SOURCE_DIR/.."
export E2E_TEST_IMAGE=gcr.io/k8s-staging-perf-tests/sleep:v0.1.0

source ${SOURCE_DIR}/e2e-common.sh
# shellcheck source=hack/e2e-common.sh
source "${SOURCE_DIR}/e2e-common.sh"

function cleanup {
if [ $CREATE_KIND_CLUSTER == 'true' ]
if [ "$CREATE_KIND_CLUSTER" == 'true' ]
then
if [ ! -d "$ARTIFACTS" ]; then
mkdir -p "$ARTIFACTS"
fi
cluster_cleanup $KIND_CLUSTER_NAME
cluster_cleanup "$KIND_CLUSTER_NAME"
fi
#do the image restore here for the case when an error happened during deploy
restore_managers_image
}

function startup {
if [ $CREATE_KIND_CLUSTER == 'true' ]
if [ "$CREATE_KIND_CLUSTER" == 'true' ]
then
if [ ! -d "$ARTIFACTS" ]; then
mkdir -p "$ARTIFACTS"
Expand All @@ -47,22 +48,23 @@ function startup {
}

function kind_load {
if [ $CREATE_KIND_CLUSTER == 'true' ]
if [ "$CREATE_KIND_CLUSTER" == 'true' ]
then
docker pull $E2E_TEST_IMAGE
cluster_kind_load $KIND_CLUSTER_NAME
cluster_kind_load "$KIND_CLUSTER_NAME"
fi
docker pull registry.k8s.io/jobset/jobset:$JOBSET_VERSION
install_jobset $KIND_CLUSTER_NAME
docker pull "registry.k8s.io/jobset/jobset:$JOBSET_VERSION"
install_jobset "$KIND_CLUSTER_NAME"
}

function kueue_deploy {
(cd config/components/manager && $KUSTOMIZE edit set image controller=$IMAGE_TAG)
cluster_kueue_deploy $KIND_CLUSTER_NAME
(cd config/components/manager && $KUSTOMIZE edit set image controller="$IMAGE_TAG")
cluster_kueue_deploy "$KIND_CLUSTER_NAME"
}

trap cleanup EXIT
startup
kind_load
kueue_deploy
$GINKGO $GINKGO_ARGS --junit-report=junit.xml --output-dir=$ARTIFACTS -v ./test/e2e/singlecluster/...
# shellcheck disable=SC2086
$GINKGO $GINKGO_ARGS --junit-report=junit.xml --output-dir="$ARTIFACTS" -v ./test/e2e/singlecluster/...
Loading

0 comments on commit 97cc53b

Please sign in to comment.