feat: add lint/e2e tests support (#126)

Signed-off-by: bitliu <bitliu@tencent.com>
This commit is contained in:
Xunzhuo
2023-01-18 10:14:22 +08:00
committed by GitHub
parent 0bf395a423
commit b410fc96e3
38 changed files with 2897 additions and 19 deletions

32
tools/hack/cluster.conf Normal file
View File

@@ -0,0 +1,32 @@
# Copyright (c) 2022 Alibaba Group Holding Ltd.
# 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.
# cluster.conf
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
kubeadmConfigPatches:
- |
kind: InitConfiguration
nodeRegistration:
kubeletExtraArgs:
node-labels: "ingress-ready=true"
extraPortMappings:
- containerPort: 80
hostPort: 80
protocol: TCP
- containerPort: 443
hostPort: 443
protocol: TCP

29
tools/hack/create-cluster.sh Executable file
View File

@@ -0,0 +1,29 @@
# Copyright (c) 2022 Alibaba Group Holding Ltd.
# 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.
#!/usr/bin/env bash
set -euo pipefail
# Setup default values
CLUSTER_NAME=${CLUSTER_NAME:-"higress"}
METALLB_VERSION=${METALLB_VERSION:-"v0.13.7"}
KIND_NODE_TAG=${KIND_NODE_TAG:-"v1.25.3"}
## Create kind cluster.
if [[ -z "${KIND_NODE_TAG}" ]]; then
tools/bin/kind create cluster --name "${CLUSTER_NAME}" --config=tools/hack/cluster.conf
else
tools/bin/kind create cluster --image "kindest/node:${KIND_NODE_TAG}" --name "${CLUSTER_NAME}" --config=tools/hack/cluster.conf
fi

86
tools/hack/gobuild.sh Executable file
View File

@@ -0,0 +1,86 @@
#!/bin/bash
# WARNING: DO NOT EDIT, THIS FILE IS PROBABLY A COPY
#
# The original version of this file is located in the https://github.com/istio/common-files repo.
# If you're looking at this file in a different repo and want to make a change, please go to the
# common-files repo, make the change there and check it in. Then come back to this repo and run
# "make update-common".
# Copyright Istio Authors. All Rights Reserved.
#
# 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 builds and version stamps the output
export GOPROXY
VERBOSE=${VERBOSE:-"0"}
V=""
if [[ "${VERBOSE}" == "1" ]];then
V="-x"
set -x
fi
SCRIPTPATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
OUT=${1:?"output path"}
shift
set -e
BUILD_GOOS=${GOOS:-linux}
BUILD_GOARCH=${GOARCH:-amd64}
GOBINARY=${GOBINARY:-go}
GOPKG="$GOPATH/pkg"
BUILDINFO=${BUILDINFO:-""}
STATIC=${STATIC:-1}
LDFLAGS=${LDFLAGS:--extldflags -static}
GOBUILDFLAGS=${GOBUILDFLAGS:-""}
# Split GOBUILDFLAGS by spaces into an array called GOBUILDFLAGS_ARRAY.
IFS=' ' read -r -a GOBUILDFLAGS_ARRAY <<< "$GOBUILDFLAGS"
GCFLAGS=${GCFLAGS:-}
export CGO_ENABLED=${CGO_ENABLED:-0}
if [[ "${STATIC}" != "1" ]];then
LDFLAGS=""
fi
# BUILD LD_EXTRAFLAGS
LD_EXTRAFLAGS=""
# gather buildinfo if not already provided
# For a release build BUILDINFO should be produced
# at the beginning of the build and used throughout
if [[ -z ${BUILDINFO} ]];then
BUILDINFO=$(mktemp)
"${SCRIPTPATH}/report_build_info.sh" > "${BUILDINFO}"
fi
while read -r line; do
echo -e "\n${line}"
LD_EXTRAFLAGS="${LD_EXTRAFLAGS} -X ${line}"
done < "${BUILDINFO}"
OPTIMIZATION_FLAGS=(-trimpath)
if [ "${DEBUG}" == "1" ]; then
OPTIMIZATION_FLAGS=()
fi
time GOOS=${BUILD_GOOS} GOARCH=${BUILD_GOARCH} ${GOBINARY} build \
${V} "${GOBUILDFLAGS_ARRAY[@]}" ${GCFLAGS:+-gcflags "${GCFLAGS}"} \
-o "${OUT}" \
"${OPTIMIZATION_FLAGS[@]}" \
-pkgdir="${GOPKG}/${BUILD_GOOS}_${BUILD_GOARCH}" \
-ldflags "${LDFLAGS} ${LD_EXTRAFLAGS}" "${@}"

56
tools/hack/kind-load-image.sh Executable file
View File

@@ -0,0 +1,56 @@
# Copyright (c) 2022 Alibaba Group Holding Ltd.
# 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.
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
readonly KIND=${KIND:-tools/bin/kind}
readonly CLUSTER_NAME=${CLUSTER_NAME:-"higress"}
# Docker variables
readonly IMAGE="$1"
readonly TAG="$2"
# Wrap sed to deal with GNU and BSD sed flags.
run::sed() {
if sed --version </dev/null 2>&1 | grep -q GNU; then
# GNU sed
sed -i "$@"
else
# assume BSD sed
sed -i '' "$@"
fi
}
kind::cluster::exists() {
${KIND} get clusters | grep -q "$1"
}
kind::cluster::load() {
${KIND} load docker-image \
--name "${CLUSTER_NAME}" \
"$@"
}
if ! kind::cluster::exists "$CLUSTER_NAME" ; then
echo "cluster $CLUSTER_NAME does not exist"
exit 2
fi
# Push the Higress image to the kind cluster.
echo "Loading image ${IMAGE}:${TAG} to kind cluster ${CLUSTER_NAME}..."
kind::cluster::load "${IMAGE}:${TAG}"

46
tools/hack/prebuild.sh Executable file
View File

@@ -0,0 +1,46 @@
#!/bin/bash
set -e
ENVOY_VERSION="${ENVOY_VERSION:=1.20}"
ISITO_VERSION="${ISTIO_VERSION:=1.12}"
WORK_DIR=`cd $(dirname "$0")/../..;pwd`
cd $WORK_DIR
mkdir -p external/package
envoy_repos=("go-control-plane" "envoy")
for repo in ${envoy_repos[@]}; do
if [ -e external/$repo ];then
continue
fi
cp -r envoy/${ENVOY_VERSION}/$repo external/$repo
for patch in `ls envoy/${ENVOY_VERSION}/patches/$repo/*.patch`; do
patch -d external/$repo -p1 < $patch
done
cd external/$repo
echo "gitdir: /parent/.git/modules/envoy/${ENVOY_VERSION}/$repo" > .git
if [ -f "go.mod" ]; then
go mod tidy
fi
cd $WORK_DIR
done
istio_repos=("api" "client-go" "pkg" "istio" "proxy")
for repo in ${istio_repos[@]}; do
if [ -e external/$repo ];then
continue
fi
cp -r istio/${ISTIO_VERSION}/$repo external/$repo
for patch in `ls istio/${ISTIO_VERSION}/patches/$repo/*.patch`; do
patch -d external/$repo -p1 < $patch
done
cd external/$repo
echo "gitdir: /parent/.git/modules/istio/${ISTIO_VERSION}/$repo" > .git
if [ -f "go.mod" ]; then
go mod tidy
fi
cd $WORK_DIR
done

46
tools/hack/report_build_info.sh Executable file
View File

@@ -0,0 +1,46 @@
#!/bin/bash
# WARNING: DO NOT EDIT, THIS FILE IS PROBABLY A COPY
#
# The original version of this file is located in the https://github.com/istio/common-files repo.
# If you're looking at this file in a different repo and want to make a change, please go to the
# common-files repo, make the change there and check it in. Then come back to this repo and run
# "make update-common".
# Copyright Istio 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.
if BUILD_GIT_REVISION=$(git rev-parse HEAD 2> /dev/null); then
if [[ -z "${IGNORE_DIRTY_TREE}" ]] && [[ -n "$(git status --porcelain 2>/dev/null)" ]]; then
BUILD_GIT_REVISION=${BUILD_GIT_REVISION}"-dirty"
fi
else
BUILD_GIT_REVISION=unknown
fi
# Check for local changes
tree_status="Clean"
if [[ -z "${IGNORE_DIRTY_TREE}" ]] && ! git diff-index --quiet HEAD --; then
tree_status="Modified"
fi
GIT_DESCRIBE_TAG=$(cat VERSION)
HUB=${HUB:-"higress-registry.cn-hangzhou.cr.aliyuncs.com/higress"}
# used by common/scripts/gobuild.sh
echo "istio.io/pkg/version.buildVersion=${VERSION:-$BUILD_GIT_REVISION}"
echo "istio.io/pkg/version.buildGitRevision=${BUILD_GIT_REVISION}"
echo "istio.io/pkg/version.buildStatus=${tree_status}"
echo "istio.io/pkg/version.buildTag=${GIT_DESCRIBE_TAG}"
echo "istio.io/pkg/version.buildHub=${HUB}"

65
tools/hack/run.sh Executable file
View File

@@ -0,0 +1,65 @@
#!/bin/bash
# WARNING: DO NOT EDIT, THIS FILE IS PROBABLY A COPY
#
# The original version of this file is located in the https://github.com/istio/common-files repo.
# If you're looking at this file in a different repo and want to make a change, please go to the
# common-files repo, make the change there and check it in. Then come back to this repo and run
# "make update-common".
# Copyright Istio 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.
set -e
WD=$(dirname "$0")
WD=$(cd "$WD"; pwd)
# shellcheck disable=SC1090
source "${WD}/setup_env.sh"
# Override variables with container specific
export TARGET_OUT=${CONTAINER_TARGET_OUT}
export TARGET_OUT_LINUX=${CONTAINER_TARGET_OUT_LINUX}
export REPO_ROOT=/work
HUB="${HUB:-higress-registry.cn-hangzhou.cr.aliyuncs.com/higress}"
MOUNT_SOURCE="${MOUNT_SOURCE:-${PWD}}"
MOUNT_DEST="${MOUNT_DEST:-/work}"
read -ra DOCKER_RUN_OPTIONS <<< "${DOCKER_RUN_OPTIONS:-}"
[[ -t 1 ]] && DOCKER_RUN_OPTIONS+=("-it")
# $CONTAINER_OPTIONS becomes an empty arg when quoted, so SC2086 is disabled for the
# following command only
# shellcheck disable=SC2086
"${CONTAINER_CLI}" run \
--rm \
"${DOCKER_RUN_OPTIONS[@]}" \
--init \
--sig-proxy=true \
${DOCKER_SOCKET_MOUNT:--v /var/run/docker.sock:/var/run/docker.sock} \
$CONTAINER_OPTIONS \
--env-file <(env | grep -v ${ENV_BLOCKLIST}) \
-e IN_BUILD_CONTAINER=1 \
-e TZ="${TIMEZONE:-$TZ}" \
-e HUB="${HUB}" \
--mount "type=bind,source=${MOUNT_SOURCE},destination=/work" \
--mount "type=volume,source=go,destination=/go" \
--mount "type=volume,source=gocache,destination=/gocache" \
--mount "type=volume,source=cache,destination=/home/.cache" \
${CONDITIONAL_HOST_MOUNTS} \
-w "${MOUNT_DEST}" "${IMG}" "$@"

184
tools/hack/setup_env.sh Executable file
View File

@@ -0,0 +1,184 @@
#!/bin/bash
# shellcheck disable=SC2034
# WARNING: DO NOT EDIT, THIS FILE IS PROBABLY A COPY
#
# The original version of this file is located in the https://github.com/istio/common-files repo.
# If you're looking at this file in a different repo and want to make a change, please go to the
# common-files repo, make the change there and check it in. Then come back to this repo and run
# "make update-common".
# Copyright Istio 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.
set -e
LOCAL_ARCH=$(uname -m)
export LOCAL_ARCH
# Pass environment set target architecture to build system
if [[ ${TARGET_ARCH} ]]; then
export TARGET_ARCH
elif [[ ${LOCAL_ARCH} == x86_64 ]]; then
export TARGET_ARCH=amd64
elif [[ ${LOCAL_ARCH} == armv8* ]]; then
export TARGET_ARCH=arm64
elif [[ ${LOCAL_ARCH} == arm64* ]]; then
export TARGET_ARCH=arm64
elif [[ ${LOCAL_ARCH} == aarch64* ]]; then
export TARGET_ARCH=arm64
elif [[ ${LOCAL_ARCH} == armv* ]]; then
export TARGET_ARCH=arm
elif [[ ${LOCAL_ARCH} == s390x ]]; then
export TARGET_ARCH=s390x
elif [[ ${LOCAL_ARCH} == ppc64le ]]; then
export TARGET_ARCH=ppc64le
else
echo "This system's architecture, ${LOCAL_ARCH}, isn't supported"
exit 1
fi
LOCAL_OS=$(uname)
export LOCAL_OS
# Pass environment set target operating-system to build system
if [[ ${TARGET_OS} ]]; then
export TARGET_OS
elif [[ $LOCAL_OS == Linux ]]; then
export TARGET_OS=linux
readlink_flags="-f"
elif [[ $LOCAL_OS == Darwin ]]; then
export TARGET_OS=darwin
readlink_flags=""
else
echo "This system's OS, $LOCAL_OS, isn't supported"
exit 1
fi
# Build image to use
if [[ "${IMAGE_VERSION:-}" == "" ]]; then
export IMAGE_VERSION=34b06c08ee613a15e08c5888ac269ad22f23d23e
fi
if [[ "${IMAGE_NAME:-}" == "" ]]; then
export IMAGE_NAME=build-tools
fi
export UID
DOCKER_GID="${DOCKER_GID:-$(grep '^docker:' /etc/group | cut -f3 -d:)}"
export DOCKER_GID
TIMEZONE=$(readlink "$readlink_flags" /etc/localtime | sed -e 's/^.*zoneinfo\///')
export TIMEZONE
export TARGET_OUT="${TARGET_OUT:-$(pwd)/out/${TARGET_OS}_${TARGET_ARCH}}"
export TARGET_OUT_LINUX="${TARGET_OUT_LINUX:-$(pwd)/out/linux_${TARGET_ARCH}}"
export CONTAINER_TARGET_OUT="${CONTAINER_TARGET_OUT:-/work/out/${TARGET_OS}_${TARGET_ARCH}}"
export CONTAINER_TARGET_OUT_LINUX="${CONTAINER_TARGET_OUT_LINUX:-/work/out/linux_${TARGET_ARCH}}"
export IMG="${IMG:-${HUB:-higress-registry.cn-hangzhou.cr.aliyuncs.com/higress}/${IMAGE_NAME}:${IMAGE_VERSION}}"
export CONTAINER_CLI="${CONTAINER_CLI:-docker}"
export ENV_BLOCKLIST="${ENV_BLOCKLIST:-^_\|PATH\|SHELL\|EDITOR\|TMUX\|USER\|HOME\|PWD\|TERM\|GO\|rvm\|SSH\|TMPDIR\|CC\|CXX\|MAKEFILE_LIST}"
# Remove functions from the list of exported variables, they mess up with the `env` command.
for f in $(declare -F -x | cut -d ' ' -f 3);
do
unset -f "${f}"
done
# Set conditional host mounts
export CONDITIONAL_HOST_MOUNTS=${CONDITIONAL_HOST_MOUNTS:-}
container_kubeconfig=''
# docker conditional host mount (needed for make docker push)
if [[ -d "${HOME}/.docker" ]]; then
CONDITIONAL_HOST_MOUNTS+="--mount type=bind,source=${HOME}/.docker,destination=/config/.docker,readonly "
fi
# gcloud conditional host mount (needed for docker push with the gcloud auth configure-docker)
if [[ -d "${HOME}/.config/gcloud" ]]; then
CONDITIONAL_HOST_MOUNTS+="--mount type=bind,source=${HOME}/.config/gcloud,destination=/config/.config/gcloud,readonly "
fi
# gitconfig conditional host mount (needed for git commands inside container)
if [[ -f "${HOME}/.gitconfig" ]]; then
CONDITIONAL_HOST_MOUNTS+="--mount type=bind,source=${HOME}/.gitconfig,destination=/home/.gitconfig,readonly "
fi
# .netrc conditional host mount (needed for git commands inside container)
if [[ -f "${HOME}/.netrc" ]]; then
CONDITIONAL_HOST_MOUNTS+="--mount type=bind,source=${HOME}/.netrc,destination=/home/.netrc,readonly "
fi
# echo ${CONDITIONAL_HOST_MOUNTS}
# This function checks if the file exists. If it does, it creates a randomly named host location
# for the file, adds it to the host KUBECONFIG, and creates a mount for it.
add_KUBECONFIG_if_exists () {
if [[ -f "$1" ]]; then
kubeconfig_random="$(od -vAn -N4 -tx /dev/random | tr -d '[:space:]' | cut -c1-8)"
container_kubeconfig+="/config/${kubeconfig_random}:"
CONDITIONAL_HOST_MOUNTS+="--mount type=bind,source=${1},destination=/config/${kubeconfig_random},readonly "
fi
}
# This function is designed for maximum compatibility with various platforms. This runs on
# any Mac or Linux platform with bash 4.2+. Please take care not to modify this function
# without testing properly.
#
# This function will properly handle any type of path including those with spaces using the
# loading pattern specified by *kubectl config*.
#
# testcase: "a:b c:d"
# testcase: "a b:c d:e f"
# testcase: "a b:c:d e"
parse_KUBECONFIG () {
TMPDIR=""
if [[ "$1" =~ ([^:]*):(.*) ]]; then
while true; do
rematch=${BASH_REMATCH[1]}
add_KUBECONFIG_if_exists "$rematch"
remainder="${BASH_REMATCH[2]}"
if [[ ! "$remainder" =~ ([^:]*):(.*) ]]; then
if [[ -n "$remainder" ]]; then
add_KUBECONFIG_if_exists "$remainder"
break
fi
fi
done
else
add_KUBECONFIG_if_exists "$1"
fi
}
KUBECONFIG=${KUBECONFIG:="$HOME/.kube/config"}
parse_KUBECONFIG "${KUBECONFIG}"
if [[ "${BUILD_WITH_CONTAINER:-1}" -eq "1" ]]; then
export KUBECONFIG="${container_kubeconfig%?}"
fi
# Avoid recursive calls to make from attempting to start an additional container
export BUILD_WITH_CONTAINER=0
# For non container build, we need to write env to file
if [[ "${1}" == "envfile" ]]; then
echo "TARGET_OUT_LINUX=${TARGET_OUT_LINUX}"
echo "TARGET_OUT=${TARGET_OUT}"
echo "TIMEZONE=${TIMEZONE}"
echo "LOCAL_OS=${LOCAL_OS}"
echo "TARGET_OS=${TARGET_OS}"
echo "LOCAL_ARCH=${LOCAL_ARCH}"
echo "TARGET_ARCH=${TARGET_ARCH}"
echo "BUILD_WITH_CONTAINER=0"
fi