Skip to content

Commit

Permalink
feat: add support for e2e tests
Browse files Browse the repository at this point in the history
Signed-off-by: bitliu <bitliu@tencent.com>
  • Loading branch information
Xunzhuo committed Jan 17, 2023
1 parent 0bf395a commit 609a566
Show file tree
Hide file tree
Showing 38 changed files with 2,897 additions and 19 deletions.
16 changes: 11 additions & 5 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ on:
branches: ["*"]

jobs:
#TODO(@Xunzhuo): add lint tools to do static code analyse.
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: 1.19
# There are too many lint errors in current code bases
# uncomment when we decide what lint should be addressed or ignored.
# - run: make lint

coverage-test:
runs-on: ubuntu-latest
Expand All @@ -32,10 +37,6 @@ jobs:
# The type of runner that the job will run on
runs-on: ubuntu-latest
needs: [lint,coverage-test]
strategy:
matrix:
golang:
- 1.19
steps:
- name: "Setup Go"
uses: actions/setup-go@v3
Expand Down Expand Up @@ -67,7 +68,12 @@ jobs:
runs-on: ubuntu-latest
needs: [build]
steps:
- name: "Setup Go"
uses: actions/setup-go@v3
with:
go-version: 1.19
- uses: actions/checkout@v3
- run: make e2e-test

publish:
runs-on: ubuntu-latest
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ out
*.out
*.tgz
*.wasm
.DS_Store
coverage.xml
.idea/
bazel-bin
bazel-out
bazel-testlogs
bazel-wasm-cpp
bazel-wasm-cpp
tools/bin/
1 change: 1 addition & 0 deletions .licenserc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ header:
- 'plugins/**'
- 'CODEOWNERS'
- 'VERSION'
- 'tools/'

comment: on-failure
dependency:
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ ifeq ($(BUILD_WITH_CONTAINER),1)
# environment. This is needed to allow overrides from Makefile.overrides.mk.
export

$(shell $(shell pwd)/script/setup_env.sh)
$(shell $(shell pwd)/tools/hack/setup_env.sh)

RUN = ./script/run.sh
RUN = ./tools/hack/run.sh

MAKE_DOCKER = $(RUN) make --no-print-directory -e -f Makefile.core.mk

Expand All @@ -58,7 +58,7 @@ else
# If we are not in build container, we need a workaround to get environment properly set
# Write to file, then include
$(shell mkdir -p out)
$(shell $(shell pwd)/script/setup_env.sh envfile > out/.env)
$(shell $(shell pwd)/tools/hack/setup_env.sh envfile > out/.env)
include out/.env
# An export free of arugments in a Makefile places all variables in the Makefile into the
# environment. This behavior may be surprising to many that use shell often, which simply
Expand Down
63 changes: 54 additions & 9 deletions Makefile.core.mk
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ submodule:
git submodule update --init

prebuild: submodule
./script/prebuild.sh
./tools/hack/prebuild.sh

.PHONY: default
default: build
Expand All @@ -52,11 +52,11 @@ go.test.coverage: prebuild

.PHONY: build
build: prebuild $(OUT)
GOPROXY=$(GOPROXY) GOOS=$(GOOS_LOCAL) GOARCH=$(GOARCH_LOCAL) LDFLAGS=$(RELEASE_LDFLAGS) script/gobuild.sh $(OUT)/ $(BINARIES)
GOPROXY=$(GOPROXY) GOOS=$(GOOS_LOCAL) GOARCH=$(GOARCH_LOCAL) LDFLAGS=$(RELEASE_LDFLAGS) tools/hack/gobuild.sh $(OUT)/ $(BINARIES)

.PHONY: build-linux
build-linux: prebuild $(OUT)
GOPROXY=$(GOPROXY) GOOS=linux GOARCH=$(GOARCH_LOCAL) LDFLAGS=$(RELEASE_LDFLAGS) script/gobuild.sh $(OUT_LINUX)/ $(BINARIES)
GOPROXY=$(GOPROXY) GOOS=linux GOARCH=$(GOARCH_LOCAL) LDFLAGS=$(RELEASE_LDFLAGS) tools/hack/gobuild.sh $(OUT_LINUX)/ $(BINARIES)

# Create targets for OUT_LINUX/binary
# There are two use cases here:
Expand All @@ -69,7 +69,7 @@ ifeq ($(BUILD_ALL),true)
$(OUT_LINUX)/$(shell basename $(1)): build-linux
else
$(OUT_LINUX)/$(shell basename $(1)): $(OUT_LINUX)
GOPROXY=$(GOPROXY) GOOS=linux GOARCH=$(GOARCH_LOCAL) LDFLAGS=$(RELEASE_LDFLAGS) script/gobuild.sh $(OUT_LINUX)/ -tags=$(2) $(1)
GOPROXY=$(GOPROXY) GOOS=linux GOARCH=$(GOARCH_LOCAL) LDFLAGS=$(RELEASE_LDFLAGS) tools/hack/gobuild.sh $(OUT_LINUX)/ -tags=$(2) $(1)
endif
endef

Expand Down Expand Up @@ -115,10 +115,19 @@ define create_ns
endef

install: pre-install
$(call create_ns,istio-system)
$(call create_ns,higress-system)
helm install istio helm/kind/istio -n istio-system
helm install higress helm/kind/higress -n higress-system
helm install istio helm/kind/istio -n istio-system --create-namespace
helm install higress helm/kind/higress -n higress-system --create-namespace

ENVOY_LATEST_IMAGE_TAG ?= bf607ae5541ce5c1cc95b4f98b3fd50a83346d33
ISTIO_LATEST_IMAGE_TAG ?= bf607ae5541ce5c1cc95b4f98b3fd50a83346d33

install-dev: pre-install
helm install istio helm/istio -n istio-system --create-namespace --set-json='pilot.tag="$(ISTIO_LATEST_IMAGE_TAG)"' --set-json='global.kind=true'
helm install higress helm/higress -n higress-system --create-namespace --set-json='controller.tag="$(TAG)"' --set-json='gateway.replicas=1' --set-json='gateway.tag="$(ENVOY_LATEST_IMAGE_TAG)"' --set-json='global.kind=true'

uninstall:
helm uninstall istio -n istio-system
helm uninstall higress -n higress-system

upgrade: pre-install
helm upgrade istio helm/kind/istio -n istio-system
Expand Down Expand Up @@ -163,4 +172,40 @@ clean-gateway: clean-istio
clean-env:
rm -rf out/

clean: clean-higress clean-gateway clean-istio clean-env
clean-tool:
rm -rf tools/bin

clean: clean-higress clean-gateway clean-istio clean-env clean-tool

include tools/tools.mk
include tools/lint.mk

.PHONY: e2e-test
e2e-test: $(tools/kind) create-cluster kube-load-image install-dev run-e2e-test delete-cluster

create-cluster: $(tools/kind)
tools/hack/create-cluster.sh

.PHONY: delete-cluster
delete-cluster: $(tools/kind) ## Delete kind cluster.
$(tools/kind) delete cluster --name higress

.PHONY: kube-load-image
kube-load-image: docker-build $(tools/kind) ## Install the EG image to a kind cluster using the provided $IMAGE and $TAG.
tools/hack/kind-load-image.sh higress-registry.cn-hangzhou.cr.aliyuncs.com/higress/higress $(TAG)

.PHONY: run-e2e-test
run-e2e-test:
@echo -e "\n\033[36mRunning higress e2e tests\033[0m\n"
kubectl apply -f samples/hello-world/quickstart.yaml
@echo -e "\n\033[36mWaiting higress-controller to be ready...\033[0m\n"
kubectl wait --timeout=5m -n higress-system deployment/higress-controller --for=condition=Available
@echo -e "\n\033[36mWaiting istiod to be ready...\033[0m\n"
kubectl wait --timeout=5m -n istio-system deployment/istiod --for=condition=Available
@echo -e "\n\033[36mWaiting higress-gateway to be ready...\033[0m\n"
kubectl wait --timeout=5m -n higress-system deployment/higress-gateway --for=condition=Available

@echo -e "\n\033[36mSend request to call foo service...\033[0m\n"
curl -i -v http://localhost/foo
@echo -e "\n\n\033[36mSend request to call bar service...\033[0m\n"
curl -i -v http://localhost/bar
80 changes: 80 additions & 0 deletions samples/hello-world/quickstart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
kind: Pod
apiVersion: v1
metadata:
name: foo-app
labels:
app: foo
spec:
containers:
- name: foo-app
image: higress-registry.cn-hangzhou.cr.aliyuncs.com/higress/http-echo:0.2.3
args:
- "-text=foo"
---
kind: Service
apiVersion: v1
metadata:
name: foo-service
spec:
selector:
app: foo
ports:
# Default port used by the image
- port: 5678
---
kind: Pod
apiVersion: v1
metadata:
name: bar-app
labels:
app: bar
spec:
containers:
- name: bar-app
image: higress-registry.cn-hangzhou.cr.aliyuncs.com/higress/http-echo:0.2.3
args:
- "-text=bar"
---
kind: Service
apiVersion: v1
metadata:
name: bar-service
spec:
selector:
app: bar
ports:
# Default port used by the image
- port: 5678
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: foo
spec:
rules:
- http:
paths:
- pathType: Prefix
path: "/foo"
backend:
service:
name: foo-service
port:
number: 5678
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: bar
spec:
rules:
- http:
paths:
- pathType: Prefix
path: "/bar"
backend:
service:
name: bar-service
port:
number: 5678
---
32 changes: 32 additions & 0 deletions tools/hack/cluster.conf
Original file line number Diff line number Diff line change
@@ -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 changes: 29 additions & 0 deletions tools/hack/create-cluster.sh
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.
56 changes: 56 additions & 0 deletions tools/hack/kind-load-image.sh
Original file line number Diff line number Diff line change
@@ -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}"
2 changes: 1 addition & 1 deletion script/prebuild.sh → tools/hack/prebuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -e

ENVOY_VERSION="${ENVOY_VERSION:=1.20}"
ISITO_VERSION="${ISTIO_VERSION:=1.12}"
WORK_DIR=`cd $(dirname "$0")/..;pwd`
WORK_DIR=`cd $(dirname "$0")/../..;pwd`

cd $WORK_DIR

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 609a566

Please sign in to comment.