Skip to content

Commit 7d747cf

Browse files
add mock testdata for plugins with --pattern=addon
1 parent 68caa2b commit 7d747cf

File tree

64 files changed

+2206
-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.

64 files changed

+2206
-0
lines changed

generate_golden.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,21 @@ scaffold_test_project() {
9494
$kb create api --group sea-creatures --version v1beta1 --kind Kraken --controller=true --resource=true --make=false
9595
$kb create api --group sea-creatures --version v1beta2 --kind Leviathan --controller=true --resource=true --make=false
9696
$kb create api --group foo.policy --version v1 --kind HealthCheckPolicy --controller=true --resource=true --make=false
97+
elif [ $project == "project-v2-addon" ]; then
98+
header_text 'Generating project-v2-addon'
99+
export GO111MODULE=on
100+
export PATH=$PATH:$(go env GOPATH)/bin
101+
go mod init sigs.k8s.io/kubebuilder/testdata/project-v2-addon # our repo autodetection will traverse up to the kb module if we don't do this
102+
103+
header_text 'initializing project-v2-addon ...'
104+
$kb init --project-version $version --domain testproject.org --license apache2 --owner "The Kubernetes authors"
105+
106+
header_text 'enableling --pattern flag ...'
107+
export KUBEBUILDER_ENABLE_PLUGINS=1
108+
header_text 'Creating APIs ...'
109+
$kb create api --group crew --version v1 --kind Captain --controller=true --resource=true --pattern=addon
110+
$kb create api --group crew --version v1 --kind FirstMate --controller=true --resource=true --make=false --pattern=addon
111+
$kb create api --group crew --version v1 --kind Admiral --controller=true --resource=true --namespaced=false --make=false --pattern=addon
97112
fi
98113
fi
99114
make all test # v2 doesn't test by default
@@ -111,3 +126,4 @@ build_kb
111126
scaffold_test_project gopath/src/project 1
112127
scaffold_test_project project-v2 2
113128
scaffold_test_project project-v2-multigroup 2
129+
scaffold_test_project project-v2-addon 2
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
!vendor/**/zz_generated.*
19+
20+
# editor and IDE paraphernalia
21+
.idea
22+
*.swp
23+
*.swo
24+
*~
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Build the manager binary
2+
FROM golang:1.13 as builder
3+
4+
WORKDIR /workspace
5+
# Copy the Go Modules manifests
6+
COPY go.mod go.mod
7+
COPY go.sum go.sum
8+
# cache deps before building and copying source so that we don't need to re-download as much
9+
# and so that source changes don't invalidate our downloaded layer
10+
RUN go mod download
11+
12+
# Copy the go source
13+
COPY main.go main.go
14+
COPY api/ api/
15+
COPY controllers/ controllers/
16+
17+
# Build
18+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager main.go
19+
20+
# Use distroless as minimal base image to package the manager binary
21+
# Refer to https://github.com/GoogleContainerTools/distroless for more details
22+
FROM gcr.io/distroless/static:nonroot
23+
WORKDIR /
24+
COPY --from=builder /workspace/manager .
25+
USER nonroot:nonroot
26+
27+
ENTRYPOINT ["/manager"]

testdata/project-v2-addon/Makefile

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
2+
# Image URL to use all building/pushing image targets
3+
IMG ?= controller:latest
4+
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
5+
CRD_OPTIONS ?= "crd:trivialVersions=true"
6+
7+
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
8+
ifeq (,$(shell go env GOBIN))
9+
GOBIN=$(shell go env GOPATH)/bin
10+
else
11+
GOBIN=$(shell go env GOBIN)
12+
endif
13+
14+
all: manager
15+
16+
# Run tests
17+
test: generate fmt vet manifests
18+
go test ./... -coverprofile cover.out
19+
20+
# Build manager binary
21+
manager: generate fmt vet
22+
go build -o bin/manager main.go
23+
24+
# Run against the configured Kubernetes cluster in ~/.kube/config
25+
run: generate fmt vet manifests
26+
go run ./main.go
27+
28+
# Install CRDs into a cluster
29+
install: manifests
30+
kustomize build config/crd | kubectl apply -f -
31+
32+
# Uninstall CRDs from a cluster
33+
uninstall: manifests
34+
kustomize build config/crd | kubectl delete -f -
35+
36+
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
37+
deploy: manifests
38+
cd config/manager && kustomize edit set image controller=${IMG}
39+
kustomize build config/default | kubectl apply -f -
40+
41+
# Generate manifests e.g. CRD, RBAC etc.
42+
manifests: controller-gen
43+
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
44+
45+
# Run go fmt against code
46+
fmt:
47+
go fmt ./...
48+
49+
# Run go vet against code
50+
vet:
51+
go vet ./...
52+
53+
# Generate code
54+
generate: controller-gen
55+
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
56+
57+
# Build the docker image
58+
docker-build: test
59+
docker build . -t ${IMG}
60+
61+
# Push the docker image
62+
docker-push:
63+
docker push ${IMG}
64+
65+
# find or download controller-gen
66+
# download controller-gen if necessary
67+
controller-gen:
68+
ifeq (, $(shell which controller-gen))
69+
@{ \
70+
set -e ;\
71+
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
72+
cd $$CONTROLLER_GEN_TMP_DIR ;\
73+
go mod init tmp ;\
74+
go get sigs.k8s.io/controller-tools/cmd/[email protected] ;\
75+
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
76+
}
77+
CONTROLLER_GEN=$(GOBIN)/controller-gen
78+
else
79+
CONTROLLER_GEN=$(shell which controller-gen)
80+
endif

testdata/project-v2-addon/PROJECT

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
domain: testproject.org
2+
repo: sigs.k8s.io/kubebuilder/testdata/project-v2-addon
3+
resources:
4+
- group: crew
5+
kind: Captain
6+
version: v1
7+
- group: crew
8+
kind: FirstMate
9+
version: v1
10+
- group: crew
11+
kind: Admiral
12+
version: v1
13+
version: "2"
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
Copyright 2020 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 v1
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
addonv1alpha1 "sigs.k8s.io/kubebuilder-declarative-pattern/pkg/patterns/addon/pkg/apis/v1alpha1"
22+
)
23+
24+
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
25+
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
26+
27+
// AdmiralSpec defines the desired state of Admiral
28+
type AdmiralSpec struct {
29+
addonv1alpha1.CommonSpec `json:",inline"`
30+
addonv1alpha1.PatchSpec `json:",inline"`
31+
32+
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
33+
// Important: Run "make" to regenerate code after modifying this file
34+
}
35+
36+
// AdmiralStatus defines the observed state of Admiral
37+
type AdmiralStatus struct {
38+
addonv1alpha1.CommonStatus `json:",inline"`
39+
40+
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
41+
// Important: Run "make" to regenerate code after modifying this file
42+
}
43+
44+
// +kubebuilder:object:root=true
45+
// +kubebuilder:resource:scope=Cluster
46+
47+
// Admiral is the Schema for the admirals API
48+
type Admiral struct {
49+
metav1.TypeMeta `json:",inline"`
50+
metav1.ObjectMeta `json:"metadata,omitempty"`
51+
52+
Spec AdmiralSpec `json:"spec,omitempty"`
53+
Status AdmiralStatus `json:"status,omitempty"`
54+
}
55+
56+
var _ addonv1alpha1.CommonObject = &Admiral{}
57+
58+
func (o *Admiral) ComponentName() string {
59+
return "admiral"
60+
}
61+
62+
func (o *Admiral) CommonSpec() addonv1alpha1.CommonSpec {
63+
return o.Spec.CommonSpec
64+
}
65+
66+
func (o *Admiral) PatchSpec() addonv1alpha1.PatchSpec {
67+
return o.Spec.PatchSpec
68+
}
69+
70+
func (o *Admiral) GetCommonStatus() addonv1alpha1.CommonStatus {
71+
return o.Status.CommonStatus
72+
}
73+
74+
func (o *Admiral) SetCommonStatus(s addonv1alpha1.CommonStatus) {
75+
o.Status.CommonStatus = s
76+
}
77+
78+
// +kubebuilder:object:root=true
79+
// +kubebuilder:resource:scope=Cluster
80+
81+
// AdmiralList contains a list of Admiral
82+
type AdmiralList struct {
83+
metav1.TypeMeta `json:",inline"`
84+
metav1.ListMeta `json:"metadata,omitempty"`
85+
Items []Admiral `json:"items"`
86+
}
87+
88+
func init() {
89+
SchemeBuilder.Register(&Admiral{}, &AdmiralList{})
90+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
Copyright 2020 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 v1
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
addonv1alpha1 "sigs.k8s.io/kubebuilder-declarative-pattern/pkg/patterns/addon/pkg/apis/v1alpha1"
22+
)
23+
24+
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
25+
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
26+
27+
// CaptainSpec defines the desired state of Captain
28+
type CaptainSpec struct {
29+
addonv1alpha1.CommonSpec `json:",inline"`
30+
addonv1alpha1.PatchSpec `json:",inline"`
31+
32+
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
33+
// Important: Run "make" to regenerate code after modifying this file
34+
}
35+
36+
// CaptainStatus defines the observed state of Captain
37+
type CaptainStatus struct {
38+
addonv1alpha1.CommonStatus `json:",inline"`
39+
40+
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
41+
// Important: Run "make" to regenerate code after modifying this file
42+
}
43+
44+
// +kubebuilder:object:root=true
45+
46+
// Captain is the Schema for the captains API
47+
type Captain struct {
48+
metav1.TypeMeta `json:",inline"`
49+
metav1.ObjectMeta `json:"metadata,omitempty"`
50+
51+
Spec CaptainSpec `json:"spec,omitempty"`
52+
Status CaptainStatus `json:"status,omitempty"`
53+
}
54+
55+
var _ addonv1alpha1.CommonObject = &Captain{}
56+
57+
func (o *Captain) ComponentName() string {
58+
return "captain"
59+
}
60+
61+
func (o *Captain) CommonSpec() addonv1alpha1.CommonSpec {
62+
return o.Spec.CommonSpec
63+
}
64+
65+
func (o *Captain) PatchSpec() addonv1alpha1.PatchSpec {
66+
return o.Spec.PatchSpec
67+
}
68+
69+
func (o *Captain) GetCommonStatus() addonv1alpha1.CommonStatus {
70+
return o.Status.CommonStatus
71+
}
72+
73+
func (o *Captain) SetCommonStatus(s addonv1alpha1.CommonStatus) {
74+
o.Status.CommonStatus = s
75+
}
76+
77+
// +kubebuilder:object:root=true
78+
79+
// CaptainList contains a list of Captain
80+
type CaptainList struct {
81+
metav1.TypeMeta `json:",inline"`
82+
metav1.ListMeta `json:"metadata,omitempty"`
83+
Items []Captain `json:"items"`
84+
}
85+
86+
func init() {
87+
SchemeBuilder.Register(&Captain{}, &CaptainList{})
88+
}

0 commit comments

Comments
 (0)