Skip to content

Commit 2c1cb3b

Browse files
author
Mengqi Yu
committed
move test project from controller-tools
1 parent d2255fe commit 2c1cb3b

File tree

93 files changed

+4428
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+4428
-0
lines changed

generated_golden.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2018 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -e
18+
19+
go build -o ./bin/kubebuilder sigs.k8s.io/kubebuilder/cmd/kubebuilder
20+
rm -rf ./test/project/*
21+
cd test/project
22+
ln -s ../../vendor vendor
23+
../../bin/kubebuilder init --domain testproject.org --license apache2 --owner "The Kubernetes authors" --dep=false
24+
../../bin/kubebuilder create api --group crew --version v1 --kind FirstMate --controller=true --resource=true --make=false
25+
../../bin/kubebuilder alpha webhook --group crew --version v1 --kind FirstMate --type=mutating --operations=create,update
26+
../../bin/kubebuilder alpha webhook --group crew --version v1 --kind FirstMate --type=mutating --operations=delete
27+
../../bin/kubebuilder create api --group ship --version v1beta1 --kind Frigate --example=false --controller=true --resource=true --make=false
28+
../../bin/kubebuilder alpha webhook --group ship --version v1beta1 --kind Frigate --type=validating --operations=update
29+
../../bin/kubebuilder create api --group creatures --version v2alpha1 --kind Kraken --namespaced=false --example=false --controller=true --resource=true --make=false
30+
../../bin/kubebuilder alpha webhook --group creatures --version v2alpha1 --kind Kraken --type=validating --operations=create
31+
../../bin/kubebuilder create api --group core --version v1 --kind Namespace --example=false --controller=true --resource=false --namespaced=false
32+
../../bin/kubebuilder alpha webhook --group core --version v1 --kind Namespace --type=mutating --operations=update
33+
../../bin/kubebuilder create api --group policy --version v1beta1 --kind HealthCheckPolicy --example=false --controller=true --resource=true --namespaced=false
34+
make
35+
rm -rf ./bin/
36+
cd -

test/project/.gitignore

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
# Binaries for programs and plugins
3+
*.exe
4+
*.exe~
5+
*.dll
6+
*.so
7+
*.dylib
8+
bin
9+
10+
# Test binary, build with `go test -c`
11+
*.test
12+
13+
# Output of the go coverage tool, specifically when used with LiteIDE
14+
*.out
15+
16+
# Kubernetes Generated files - skip generated files, except for vendored files
17+
18+
zz_generated.*
19+
!vendor/**/zz_generated.*
20+
21+
# editor and IDE paraphernalia
22+
.idea
23+
*.swp
24+
*.swo
25+
*~

test/project/Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Build the manager binary
2+
FROM golang:1.10.3 as builder
3+
4+
# Copy in the go src
5+
WORKDIR /go/src/sigs.k8s.io/kubebuilder/test/project
6+
COPY pkg/ pkg/
7+
COPY cmd/ cmd/
8+
COPY vendor/ vendor/
9+
10+
# Build
11+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager sigs.k8s.io/kubebuilder/test/project/cmd/manager
12+
13+
# Copy the controller-manager into a thin image
14+
FROM ubuntu:latest
15+
WORKDIR /root/
16+
COPY --from=builder /go/src/sigs.k8s.io/kubebuilder/test/project/manager .
17+
ENTRYPOINT ["./manager"]

test/project/Gopkg.toml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
required = [
2+
"github.com/emicklei/go-restful",
3+
"github.com/onsi/ginkgo", # for test framework
4+
"github.com/onsi/gomega", # for test matchers
5+
"k8s.io/client-go/plugin/pkg/client/auth/gcp", # for development against gcp
6+
"k8s.io/code-generator/cmd/client-gen", # for go generate
7+
"k8s.io/code-generator/cmd/deepcopy-gen", # for go generate
8+
"sigs.k8s.io/controller-tools/cmd/controller-gen", # for crd/rbac generation
9+
"sigs.k8s.io/controller-runtime/pkg/client/config",
10+
"sigs.k8s.io/controller-runtime/pkg/controller",
11+
"sigs.k8s.io/controller-runtime/pkg/handler",
12+
"sigs.k8s.io/controller-runtime/pkg/manager",
13+
"sigs.k8s.io/controller-runtime/pkg/runtime/signals",
14+
"sigs.k8s.io/controller-runtime/pkg/source",
15+
"sigs.k8s.io/testing_frameworks/integration", # for integration testing
16+
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1",
17+
]
18+
19+
[prune]
20+
go-tests = true
21+
22+
23+
# STANZAS BELOW ARE GENERATED AND MAY BE WRITTEN - DO NOT MODIFY BELOW THIS LINE.
24+
25+
[[constraint]]
26+
name="sigs.k8s.io/controller-runtime"
27+
version="v0.1.1"
28+
29+
[[constraint]]
30+
name="sigs.k8s.io/controller-tools"
31+
version="v0.1.1"
32+
33+
# For dependency below: Refer to issue https://github.com/golang/dep/issues/1799
34+
[[override]]
35+
name = "gopkg.in/fsnotify.v1"
36+
source = "https://github.com/fsnotify/fsnotify.git"
37+
version="v1.4.7"

test/project/Makefile

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
2+
# Image URL to use all building/pushing image targets
3+
IMG ?= controller:latest
4+
5+
all: test manager
6+
7+
# Run tests
8+
test: generate fmt vet manifests
9+
go test ./pkg/... ./cmd/... -coverprofile cover.out
10+
11+
# Build manager binary
12+
manager: generate fmt vet
13+
go build -o bin/manager sigs.k8s.io/kubebuilder/test/project/cmd/manager
14+
15+
# Run against the configured Kubernetes cluster in ~/.kube/config
16+
run: generate fmt vet
17+
go run ./cmd/manager/main.go
18+
19+
# Install CRDs into a cluster
20+
install: manifests
21+
kubectl apply -f config/crds
22+
23+
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
24+
deploy: manifests
25+
kubectl apply -f config/crds
26+
kustomize build config/default | kubectl apply -f -
27+
28+
# Generate manifests e.g. CRD, RBAC etc.
29+
manifests:
30+
go run vendor/sigs.k8s.io/controller-tools/cmd/controller-gen/main.go all
31+
32+
# Run go fmt against code
33+
fmt:
34+
go fmt ./pkg/... ./cmd/...
35+
36+
# Run go vet against code
37+
vet:
38+
go vet ./pkg/... ./cmd/...
39+
40+
# Generate code
41+
generate:
42+
go generate ./pkg/... ./cmd/...
43+
44+
# Build the docker image
45+
docker-build: test
46+
docker build . -t ${IMG}
47+
@echo "updating kustomize image patch file for manager resource"
48+
sed -i'' -e 's@image: .*@image: '"${IMG}"'@' ./config/default/manager_image_patch.yaml
49+
50+
# Push the docker image
51+
docker-push:
52+
docker push ${IMG}

test/project/PROJECT

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version: "1"
2+
domain: testproject.org
3+
repo: sigs.k8s.io/kubebuilder/test/project

test/project/cmd/manager/main.go

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
Copyright 2018 The Kubernetes authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package main
18+
19+
import (
20+
"os"
21+
22+
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
23+
"sigs.k8s.io/controller-runtime/pkg/client/config"
24+
"sigs.k8s.io/controller-runtime/pkg/manager"
25+
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
26+
"sigs.k8s.io/controller-runtime/pkg/runtime/signals"
27+
"sigs.k8s.io/kubebuilder/test/project/pkg/apis"
28+
"sigs.k8s.io/kubebuilder/test/project/pkg/controller"
29+
"sigs.k8s.io/kubebuilder/test/project/pkg/webhook"
30+
)
31+
32+
func main() {
33+
logf.SetLogger(logf.ZapLogger(false))
34+
log := logf.Log.WithName("entrypoint")
35+
36+
// Get a config to talk to the apiserver
37+
log.Info("setting up client for manager")
38+
cfg, err := config.GetConfig()
39+
if err != nil {
40+
log.Error(err, "unable to set up client config")
41+
os.Exit(1)
42+
}
43+
44+
// Create a new Cmd to provide shared dependencies and start components
45+
log.Info("setting up manager")
46+
mgr, err := manager.New(cfg, manager.Options{})
47+
if err != nil {
48+
log.Error(err, "unable to set up overall controller manager")
49+
os.Exit(1)
50+
}
51+
52+
log.Info("Registering Components.")
53+
54+
// Setup Scheme for all resources
55+
log.Info("setting up scheme")
56+
if err := apis.AddToScheme(mgr.GetScheme()); err != nil {
57+
log.Error(err, "unable add APIs to scheme")
58+
os.Exit(1)
59+
}
60+
61+
// Setup all Controllers
62+
log.Info("Setting up controller")
63+
if err := controller.AddToManager(mgr); err != nil {
64+
log.Error(err, "unable to register controllers to the manager")
65+
os.Exit(1)
66+
}
67+
68+
log.Info("setting up webhooks")
69+
if err := webhook.AddToManager(mgr); err != nil {
70+
log.Error(err, "unable to register webhooks to the manager")
71+
os.Exit(1)
72+
}
73+
74+
// Start the Cmd
75+
log.Info("Starting the Cmd.")
76+
if err := mgr.Start(signals.SetupSignalHandler()); err != nil {
77+
log.Error(err, "unable to run the manager")
78+
os.Exit(1)
79+
}
80+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
apiVersion: apiextensions.k8s.io/v1beta1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
creationTimestamp: null
5+
labels:
6+
controller-tools.k8s.io: "1.0"
7+
name: krakens.creatures.testproject.org
8+
spec:
9+
group: creatures.testproject.org
10+
names:
11+
kind: Kraken
12+
plural: krakens
13+
scope: Cluster
14+
validation:
15+
openAPIV3Schema:
16+
properties:
17+
apiVersion:
18+
type: string
19+
kind:
20+
type: string
21+
metadata:
22+
type: object
23+
spec:
24+
type: object
25+
status:
26+
type: object
27+
version: v2alpha1
28+
status:
29+
acceptedNames:
30+
kind: ""
31+
plural: ""
32+
conditions: []
33+
storedVersions: []
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
apiVersion: apiextensions.k8s.io/v1beta1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
creationTimestamp: null
5+
labels:
6+
controller-tools.k8s.io: "1.0"
7+
name: firstmates.crew.testproject.org
8+
spec:
9+
group: crew.testproject.org
10+
names:
11+
kind: FirstMate
12+
plural: firstmates
13+
scope: Namespaced
14+
validation:
15+
openAPIV3Schema:
16+
properties:
17+
apiVersion:
18+
type: string
19+
kind:
20+
type: string
21+
metadata:
22+
type: object
23+
spec:
24+
type: object
25+
status:
26+
type: object
27+
version: v1
28+
status:
29+
acceptedNames:
30+
kind: ""
31+
plural: ""
32+
conditions: []
33+
storedVersions: []
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
apiVersion: apiextensions.k8s.io/v1beta1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
creationTimestamp: null
5+
labels:
6+
controller-tools.k8s.io: "1.0"
7+
name: healthcheckpolicies.policy.testproject.org
8+
spec:
9+
group: policy.testproject.org
10+
names:
11+
kind: HealthCheckPolicy
12+
plural: healthcheckpolicies
13+
scope: Cluster
14+
validation:
15+
openAPIV3Schema:
16+
properties:
17+
apiVersion:
18+
type: string
19+
kind:
20+
type: string
21+
metadata:
22+
type: object
23+
spec:
24+
type: object
25+
status:
26+
type: object
27+
version: v1beta1
28+
status:
29+
acceptedNames:
30+
kind: ""
31+
plural: ""
32+
conditions: []
33+
storedVersions: []
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
apiVersion: apiextensions.k8s.io/v1beta1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
creationTimestamp: null
5+
labels:
6+
controller-tools.k8s.io: "1.0"
7+
name: frigates.ship.testproject.org
8+
spec:
9+
group: ship.testproject.org
10+
names:
11+
kind: Frigate
12+
plural: frigates
13+
scope: Namespaced
14+
validation:
15+
openAPIV3Schema:
16+
properties:
17+
apiVersion:
18+
type: string
19+
kind:
20+
type: string
21+
metadata:
22+
type: object
23+
spec:
24+
type: object
25+
status:
26+
type: object
27+
version: v1beta1
28+
status:
29+
acceptedNames:
30+
kind: ""
31+
plural: ""
32+
conditions: []
33+
storedVersions: []

0 commit comments

Comments
 (0)