Skip to content

Commit

Permalink
Merge pull request #2884 from fabriziopandini/e2e-quickstart
Browse files Browse the repository at this point in the history
✨introduce test E2E
  • Loading branch information
k8s-ci-robot authored Apr 17, 2020
2 parents 04d9db7 + 5596ab2 commit 2481422
Show file tree
Hide file tree
Showing 29 changed files with 2,045 additions and 22 deletions.
3 changes: 3 additions & 0 deletions cmd/clusterctl/test/e2e/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/imdario/mergo v0.3.6 h1:xTNEAn+kxVO7dTZGu0CegyqKZmoWFI0rF8UxjlB2d28=
github.com/imdario/mergo v0.3.6/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/imdario/mergo v0.3.8 h1:CGgOkSJeqMRmt0D9XLWExdT4m4F1vd3FV3VPt+0VxkQ=
github.com/imdario/mergo v0.3.8/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
Expand Down Expand Up @@ -487,6 +488,7 @@ golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 h1:SvFZT6jyqRaOeXpc5h/JSfZenJ2O330aBsf7JfSUXmQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 h1:/5xXl8Y5W96D+TtHSlonuFqGHIWVuyCkGJLwGh9JJFs=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down Expand Up @@ -571,6 +573,7 @@ k8s.io/apimachinery v0.0.0-20190913080033-27d36303b655/go.mod h1:nL6pwRT8NgfF8TT
k8s.io/apimachinery v0.17.0/go.mod h1:b9qmWdKlLuU9EBh+06BtLcSf/Mu89rWL33naRxs1uZg=
k8s.io/apimachinery v0.17.2 h1:hwDQQFbdRlpnnsR64Asdi55GyCaIP/3WQpMmbNBeWr4=
k8s.io/apimachinery v0.17.2/go.mod h1:b9qmWdKlLuU9EBh+06BtLcSf/Mu89rWL33naRxs1uZg=
k8s.io/apiserver v0.17.2 h1:NssVvPALll6SSeNgo1Wk1h2myU1UHNwmhxV0Oxbcl8Y=
k8s.io/apiserver v0.17.2/go.mod h1:lBmw/TtQdtxvrTk0e2cgtOxHizXI+d0mmGQURIHQZlo=
k8s.io/client-go v0.0.0-20190918160344-1fbdaa4c8d90 h1:mLmhKUm1X+pXu0zXMEzNsOF5E2kKFGe5o6BZBIIqA6A=
k8s.io/client-go v0.0.0-20190918160344-1fbdaa4c8d90/go.mod h1:J69/JveO6XESwVgG53q3Uz5OSfgsv4uxpScmmyYOOlk=
Expand Down
1 change: 1 addition & 0 deletions hack/tools/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
github.com/go-bindata/go-bindata v3.1.2+incompatible
github.com/golangci/golangci-lint v1.23.8
github.com/joelanford/go-apidiff v0.0.0-20191206194835-106bcff5f060
github.com/onsi/ginkgo v1.11.0
github.com/raviqqe/liche v0.0.0-20200229003944-f57a5d1c5be4
golang.org/x/tools v0.0.0-20200204192400-7124308813f3
k8s.io/code-generator v0.18.0-alpha.2.0.20200130061103-7dfd5e9157ef
Expand Down
1 change: 1 addition & 0 deletions hack/tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
_ "github.com/go-bindata/go-bindata"
_ "github.com/golangci/golangci-lint/cmd/golangci-lint"
_ "github.com/joelanford/go-apidiff"
_ "github.com/onsi/ginkgo/ginkgo"
_ "github.com/raviqqe/liche"
_ "k8s.io/code-generator/cmd/conversion-gen"
_ "sigs.k8s.io/controller-tools/cmd/controller-gen"
Expand Down
60 changes: 60 additions & 0 deletions scripts/ci-e2e.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash

# Copyright 2018 The Kubernetes 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 -o errexit
set -o nounset
set -o pipefail

REPO_ROOT=$(git rev-parse --show-toplevel)
cd "${REPO_ROOT}" || exit 1

# shellcheck source=./hack/ensure-go.sh
source "${REPO_ROOT}/hack/ensure-go.sh"
# shellcheck source=./hack/ensure-kubectl.sh
source "${REPO_ROOT}/hack/ensure-kubectl.sh"
# shellcheck source=./hack/ensure-kustomize.sh
source "${REPO_ROOT}/hack/ensure-kustomize.sh"

# Configure provider images generation;
# please ensure the generated image name matches image names used in the E2E_CONF_FILE
export REGISTRY=gcr.io/k8s-staging-cluster-api
export TAG=ci
export ARCH=amd64
export PULL_POLICY=IfNotPresent

## Rebuild all Cluster API provider images
make docker-build

## Rebuild CAPD provider images
make -C test/infrastructure/docker docker-build

## Pulling cert manager images so we can pre-load in kind nodes
docker pull quay.io/jetstack/cert-manager-cainjector:v0.11.0
docker pull quay.io/jetstack/cert-manager-webhook:v0.11.0
docker pull quay.io/jetstack/cert-manager-controller:v0.11.0

# Configure e2e tests
export GINKGO_FOCUS=
export GINKGO_NODES=2
export GINKGO_NOCOLOR=true
export E2E_CONF_FILE="${REPO_ROOT}/test/e2e/config/docker-ci.yaml"
export ARTIFACTS="${ARTIFACTS:-${REPO_ROOT}/_artifacts}"
export SKIP_RESOURCE_CLEANUP=false
export USE_EXISTING_CLUSTER=false

# Run e2e tests
mkdir -p "$ARTIFACTS"
make -C test/e2e/ run
65 changes: 65 additions & 0 deletions test/e2e/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Copyright 2020 The Kubernetes 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 you update this file, please follow:
# https://suva.sh/posts/well-documented-makefiles/

# Use GOPROXY environment variable if set

.DEFAULT_GOAL:=help

GOPROXY := $(shell go env GOPROXY)
ifeq ($(GOPROXY),)
GOPROXY := https://proxy.golang.org
endif
export GOPROXY

REPO_ROOT := $(shell git rev-parse --show-toplevel)

help: ## Display this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

## --------------------------------------
## Binaries
## --------------------------------------

TOOLS_DIR := $(REPO_ROOT)/hack/tools
BIN_DIR := bin
TOOLS_BIN_DIR := $(TOOLS_DIR)/$(BIN_DIR)
GINKGO := $(TOOLS_BIN_DIR)/ginkgo

.PHONY: ginkgo
ginkgo:
cd $(TOOLS_DIR) && go build -tags=tools -o $(BIN_DIR)/ginkgo github.com/onsi/ginkgo/ginkgo

## --------------------------------------
## Testing
## --------------------------------------

TEST_E2E_DIR := $(REPO_ROOT)/test/e2e

GINKGO_FOCUS ?=
GINKGO_NODES ?= 1
E2E_CONF_FILE ?= ${REPO_ROOT}/test/e2e/config/docker-dev.yaml
ARTIFACTS ?= ${REPO_ROOT}/_artifacts
SKIP_RESOURCE_CLEANUP ?= false
USE_EXISTING_CLUSTER ?= false
GINKGO_NOCOLOR ?= false

.PHONY: run
run: ginkgo ## Run the end-to-end tests
cd $(TEST_E2E_DIR); $(GINKGO) -v -trace -tags=e2e -focus=$(GINKGO_FOCUS) -nodes=$(GINKGO_NODES) --noColor=$(GINKGO_NOCOLOR) . -- \
-e2e.artifacts-folder="$(ARTIFACTS)" \
-e2e.config="$(E2E_CONF_FILE)" \
-e2e.skip-resource-cleanup=$(SKIP_RESOURCE_CLEANUP) -e2e.use-existing-cluster=$(USE_EXISTING_CLUSTER)
71 changes: 71 additions & 0 deletions test/e2e/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
Copyright 2020 The Kubernetes 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.
*/

package e2e

import (
"context"
"fmt"
"path/filepath"

. "github.com/onsi/ginkgo"

corev1 "k8s.io/api/core/v1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3"
"sigs.k8s.io/cluster-api/test/framework"
"sigs.k8s.io/cluster-api/util"
)

func Byf(format string, a ...interface{}) {
By(fmt.Sprintf(format, a...))
}

func setupSpecNamespace(ctx context.Context, specName string, clusterProxy framework.ClusterProxy, artifactFolder string) (*corev1.Namespace, context.CancelFunc) {
Byf("Creating a namespace for hosting the %q test spec", specName)
namespace, cancelWatches := framework.CreateNamespaceAndWatchEvents(ctx, framework.CreateNamespaceAndWatchEventsInput{
Creator: clusterProxy.GetClient(),
ClientSet: clusterProxy.GetClientSet(),
Name: fmt.Sprintf("%s-%s", specName, util.RandomString(6)),
LogFolder: filepath.Join(artifactFolder, "clusters", clusterProxy.GetName()),
})

return namespace, cancelWatches
}

func dumpSpecResourcesAndCleanup(ctx context.Context, specName string, clusterProxy framework.ClusterProxy, artifactFolder string, namespace *corev1.Namespace, cancelWatches context.CancelFunc, cluster *clusterv1.Cluster, intervalsGetter func(spec, key string) []interface{}, skipCleanup bool) {
Byf("Dumping all the Cluster API resources in the %q namespace", namespace.Name)
// Dump all Cluster API related resources to artifacts before deleting them.
framework.DumpAllResources(ctx, framework.DumpAllResourcesInput{
Lister: clusterProxy.GetClient(),
Namespace: namespace.Name,
LogPath: filepath.Join(artifactFolder, "clusters", clusterProxy.GetName(), "resources"),
})

if !skipCleanup {
Byf("Deleting cluster %s/%s", cluster.Namespace, cluster.Name)
framework.DeleteClusterAndWait(ctx, framework.DeleteClusterAndWaitInput{
Client: clusterProxy.GetClient(),
Cluster: cluster,
}, intervalsGetter(specName, "wait-delete-cluster")...)

Byf("Deleting namespace used for hosting the %q test spec", specName)
framework.DeleteNamespace(ctx, framework.DeleteNamespaceInput{
Deleter: clusterProxy.GetClient(),
Name: namespace.Name,
})
}
cancelWatches()
}
77 changes: 77 additions & 0 deletions test/e2e/config/docker-ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
---
# CI E2E test test configuration scenario using locally build images and manifests for:
# - cluster-api
# - bootstrap kubeadm
# - control-plane kubeadm
# - docker

# For creating local dev images run ./scripts/ci-e2e.sh

images:
# Use local dev images built source tree;
- name: gcr.io/k8s-staging-cluster-api/cluster-api-controller-amd64:ci
loadBehavior: mustLoad
- name: gcr.io/k8s-staging-cluster-api/kubeadm-bootstrap-controller-amd64:ci
loadBehavior: mustLoad
- name: gcr.io/k8s-staging-cluster-api/kubeadm-control-plane-controller-amd64:ci
loadBehavior: mustLoad
- name: gcr.io/k8s-staging-cluster-api/capd-manager-amd64:ci
loadBehavior: mustLoad
- name: quay.io/jetstack/cert-manager-cainjector:v0.11.0
loadBehavior: tryLoad
- name: quay.io/jetstack/cert-manager-webhook:v0.11.0
loadBehavior: tryLoad
- name: quay.io/jetstack/cert-manager-controller:v0.11.0
loadBehavior: tryLoad

providers:

- name: cluster-api
type: CoreProvider
versions:
- name: v0.3.0
# Use manifest from source files
value: ../../../config

- name: kubeadm
type: BootstrapProvider
versions:
- name: v0.3.0
# Use manifest from source files
value: ../../../bootstrap/kubeadm/config

- name: kubeadm
type: ControlPlaneProvider
versions:
- name: v0.3.0
# Use manifest from source files
value: ../../../controlplane/kubeadm/config

- name: docker
type: InfrastructureProvider
versions:
- name: v0.3.0
# Use manifest from source files
value: ../../../test/infrastructure/docker/config
files:
# Add a metadata for docker provider
- sourcePath: "../data/infrastructure-docker/metadata.yaml"
# Add a cluster template
- sourcePath: "../data/infrastructure-docker/cluster-template-ci.yaml"
targetName: "cluster-template.yaml"

variables:
KUBERNETES_VERSION: "v1.17.0"
DOCKER_SERVICE_DOMAIN: "cluster.local"
DOCKER_SERVICE_CIDRS: "10.128.0.0/12"
# IMPORTANT! This values should match the one used by the CNI provider
DOCKER_POD_CIDRS: "192.168.0.0/16"
CNI: "./data/cni/kindnet/kindnet.yaml"

intervals:
default/wait-controllers: ["3m", "10s"]
default/wait-cluster: ["3m", "10s"]
default/wait-control-plane: ["3m", "10s"]
default/wait-worker-nodes: ["3m", "10s"]
default/wait-delete-cluster: ["3m", "10s"]
default/wait-machine-upgrade: ["15m", "1m"]
Loading

0 comments on commit 2481422

Please sign in to comment.