From 5198308da32fa00738e4bb5ab7addf5a1181ba97 Mon Sep 17 00:00:00 2001 From: Sunil Thaha Date: Thu, 19 Oct 2023 14:17:41 +1000 Subject: [PATCH 1/4] chore(tools): add shfmt to format shell scripts Signed-off-by: Sunil Thaha --- Makefile | 4 ++++ hack/tools.sh | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/Makefile b/Makefile index 9cefeeba..9dd270ca 100644 --- a/Makefile +++ b/Makefile @@ -281,6 +281,10 @@ yq: ## Download yq locally if necessary oc: ## Download oc locally if necessary @./hack/tools.sh oc +.PHONY: shfmt +shfmt: ## Download shmft locally if necessary + @./hack/tools.sh shfmt + .PHONY: install-govulncheck install-govulncheck: ## Download govulncheck locally if necessary @./hack/tools.sh govulncheck diff --git a/hack/tools.sh b/hack/tools.sh index db2a85cf..402d2d77 100755 --- a/hack/tools.sh +++ b/hack/tools.sh @@ -34,6 +34,7 @@ declare -r OPERATOR_SDK_VERSION=${OPERATOR_SDK_VERSION:-v1.27.0} declare -r YQ_VERSION=${YQ_VERSION:-v4.34.2} declare -r CRDOC_VERSION=${CRDOC_VERSION:-v0.6.2} declare -r OC_VERSION=${OC_VERSION:-4.13.0} +declare -r SHFMT_VERSION=${SHFMT_VERSION:-v3.7.0} # install declare -r KUSTOMIZE_INSTALL_SCRIPT="https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" @@ -123,6 +124,42 @@ install_yq() { ok "yq was installed successfully" } +go_install() { + local pkg="$1" + local version="$2" + shift 2 + + info "installing $pkg version: $version" + + GOBIN=$LOCAL_BIN \ + go install "$pkg@$version" || { + fail "failed to install $pkg - $version" + return 1 + } + ok "$pkg - $version was installed successfully" + +} + +validate_verison() { + local cmd="$1" + local version_arg="$2" + local version_regex="$3" + shift 3 + + command -v "$cmd" >/dev/null 2>&1 || return 1 + [[ $(eval "$cmd $version_arg" | grep -o "$version_regex") =~ $version_regex ]] || { + return 1 + } + + ok "$cmd installed successfully" +} +install_shfmt() { + validate_verison shfmt --version "$SHFMT_VERSION" && { + return 0 + } + go_install mvdan.cc/sh/v3/cmd/shfmt "$SHFMT_VERSION" +} + install_crdoc() { local version_regex="version $CRDOC_VERSION" From bcfbe7d1d0b465813a3d49a04b6fc1c3a61fe3e5 Mon Sep 17 00:00:00 2001 From: Sunil Thaha Date: Thu, 19 Oct 2023 14:18:17 +1000 Subject: [PATCH 2/4] chore: make fmt formats shell scripts as well Signed-off-by: Sunil Thaha --- Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 9dd270ca..ae58b7ae 100644 --- a/Makefile +++ b/Makefile @@ -94,8 +94,11 @@ generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./pkg/..." .PHONY: fmt -fmt: ## Run go fmt against code. +fmt: shfmt ## Run go fmt against code. go fmt ./... + PATH=./tmp/bin:$$PATH \ + shfmt -l -w ./**/*.sh \ + ./must-gather/gather* ./must-gather/common .PHONY: vet vet: ## Run go vet against code. From b1e0cfe1339c43f6d83a9c88453d5e86651180a6 Mon Sep 17 00:00:00 2001 From: Sunil Thaha Date: Thu, 19 Oct 2023 14:19:36 +1000 Subject: [PATCH 3/4] chore: format all shell scripts Signed-off-by: Sunil Thaha --- hack/cluster-clean.sh | 20 ++-- hack/common.sh | 23 ++--- hack/integration_cluster.sh | 68 ++++++------- must-gather/common | 24 ++--- must-gather/gather | 129 ++++++++++++------------ must-gather/gather-kepler-exporter-info | 54 +++++----- must-gather/gather-kepler-operator-info | 70 ++++++------- must-gather/gather-olm-info | 19 ++-- 8 files changed, 202 insertions(+), 205 deletions(-) diff --git a/hack/cluster-clean.sh b/hack/cluster-clean.sh index 11d37cc2..e1d716be 100644 --- a/hack/cluster-clean.sh +++ b/hack/cluster-clean.sh @@ -24,19 +24,19 @@ source ./hack/common.sh MANIFESTS_OUT_DIR=${MANIFESTS_OUT_DIR:-"_output/generated-manifest"} function main() { - echo "Cleaning up ..." + echo "Cleaning up ..." - if [ ! -d "${MANIFESTS_OUT_DIR}" ]; then - echo "Directory ${MANIFESTS_OUT_DIR} DOES NOT exists. Run make generate first." - exit - fi + if [ ! -d "${MANIFESTS_OUT_DIR}" ]; then + echo "Directory ${MANIFESTS_OUT_DIR} DOES NOT exists. Run make generate first." + exit + fi - # Ignore errors because some clusters might not have prometheus operator - kubectl delete --ignore-not-found=true -f ${MANIFESTS_OUT_DIR}/*.yaml || true + # Ignore errors because some clusters might not have prometheus operator + kubectl delete --ignore-not-found=true -f ${MANIFESTS_OUT_DIR}/*.yaml || true - sleep 2 + sleep 2 - echo "Done $0" + echo "Done $0" } -main "$@" \ No newline at end of file +main "$@" diff --git a/hack/common.sh b/hack/common.sh index eacd0be3..3cc3e7ab 100644 --- a/hack/common.sh +++ b/hack/common.sh @@ -19,7 +19,6 @@ set -e - _registry_port="5001" _registry_name="kind-registry" @@ -42,21 +41,21 @@ IMAGE_TAG=${IMAGE_TAG:-devel} PLATFORM=$(uname -m) case ${PLATFORM} in x86_64* | i?86_64* | amd64*) - ARCH="amd64" - ;; + ARCH="amd64" + ;; ppc64le) - ARCH="ppc64le" - ;; + ARCH="ppc64le" + ;; aarch64* | arm64*) - ARCH="arm64" - ;; + ARCH="arm64" + ;; *) - echo "invalid Arch, only support x86_64, ppc64le, aarch64" - exit 1 - ;; + echo "invalid Arch, only support x86_64, ppc64le, aarch64" + exit 1 + ;; esac # the cluster kind is a kubernetes cluster if [ ${CLUSTER_PROVIDER} = "kind" ]; then - CLUSTER_PROVIDER="kubernetes" -fi \ No newline at end of file + CLUSTER_PROVIDER="kubernetes" +fi diff --git a/hack/integration_cluster.sh b/hack/integration_cluster.sh index 43abe1dd..d4a41159 100644 --- a/hack/integration_cluster.sh +++ b/hack/integration_cluster.sh @@ -11,32 +11,32 @@ NGINX_HTTP_PORT=${ENV_NETWORK_INGRESS_HTTP_PORT:-80} NGINX_HTTPS_PORT=${ENV_NETWORK_INGRESS_HTTPS_PORT:-443} main() { - if [[ $# -lt 1 ]] ; then - exit 0 - else - MODE=$1 - shift - fi + if [[ $# -lt 1 ]]; then + exit 0 + else + MODE=$1 + shift + fi - if [ "${MODE}" == "kind" ]; then - kindTest - fi + if [ "${MODE}" == "kind" ]; then + kindTest + fi } function kindTest() { - echo "install kind" - go install sigs.k8s.io/kind@v0.12.0 + echo "install kind" + go install sigs.k8s.io/kind@v0.12.0 - echo "Starting kind with cluster name \"${CLUSTER_NAME}\"" + echo "Starting kind with cluster name \"${CLUSTER_NAME}\"" - local reg_name=${LOCAL_REGISTRY_NAME} - local reg_port=${LOCAL_REGISTRY_PORT} - local ingress_http_port=${NGINX_HTTP_PORT} - local ingress_https_port=${NGINX_HTTPS_PORT} - docker rm -f ${reg_name} - kind delete cluster --name $CLUSTER_NAME + local reg_name=${LOCAL_REGISTRY_NAME} + local reg_port=${LOCAL_REGISTRY_PORT} + local ingress_http_port=${NGINX_HTTP_PORT} + local ingress_https_port=${NGINX_HTTPS_PORT} + docker rm -f ${reg_name} + kind delete cluster --name $CLUSTER_NAME - cat </dev/null || true)" - if [ "${running}" != 'true' ]; then - docker run \ - -d --restart=always -p "127.0.0.1:${reg_port}:5000" --name "${reg_name}" \ - registry:2 - fi + echo "Launching container registry \"${LOCAL_REGISTRY_NAME}\" at localhost:${LOCAL_REGISTRY_PORT}" + running="$(docker inspect -f '{{.State.Running}}' "${reg_name}" 2>/dev/null || true)" + if [ "${running}" != 'true' ]; then + docker run \ + -d --restart=always -p "127.0.0.1:${reg_port}:5000" --name "${reg_name}" \ + registry:2 + fi - # connect the registry to the cluster network - # (the network may already be connected) - docker network connect "kind" "${reg_name}" || true + # connect the registry to the cluster network + # (the network may already be connected) + docker network connect "kind" "${reg_name}" || true - # Document the local registry - # https://github.com/kubernetes/enhancements/tree/master/keps/sig-cluster-lifecycle/generic/1755-communicating-a-local-registry - cat <> "$LOGFILE_PATH" + echo "$(get_timestamp) $*" >>"$LOGFILE_PATH" } log_stdout_and_file() { - echo "$(get_timestamp) $*" | tee -a "$LOGFILE_PATH" + echo "$(get_timestamp) $*" | tee -a "$LOGFILE_PATH" } -log(){ - log_stdout_and_file "$@" +log() { + log_stdout_and_file "$@" } run() { - length=$(($#-1)) - cmd=${@:1:$length} - gather_file="${@: -1}" + length=$(($# - 1)) + cmd=${@:1:$length} + gather_file="${@: -1}" - log_file "$cmd" - $cmd >> "$gather_file" 2>> "$LOGFILE_PATH" || true + log_file "$cmd" + $cmd >>"$gather_file" 2>>"$LOGFILE_PATH" || true } diff --git a/must-gather/gather b/must-gather/gather index 733921cc..0e2dcac4 100755 --- a/must-gather/gather +++ b/must-gather/gather @@ -17,103 +17,102 @@ set -eu -o pipefail -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) source "${SCRIPT_DIR}"/common print_usage() { - echo -e "Usage: /usr/bin/gather " + echo -e "Usage: /usr/bin/gather " } get_kepler_instance() { - log "getting kepler instance(s)" - KEPLERS=$(oc get keplers.kepler.system.sustainable.computing.io -oname) - if [ ! -z "$KEPLERS" ] - then - run oc get $KEPLERS -oyaml "$BASE_COLLECTION_PATH/keplers.yaml" - else - echo "no keplers found" >> "$BASE_COLLECTION_PATH/keplers.yaml" - fi + log "getting kepler instance(s)" + KEPLERS=$(oc get keplers.kepler.system.sustainable.computing.io -oname) + if [ ! -z "$KEPLERS" ]; then + run oc get $KEPLERS -oyaml "$BASE_COLLECTION_PATH/keplers.yaml" + else + echo "no keplers found" >>"$BASE_COLLECTION_PATH/keplers.yaml" + fi } get_kepler_events() { - log "getting $KEPLER_NS events" - run oc -n "$KEPLER_NS" get events "$BASE_COLLECTION_PATH/$KEPLER_NS""_events" + log "getting $KEPLER_NS events" + run oc -n "$KEPLER_NS" get events "$BASE_COLLECTION_PATH/$KEPLER_NS""_events" } get_kepler_daemon_set() { - KEPLER_EXPORTER_DS="kepler-exporter-ds" - log "getting kepler exporter daemonset" - run oc -n "$KEPLER_NS" get ds $KEPLER_EXPORTER_DS -oyaml "$BASE_COLLECTION_PATH/$KEPLER_EXPORTER_DS"".yaml" + KEPLER_EXPORTER_DS="kepler-exporter-ds" + log "getting kepler exporter daemonset" + run oc -n "$KEPLER_NS" get ds $KEPLER_EXPORTER_DS -oyaml "$BASE_COLLECTION_PATH/$KEPLER_EXPORTER_DS"".yaml" } get_kepler_config_map() { - KEPLER_EXPORTER_CM="kepler-exporter-cm" - log "getting kepler exporter config map" - run oc -n "$KEPLER_NS" get cm $KEPLER_EXPORTER_CM -oyaml "$BASE_COLLECTION_PATH/$KEPLER_EXPORTER_CM"".yaml" + KEPLER_EXPORTER_CM="kepler-exporter-cm" + log "getting kepler exporter config map" + run oc -n "$KEPLER_NS" get cm $KEPLER_EXPORTER_CM -oyaml "$BASE_COLLECTION_PATH/$KEPLER_EXPORTER_CM"".yaml" } get_kepler_sa() { - KEPLER_EXPORTER_SA="kepler-exporter-sa" - log "getting kepler exporter service account" - run oc -n "$KEPLER_NS" get serviceaccount $KEPLER_EXPORTER_SA -oyaml "$BASE_COLLECTION_PATH/$KEPLER_EXPORTER_SA"".yaml" + KEPLER_EXPORTER_SA="kepler-exporter-sa" + log "getting kepler exporter service account" + run oc -n "$KEPLER_NS" get serviceaccount $KEPLER_EXPORTER_SA -oyaml "$BASE_COLLECTION_PATH/$KEPLER_EXPORTER_SA"".yaml" } get_kepler_scc() { - KEPLER_EXPORTER_SCC="kepler-exporter-scc" - log "getting kepler exporter scc" - run oc get scc "$KEPLER_EXPORTER_SCC" -oyaml "$BASE_COLLECTION_PATH/$KEPLER_EXPORTER_SCC"".yaml" + KEPLER_EXPORTER_SCC="kepler-exporter-scc" + log "getting kepler exporter scc" + run oc get scc "$KEPLER_EXPORTER_SCC" -oyaml "$BASE_COLLECTION_PATH/$KEPLER_EXPORTER_SCC"".yaml" } gather_kepler_exporter_info() { - KEPLER_PODS=$(oc -n "$KEPLER_NS" get pods -oname 2>/dev/null || echo "") - for pod in $KEPLER_PODS - do - pod=$(echo "$pod" | awk -F '/' '{print $2}') - log "running gather script for kepler pod: $pod" - "$SCRIPT_DIR"/gather-kepler-exporter-info "$BASE_COLLECTION_PATH" "$pod" - done + KEPLER_PODS=$(oc -n "$KEPLER_NS" get pods -oname 2>/dev/null || echo "") + for pod in $KEPLER_PODS; do + pod=$(echo "$pod" | awk -F '/' '{print $2}') + log "running gather script for kepler pod: $pod" + "$SCRIPT_DIR"/gather-kepler-exporter-info "$BASE_COLLECTION_PATH" "$pod" + done } -gather_olm_info(){ - log "running gather script for olm" - "$SCRIPT_DIR"/gather-olm-info "$BASE_COLLECTION_PATH" +gather_olm_info() { + log "running gather script for olm" + "$SCRIPT_DIR"/gather-olm-info "$BASE_COLLECTION_PATH" } gather_kepler_operator_info() { - log "getting kepler-operator info" - "$SCRIPT_DIR"/gather-kepler-operator-info "$BASE_COLLECTION_PATH" + log "getting kepler-operator info" + "$SCRIPT_DIR"/gather-kepler-operator-info "$BASE_COLLECTION_PATH" } -main(){ - case ${1-} in - --help | -h ) - print_usage - exit 0 - esac - - BASE_COLLECTION_PATH="${1:-/must-gather}" - export LOGFILE_PATH="${BASE_COLLECTION_PATH}/${LOGFILE_NAME}" - - mkdir -p "${BASE_COLLECTION_PATH}" - cd "${BASE_COLLECTION_PATH}" - echo -e "must-gather logs are located at: '${LOGFILE_PATH}'" - - mkdir -p "/tmp/cache-dir" - export KUBECACHEDIR=/tmp/cache-dir - - echo "powermon must-gather started..." - get_kepler_instance - get_kepler_events - get_kepler_daemon_set - get_kepler_config_map - get_kepler_sa - get_kepler_scc - gather_kepler_exporter_info - gather_olm_info - gather_kepler_operator_info - - echo "powermon must-gather completed" +main() { + case ${1-} in + --help | -h) + print_usage + exit 0 + ;; + esac + + BASE_COLLECTION_PATH="${1:-/must-gather}" + export LOGFILE_PATH="${BASE_COLLECTION_PATH}/${LOGFILE_NAME}" + + mkdir -p "${BASE_COLLECTION_PATH}" + cd "${BASE_COLLECTION_PATH}" + echo -e "must-gather logs are located at: '${LOGFILE_PATH}'" + + mkdir -p "/tmp/cache-dir" + export KUBECACHEDIR=/tmp/cache-dir + + echo "powermon must-gather started..." + get_kepler_instance + get_kepler_events + get_kepler_daemon_set + get_kepler_config_map + get_kepler_sa + get_kepler_scc + gather_kepler_exporter_info + gather_olm_info + gather_kepler_operator_info + + echo "powermon must-gather completed" } main "$@" diff --git a/must-gather/gather-kepler-exporter-info b/must-gather/gather-kepler-exporter-info index 224e1401..5229b163 100755 --- a/must-gather/gather-kepler-exporter-info +++ b/must-gather/gather-kepler-exporter-info @@ -17,56 +17,56 @@ set -eu -o pipefail -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) source "${SCRIPT_DIR}/common" BASE_COLLECTION_PATH=$1 KEPLER_POD=$2 -get_kepler_pod(){ - log "getting pod yaml for kepler pod: $KEPLER_POD" - run oc -n "$KEPLER_NS" get pod "$KEPLER_POD" -oyaml "$KEPLER_POD_INFO_DIR/kepler-pod.yaml" +get_kepler_pod() { + log "getting pod yaml for kepler pod: $KEPLER_POD" + run oc -n "$KEPLER_NS" get pod "$KEPLER_POD" -oyaml "$KEPLER_POD_INFO_DIR/kepler-pod.yaml" } -get_kepler_cpuid(){ - log "getting information from \"cpuid\" from kepler pod: $KEPLER_POD" - run oc -n "$KEPLER_NS" exec "$KEPLER_POD" -c kepler-exporter -- cpuid -1 "$KEPLER_POD_INFO_DIR/node-cpuid-info" +get_kepler_cpuid() { + log "getting information from \"cpuid\" from kepler pod: $KEPLER_POD" + run oc -n "$KEPLER_NS" exec "$KEPLER_POD" -c kepler-exporter -- cpuid -1 "$KEPLER_POD_INFO_DIR/node-cpuid-info" } get_kepler_env_var() { - log "getting environment variables from kepler pod: $KEPLER_POD" - run oc -n "$KEPLER_NS" exec "$KEPLER_POD" -c kepler-exporter -- env "$KEPLER_POD_INFO_DIR/env-variables" + log "getting environment variables from kepler pod: $KEPLER_POD" + run oc -n "$KEPLER_NS" exec "$KEPLER_POD" -c kepler-exporter -- env "$KEPLER_POD_INFO_DIR/env-variables" } get_kepler_kernel_info() { - log "getting kernel version from kepler pod: $KEPLER_POD" - echo "kernel version:" >> "$KEPLER_POD_INFO_DIR/kernel-info" - run oc -n "$KEPLER_NS" exec "$KEPLER_POD" -c kepler-exporter -- uname -a "$KEPLER_POD_INFO_DIR/kernel-info" + log "getting kernel version from kepler pod: $KEPLER_POD" + echo "kernel version:" >>"$KEPLER_POD_INFO_DIR/kernel-info" + run oc -n "$KEPLER_NS" exec "$KEPLER_POD" -c kepler-exporter -- uname -a "$KEPLER_POD_INFO_DIR/kernel-info" } -get_kepler_ebpf_info(){ - log "getting ebpf information from kepler pod: $KEPLER_POD" - echo "## kprobes list only applicable for bcc" >> "$KEPLER_POD_INFO_DIR/ebpf-info" - echo "kprobes list:" >> "$KEPLER_POD_INFO_DIR/ebpf-info" - run oc -n "$KEPLER_NS" exec "$KEPLER_POD" -c kepler-exporter -- cat /sys/kernel/debug/kprobes/list "$KEPLER_POD_INFO_DIR/ebpf-info" +get_kepler_ebpf_info() { + log "getting ebpf information from kepler pod: $KEPLER_POD" + echo "## kprobes list only applicable for bcc" >>"$KEPLER_POD_INFO_DIR/ebpf-info" + echo "kprobes list:" >>"$KEPLER_POD_INFO_DIR/ebpf-info" + run oc -n "$KEPLER_NS" exec "$KEPLER_POD" -c kepler-exporter -- cat /sys/kernel/debug/kprobes/list "$KEPLER_POD_INFO_DIR/ebpf-info" } get_kepler_logs() { - log "getting logs from kepler pod: $KEPLER_POD" - run oc -n "$KEPLER_NS" logs "$KEPLER_POD" -c kepler-exporter "$KEPLER_POD_INFO_DIR/kepler.log" + log "getting logs from kepler pod: $KEPLER_POD" + run oc -n "$KEPLER_NS" logs "$KEPLER_POD" -c kepler-exporter "$KEPLER_POD_INFO_DIR/kepler.log" } main() { - KEPLER_POD_INFO_DIR="$BASE_COLLECTION_PATH/kepler-exporter-info/$KEPLER_POD" - mkdir -p "$KEPLER_POD_INFO_DIR" + KEPLER_POD_INFO_DIR="$BASE_COLLECTION_PATH/kepler-exporter-info/$KEPLER_POD" + mkdir -p "$KEPLER_POD_INFO_DIR" - get_kepler_pod - get_kepler_cpuid - get_kepler_env_var - get_kepler_kernel_info - get_kepler_ebpf_info - get_kepler_logs + get_kepler_pod + get_kepler_cpuid + get_kepler_env_var + get_kepler_kernel_info + get_kepler_ebpf_info + get_kepler_logs } main "$@" diff --git a/must-gather/gather-kepler-operator-info b/must-gather/gather-kepler-operator-info index a250ec54..c2c934f8 100755 --- a/must-gather/gather-kepler-operator-info +++ b/must-gather/gather-kepler-operator-info @@ -17,7 +17,7 @@ set -eu -o pipefail -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) source "${SCRIPT_DIR}/common" BASE_COLLECTION_PATH=$1 @@ -25,68 +25,68 @@ BASE_COLLECTION_PATH=$1 KEPLER_OPERATOR_NS="openshift-operators" get_catalogsource() { - log "getting catalogsource info for kepler-operator" - run oc -n "$KEPLER_OPERATOR_NS" get catalogsource kepler-operator-catalog -oyaml "$KEPLER_OPERATOR_INFO_DIR/kepler-operator-catalogsource.yaml" + log "getting catalogsource info for kepler-operator" + run oc -n "$KEPLER_OPERATOR_NS" get catalogsource kepler-operator-catalog -oyaml "$KEPLER_OPERATOR_INFO_DIR/kepler-operator-catalogsource.yaml" } get_subscription() { - log "getting subscription info for kepler-operator" - run oc -n "$KEPLER_OPERATOR_NS" get subscription -l operators.coreos.com/kepler-operator.openshift-operators= -oyaml "$KEPLER_OPERATOR_INFO_DIR/kepler-operator-subscription.yaml" + log "getting subscription info for kepler-operator" + run oc -n "$KEPLER_OPERATOR_NS" get subscription -l operators.coreos.com/kepler-operator.openshift-operators= -oyaml "$KEPLER_OPERATOR_INFO_DIR/kepler-operator-subscription.yaml" } get_install_plan() { - log "getting installplan info for kepler-operator" - run oc -n "$KEPLER_OPERATOR_NS" get installplan -l operators.coreos.com/kepler-operator.openshift-operators= -oyaml "$KEPLER_OPERATOR_INFO_DIR/kepler-operator-installplan.yaml" + log "getting installplan info for kepler-operator" + run oc -n "$KEPLER_OPERATOR_NS" get installplan -l operators.coreos.com/kepler-operator.openshift-operators= -oyaml "$KEPLER_OPERATOR_INFO_DIR/kepler-operator-installplan.yaml" } get_csv() { - log "getting CSV for kepler-operator" - run oc -n "$KEPLER_OPERATOR_NS" get csv -l operators.coreos.com/kepler-operator.openshift-operators= -oyaml "$KEPLER_OPERATOR_INFO_DIR/kepler-operator-csv.yaml" + log "getting CSV for kepler-operator" + run oc -n "$KEPLER_OPERATOR_NS" get csv -l operators.coreos.com/kepler-operator.openshift-operators= -oyaml "$KEPLER_OPERATOR_INFO_DIR/kepler-operator-csv.yaml" } get_kepler_operator_deployment_info() { - KEPLER_OPERATOR_DEPLOY="kepler-operator-controller-manager" - log "getting deployment info for kepler-operator" - run oc -n "$KEPLER_OPERATOR_NS" get deployment "$KEPLER_OPERATOR_DEPLOY" -oyaml "$KEPLER_OPERATOR_INFO_DIR/kepler-operator-deployment.yaml" + KEPLER_OPERATOR_DEPLOY="kepler-operator-controller-manager" + log "getting deployment info for kepler-operator" + run oc -n "$KEPLER_OPERATOR_NS" get deployment "$KEPLER_OPERATOR_DEPLOY" -oyaml "$KEPLER_OPERATOR_INFO_DIR/kepler-operator-deployment.yaml" } get_kepler_operator_pod_info() { - log "getting pod info for kepler-operator" - run oc -n "$KEPLER_OPERATOR_NS" get pod -l control-plane=controller-manager -oyaml "$KEPLER_OPERATOR_INFO_DIR/kepler-operator.yaml" + log "getting pod info for kepler-operator" + run oc -n "$KEPLER_OPERATOR_NS" get pod -l control-plane=controller-manager -oyaml "$KEPLER_OPERATOR_INFO_DIR/kepler-operator.yaml" } get_summary() { - run oc -n "$KEPLER_OPERATOR_NS" get catalogsource kepler-operator-catalog -owide "$KEPLER_OPERATOR_INFO_DIR/summary.txt" - echo -e "\n" >> "$KEPLER_OPERATOR_INFO_DIR/summary.txt" + run oc -n "$KEPLER_OPERATOR_NS" get catalogsource kepler-operator-catalog -owide "$KEPLER_OPERATOR_INFO_DIR/summary.txt" + echo -e "\n" >>"$KEPLER_OPERATOR_INFO_DIR/summary.txt" - run oc -n "$KEPLER_OPERATOR_NS" get subscription -owide "$KEPLER_OPERATOR_INFO_DIR/summary.txt" - echo -e "\n" >> "$KEPLER_OPERATOR_INFO_DIR/summary.txt" + run oc -n "$KEPLER_OPERATOR_NS" get subscription -owide "$KEPLER_OPERATOR_INFO_DIR/summary.txt" + echo -e "\n" >>"$KEPLER_OPERATOR_INFO_DIR/summary.txt" - run oc -n "$KEPLER_OPERATOR_NS" get installplan -owide "$KEPLER_OPERATOR_INFO_DIR/summary.txt" - echo -e "\n" >> "$KEPLER_OPERATOR_INFO_DIR/summary.txt" + run oc -n "$KEPLER_OPERATOR_NS" get installplan -owide "$KEPLER_OPERATOR_INFO_DIR/summary.txt" + echo -e "\n" >>"$KEPLER_OPERATOR_INFO_DIR/summary.txt" - run oc -n "$KEPLER_OPERATOR_NS" get csv -owide "$KEPLER_OPERATOR_INFO_DIR/summary.txt" - echo -e "\n" >> "$KEPLER_OPERATOR_INFO_DIR/summary.txt" + run oc -n "$KEPLER_OPERATOR_NS" get csv -owide "$KEPLER_OPERATOR_INFO_DIR/summary.txt" + echo -e "\n" >>"$KEPLER_OPERATOR_INFO_DIR/summary.txt" - KEPLER_OPERATOR_DEPLOY="kepler-operator-controller-manager" - run oc -n "$KEPLER_OPERATOR_NS" get deployment "$KEPLER_OPERATOR_DEPLOY" -owide "$KEPLER_OPERATOR_INFO_DIR/summary.txt" - echo -e "\n" >> "$KEPLER_OPERATOR_INFO_DIR/summary.txt" + KEPLER_OPERATOR_DEPLOY="kepler-operator-controller-manager" + run oc -n "$KEPLER_OPERATOR_NS" get deployment "$KEPLER_OPERATOR_DEPLOY" -owide "$KEPLER_OPERATOR_INFO_DIR/summary.txt" + echo -e "\n" >>"$KEPLER_OPERATOR_INFO_DIR/summary.txt" - run oc -n "$KEPLER_OPERATOR_NS" get pod -l control-plane=controller-manager -owide "$KEPLER_OPERATOR_INFO_DIR/summary.txt" + run oc -n "$KEPLER_OPERATOR_NS" get pod -l control-plane=controller-manager -owide "$KEPLER_OPERATOR_INFO_DIR/summary.txt" } main() { - KEPLER_OPERATOR_INFO_DIR="$BASE_COLLECTION_PATH/kepler-operator-info" - mkdir -p "$KEPLER_OPERATOR_INFO_DIR" + KEPLER_OPERATOR_INFO_DIR="$BASE_COLLECTION_PATH/kepler-operator-info" + mkdir -p "$KEPLER_OPERATOR_INFO_DIR" - get_subscription - get_catalogsource - get_install_plan - get_csv - get_kepler_operator_deployment_info - get_kepler_operator_pod_info - get_summary + get_subscription + get_catalogsource + get_install_plan + get_csv + get_kepler_operator_deployment_info + get_kepler_operator_pod_info + get_summary } main "$@" diff --git a/must-gather/gather-olm-info b/must-gather/gather-olm-info index e96a5f36..6c465766 100755 --- a/must-gather/gather-olm-info +++ b/must-gather/gather-olm-info @@ -17,7 +17,7 @@ set -eu -o pipefail -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) source "${SCRIPT_DIR}/common" BASE_COLLECTION_PATH=$1 @@ -26,23 +26,22 @@ KEPLER_OPERATOR_NS="openshift-operators" KEPLER_OPERATOR_LABELS="operators.coreos.com/kepler-operator.openshift-operators" get_olm() { - log "collecting olm info for kepler-operator" - run oc -n "$KEPLER_OPERATOR_NS" get olm -l "${KEPLER_OPERATOR_LABELS}"= -oyaml "$OLM_INFO_DIR/olm-reources.yaml" + log "collecting olm info for kepler-operator" + run oc -n "$KEPLER_OPERATOR_NS" get olm -l "${KEPLER_OPERATOR_LABELS}"= -oyaml "$OLM_INFO_DIR/olm-reources.yaml" } get_summary() { - log "collecting olm summary" - run oc -n "$KEPLER_OPERATOR_NS" get olm -owide "$OLM_INFO_DIR/summary.txt" + log "collecting olm summary" + run oc -n "$KEPLER_OPERATOR_NS" get olm -owide "$OLM_INFO_DIR/summary.txt" } - main() { - OLM_INFO_DIR=$BASE_COLLECTION_PATH/olm-info - mkdir -p "$OLM_INFO_DIR" + OLM_INFO_DIR=$BASE_COLLECTION_PATH/olm-info + mkdir -p "$OLM_INFO_DIR" - get_olm - get_summary + get_olm + get_summary } main "$@" From bf6d2a3e8e500ec748790ac76352df322a8e84b0 Mon Sep 17 00:00:00 2001 From: Sunil Thaha Date: Thu, 19 Oct 2023 14:20:32 +1000 Subject: [PATCH 4/4] ci: use make fmt to check for formatting Signed-off-by: Sunil Thaha --- .github/workflows/pr-checks.yaml | 14 +++++++----- automation/presubmit-tests/gofmt.sh | 35 ----------------------------- 2 files changed, 8 insertions(+), 41 deletions(-) delete mode 100755 automation/presubmit-tests/gofmt.sh diff --git a/.github/workflows/pr-checks.yaml b/.github/workflows/pr-checks.yaml index 0432e974..d556c616 100644 --- a/.github/workflows/pr-checks.yaml +++ b/.github/workflows/pr-checks.yaml @@ -17,15 +17,17 @@ jobs: make docs git diff --exit-code - gofmt: + fmt: runs-on: ubuntu-latest steps: - uses: actions/checkout@main - uses: actions/setup-go@main with: go-version-file: go.mod - - name: run gofmt test - run: ./automation/presubmit-tests/gofmt.sh + - name: Install all tools + uses: ./.github/tools-cache + - name: make fmt + run: make fmt && git diff --exit-code escapes_detect: runs-on: ubuntu-latest @@ -71,7 +73,7 @@ jobs: run: make govulncheck bundle: - needs: [docs, golangci, gofmt, vulnerability_detect, escapes_detect] + needs: [docs, golangci, fmt, vulnerability_detect, escapes_detect] runs-on: ubuntu-latest steps: - uses: actions/checkout@main @@ -87,7 +89,7 @@ jobs: git diff --exit-code build-images: - needs: [docs, golangci, gofmt, vulnerability_detect, escapes_detect] + needs: [docs, golangci, fmt, vulnerability_detect, escapes_detect] runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -115,7 +117,7 @@ jobs: additional_tags: ${{ steps.additional_tags.outputs.result }} e2e: - needs: [docs, golangci, gofmt, vulnerability_detect, escapes_detect] + needs: [docs, golangci, fmt, vulnerability_detect, escapes_detect] env: KIND_VERSION: "0.15.0" GO111MODULE: "on" diff --git a/automation/presubmit-tests/gofmt.sh b/automation/presubmit-tests/gofmt.sh deleted file mode 100755 index 5f223d90..00000000 --- a/automation/presubmit-tests/gofmt.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env bash -# -# This file is part of the Kepler project -# -# 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. -# -# Copyright 2022 The Kepler Contributors. -# - -set -e - -echo "Checking go format" -sources="./cmd/ ./pkg/" -unformatted=$(gofmt -e -d -s -l $sources) -if [ ! -z "$unformatted" ]; then - # Some files are not gofmt. - echo >&2 "The following Go files must be formatted with gofmt:" - for fn in $unformatted; do - echo >&2 " $fn" - done - echo >&2 "Please run 'make format'." - exit 1 -fi - -exit 0