From 0615395d1ad9e0f08dba2b7cfe5479c8b05f1967 Mon Sep 17 00:00:00 2001 From: Andrei Vagin Date: Wed, 26 Jul 2017 22:44:23 -0700 Subject: [PATCH 1/2] travis: add a new test case to create a test api server from scratch This test does these action: * build an apserver-boot tarball * genereate a test api server with namespaces and non-namespaced resources. * run tests for this api server Signed-off-by: Andrei Vagin --- .travis.yml | 17 ++++++++++---- test/Makefile | 49 +++++++++++++++++++++++++++++++++++++++++ test/boilerplate.go.txt | 16 ++++++++++++++ test/build-tools.sh | 26 ++++++++++++++++++++++ test/travis.sh | 11 +++++++++ 5 files changed, 115 insertions(+), 4 deletions(-) create mode 100644 test/Makefile create mode 100644 test/boilerplate.go.txt create mode 100755 test/build-tools.sh create mode 100755 test/travis.sh diff --git a/.travis.yml b/.travis.yml index fad93b8d86..002379acfa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,14 +1,23 @@ language: go go: -- 1.8.1 +- 1.8.3 + +go_import_path: github.com/kubernetes-incubator/apiserver-builder + +cache: + directories: + - $HOME/.glide git: depth: 3 +env: + - TEST=example + - TEST=test + install: -- scripts/install_etcd.sh + - scripts/install_etcd.sh script: -- cd example -- PATH=$PATH:/tmp/test-etcd make test + ./test/travis.sh diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000000..15281ae3fc --- /dev/null +++ b/test/Makefile @@ -0,0 +1,49 @@ +# Copyright 2017 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. + +.PHONY: all test build generate docs cmds clean cleangenerated cleandocs skeleton + +all: test + +test: build + go test ./pkg/... + bash -c "find pkg/apis/ -name apiserver.local.config | xargs rm -rf" + +skeleton: cmds + apiserver-boot init repo --domain sample.kubernetes.io + apiserver-boot create group version resource --group storage --version v1 --kind VolumeClaim + apiserver-boot create group version resource --group storage --version v1 --kind SnapshotClaim + apiserver-boot create group version resource --group storage --version v1 --kind Volume --non-namespaced + apiserver-boot create group version resource --group storage --version v1 --kind Snapshot --non-namespaced + +build: cmds skeleton + apiserver-boot build executables + +# Build docs +docs: cleandocs build + apiserver-boot build docs --server bin/apiserver + +# Build the tools +# Note: These are available in the apiserver-builder release tar.gz +cmds: + ./build-tools.sh + +# Clean up functions +clean: cleangenerated cleandocs + +cleangenerated: cmds + apiserver-boot build generated clean + +cleandocs: cmds + apiserver-boot build docs clean diff --git a/test/boilerplate.go.txt b/test/boilerplate.go.txt new file mode 100644 index 0000000000..59e740c1ee --- /dev/null +++ b/test/boilerplate.go.txt @@ -0,0 +1,16 @@ +/* +Copyright YEAR 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. +*/ + diff --git a/test/build-tools.sh b/test/build-tools.sh new file mode 100755 index 0000000000..937a09515c --- /dev/null +++ b/test/build-tools.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +set -x -e + +# NOTE: Do not copy this file unless you need to use apiserver-builder at HEAD. +# Otherwise, download the pre-built apiserver-builder tar release from +# https://github.com/kubernetes-incubator/apiserver-builder/releases instead. + +( + cd /home/travis/gopath/src/github.com/ + mkdir Masterminds + cd Masterminds + git clone https://github.com/Masterminds/glide.git + cd glide + make build +) + +export PATH=/home/travis/gopath/src/github.com/Masterminds/glide:$PATH + +# Install generators from this repo +cd .. +go build -o bin/apiserver-builder-release cmd/apiserver-builder-release/main.go +./bin/apiserver-builder-release vendor --version 1.0 +./bin/apiserver-builder-release build --version 1.0 --targets linux:amd64 + +tar -xzf apiserver-builder-1.0-linux-amd64.tar.gz -C test diff --git a/test/travis.sh b/test/travis.sh new file mode 100755 index 0000000000..7d31bf8e4f --- /dev/null +++ b/test/travis.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +set -x -e + +if [ "$TEST" == "example" ]; then + cd example + PATH=$PATH:/tmp/test-etcd make test +elif [ "$TEST" == "test" ]; then + cd test + PATH=$PATH:/tmp/test-etcd:`pwd`/bin/ make test +fi From ae00af2bc52ac5435a02552a9f09666546c5a603 Mon Sep 17 00:00:00 2001 From: Andrei Vagin Date: Fri, 28 Jul 2017 05:15:12 +0300 Subject: [PATCH 2/2] Handle properly CamelCased resource kinds Here is an error without this patch: c.lister.Snapshotclaims undefined (type SnapshotClaimLister has no field or method Snapshotclaims, but does have SnapshotClaims) Signed-off-by: Andrei Vagin --- cmd/apiserver-boot/boot/create/resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/apiserver-boot/boot/create/resource.go b/cmd/apiserver-boot/boot/create/resource.go index ac6fc11e18..c2ee16fe6d 100644 --- a/cmd/apiserver-boot/boot/create/resource.go +++ b/cmd/apiserver-boot/boot/create/resource.go @@ -425,7 +425,7 @@ func (c *{{.Kind}}ControllerImpl) Reconcile(u *{{.Version}}.{{.Kind}}) error { } func (c *{{.Kind}}ControllerImpl) Get(namespace, name string) (*{{.Version}}.{{.Kind}}, error) { - return c.lister.{{ if not .NonNamespacedKind }}{{ title .Resource }}(namespace).{{ end }}Get(name) + return c.lister.{{ if not .NonNamespacedKind }}{{plural .Kind}}(namespace).{{ end }}Get(name) } `