diff --git a/common.sh b/common.sh index 1ba862be5ea..6a0eb221af9 100644 --- a/common.sh +++ b/common.sh @@ -126,9 +126,6 @@ function fetch_tools { curl -sL ${kb_tools_download_url} -o "$kb_tools_archive_path" fi tar -zvxf "$kb_tools_archive_path" -C "$tmp_root/" - - header_text "fetching controller-gen from source (till it's packaged)" - GO111MODULE=on go get sigs.k8s.io/controller-tools/cmd/controller-gen@crdgeneratortmp } function build_kb { diff --git a/generated_golden.sh b/generated_golden.sh index 96060968cae..2c3491c6583 100755 --- a/generated_golden.sh +++ b/generated_golden.sh @@ -58,7 +58,6 @@ scaffold_test_project() { $kb create api --group policy --version v1beta1 --kind HealthCheckPolicy --example=false --controller=true --resource=true --namespaced=false --make=false elif [ $version == "2" ]; then export GO111MODULE=on - go get sigs.k8s.io/controller-tools/cmd/controller-gen@crdgeneratortmp export PATH=$PATH:$(go env GOPATH)/bin go mod init sigs.k8s.io/kubebuilder/testdata/project_v2 # our repo autodetection will traverse up to the kb module if we don't do this diff --git a/pkg/scaffold/api.go b/pkg/scaffold/api.go index ad27e585bc9..223b719cc83 100644 --- a/pkg/scaffold/api.go +++ b/pkg/scaffold/api.go @@ -148,18 +148,13 @@ func (api *API) scaffoldV2() error { err := (&Scaffold{}).Execute( input.Options{}, - &resourcev2.ResourceDoc{ - Input: input.Input{ - Path: filepath.Join("api", r.Version, "doc.go"), - }, - Resource: r}, - &resourcev1.Types{ + &resourcev2.Types{ Input: input.Input{ Path: filepath.Join("api", r.Version, fmt.Sprintf("%s_types.go", strings.ToLower(r.Kind))), }, Resource: r}, &resourcev2.Group{Resource: r}, - &resourcev1.CRDSample{Resource: r}, + &resourcev2.CRDSample{Resource: r}, &crdv2.EnableWebhookPatch{Resource: r}, ) if err != nil { diff --git a/pkg/scaffold/project.go b/pkg/scaffold/project.go index b96257d97f1..d20c7a8a4f8 100644 --- a/pkg/scaffold/project.go +++ b/pkg/scaffold/project.go @@ -188,11 +188,12 @@ func (p *V2Project) Scaffold() error { &managerv2.Config{Image: imgName}, &scaffoldv2.Main{}, &scaffoldv2.GoMod{}, - &scaffoldv2.Doc{}, &scaffoldv2.Makefile{Image: imgName}, &scaffoldv2.Dockerfile{}, &scaffoldv2.Kustomize{}, &scaffoldv2.ManagerWebhookPatch{}, + &scaffoldv2.ManagerRoleBinding{}, + &scaffoldv2.KustomizeRBAC{}, &managerv2.Kustomization{}, &webhook.Kustomization{}, &webhook.KustomizeConfigWebhook{}, diff --git a/pkg/scaffold/scaffold.go b/pkg/scaffold/scaffold.go index f79aab74103..a0b0bf978cb 100644 --- a/pkg/scaffold/scaffold.go +++ b/pkg/scaffold/scaffold.go @@ -29,7 +29,6 @@ import ( "golang.org/x/tools/imports" yaml "gopkg.in/yaml.v2" - "sigs.k8s.io/controller-tools/pkg/util" "sigs.k8s.io/kubebuilder/pkg/scaffold/input" "sigs.k8s.io/kubebuilder/pkg/scaffold/project" ) diff --git a/pkg/scaffold/v2/controller.go b/pkg/scaffold/v2/controller.go index 8ef01a008a3..a6aab1da772 100644 --- a/pkg/scaffold/v2/controller.go +++ b/pkg/scaffold/v2/controller.go @@ -85,7 +85,7 @@ func (a *Controller) UpdateMain(path string) error { reconcilerSetupCodeFragment := fmt.Sprintf(`err = (&controllers.%sReconciler{ Client: mgr.GetClient(), - Log: ctrl.Log.WithName("%s-controller"), + Log: ctrl.Log.WithName("controllers").WithName("%s"), }).SetupWithManager(mgr) if err != nil { setupLog.Error(err, "unable to create controller", "controller", "%s") @@ -158,9 +158,10 @@ type {{ .Resource.Kind }}Reconciler struct { // +kubebuilder:rbac:groups={{.GroupDomain}},resources={{ .Plural }},verbs=get;list;watch;create;update;patch;delete // +kubebuilder:rbac:groups={{.GroupDomain}},resources={{ .Plural }}/status,verbs=get;update;patch + func (r *{{ .Resource.Kind }}Reconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { _ = context.Background() - _ = r.Log.WithValues("{{ .Resource.Kind }}", req.NamespacedName) + _ = r.Log.WithValues("{{ .Resource.Kind | lower }}", req.NamespacedName) // your logic here diff --git a/pkg/scaffold/v2/crd/enablewebhook_patch.go b/pkg/scaffold/v2/crd/enablewebhook_patch.go index bd9ddc39858..68a9c172756 100644 --- a/pkg/scaffold/v2/crd/enablewebhook_patch.go +++ b/pkg/scaffold/v2/crd/enablewebhook_patch.go @@ -36,7 +36,7 @@ type EnableWebhookPatch struct { // GetInput implements input.File func (p *EnableWebhookPatch) GetInput() (input.Input, error) { if p.Path == "" { - p.Path = filepath.Join("config", "crds", "patches", + p.Path = filepath.Join("config", "crd", "patches", fmt.Sprintf("webhook_in_%s.yaml", strings.ToLower(p.Resource.Kind))) } p.TemplateBody = enableWebhookPatchTemplate diff --git a/pkg/scaffold/v2/crd/kustomization.go b/pkg/scaffold/v2/crd/kustomization.go index dad0c8ccc22..19f46d93873 100644 --- a/pkg/scaffold/v2/crd/kustomization.go +++ b/pkg/scaffold/v2/crd/kustomization.go @@ -21,6 +21,8 @@ import ( "path/filepath" "strings" + "github.com/markbates/inflect" + "sigs.k8s.io/kubebuilder/pkg/scaffold/input" "sigs.k8s.io/kubebuilder/pkg/scaffold/v1/resource" "sigs.k8s.io/kubebuilder/pkg/scaffold/v2/internal" @@ -44,7 +46,7 @@ type Kustomization struct { // GetInput implements input.File func (c *Kustomization) GetInput() (input.Input, error) { if c.Path == "" { - c.Path = filepath.Join("config", "crds", "kustomization.yaml") + c.Path = filepath.Join("config", "crd", "kustomization.yaml") } c.TemplateBody = kustomizationTemplate c.Input.IfExistsAction = input.Error @@ -53,13 +55,16 @@ func (c *Kustomization) GetInput() (input.Input, error) { func (c *Kustomization) Update() error { if c.Path == "" { - c.Path = filepath.Join("config", "crds", "kustomization.yaml") + c.Path = filepath.Join("config", "crd", "kustomization.yaml") } - kustomizeResourceCodeFragment := fmt.Sprintf(`- bases/%s_%s.yaml -`, c.Resource.Group, strings.ToLower(c.Resource.Kind)) - kustomizePatchCodeFragment := fmt.Sprintf(`#- patches/webhook_in_%s.yaml -`, strings.ToLower(c.Resource.Kind)) + // TODO(directxman12): not technically valid if something changes from the default + // (we'd need to parse the markers) + rs := inflect.NewDefaultRuleset() + plural := rs.Pluralize(strings.ToLower(c.Resource.Kind)) + + kustomizeResourceCodeFragment := fmt.Sprintf("- bases/%s.%s_%s.yaml\n", c.Resource.Group, c.Domain, plural) + kustomizePatchCodeFragment := fmt.Sprintf("#- patches/webhook_in_%s.yaml\n", plural) return internal.InsertStringsInFile(c.Path, kustomizeResourceScaffoldMarker, kustomizeResourceCodeFragment, diff --git a/pkg/scaffold/v2/crd/kustomizeconfig.go b/pkg/scaffold/v2/crd/kustomizeconfig.go index 2f08a6570f3..4fe021e82bb 100644 --- a/pkg/scaffold/v2/crd/kustomizeconfig.go +++ b/pkg/scaffold/v2/crd/kustomizeconfig.go @@ -32,7 +32,7 @@ type KustomizeConfig struct { // GetInput implements input.File func (c *KustomizeConfig) GetInput() (input.Input, error) { if c.Path == "" { - c.Path = filepath.Join("config", "crds", "kustomizeconfig.yaml") + c.Path = filepath.Join("config", "crd", "kustomizeconfig.yaml") } c.TemplateBody = kustomizeConfigTemplate c.Input.IfExistsAction = input.Error diff --git a/pkg/scaffold/v2/crd_sample.go b/pkg/scaffold/v2/crd_sample.go new file mode 100644 index 00000000000..0de2f5cee50 --- /dev/null +++ b/pkg/scaffold/v2/crd_sample.go @@ -0,0 +1,62 @@ +/* +Copyright 2018 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. +*/ + +package v2 + +import ( + "fmt" + "path/filepath" + "strings" + + "sigs.k8s.io/kubebuilder/pkg/scaffold/input" + "sigs.k8s.io/kubebuilder/pkg/scaffold/v1/resource" +) + +var _ input.File = &CRDSample{} + +// CRDSample scaffolds a manifest for CRD sample. +type CRDSample struct { + input.Input + + // Resource is a resource in the API group + Resource *resource.Resource +} + +// GetInput implements input.File +func (c *CRDSample) GetInput() (input.Input, error) { + if c.Path == "" { + c.Path = filepath.Join("config", "samples", fmt.Sprintf( + "%s_%s_%s.yaml", c.Resource.Group, c.Resource.Version, strings.ToLower(c.Resource.Kind))) + } + + c.IfExistsAction = input.Error + c.TemplateBody = crdSampleTemplate + return c.Input, nil +} + +// Validate validates the values +func (c *CRDSample) Validate() error { + return c.Resource.Validate() +} + +var crdSampleTemplate = `apiVersion: {{ .Resource.Group }}.{{ .Domain }}/{{ .Resource.Version }} +kind: {{ .Resource.Kind }} +metadata: + name: {{ lower .Resource.Kind }}-sample +spec: + # Add fields here + foo: bar +` diff --git a/pkg/scaffold/v2/group.go b/pkg/scaffold/v2/group.go index 36a605faeff..db251333a49 100644 --- a/pkg/scaffold/v2/group.go +++ b/pkg/scaffold/v2/group.go @@ -25,7 +25,7 @@ import ( var _ input.File = &Group{} -// Group scaffolds the pkg/apis/group/group.go +// Group scaffolds the api//groupversion_info.go type Group struct { input.Input @@ -50,10 +50,7 @@ func (g *Group) Validate() error { var groupTemplate = `{{ .Boilerplate }} // Package {{.Resource.Version}} contains API Schema definitions for the {{ .Resource.Group }} {{.Resource.Version}} API group -// +k8s:openapi-gen=true -// +k8s:deepcopy-gen=package,register -// +k8s:conversion-gen={{ .Repo }}/pkg/apis/{{ .Resource.Group }} -// +k8s:defaulter-gen=TypeMeta +// +kubebuilder:object:generate=true // +groupName={{ .Resource.Group }}.{{ .Domain }} package {{ .Resource.Version }} diff --git a/pkg/scaffold/v2/kustomize.go b/pkg/scaffold/v2/kustomize.go index b7323e89fde..76ee14db792 100644 --- a/pkg/scaffold/v2/kustomize.go +++ b/pkg/scaffold/v2/kustomize.go @@ -66,12 +66,12 @@ namePrefix: {{.Prefix}}- # someName: someValue bases: -- ../crds +- ../crd - ../rbac - ../manager -- ../webhook +# - ../webhook # Comment the next line if you want to disable cert-manager -- ../certmanager +# - ../certmanager patches: - manager_image_patch.yaml diff --git a/pkg/scaffold/v2/makefile.go b/pkg/scaffold/v2/makefile.go index dbcadd85496..b075ae5c3d1 100644 --- a/pkg/scaffold/v2/makefile.go +++ b/pkg/scaffold/v2/makefile.go @@ -27,9 +27,6 @@ type Makefile struct { input.Input // Image is controller manager image name Image string - - // path for controller-tools pkg - ControllerToolsPath string } // GetInput implements input.File @@ -40,9 +37,6 @@ func (c *Makefile) GetInput() (input.Input, error) { if c.Image == "" { c.Image = "controller:latest" } - if c.ControllerToolsPath == "" { - c.ControllerToolsPath = "vendor/sigs.k8s.io/controller-tools" - } c.TemplateBody = makefileTemplate c.Input.IfExistsAction = input.Error return c.Input, nil @@ -51,8 +45,10 @@ func (c *Makefile) GetInput() (input.Input, error) { var makefileTemplate = ` # Image URL to use all building/pushing image targets IMG ?= {{ .Image }} +# Produce CRDs that work back to Kubernetes 1.11 (no version conversion) +CRD_OPTIONS ?= "crd:trivialVersions=true" -all: test manager +all: manager # Run tests test: generate fmt vet manifests @@ -68,34 +64,28 @@ run: generate fmt vet # Install CRDs into a cluster install: manifests - kubectl apply -f config/crds/bases + kubectl apply -f config/crd/bases # Deploy controller in the configured Kubernetes cluster in ~/.kube/config deploy: manifests - kubectl apply -f config/crds/bases + kubectl apply -f config/crd/bases kustomize build config/default | kubectl apply -f - # Generate manifests e.g. CRD, RBAC etc. -manifests: -# TODO(droot): controller-gen will require fix to take new api-path as input, so disabling this for now -# -# go run {{ .ControllerToolsPath }}/cmd/controller-gen/main.go all --output-dir=config/crds/bases/ +manifests: controller-gen + $(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./api/...;./controllers/..." output:crd:artifacts:config=config/crd/bases # Run go fmt against code fmt: - go fmt ./api/... ./controllers/... + go fmt ./... # Run go vet against code vet: - go vet ./api/... ./controllers/... + go vet ./... # Generate code -generate: -ifndef GOPATH - $(error GOPATH not defined, please define GOPATH. Run "go help gopath" to learn more about GOPATH) -endif - go run ./vendor/k8s.io/code-generator/cmd/deepcopy-gen/main.go -O zz_generated.deepcopy --go-header-file ./hack/boilerplate.go.txt -i ./api/... - +generate: controller-gen + $(CONTROLLER_GEN) object:headerFile=./hack/boilerplate.go.txt paths=./api/... # Build the docker image docker-build: test @@ -106,4 +96,14 @@ docker-build: test # Push the docker image docker-push: docker push ${IMG} + +# find or download controller-gen +# download controller-gen if necessary +controller-gen: +ifeq (, $(shell which controller-gen)) + go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.2.0-alpha.1 +CONTROLLER_GEN=$(shell go env GOPATH)/bin/controller-gen +else +CONTROLLER_GEN=$(shell which controller-gen) +endif ` diff --git a/pkg/scaffold/v2/manager/kustomization.go b/pkg/scaffold/v2/manager/kustomization.go index cf2b7698bd3..7cb74027d48 100644 --- a/pkg/scaffold/v2/manager/kustomization.go +++ b/pkg/scaffold/v2/manager/kustomization.go @@ -43,17 +43,17 @@ var kustomizeManagerTemplate = `resources: - manager.yaml # the following config is for teaching kustomize how to do var substitution -vars: -- name: NAMESPACE - objref: - kind: Service - version: v1 - name: webhook-service - fieldref: - fieldpath: metadata.namespace -- name: SERVICENAME - objref: - kind: Service - version: v1 - name: webhook-service +# vars: +# - name: NAMESPACE +# objref: +# kind: Service +# version: v1 +# name: webhook-service +# fieldref: +# fieldpath: metadata.namespace +# - name: SERVICENAME +# objref: +# kind: Service +# version: v1 +# name: webhook-service ` diff --git a/pkg/scaffold/v2/doc.go b/pkg/scaffold/v2/mgrrolebinding.go similarity index 52% rename from pkg/scaffold/v2/doc.go rename to pkg/scaffold/v2/mgrrolebinding.go index d39cfb56638..1b55bc683eb 100644 --- a/pkg/scaffold/v2/doc.go +++ b/pkg/scaffold/v2/mgrrolebinding.go @@ -22,35 +22,33 @@ import ( "sigs.k8s.io/kubebuilder/pkg/scaffold/input" ) -var _ input.File = &Doc{} +var _ input.File = &ManagerRoleBinding{} -// Doc scaffolds the api/doc.go directory so that deep-copy gen can discover all -// the api version pkgs. Once we fix deepcopy-gen, we can remove scaffolding for -// this. -type Doc struct { +// ManagerRoleBinding scaffolds the config/rbac/role_binding.yaml file +type ManagerRoleBinding struct { input.Input - - // Comments are additional lines to write to the doc.go file - Comments []string } // GetInput implements input.File -func (a *Doc) GetInput() (input.Input, error) { - if a.Path == "" { - a.Path = filepath.Join("api", "doc.go") +func (r *ManagerRoleBinding) GetInput() (input.Input, error) { + if r.Path == "" { + r.Path = filepath.Join("config", "rbac", "role_binding.yaml") } - a.TemplateBody = docGoTemplate - return a.Input, nil -} - -// Validate validates the values -func (a *Doc) Validate() error { - return nil + r.TemplateBody = managerBindingTemplate + return r.Input, nil } -var docGoTemplate = `{{ .Boilerplate }} - -// +k8s:openapi-gen=true -// +k8s:deepcopy-gen=package,register -package api +var managerBindingTemplate = `apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: manager-rolebinding +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: manager-role +subjects: +- kind: ServiceAccount + name: default + namespace: system ` + diff --git a/pkg/scaffold/v2/rbac.go b/pkg/scaffold/v2/rbac.go new file mode 100644 index 00000000000..35e0f0bf378 --- /dev/null +++ b/pkg/scaffold/v2/rbac.go @@ -0,0 +1,52 @@ +/* +Copyright 2019 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. +*/ + +package v2 + +import ( + "path/filepath" + + "sigs.k8s.io/kubebuilder/pkg/scaffold/input" +) + +var _ input.File = &KustomizeRBAC{} + +// KustomizeRBAC scaffolds the Kustomization file in rbac folder. +type KustomizeRBAC struct { + input.Input +} + +// GetInput implements input.File +func (c *KustomizeRBAC) GetInput() (input.Input, error) { + if c.Path == "" { + c.Path = filepath.Join("config", "rbac", "kustomization.yaml") + } + c.TemplateBody = kustomizeRBACTemplate + c.Input.IfExistsAction = input.Error + return c.Input, nil +} + +var kustomizeRBACTemplate = `resources: +- role.yaml +- role_binding.yaml +# Comment the following 3 lines if you want to disable +# the auth proxy (https://github.com/brancz/kube-rbac-proxy) +# which protects your /metrics endpoint. +- auth_proxy_service.yaml +- auth_proxy_role.yaml +- auth_proxy_role_binding.yaml +` + diff --git a/pkg/scaffold/v2/resource_doc.go b/pkg/scaffold/v2/resource_doc.go deleted file mode 100644 index 0818c7515fd..00000000000 --- a/pkg/scaffold/v2/resource_doc.go +++ /dev/null @@ -1,62 +0,0 @@ -/* -Copyright 2018 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. -*/ - -package v2 - -import ( - "path/filepath" - - "sigs.k8s.io/kubebuilder/pkg/scaffold/input" - "sigs.k8s.io/kubebuilder/pkg/scaffold/v1/resource" -) - -var _ input.File = &ResourceDoc{} - -// Doc scaffolds the api/version/doc.go directory -type ResourceDoc struct { - input.Input - - // Resource is a resource for the API version - Resource *resource.Resource - - // Comments are additional lines to write to the doc.go file - Comments []string -} - -// GetInput implements input.File -func (a *ResourceDoc) GetInput() (input.Input, error) { - if a.Path == "" { - a.Path = filepath.Join("api", a.Resource.Version, "doc.go") - } - a.TemplateBody = resourceDocGoTemplate - return a.Input, nil -} - -// Validate validates the values -func (a *ResourceDoc) Validate() error { - return a.Resource.Validate() -} - -var resourceDocGoTemplate = `{{ .Boilerplate }} - -// Package {{.Resource.Version}} contains API Schema definitions for the {{ .Resource.Group }} {{.Resource.Version}} API group -// +k8s:openapi-gen=true -// +k8s:deepcopy-gen=package,register -// +k8s:conversion-gen={{ .Repo }}/api/{{ .Resource.Version }} -// +k8s:defaulter-gen=TypeMeta -// +groupName={{ .Resource.Group }}.{{ .Domain }} -package {{.Resource.Version}} -` diff --git a/pkg/scaffold/v2/types.go b/pkg/scaffold/v2/types.go new file mode 100644 index 00000000000..24366cca8f3 --- /dev/null +++ b/pkg/scaffold/v2/types.go @@ -0,0 +1,100 @@ +/* +Copyright 2018 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. +*/ + +package v2 + +import ( + "fmt" + "path/filepath" + "strings" + + "sigs.k8s.io/kubebuilder/pkg/scaffold/input" + "sigs.k8s.io/kubebuilder/pkg/scaffold/v1/resource" +) + +var _ input.File = &Types{} + +// Types scaffolds the api//_types.go file to define the schema for an API +type Types struct { + input.Input + + // Resource is the resource to scaffold the types_test.go file for + Resource *resource.Resource +} + +// GetInput implements input.File +func (t *Types) GetInput() (input.Input, error) { + if t.Path == "" { + t.Path = filepath.Join("pkg", "apis", t.Resource.Group, t.Resource.Version, + fmt.Sprintf("%s_types.go", strings.ToLower(t.Resource.Kind))) + } + t.TemplateBody = typesTemplate + t.IfExistsAction = input.Error + return t.Input, nil +} + +// Validate validates the values +func (t *Types) Validate() error { + return t.Resource.Validate() +} + +var typesTemplate = `{{ .Boilerplate }} + +package {{ .Resource.Version }} + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! +// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. + +// {{.Resource.Kind}}Spec defines the desired state of {{.Resource.Kind}} +type {{.Resource.Kind}}Spec struct { + // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster + // Important: Run "make" to regenerate code after modifying this file +} + +// {{.Resource.Kind}}Status defines the observed state of {{.Resource.Kind}} +type {{.Resource.Kind}}Status struct { + // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster + // Important: Run "make" to regenerate code after modifying this file +} + +// +kubebuilder:object:root=true + +// {{.Resource.Kind}} is the Schema for the {{ .Resource.Resource }} API +type {{.Resource.Kind}} struct { + metav1.TypeMeta ` + "`" + `json:",inline"` + "`" + ` + metav1.ObjectMeta ` + "`" + `json:"metadata,omitempty"` + "`" + ` + + Spec {{.Resource.Kind}}Spec ` + "`" + `json:"spec,omitempty"` + "`" + ` + Status {{.Resource.Kind}}Status ` + "`" + `json:"status,omitempty"` + "`" + ` +} + +// +kubebuilder:object:root=true + +// {{.Resource.Kind}}List contains a list of {{.Resource.Kind}} +type {{.Resource.Kind}}List struct { + metav1.TypeMeta ` + "`" + `json:",inline"` + "`" + ` + metav1.ListMeta ` + "`" + `json:"metadata,omitempty"` + "`" + ` + Items []{{ .Resource.Kind }} ` + "`" + `json:"items"` + "`" + ` +} + +func init() { + SchemeBuilder.Register(&{{.Resource.Kind}}{}, &{{.Resource.Kind}}List{}) +} +` diff --git a/pkg/scaffold/v2/webhook/kustomization.go b/pkg/scaffold/v2/webhook/kustomization.go index aee51f6aea6..d874eb1b223 100644 --- a/pkg/scaffold/v2/webhook/kustomization.go +++ b/pkg/scaffold/v2/webhook/kustomization.go @@ -40,7 +40,7 @@ func (c *Kustomization) GetInput() (input.Input, error) { } var KustomizeWebhookTemplate = `resources: -- webhookmanifests.yaml +- webhookmanifests.yaml # disabled till v2 has webhook support configurations: - kustomizeconfig.yaml diff --git a/test.sh b/test.sh index 9182c1d90be..c8043f5153c 100755 --- a/test.sh +++ b/test.sh @@ -90,12 +90,17 @@ function test_project { version=$2 header_text "performing tests in dir $project_dir for project version v$version" vendor_tarball=$(pwd)/testdata/vendor.v$version.tgz + old_gopath=$GOPATH + if [[ $version == "1" ]]; then + export GOPATH=$(pwd)/testdata/gopath + fi cd testdata/$project_dir # v2 uses modules, and thus doesn't have a vendor directory [[ -e ${vendor_tarball} ]] && tar -zxf $vendor_tarball make all test # v2 doesn't test on all by default [[ -e ${vendor_tarball} ]] && rm -rf ./vendor && rm -f Gopkg.lock cd - + export GOPATH=$old_gopath } prepare_staging_dir @@ -137,8 +142,10 @@ prepare_testdir_under_gopath dump_project test_create_namespaced_coretype_controller +header_text "running kubebuilder unit tests" cd ${go_workspace}/src/sigs.k8s.io/kubebuilder +export GO111MODULE=on go test ./cmd/... ./pkg/... # test project v1