Skip to content

Commit

Permalink
update hack and tests/e2e scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Poorunga committed Nov 25, 2023
1 parent 7975b60 commit 96d0303
Show file tree
Hide file tree
Showing 11 changed files with 130 additions and 158 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
pull_request:

env:
KUBEEDGE_VERSION: v1.8.2
KUBEEDGE_VERSION: v1.13.3

jobs:
verify-and-lint:
Expand All @@ -21,7 +21,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.17.x
go-version: 1.19.x

- name: Checkout code
uses: actions/checkout@v3
Expand Down Expand Up @@ -53,7 +53,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.17.x
go-version: 1.19.x

- uses: actions/cache@v3
with:
Expand All @@ -77,7 +77,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.17.x
go-version: 1.19.x

- uses: actions/cache@v3
with:
Expand All @@ -91,9 +91,9 @@ jobs:

- name: Install dependences
run: |
command -v ginkgo || go get github.com/onsi/ginkgo/ginkgo
go get sigs.k8s.io/kind@v0.11.1
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.19.3/bin/linux/amd64/kubectl && sudo install kubectl /usr/local/bin/kubectl
command -v ginkgo || go install github.com/onsi/ginkgo/ginkgo@latest
go install sigs.k8s.io/kind@v0.19.0
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.27.7/bin/linux/amd64/kubectl && sudo install kubectl /usr/local/bin/kubectl
type keadm || {
curl -LO https://github.com/kubeedge/kubeedge/releases/download/$KUBEEDGE_VERSION/keadm-$KUBEEDGE_VERSION-linux-amd64.tar.gz
tar -C . -xzf keadm-$KUBEEDGE_VERSION-linux-amd64.tar.gz
Expand All @@ -115,7 +115,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.17.x
go-version: 1.19.x

- uses: actions/cache@v3
with:
Expand All @@ -137,7 +137,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.17.x
go-version: 1.19.x

- uses: actions/cache@v3
with:
Expand Down
13 changes: 1 addition & 12 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# options for analysis running
run:
# default concurrency is a available CPU number
# default concurrency is an available CPU number
concurrency: 4

# timeout for analysis, e.g. 30s, 5m, default is 1m
Expand Down Expand Up @@ -55,14 +55,3 @@ linters:
- govet
- misspell
- whitespace

issues:
# Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
- path: edge
linters:
- errcheck
- path: cloud/pkg/client
linters:
- gci

54 changes: 19 additions & 35 deletions hack/lib/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# copy from https://github.com/kubeedge/kubeedge/blob/081d4f245725d44f23d9a2919db99a01c56a83e9/hack/lib/install.sh

# check if kubectl installed
function check_kubectl {
echo "checking kubectl"
Expand All @@ -34,13 +32,13 @@ function check_kind {
command -v kind >/dev/null 2>&1
if [[ $? -ne 0 ]]; then
echo "installing kind ."
GO111MODULE="on" go get sigs.k8s.io/kind@v0.9.0
GO111MODULE="on" go install sigs.k8s.io/kind@v0.19.0
if [[ $? -ne 0 ]]; then
echo "kind installed failed, exiting."
exit 1
fi

# avoid modifing go.sum and go.mod when installing the kind
# avoid modifying go.sum and go.mod when installing the kind
git checkout -- go.mod go.sum

export PATH=$PATH:$GOPATH/bin
Expand All @@ -51,45 +49,31 @@ function check_kind {

# check if golangci-lint installed
function check_golangci-lint {
GOPATH="${GOPATH:-$(go env GOPATH)}"
echo "checking golangci-lint"
export PATH=$PATH:$GOPATH/bin
expectedVersion="1.51.1"
command -v golangci-lint >/dev/null 2>&1
if [[ $? -ne 0 ]]; then
echo "installing golangci-lint ."
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.30.0
if [[ $? -ne 0 ]]; then
echo "golangci-lint installed failed, exiting."
exit 1
fi

export PATH=$PATH:$GOPATH/bin
install_golangci-lint
else
echo -n "found golangci-lint, version: " && golangci-lint version
version=$(golangci-lint version)
if [[ $version =~ $expectedVersion ]]; then
echo -n "found golangci-lint, version: " && golangci-lint version
else
echo "golangci-lint version not matched, now version is $version, begin to install new version $expectedVersion"
install_golangci-lint
fi
fi
}

verify_go_version(){
if [[ -z "$(command -v go)" ]]; then
echo "Can't find 'go' in PATH, please fix and retry.
See http://golang.org/doc/install for installation instructions."
exit 1
fi

local go_version
IFS=" " read -ra go_version <<< "$(go version)"
local minimum_go_version
minimum_go_version=go1.12.1
if [[ "${minimum_go_version}" != $(echo -e "${minimum_go_version}\n${go_version[2]}" | sort -s -t. -k 1,1 -k 2,2n -k 3,3n | head -n1) && "${go_version[2]}" != "devel" ]]; then
echo "Detected go version: ${go_version[*]}.
Kubernetes requires ${minimum_go_version} or greater.
Please install ${minimum_go_version} or later."
function install_golangci-lint {
echo "installing golangci-lint ."
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ${GOPATH}/bin v1.51.1
if [[ $? -ne 0 ]]; then
echo "golangci-lint installed failed, exiting."
exit 1
fi
}

verify_docker_installed(){
# verify the docker installed
command -v docker >/dev/null || {
echo "must install the docker first"
exit 1
}
export PATH=$PATH:$GOPATH/bin
}
58 changes: 29 additions & 29 deletions hack/lib/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,62 +16,62 @@
#limitations under the License.
###

# copy from https://github.com/kubeedge/kubeedge/blob/081d4f245725d44f23d9a2919db99a01c56a83e9/hack/lib/lint.sh

set -o errexit
set -o nounset
set -o pipefail

SED_CMD=""
function edgemesh::lint::init() {
SED_CMD=""
KUBEEDGE_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)"

if [[ "$OSTYPE" == "darwin"* ]]
then
SED_CMD=`which gsed`
if [ -z $SED_CMD ]
if [[ "$OSTYPE" == "darwin"* ]]
then
echo "Please install gnu-sed (brew install gnu-sed)"
exit 1
fi
elif [[ "$OSTYPE" == "linux"* ]]
then
SED_CMD=`which sed`
if [ -z $SED_CMD ]
if ! which gsed >/dev/null 2>&1
then
echo "Please install gnu-sed (brew install gnu-sed)"
exit 1
else
SED_CMD=`which gsed`
fi
elif [[ "$OSTYPE" == "linux"* ]]
then
echo "Please install sed"
if ! which sed >/dev/null 2>&1
then
echo "Please install sed"
exit 1
else
SED_CMD=`which sed`
fi
else
echo "Unsupported OS $OSTYPE"
exit 1
fi
else
echo "Unsupported OS $OSTYPE"
exit 1
fi
}

edgemesh::lint::check() {
cd ${EDGEMESH_ROOT}
edgemesh::lint::init
cd ${KUBEEDGE_ROOT}
echo "start lint ..."
set +o pipefail
echo "check any whitenoise ..."
echo "check any white noise ..."
# skip deleted files
if [[ "$OSTYPE" == "darwin"* ]]
then
git diff --cached --name-only --diff-filter=ACRMTU main | grep -Ev "externalversions|fake|vendor|images|adopters|helm" | xargs $SED_CMD -i 's/[ \t]*$//'
git diff --cached --name-only --diff-filter=ACRMTU master | grep -Ev "externalversions|fake|vendor|images|adopters" | xargs $SED_CMD -i 's/[ \t]*$//'
elif [[ "$OSTYPE" == "linux"* ]]
then
git diff --cached --name-only --diff-filter=ACRMTU main | grep -Ev "externalversions|fake|vendor|images|adopters|helm" | xargs --no-run-if-empty $SED_CMD -i 's/[ \t]*$//'
git diff --cached --name-only --diff-filter=ACRMTU master | grep -Ev "externalversions|fake|vendor|images|adopters" | xargs --no-run-if-empty $SED_CMD -i 's/[ \t]*$//'
else
echo "Unsupported OS $OSTYPE"
exit 1
fi

[[ $(git diff --name-only) ]] && {
echo "Some files have white noise issue, please run \`make lint\` to solve this issue"
echo "Some files have white noise issue, please run \`make lint\` to solve and \`git status\` to find and fix this issue"
return 1
}
set -o pipefail

echo "check any issue by golangci-lint ..."
GOOS="linux" golangci-lint run -v --timeout=10m

# only check format issue under staging dir
# echo "check any issue under staging dir by gofmt ..."
# gofmt -l -w staging
GOOS="linux" golangci-lint run -v --timeout=12m
}
25 changes: 18 additions & 7 deletions hack/local-up-edgemesh.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ CLUSTER_NAME=test
MASTER_NODENAME=${CLUSTER_NAME}-control-plane
HOST_IP=`hostname -I | awk '{print $1}'`
EDGE_NODENAME=edge-node
KUBEEDGE_VERSION=1.8.2
KUBEEDGE_VERSION=1.13.3
NAMESPACE=kubeedge
LOG_DIR=${LOG_DIR:-"/tmp"}
TIMEOUT=${TIMEOUT:-120}s
Expand All @@ -56,7 +56,7 @@ if [[ "${CLUSTER_NAME}x" == "x" ]];then
CLUSTER_NAME="test"
fi

export CLUSTER_CONTEXT="--name ${CLUSTER_NAME}"
export CLUSTER_CONTEXT="--name ${CLUSTER_NAME} --config kind-cfg.yaml"


TMP_DIR="$(realpath local-up-tmp)"
Expand All @@ -70,6 +70,17 @@ get_kubeedge_pid() {

# spin up cluster with kind command
function kind_up_cluster {
cat <<EOF > kind-cfg.yaml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
extraPortMappings:
- containerPort: 10000
hostPort: 10000
- containerPort: 10002
hostPort: 10002
EOF
echo "Running kind: [kind create cluster ${CLUSTER_CONTEXT}]"
kind create cluster ${CLUSTER_CONTEXT}
add_cleanup '
Expand Down Expand Up @@ -121,15 +132,14 @@ localup_kubeedge() {
token=$(sudo keadm gettoken --kube-config=${KUBECONFIG})
echo $token

# turn off edgemesh and turn on local apiserver featuren and resart edgeocre
export CHECK_EDGECORE_ENVIRONMENT="false"
sudo -E keadm join --cloudcore-ipport=${HOST_IP}:10000 --kubeedge-version=${KUBEEDGE_VERSION} --token=${token} --edgenode-name=${EDGE_NODENAME}
# turn off edgemesh and turn on local apiserver feature and restart edgecore
sudo -E systemctl set-environment CHECK_EDGECORE_ENVIRONMENT="false"
sudo -E keadm join --cloudcore-ipport=${HOST_IP}:10000 --kubeedge-version=${KUBEEDGE_VERSION} --token=${token} --edgenode-name=${EDGE_NODENAME} --with-mqtt=false --runtimetype=docker

EDGE_BIN=/usr/local/bin/edgecore
EDGE_CONFIGFILE=/etc/kubeedge/config/edgecore.yaml
EDGECORE_LOG=${LOG_DIR}/edgecore.log
sudo sed -i 's/clusterDNS:\ \"\"/clusterDNS:\ 169.254.96.16/g' ${EDGE_CONFIGFILE}
sudo sed -i 's/clusterDomain:\ \"\"/clusterDomain:\ cluster.local/g' ${EDGE_CONFIGFILE}
sudo sed -i 's/clusterDomain:\ cluster.local/clusterDomain:\ cluster.local\n\ \ \ \ \ \ clusterDNS:\n\ \ \ \ \ \ -\ 169.254.96.16/g' ${EDGE_CONFIGFILE}

ps -aux | grep edgecore

Expand All @@ -138,6 +148,7 @@ localup_kubeedge() {
EDGECORE_PID=$!
sleep 15
ps -aux | grep edgecore

check_node_ready ${EDGE_NODENAME}
}

Expand Down
4 changes: 1 addition & 3 deletions hack/make-rules/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
#limitations under the License.
###

# copy from https://github.com/kubeedge/kubeedge/blob/081d4f245725d44f23d9a2919db99a01c56a83e9/hack/make-rules/lint.sh

set -o errexit
set -o nounset
set -o pipefail
Expand All @@ -30,4 +28,4 @@ set +e
check_golangci-lint
set -e

edgemesh::lint::check "$@"
edgemesh::lint::check "$@"
Loading

0 comments on commit 96d0303

Please sign in to comment.