Skip to content

Commit

Permalink
add e2e unittest
Browse files Browse the repository at this point in the history
Signed-off-by: dongjiang1989 <[email protected]>
  • Loading branch information
dongjiang1989 committed Dec 21, 2023
1 parent 7951134 commit cfd9647
Show file tree
Hide file tree
Showing 881 changed files with 90,766 additions and 19,866 deletions.
3 changes: 3 additions & 0 deletions .github/env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
golang-version=1.19
kind-version=v0.20.0
kind-image=kindest/node:v1.27.3
78 changes: 78 additions & 0 deletions .github/kind-rbac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Wide open access to the cluster (mostly for kubelet)
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: cluster-writer
rules:
- apiGroups: ["*"]
resources: ["*"]
verbs: ["*"]
- nonResourceURLs: ["*"]
verbs: ["*"]

---

# Full read access to the api and resources
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: cluster-reader
rules:
- apiGroups: ["*"]
resources: ["*"]
verbs: ["get", "list", "watch"]
- nonResourceURLs: ["*"]
verbs: ["*"]
---
# Give admin, kubelet, kube-system, kube-proxy god access
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: cluster-write
subjects:
- kind: User
name: admin
- kind: User
name: kubelet
- kind: ServiceAccount
name: default
namespace: kube-system
- kind: User
name: kube-proxy
roleRef:
kind: ClusterRole
name: cluster-writer
apiGroup: rbac.authorization.k8s.io

---

# Setup sd-build as a reader. This has to be a
# ClusterRoleBinding to get access to non-resource URLs
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: cluster-read
subjects:
- kind: ServiceAccount
name: sd-build
namespace: default
roleRef:
kind: ClusterRole
name: cluster-reader
apiGroup: rbac.authorization.k8s.io

---

# Setup sd-build as a writer in its namespace
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: sd-build-write
subjects:
- kind: ServiceAccount
name: sd-build
namespace: default
roleRef:
kind: ClusterRole
name: cluster-writer
apiGroup: rbac.authorization.k8s.io
2 changes: 1 addition & 1 deletion .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
-
name: Checkout
uses: actions/checkout@v3
-
-
name: Set up Go
uses: actions/[email protected]
with:
Expand Down
15 changes: 4 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Set up Go
uses: actions/[email protected]
with:
go-version: 1.18
go-version: 1.19
- uses: actions/cache@v2
with:
path: ~/go/pkg/mod
Expand All @@ -29,7 +29,7 @@ jobs:
${{ runner.os }}-go-
- name: Test and update codecov
run: |
go test -race -coverprofile=coverage.txt -covermode=atomic ./...
go test $(go list ./... | grep -v /vendor/ | grep -v e2e) -race -coverprofile=coverage.txt -covermode=atomic
- uses: codecov/codecov-action@v2
with:
file: ./coverage.txt
Expand All @@ -46,13 +46,6 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Docker meta
id: meta
uses: docker/metadata-action@v3
Expand All @@ -61,10 +54,10 @@ jobs:
tags: |
type=ref,event=tag
- name: Build image
uses: docker/build-push-action@v2.5.0
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: linux/amd64
push: false
tags: ${{ steps.meta.outputs.tags }}
tags: ${{ steps.meta.outputs.tags }}
71 changes: 71 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: e2e
on:
pull_request:
push:
branches:
- 'release-*'
- 'master'
- 'main'
tags:
- 'v*'
jobs:
e2e-tests:
name: E2E tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Import environment variables from file
run: cat ".github/env" >> $GITHUB_ENV
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: '${{ env.golang-version }}'
check-latest: true
- name: Build images
run: |
export SHELL=/bin/bash
make build image
- name: Start kind cluster
uses: helm/[email protected]
with:
version: ${{ env.kind-version }}
node_image: ${{ env.kind-image }}
wait: 300s
config: ./test/e2e/kind-conf.yaml
cluster_name: e2e
- name: Wait for cluster to finish bootstraping
run: |
kubectl wait --for=condition=Ready pods --all --all-namespaces --timeout=300s
kubectl cluster-info
kubectl get pods -A
- name: Load images
run: |
kind load docker-image -n e2e openlocal/open-local:$(cat VERSION)
docker pull openlocal/csi-node-driver-registrar:v2.3.0
kind load docker-image -n e2e openlocal/csi-node-driver-registrar:v2.3.0
docker pull openlocal/csi-provisioner:v2.2.2
kind load docker-image -n e2e openlocal/csi-provisioner:v2.2.2
docker pull openlocal/csi-resizer:v1.3.0
kind load docker-image -n e2e openlocal/csi-resizer:v1.3.0
docker pull openlocal/csi-snapshotter:v4.2.1
kind load docker-image -n e2e openlocal/csi-snapshotter:v4.2.1
docker pull openlocal/snapshot-controller:v4.2.1
kind load docker-image -n e2e openlocal/snapshot-controller:v4.2.1
kubectl apply -f .github/kind-rbac.yaml
- name: Run tests
run: >
make test-e2e
e2e-tests-result:
name: End-to-End Test Results
if: always()
needs:
- e2e-tests
runs-on: ubuntu-latest
steps:
- name: Mark the job as a success
if: needs.e2e-tests.result == 'success'
run: exit 0
- name: Mark the job as a failure
if: needs.e2e-tests.result != 'success'
run: exit 1
36 changes: 17 additions & 19 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,25 @@ on:
jobs:

build:
name: ubuntu - Go v1.18
name: ubuntu - Go v1.19
runs-on: ubuntu-latest

steps:

- name: Set up Go
uses: actions/setup-go@v2
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.18'
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2
go-version: '1.19'
cache: false

- name: Checkout
uses: actions/checkout@v3

# This action uses its own setup-go, which always seems to use the latest
# stable version of Go. We could run 'make lint' to ensure our desired Go
# version, but we prefer this action because it leaves 'annotations' (i.e.
# it comments on PRs to point out linter violations).
- name: Lint
uses: golangci/golangci-lint-action@v3
with:
ref: ${{ github.ref }}
path: src/github.com/alibaba/open-local

- name: Install go ci lint
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.47.3

- name: Run Linter
run: golangci-lint run -v --timeout=10m
working-directory: src/github.com/alibaba/open-local

version: 'v1.49'
args: --timeout=10m
7 changes: 7 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
linters:
disable-all: true
enable:
- gosimple
- structcheck
- typecheck
- varcheck
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM --platform=linux/amd64 golang:1.18 AS builder
FROM --platform=linux/amd64 golang:1.19 AS builder

WORKDIR /go/src/github.com/alibaba/open-local
COPY . .
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.arm64
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM --platform=linux/arm64 golang:1.18 AS builder
FROM --platform=linux/arm64 golang:1.19 AS builder

WORKDIR /go/src/github.com/alibaba/open-local
COPY . .
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.muti
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.18 AS builder
FROM golang:1.19 AS builder

WORKDIR /go/src/github.com/alibaba/open-local
COPY . .
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ IMAGE_NAME_FOR_ACR=openlocal/${NAME}
MAIN_FILE=./cmd/main.go
LD_FLAGS=-ldflags "-X '${GO_PACKAGE}/pkg/version.GitCommit=$(GIT_COMMIT)' -X '${GO_PACKAGE}/pkg/version.Version=$(VERSION)' -X 'main.VERSION=$(VERSION)' -X 'main.COMMITID=$(GIT_COMMIT)'"
GIT_COMMIT=$(shell git rev-parse HEAD)
VERSION=v0.8.0-alpha
VERSION=$(shell cat VERSION | tr -d " \t\n\r")

CRD_OPTIONS ?= "crd:trivialVersions=true"
CRD_VERSION=v1alpha1
Expand Down Expand Up @@ -54,6 +54,10 @@ manifests: controller-gen
./hack/update-codegen.sh
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role crd paths="./pkg/apis/storage/$(CRD_VERSION)/..." output:crd:artifacts:config=helm/crds/

.PHONY: image-tools
test-e2e: KUBECONFIG?=$(HOME)/.kube/config
test-e2e: controller-gen
go test -mod=readonly -timeout 120m -v ./test/e2e/ --kubeconfig=$(KUBECONFIG) --test-image=${IMAGE_NAME_FOR_ACR}:${VERSION} -count=1
.PHONY: fmt
fmt:
go fmt ./...
Expand Down
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v0.8.0-alpha
Loading

0 comments on commit cfd9647

Please sign in to comment.