diff --git a/.gitignore b/.gitignore index 8c3a9d0f52a..a1992daa264 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,16 @@ testbin/* /testdata/project-v3/go.sum /testdata/project-v3-multigroup/go.sum /testdata/project-v3-addon/go.sum + +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib +bin +testbin + +# skip shell script to setup envtest from testdata and local +testdata/*/setup_envtest.sh +setup_envtest.sh diff --git a/.travis.yml b/.travis.yml index 7c8b3d27e5d..eb975bca72a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,7 @@ os: - osx go: - - "1.13" + - 1.13.x git: depth: 3 diff --git a/docs/book/src/quick-start.md b/docs/book/src/quick-start.md index b17d107706f..6c3c0a0e07e 100644 --- a/docs/book/src/quick-start.md +++ b/docs/book/src/quick-start.md @@ -191,6 +191,16 @@ Build and push your image to the location specified by `IMG`: make docker-build docker-push IMG=/:tag ``` + + + Deploy the controller to the cluster with image specified by `IMG`: ```bash @@ -229,4 +239,5 @@ Now, follow up the [CronJob tutorial][cronjob-tutorial] to better understand how [cronjob-tutorial]: https://book.kubebuilder.io/cronjob-tutorial/cronjob-tutorial.html [GOPATH-golang-docs]: https://golang.org/doc/code.html#GOPATH [how-to-write-go-code-golang-docs]: https://golang.org/doc/code.html - +[cronjob-tutorial]: https://book.kubebuilder.io/cronjob-tutorial/cronjob-tutorial.html +[config-test]: https://book.kubebuilder.io/reference/testing/envtest.html?highlight=#configuring-your-test-control-plane \ No newline at end of file diff --git a/docs/book/src/reference/envtest.md b/docs/book/src/reference/envtest.md index dc855ae9809..72cf6a29b67 100644 --- a/docs/book/src/reference/envtest.md +++ b/docs/book/src/reference/envtest.md @@ -25,8 +25,21 @@ err = testEnv.Stop() Logs from the test runs are prefixed with `test-env`. ### Configuring your test control plane -You can use environment variables and/or flags to specify the `api-server` and `etcd` setup within your integration tests. +You can use environment variables and/or flags to specify the `kubectl`, `api-server` and `etcd` setup within your +integration tests. The location of the binaries which will be used by the EnvTest is done due the following environment +variables. See: + +```shell + export TEST_ASSET_KUBECTL= + export TEST_ASSET_KUBE_APISERVER= + export TEST_ASSET_ETCD=/ +``` + +Note that `kubebuilder` scaffold in your Makefile the `testsetup` target which creates the `testbin/` directory in the +project where you will find its required binaries by default. Also, this target will setup the above environment +variables to looking for them in the created directory as well. + #### Environment Variables | Variable name | Type | When to use | diff --git a/pkg/plugin/v3/scaffolds/init.go b/pkg/plugin/v3/scaffolds/init.go index d0125300983..1d7fded3283 100644 --- a/pkg/plugin/v3/scaffolds/init.go +++ b/pkg/plugin/v3/scaffolds/init.go @@ -40,6 +40,13 @@ const ( ControllerToolsVersion = "v0.3.0" // KustomizeVersion is the kubernetes-sigs/kustomize version to be used in the project KustomizeVersion = "v3.5.4" + //KubernetesVersion is the K8S version which will be used in the script + KubernetesVersion = "v1.18.2" + //ETCDVersion is the ETCD version which will be used in the script + ETCDVersion = "v3.4.3" + //todo: implement func which allow us get kb version + //KubebuilderVersion is the Kubebuilder version which will be used to download the script. E.g tag release + KubebuilderVersion = "master" imageName = "controller:latest" ) @@ -110,6 +117,9 @@ func (s *initScaffolder) scaffold() error { BoilerplatePath: s.boilerplatePath, ControllerToolsVersion: ControllerToolsVersion, KustomizeVersion: KustomizeVersion, + KubernetesVersion: KubernetesVersion, + ETCDVersion: ETCDVersion, + KubebuilderVersion: KubebuilderVersion, }, &templates.Dockerfile{}, &templates.DockerignoreFile{}, diff --git a/pkg/plugin/v3/scaffolds/internal/templates/gitignore.go b/pkg/plugin/v3/scaffolds/internal/templates/gitignore.go index 3910f8d3195..c68cd607df7 100644 --- a/pkg/plugin/v3/scaffolds/internal/templates/gitignore.go +++ b/pkg/plugin/v3/scaffolds/internal/templates/gitignore.go @@ -39,6 +39,9 @@ func (f *GitIgnore) SetTemplateDefaults() error { } const gitignoreTemplate = ` +# ignore shell script to setup env test +setup_envtest.sh + # Binaries for programs and plugins *.exe *.exe~ @@ -46,6 +49,7 @@ const gitignoreTemplate = ` *.so *.dylib bin +testbin # Test binary, build with ` + "`go test -c`" + ` *.test diff --git a/pkg/plugin/v3/scaffolds/internal/templates/makefile.go b/pkg/plugin/v3/scaffolds/internal/templates/makefile.go index ae4e140ed00..1537d945ce9 100644 --- a/pkg/plugin/v3/scaffolds/internal/templates/makefile.go +++ b/pkg/plugin/v3/scaffolds/internal/templates/makefile.go @@ -34,6 +34,12 @@ type Makefile struct { ControllerToolsVersion string //Kustomize version to use in the project KustomizeVersion string + //KubernetesVersion is the K8S version which will be used in the script + KubernetesVersion string + //ETCDVersion is the ETCD version which will be used in the script + ETCDVersion string + //KubebuilderVersion is the Kubebuilder version which will be used to download the script. E.g tag release + KubebuilderVersion string } // SetTemplateDefaults implements input.Template @@ -70,7 +76,7 @@ endif all: manager # Run tests -test: generate fmt vet manifests +test: testsetup generate fmt vet manifests go test -race -coverprofile cover.out ./... # Build manager binary @@ -153,4 +159,12 @@ KUSTOMIZE=$(GOBIN)/kustomize else KUSTOMIZE=$(shell which kustomize) endif + +# Setup binaries required to run the tests +# The script will create the testbin dir to store them +# See that it expects the Kubernetes and ETCD versions +testsetup: + curl -sSLo setup_envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/kubebuilder/{{ .KubebuilderVersion }}/scripts/setup_envtest_bins.sh + chmod +x setup_envtest.sh + ./setup_envtest.sh {{ .KubernetesVersion }} {{ .ETCDVersion }} ` diff --git a/testdata/project-v3-addon/Makefile b/testdata/project-v3-addon/Makefile index 514e029eedd..a51eb01897b 100644 --- a/testdata/project-v3-addon/Makefile +++ b/testdata/project-v3-addon/Makefile @@ -14,7 +14,7 @@ endif all: manager # Run tests -test: generate fmt vet manifests +test: testsetup generate fmt vet manifests go test -race -coverprofile cover.out ./... # Build manager binary @@ -97,3 +97,11 @@ KUSTOMIZE=$(GOBIN)/kustomize else KUSTOMIZE=$(shell which kustomize) endif + +# Setup binaries required to run the tests +# The script will create the testbin dir and add on it the required binaries +# See that it expects the Kubernetes and ETCD version +testsetup: + curl -sSLo setup_envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/kubebuilder/master/scripts/setup_envtest_bins.sh + chmod +x setup_envtest.sh + ./setup_envtest.sh v1.18.2 v3.4.3 diff --git a/testdata/project-v3-multigroup/Makefile b/testdata/project-v3-multigroup/Makefile index 514e029eedd..a51eb01897b 100644 --- a/testdata/project-v3-multigroup/Makefile +++ b/testdata/project-v3-multigroup/Makefile @@ -14,7 +14,7 @@ endif all: manager # Run tests -test: generate fmt vet manifests +test: testsetup generate fmt vet manifests go test -race -coverprofile cover.out ./... # Build manager binary @@ -97,3 +97,11 @@ KUSTOMIZE=$(GOBIN)/kustomize else KUSTOMIZE=$(shell which kustomize) endif + +# Setup binaries required to run the tests +# The script will create the testbin dir and add on it the required binaries +# See that it expects the Kubernetes and ETCD version +testsetup: + curl -sSLo setup_envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/kubebuilder/master/scripts/setup_envtest_bins.sh + chmod +x setup_envtest.sh + ./setup_envtest.sh v1.18.2 v3.4.3 diff --git a/testdata/project-v3/Makefile b/testdata/project-v3/Makefile index 514e029eedd..a51eb01897b 100644 --- a/testdata/project-v3/Makefile +++ b/testdata/project-v3/Makefile @@ -14,7 +14,7 @@ endif all: manager # Run tests -test: generate fmt vet manifests +test: testsetup generate fmt vet manifests go test -race -coverprofile cover.out ./... # Build manager binary @@ -97,3 +97,11 @@ KUSTOMIZE=$(GOBIN)/kustomize else KUSTOMIZE=$(shell which kustomize) endif + +# Setup binaries required to run the tests +# The script will create the testbin dir and add on it the required binaries +# See that it expects the Kubernetes and ETCD version +testsetup: + curl -sSLo setup_envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/kubebuilder/master/scripts/setup_envtest_bins.sh + chmod +x setup_envtest.sh + ./setup_envtest.sh v1.18.2 v3.4.3