Skip to content

Commit

Permalink
Backport e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mjura committed Feb 28, 2024
1 parent 3ad1dac commit 3d8748f
Show file tree
Hide file tree
Showing 16 changed files with 1,012 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: 1.21.x
- name: Build GKE operator binary
Expand Down
15 changes: 15 additions & 0 deletions .github/workflows/e2e-latest-rancher.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: e2e-latest-rancher
on:
workflow_dispatch:
push:
branches:
- main
schedule:
- cron: 0 22 * * *
permissions: read-all
jobs:
e2e-tests:
uses: ./.github/workflows/e2e.yaml
secrets:
GKE_CREDENTIALS: ${{ secrets.GKE_CREDENTIALS }}
GKE_PROJECT_ID: ${{ secrets.GKE_PROJECT_ID }}
82 changes: 82 additions & 0 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: E2E tests
on:
workflow_call:
secrets:
GKE_CREDENTIALS:
description: "GKE credentials"
required: true
GKE_PROJECT_ID:
description: "GKE project ID"
required: true
env:
GKE_CREDENTIALS: ${{ secrets.GKE_CREDENTIALS }}
GKE_PROJECT_ID: ${{ secrets.GKE_PROJECT_ID }}

jobs:
e2e-tests:
env:
REPO: ttl.sh/gke-operator-ci
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Export tag
id: export_tag
run: |
TAG="v0.0.0"
COMMITDATE=`date -d @$(git log -n1 --format="%at") "+%FT%TZ"`
echo "operator_tag=$TAG" >> $GITHUB_OUTPUT
echo "commit_date=$COMMITDATE" >> $GITHUB_OUTPUT
- name: Docker meta
id: meta
uses: docker/[email protected]
with:
images: |
${{ env.REPO }}
tags: |
type=sha,format=short,prefix=${{ steps.export_tag.outputs.operator_tag }}-
- name: Set up Docker Buildx
id: buildx
uses: docker/[email protected]
- name: Build and push image
uses: docker/[email protected]
with:
context: .
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
target: gke-operator
file: test/e2e/Dockerfile.e2e
build-args: |
TAG=${{ steps.export_tag.outputs.operator_tag }}
COMMITDATE=${{ steps.export_tag.outputs.commit_date }}
COMMIT=${{ github.sha }}
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.21.x
- uses: engineerd/[email protected]
with:
version: "v0.16.0"
skipClusterCreation: "true"
- name: Create kind cluster
run: make setup-kind
- name: Set the value
run: |
GKE_PROJECT_ID="${{ env.GKE_PROJECT_ID }}"
echo "GKE_PROJECT_ID=${GKE_PROJECT_ID}" >> $GITHUB_ENV
- name: E2E tests
env:
GKE_CREDENTIALS: "${{ secrets.GKE_CREDENTIALS }}"
run: make e2e-tests
- name: Archive artifacts
if: always()
uses: actions/[email protected]
with:
name: ci-artifacts
path: _artifacts
if-no-files-found: ignore
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: 1.21.x
- name: Analysis
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: 1.21.x
- name: Run tests
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/verify.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: 1.21.x
- name: Run make verify
Expand Down
68 changes: 37 additions & 31 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,20 @@ GO_INSTALL = ./scripts/go_install.sh
MOCKGEN_VER := v1.6.0
MOCKGEN_BIN := mockgen
MOCKGEN := $(BIN_DIR)/$(MOCKGEN_BIN)-$(MOCKGEN_VER)
MOCKGEN_PKG := github.com/golang/mock/mockgen

GINKGO_VER := v2.15.0
GINKGO_BIN := ginkgo
GINKGO := $(BIN_DIR)/$(GINKGO_BIN)-$(GINKGO_VER)
GINKGO_PKG := github.com/onsi/ginkgo/v2/ginkgo

GO_APIDIFF_VER := v0.7.0
GO_APIDIFF_BIN := go-apidiff
GO_APIDIFF := $(BIN_DIR)/$(GO_APIDIFF_BIN)-$(GO_APIDIFF_VER)
GO_APIDIFF_PKG := github.com/joelanford/go-apidiff
SETUP_ENVTEST_VER := v0.0.0-20211110210527-619e6b92dab9
SETUP_ENVTEST_BIN := setup-envtest
SETUP_ENVTEST := $(BIN_DIR)/$(SETUP_ENVTEST_BIN)-$(SETUP_ENVTEST_VER)

ifeq ($(shell go env GOOS),darwin) # Use the darwin/amd64 binary until an arm64 version is available
KUBEBUILDER_ASSETS ?= $(shell $(SETUP_ENVTEST) use --use-env -p path --arch amd64 $(KUBEBUILDER_ENVTEST_KUBERNETES_VERSION))
else
KUBEBUILDER_ASSETS ?= $(shell $(SETUP_ENVTEST) use --use-env -p path $(KUBEBUILDER_ENVTEST_KUBERNETES_VERSION))
endif

default: operator

Expand All @@ -42,40 +45,47 @@ default: operator
@./.dapper.tmp -v
@mv .dapper.tmp .dapper

$(MOCKGEN):
GOBIN=$(BIN_DIR) $(GO_INSTALL) $(MOCKGEN_PKG) $(MOCKGEN_BIN) $(MOCKGEN_VER)

$(GINKGO):
GOBIN=$(BIN_DIR) $(GO_INSTALL) $(GINKGO_PKG) $(GINKGO_BIN) $(GINKGO_VER)
.PHONY: generate-crd
generate-crd: $(MOCKGEN)
go generate main.go

$(GO_APIDIFF):
GOBIN=$(BIN_DIR) $(GO_INSTALL) $(GO_APIDIFF_PKG) $(GO_APIDIFF_BIN) $(GO_APIDIFF_VER)
.PHONY: generate
generate:
$(MAKE) generate-go
$(MAKE) generate-crd

.PHONY: $(TARGETS)
$(TARGETS): .dapper
./.dapper $@

.PHONY: generate-go
generate-go: $(MOCKGEN)
go generate ./pkg/gke/...
$(MOCKGEN):
GOBIN=$(BIN_DIR) $(GO_INSTALL) github.com/golang/mock/mockgen $(MOCKGEN_BIN) $(MOCKGEN_VER)

.PHONY: test
test: $(GINKGO)
$(GINKGO) -v -r --trace --race ./pkg/... ./controller/...
$(GINKGO):
GOBIN=$(BIN_DIR) $(GO_INSTALL) github.com/onsi/ginkgo/v2/ginkgo $(GINKGO_BIN) $(GINKGO_VER)

.PHONY: generate-crd
generate-crd: $(MOCKGEN)
go generate main.go
$(GO_APIDIFF):
GOBIN=$(BIN_DIR) $(GO_INSTALL) github.com/joelanford/go-apidiff $(GO_APIDIFF_BIN) $(GO_APIDIFF_VER)

.PHONY: generate
generate:
$(MAKE) generate-go
$(MAKE) generate-crd
$(SETUP_ENVTEST):
GOBIN=$(BIN_DIR) $(GO_INSTALL) sigs.k8s.io/controller-runtime/tools/setup-envtest $(SETUP_ENVTEST_BIN) $(SETUP_ENVTEST_VER)

.PHONY: operator
operator:
go build -o bin/gke-operator main.go

.PHONY: generate-go
generate-go: $(MOCKGEN)
go generate ./pkg/gke/...

.PHONY: test
test: $(SETUP_ENVTEST) $(GINKGO)
KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" $(GINKGO) -v -r -p --trace --race ./pkg/... ./controller/...

.PHONY: clean
clean:
rm -rf build bin dist

ALL_VERIFY_CHECKS = generate

.PHONY: verify
Expand Down Expand Up @@ -140,8 +150,4 @@ docker-build-e2e:

.PHOHY: delete-local-kind-cluster
delete-local-kind-cluster: ## Delete the local kind cluster
kind delete cluster --name=$(CLUSTER_NAME)

.PHONY: clean
clean:
rm -rf build bin dist
kind delete cluster --name=$(CLUSTER_NAME)
21 changes: 17 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,37 @@ replace (
)

require (
github.com/drone/envsubst/v2 v2.0.0-20210730161058-179042472c46
github.com/golang/mock v1.6.0
github.com/onsi/ginkgo/v2 v2.15.0
github.com/onsi/gomega v1.30.0
github.com/pkg/errors v0.9.1
github.com/rancher-sandbox/ele-testhelpers v0.0.0-20231206161614-20a517410736
github.com/rancher/lasso v0.0.0-20240123150939-7055397d6dfa
github.com/rancher/rancher/pkg/apis v0.0.0-20240126142034-676c3eb3dfa5
github.com/rancher/wrangler-api v0.6.1-0.20200427172631-a7c2f09b783e
github.com/rancher/wrangler/v2 v2.1.3
github.com/sirupsen/logrus v1.9.3
golang.org/x/net v0.21.0
golang.org/x/oauth2 v0.16.0
golang.org/x/oauth2 v0.15.0
google.golang.org/api v0.153.0
k8s.io/api v0.28.6
k8s.io/apiextensions-apiserver v0.28.6
k8s.io/apimachinery v0.28.6
k8s.io/apiserver v0.28.6
k8s.io/client-go v12.0.0+incompatible
sigs.k8s.io/controller-runtime v0.15.0
sigs.k8s.io/controller-runtime v0.15.3
sigs.k8s.io/yaml v1.4.0
)

require (
cloud.google.com/go/compute v1.23.3 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.10.2 // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
Expand Down Expand Up @@ -65,6 +71,11 @@ require (
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/rancher/aks-operator v1.3.0-rc1 // indirect
github.com/rancher/eks-operator v1.4.0-rc1 // indirect
github.com/rancher/fleet/pkg/apis v0.0.0-20231017140638-93432f288e79 // indirect
github.com/rancher/norman v0.0.0-20230831160711-5de27f66385d // indirect
github.com/rancher/rke v1.5.0 // indirect
github.com/rancher/wrangler v1.1.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
go.opencensus.io v0.24.0 // indirect
Expand All @@ -87,11 +98,13 @@ require (
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/code-generator v0.28.6 // indirect
k8s.io/component-base v0.28.6 // indirect
k8s.io/gengo v0.0.0-20230306165830-ab3349d207d4 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
k8s.io/kubernetes v1.27.9 // indirect
k8s.io/utils v0.0.0-20230505201702-9f6742963106 // indirect
sigs.k8s.io/cli-utils v0.28.0 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)
Loading

0 comments on commit 3d8748f

Please sign in to comment.