Skip to content

Commit

Permalink
add target to setup env test
Browse files Browse the repository at this point in the history
  • Loading branch information
Camila Macedo committed Aug 1, 2020
1 parent 21f9343 commit e5dade1
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 97 deletions.
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/*/fetch_ext_bins.sh
fetch_ext_bins.sh
11 changes: 9 additions & 2 deletions docs/book/src/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ export PATH=$PATH:/usr/local/kubebuilder/bin
<aside class="note">
<h1>Using master branch</h1>

Also, you can install a master snapshot from `https://go.kubebuilder.io/dl/latest/${os}/${arch}`.
Also, you can install a master snapshot from `https://go.kubebuilder.io/dl/latest/${os}/${arch}`. In this case, to configure your envtest run:

```sh
curl -sSLo fetch_ext_bins.sh https://raw.githubusercontent.com/kubernetes-sigs/cluster-api/release-0.2/scripts/fetch_ext_bins.sh
chmod +x fetch_ext_bins.sh
. ./fetch_ext_bins.sh && fetch_tools && setup_envs
```


</aside>
Expand Down Expand Up @@ -229,4 +235,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
14 changes: 13 additions & 1 deletion docs/book/src/reference/envtest.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,19 @@ 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 [EnvtTest][envtest] is done due the following environment
variables. See:

```shell
$ export TEST_ASSET_KUBECTL=<kubectl-bin-path>
$ export TEST_ASSET_KUBE_APISERVER=<api-server-bin-path>
$ export TEST_ASSET_ETCD=<etcd-bin-path>
```

Note that `kubebuilder` scaffold in your Makefile the `setupenvtest` target which download the binaries and setup it.

#### Environment Variables

| Variable name | Type | When to use |
Expand Down Expand Up @@ -71,3 +82,4 @@ expectedOwnerReference := v1.OwnerReference{
}
Expect(deployment.ObjectMeta.OwnerReferences).To(ContainElement(expectedOwnerReference))
```
[envtest]: https://godoc.org/sigs.k8s.io/controller-runtime/pkg/envtest
4 changes: 3 additions & 1 deletion pkg/plugin/v3/scaffolds/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ const (
ControllerToolsVersion = "v0.3.0"
// KustomizeVersion is the kubernetes-sigs/kustomize version to be used in the project
KustomizeVersion = "v3.5.4"

// ClusterApiTag tag to use to get the script to setup the envtest
ClusterApiTag = "release-0.2"
imageName = "controller:latest"
)

Expand Down Expand Up @@ -110,6 +111,7 @@ func (s *initScaffolder) scaffold() error {
BoilerplatePath: s.boilerplatePath,
ControllerToolsVersion: ControllerToolsVersion,
KustomizeVersion: KustomizeVersion,
ClusterApiTag: ClusterApiTag,
},
&templates.Dockerfile{},
&templates.DockerignoreFile{},
Expand Down
3 changes: 3 additions & 0 deletions pkg/plugin/v3/scaffolds/internal/templates/gitignore.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ func (f *GitIgnore) SetTemplateDefaults() error {
}

const gitignoreTemplate = `
# ignore shell script to setup env test
fetch_ext_bins.sh
# Binaries for programs and plugins
*.exe
*.exe~
Expand Down
10 changes: 9 additions & 1 deletion pkg/plugin/v3/scaffolds/internal/templates/makefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ type Makefile struct {
ControllerToolsVersion string
//Kustomize version to use in the project
KustomizeVersion string
//ClusterApiTag tag to use to get the script to setup the envtest
ClusterApiTag string
}

// SetTemplateDefaults implements input.Template
Expand Down Expand Up @@ -70,7 +72,7 @@ endif
all: manager
# Run tests
test: generate fmt vet manifests
test: setupenvtest generate fmt vet manifests
go test -race -coverprofile cover.out ./...
# Build manager binary
Expand Down Expand Up @@ -153,4 +155,10 @@ KUSTOMIZE=$(GOBIN)/kustomize
else
KUSTOMIZE=$(shell which kustomize)
endif
# Setup binaries required to run the tests
setupenvtest:
curl -sSLo fetch_ext_bins.sh https://raw.githubusercontent.com/kubernetes-sigs/cluster-api/{{ .ClusterApiTag }}/scripts/fetch_ext_bins.sh
chmod +x fetch_ext_bins.sh
. ./fetch_ext_bins.sh && fetch_tools && setup_envs
`
86 changes: 0 additions & 86 deletions scripts/setup_envtest_bins.sh

This file was deleted.

3 changes: 0 additions & 3 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,4 @@ GO111MODULE=on test_project project-v3 3-alpha
GO111MODULE=on test_project project-v3-multigroup 3-alpha
GO111MODULE=on test_project project-v3-addon 3-alpha

# test script that setup envtest
./scripts/setup_envtest_bins.sh v1.18.2 v3.4.3

exit $rc
8 changes: 7 additions & 1 deletion testdata/project-v3-addon/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ endif
all: manager

# Run tests
test: generate fmt vet manifests
test: setupenvtest generate fmt vet manifests
go test -race -coverprofile cover.out ./...

# Build manager binary
Expand Down Expand Up @@ -97,3 +97,9 @@ KUSTOMIZE=$(GOBIN)/kustomize
else
KUSTOMIZE=$(shell which kustomize)
endif

# Setup binaries required to run the tests
setupenvtest:
curl -sSLo fetch_ext_bins.sh https://raw.githubusercontent.com/kubernetes-sigs/cluster-api/release-0.2/scripts/fetch_ext_bins.sh
chmod +x fetch_ext_bins.sh
. ./fetch_ext_bins.sh && fetch_tools && setup_envs
8 changes: 7 additions & 1 deletion testdata/project-v3-multigroup/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ endif
all: manager

# Run tests
test: generate fmt vet manifests
test: setupenvtest generate fmt vet manifests
go test -race -coverprofile cover.out ./...

# Build manager binary
Expand Down Expand Up @@ -97,3 +97,9 @@ KUSTOMIZE=$(GOBIN)/kustomize
else
KUSTOMIZE=$(shell which kustomize)
endif

# Setup binaries required to run the tests
setupenvtest:
curl -sSLo fetch_ext_bins.sh https://raw.githubusercontent.com/kubernetes-sigs/cluster-api/release-0.2/scripts/fetch_ext_bins.sh
chmod +x fetch_ext_bins.sh
. ./fetch_ext_bins.sh && fetch_tools && setup_envs
8 changes: 7 additions & 1 deletion testdata/project-v3/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ endif
all: manager

# Run tests
test: generate fmt vet manifests
test: setupenvtest generate fmt vet manifests
go test -race -coverprofile cover.out ./...

# Build manager binary
Expand Down Expand Up @@ -97,3 +97,9 @@ KUSTOMIZE=$(GOBIN)/kustomize
else
KUSTOMIZE=$(shell which kustomize)
endif

# Setup binaries required to run the tests
setupenvtest:
curl -sSLo fetch_ext_bins.sh https://raw.githubusercontent.com/kubernetes-sigs/cluster-api/release-0.2/scripts/fetch_ext_bins.sh
chmod +x fetch_ext_bins.sh
. ./fetch_ext_bins.sh && fetch_tools && setup_envs

0 comments on commit e5dade1

Please sign in to comment.