diff --git a/.devcontainer/scripts/install-tools.sh b/.devcontainer/scripts/install-tools.sh index c02a39f7..3fd14396 100644 --- a/.devcontainer/scripts/install-tools.sh +++ b/.devcontainer/scripts/install-tools.sh @@ -7,13 +7,13 @@ echo "**********************************************************************" echo "Install OpenShift CLI..." echo "**********************************************************************" -if [ $(uname -m) == aarch64 ]; then - echo "Installing OpenShift CLI for ARM64..." - curl https://mirror.openshift.com/pub/openshift-v4/clients/ocp/stable/openshift-client-linux-arm64.tar.gz --output oc.tar.gz +if [ "$(uname -m)" == aarch64 ]; then + echo "Installing OpenShift CLI for ARM64..." + curl https://mirror.openshift.com/pub/openshift-v4/clients/ocp/stable/openshift-client-linux-arm64.tar.gz --output oc.tar.gz else - echo "Installing OpenShift CLI for x86_64..." - curl https://mirror.openshift.com/pub/openshift-v4/clients/ocp/stable/openshift-client-linux.tar.gz --output oc.tar.gz -fi; + echo "Installing OpenShift CLI for x86_64..." + curl https://mirror.openshift.com/pub/openshift-v4/clients/ocp/stable/openshift-client-linux.tar.gz --output oc.tar.gz +fi sudo tar xvzf oc.tar.gz -C /usr/local/bin/ oc sudo ln -s /usr/local/bin/oc /usr/bin/oc rm oc.tar.gz @@ -24,9 +24,9 @@ echo "Creatine alias for kubectl (kc) and kustomize (ku)..." echo "**********************************************************************" echo "Creating kc and kns alias for kubectl..." -echo "alias kc='/usr/local/bin/kubectl'" >> $HOME/.bash_aliases -echo "alias kns='kubectl config set-context --current --namespace'" >> $HOME/.bash_aliases +echo "alias kc='/usr/local/bin/kubectl'" >>"$HOME/.bash_aliases" +echo "alias kns='kubectl config set-context --current --namespace'" >>"$HOME/.bash_aliases" echo "Creating ku alias for kustomize..." -echo "alias ku='/usr/local/bin/kustomize'" >> $HOME/.bash_aliases +echo "alias ku='/usr/local/bin/kustomize'" >>"$HOME/.bash_aliases" -echo "Extra tools installations complete." \ No newline at end of file +echo "Extra tools installations complete." diff --git a/automation/presubmit-tests/gofmt.sh b/automation/presubmit-tests/gofmt.sh index 5f223d90..2a7df97f 100755 --- a/automation/presubmit-tests/gofmt.sh +++ b/automation/presubmit-tests/gofmt.sh @@ -20,16 +20,14 @@ 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 +unformatted="$(gofmt -e -d -s -l "./cmd" "./pkg")" +[[ -z "$unformatted" ]] && exit 0 -exit 0 +# Some files are not gofmt. +echo "The following Go files must be formatted with gofmt:" >&2 +for fn in $unformatted; do + echo " $fn" >&2 +done + +echo "Please run 'make format'." >&2 +exit 1 diff --git a/hack/bundle.sh b/hack/bundle.sh index 36f8ddb6..dc09d009 100755 --- a/hack/bundle.sh +++ b/hack/bundle.sh @@ -24,6 +24,7 @@ declare -r PROJECT_ROOT declare -r LOCAL_BIN="$PROJECT_ROOT/tmp/bin" declare -r CSV_FILE=bundle/manifests/kepler-operator.clusterserviceversion.yaml +# shellcheck source=hack/utils.bash source "$PROJECT_ROOT/hack/utils.bash" # TODO: write a git action to create bundle on every pull request merge and make a commit to new branch diff --git a/hack/cluster-clean.sh b/hack/cluster-clean.sh deleted file mode 100644 index 11d37cc2..00000000 --- a/hack/cluster-clean.sh +++ /dev/null @@ -1,42 +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 - -source ./hack/common.sh - -MANIFESTS_OUT_DIR=${MANIFESTS_OUT_DIR:-"_output/generated-manifest"} - -function main() { - echo "Cleaning up ..." - - 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 - - sleep 2 - - echo "Done $0" -} - -main "$@" \ No newline at end of file diff --git a/hack/cluster.sh b/hack/cluster.sh index 1a146ca0..05691d03 100755 --- a/hack/cluster.sh +++ b/hack/cluster.sh @@ -33,6 +33,7 @@ declare -r DEV_CLUSTER_DIR="$TMP_DIR/local-dev-cluster" declare -r BIN_DIR="$TMP_DIR/bin" declare -r OPERATOR_SDK_VERSION=${OPERATOR_SDK_VERSION:-v1.27.0} +# shellcheck source=hack/utils.bash source "$PROJECT_ROOT/hack/utils.bash" git_checkout() { diff --git a/hack/common.sh b/hack/common.sh deleted file mode 100644 index eacd0be3..00000000 --- a/hack/common.sh +++ /dev/null @@ -1,62 +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 - - -_registry_port="5001" -_registry_name="kind-registry" - -CTR_CMD=${CTR_CMD-docker} - -CONFIG_PATH="kind" -KIND_VERSION=${KIND_VERSION:-0.15.0} -KIND_MANIFESTS_DIR="$CONFIG_PATH/manifests" -CLUSTER_NAME=${KIND_CLUSTER_NAME:-kind} -REGISTRY_NAME=${REGISTRY_NAME:-kind-registry} -REGISTRY_PORT=${REGISTRY_PORT:-5001} -KIND_DEFAULT_NETWORK="kind" - -IMAGE_REPO=${IMAGE_REPO:-localhost:5001} -ESTIMATOR_REPO=${ESTIMATOR_REPO:-quay.io/sustainable_computing_io} -MODEL_SERVER_REPO=${MODEL_SERVER_REPO:-quay.io/sustainable_computing_io} -IMAGE_TAG=${IMAGE_TAG:-devel} - -# check CPU arch -PLATFORM=$(uname -m) -case ${PLATFORM} in -x86_64* | i?86_64* | amd64*) - ARCH="amd64" - ;; -ppc64le) - ARCH="ppc64le" - ;; -aarch64* | arm64*) - ARCH="arm64" - ;; -*) - 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 diff --git a/hack/dashboard/openshift/deploy-grafana.sh b/hack/dashboard/openshift/deploy-grafana.sh index ccf6c52b..ea8cac7c 100755 --- a/hack/dashboard/openshift/deploy-grafana.sh +++ b/hack/dashboard/openshift/deploy-grafana.sh @@ -17,6 +17,7 @@ declare -r UWM_CONFIG_URL="https://docs.openshift.com/container-platform/latest/ declare -r GRAFANA_NS=kepler-grafana declare -r GRAFANA_SA=grafana +# shellcheck source=hack/utils.bash source "$PROJECT_ROOT/hack/utils.bash" oc_apply_grafana_ns() { diff --git a/hack/integration_cluster.sh b/hack/integration_cluster.sh deleted file mode 100644 index 43abe1dd..00000000 --- a/hack/integration_cluster.sh +++ /dev/null @@ -1,95 +0,0 @@ -#!/bin/bash -# SPDX-License-Identifier: Apache-2.0 -set -o errexit -#set -x -CLUSTER_NAME=${ENV_KIND_CLUSTER_NAME:-kind} - -LOCAL_REGISTRY_NAME=${ENV_LOCAL_REGISTRY_NAME:-kind-registry} -LOCAL_REGISTRY_PORT=${ENV_LOCAL_REGISTRY_PORT:-5000} - -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 [ "${MODE}" == "kind" ]; then - kindTest - fi -} - -function kindTest() { - echo "install kind" - go install sigs.k8s.io/kind@v0.12.0 - - 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 - - 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 - - # 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 <