From 74ca881f7443690446bd01a174182c49814ba8bc Mon Sep 17 00:00:00 2001 From: fanzhangio Date: Fri, 3 Aug 2018 23:27:33 -0700 Subject: [PATCH] Fix domain resource issues in controller - fix in controller-tools and vendor in kubebuilder - bind resource for controller based on whether resource is created. --- cmd/Gopkg.lock | 2 +- .../cmd/controller-gen/main.go | 7 +- .../pkg/scaffold/controller/controller.go | 31 +++-- .../pkg/scaffold/controller/controllertest.go | 8 +- .../pkg/apis/addtoscheme_policy_v1beta1.go | 26 +++++ .../test/pkg/apis/creatures/v2alpha1/doc.go | 2 +- .../pkg/apis/creatures/v2alpha1/register.go | 4 +- .../test/pkg/apis/crew/v1/doc.go | 2 +- .../test/pkg/apis/crew/v1/register.go | 4 +- .../test/pkg/apis/policy/group.go | 18 +++ .../test/pkg/apis/policy/v1beta1/doc.go | 23 ++++ .../policy/v1beta1/healthcheckpolicy_types.go | 64 +++++++++++ .../test/pkg/apis/policy/v1beta1/register.go | 38 +++++++ .../test/pkg/apis/ship/v1beta1/doc.go | 2 +- .../test/pkg/apis/ship/v1beta1/register.go | 4 +- .../pkg/controller/add_healthcheckpolicy.go | 26 +++++ .../firstmate/firstmate_controller.go | 2 +- .../controller/frigate/frigate_controller.go | 2 +- .../healthcheckpolicy_controller.go | 106 ++++++++++++++++++ .../controller/kraken/kraken_controller.go | 2 +- 20 files changed, 341 insertions(+), 32 deletions(-) create mode 100644 cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/apis/addtoscheme_policy_v1beta1.go create mode 100644 cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/apis/policy/group.go create mode 100644 cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/apis/policy/v1beta1/doc.go create mode 100644 cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/apis/policy/v1beta1/healthcheckpolicy_types.go create mode 100644 cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/apis/policy/v1beta1/register.go create mode 100644 cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/controller/add_healthcheckpolicy.go create mode 100644 cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/controller/healthcheckpolicy/healthcheckpolicy_controller.go diff --git a/cmd/Gopkg.lock b/cmd/Gopkg.lock index ecc5d336a6..48276deaec 100644 --- a/cmd/Gopkg.lock +++ b/cmd/Gopkg.lock @@ -204,7 +204,7 @@ "pkg/scaffold/resource", "pkg/util" ] - revision = "baf783301797f950d03f5e13933d1c8dbab7c090" + revision = "ade554d58413a7b2327cf38fde98484e23e66c82" [solve-meta] analyzer-name = "dep" diff --git a/cmd/vendor/sigs.k8s.io/controller-tools/cmd/controller-gen/main.go b/cmd/vendor/sigs.k8s.io/controller-tools/cmd/controller-gen/main.go index 08fb3d6ba8..5fb09e55ee 100644 --- a/cmd/vendor/sigs.k8s.io/controller-tools/cmd/controller-gen/main.go +++ b/cmd/vendor/sigs.k8s.io/controller-tools/cmd/controller-gen/main.go @@ -133,9 +133,10 @@ Usage: projectDir = currDir } crdGen := &crdgenerator.Generator{ - RootPath: projectDir, - OutputDir: filepath.Join(projectDir, "config", "crds"), - Namespace: namespace, + RootPath: projectDir, + OutputDir: filepath.Join(projectDir, "config", "crds"), + Namespace: namespace, + SkipMapValidation: true, } if err := crdGen.ValidateAndInitFields(); err != nil { log.Fatal(err) diff --git a/cmd/vendor/sigs.k8s.io/controller-tools/pkg/scaffold/controller/controller.go b/cmd/vendor/sigs.k8s.io/controller-tools/pkg/scaffold/controller/controller.go index a97bf370d0..de7e4fce42 100644 --- a/cmd/vendor/sigs.k8s.io/controller-tools/pkg/scaffold/controller/controller.go +++ b/cmd/vendor/sigs.k8s.io/controller-tools/pkg/scaffold/controller/controller.go @@ -17,6 +17,8 @@ limitations under the License. package controller import ( + "fmt" + "os" "path" "path/filepath" "strings" @@ -61,16 +63,8 @@ func (a *Controller) GetInput() (input.Input, error) { "rbac.authorization": "k8s.io", "storage": "k8s.io", } - if domain, found := coreGroups[a.Resource.Group]; found { - a.ResourcePackage = path.Join("k8s.io", "api") - a.GroupDomain = a.Resource.Group - if domain != "" { - a.GroupDomain = a.Resource.Group + "." + domain - } - } else { - a.ResourcePackage = path.Join(a.Repo, "pkg", "apis") - a.GroupDomain = a.Resource.Group + "." + a.Domain - } + + a.ResourcePackage, a.GroupDomain = getResourceInfo(coreGroups, a.Resource, a.Input) if a.Plural == "" { rs := inflect.NewDefaultRuleset() @@ -87,6 +81,23 @@ func (a *Controller) GetInput() (input.Input, error) { return a.Input, nil } +func getResourceInfo(coreGroups map[string]string, r *resource.Resource, in input.Input) (resourcePackage, groupDomain string) { + resourcePath := filepath.Join("pkg", "apis", r.Group, r.Version, + fmt.Sprintf("%s_types.go", strings.ToLower(r.Kind))) + if _, err := os.Stat(resourcePath); os.IsNotExist(err) { + if domain, found := coreGroups[r.Group]; found { + resourcePackage := path.Join("k8s.io", "api") + groupDomain = r.Group + if domain != "" { + groupDomain = r.Group + "." + domain + } + return resourcePackage, groupDomain + } + // TODO: need to support '--resource-pkg-path' flag for specifying resourcePath + } + return path.Join(in.Repo, "pkg", "apis"), r.Group + "." + in.Domain +} + var controllerTemplate = `{{ .Boilerplate }} package {{ lower .Resource.Kind }} diff --git a/cmd/vendor/sigs.k8s.io/controller-tools/pkg/scaffold/controller/controllertest.go b/cmd/vendor/sigs.k8s.io/controller-tools/pkg/scaffold/controller/controllertest.go index 4b421b04f9..c01446f805 100644 --- a/cmd/vendor/sigs.k8s.io/controller-tools/pkg/scaffold/controller/controllertest.go +++ b/cmd/vendor/sigs.k8s.io/controller-tools/pkg/scaffold/controller/controllertest.go @@ -17,7 +17,6 @@ limitations under the License. package controller import ( - "path" "path/filepath" "strings" @@ -59,11 +58,8 @@ func (a *Test) GetInput() (input.Input, error) { "rbac.authorization": "k8s.io", "storage": "k8s.io", } - if _, found := coreGroups[a.Resource.Group]; found { - a.ResourcePackage = path.Join("k8s.io", "api") - } else { - a.ResourcePackage = path.Join(a.Repo, "pkg", "apis") - } + + a.ResourcePackage, _ = getResourceInfo(coreGroups, a.Resource, a.Input) a.TemplateBody = controllerTestTemplate a.Input.IfExistsAction = input.Error diff --git a/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/apis/addtoscheme_policy_v1beta1.go b/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/apis/addtoscheme_policy_v1beta1.go new file mode 100644 index 0000000000..ae7ce242f9 --- /dev/null +++ b/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/apis/addtoscheme_policy_v1beta1.go @@ -0,0 +1,26 @@ +/* +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 apis + +import ( + "sigs.k8s.io/controller-tools/test/pkg/apis/policy/v1beta1" +) + +func init() { + // Register the types with the Scheme so the components can map objects to GroupVersionKinds and back + AddToSchemes = append(AddToSchemes, v1beta1.SchemeBuilder.AddToScheme) +} diff --git a/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/apis/creatures/v2alpha1/doc.go b/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/apis/creatures/v2alpha1/doc.go index 1bb98d32b7..73fa73a37c 100644 --- a/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/apis/creatures/v2alpha1/doc.go +++ b/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/apis/creatures/v2alpha1/doc.go @@ -19,5 +19,5 @@ limitations under the License. // +k8s:deepcopy-gen=package,register // +k8s:conversion-gen=sigs.k8s.io/controller-tools/test/pkg/apis/creatures // +k8s:defaulter-gen=TypeMeta -// +groupName=creatures.k8s.io +// +groupName=creatures.testproject.org package v2alpha1 diff --git a/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/apis/creatures/v2alpha1/register.go b/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/apis/creatures/v2alpha1/register.go index ae0dde124f..3807d89883 100644 --- a/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/apis/creatures/v2alpha1/register.go +++ b/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/apis/creatures/v2alpha1/register.go @@ -21,7 +21,7 @@ limitations under the License. // +k8s:deepcopy-gen=package,register // +k8s:conversion-gen=sigs.k8s.io/controller-tools/test/pkg/apis/creatures // +k8s:defaulter-gen=TypeMeta -// +groupName=creatures.k8s.io +// +groupName=creatures.testproject.org package v2alpha1 import ( @@ -31,7 +31,7 @@ import ( var ( // SchemeGroupVersion is group version used to register these objects - SchemeGroupVersion = schema.GroupVersion{Group: "creatures.k8s.io", Version: "v2alpha1"} + SchemeGroupVersion = schema.GroupVersion{Group: "creatures.testproject.org", Version: "v2alpha1"} // SchemeBuilder is used to add go types to the GroupVersionKind scheme SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion} diff --git a/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/apis/crew/v1/doc.go b/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/apis/crew/v1/doc.go index c3a5aaffa9..15287c8d06 100644 --- a/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/apis/crew/v1/doc.go +++ b/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/apis/crew/v1/doc.go @@ -19,5 +19,5 @@ limitations under the License. // +k8s:deepcopy-gen=package,register // +k8s:conversion-gen=sigs.k8s.io/controller-tools/test/pkg/apis/crew // +k8s:defaulter-gen=TypeMeta -// +groupName=crew.k8s.io +// +groupName=crew.testproject.org package v1 diff --git a/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/apis/crew/v1/register.go b/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/apis/crew/v1/register.go index dca99b02ff..c70b2202fe 100644 --- a/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/apis/crew/v1/register.go +++ b/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/apis/crew/v1/register.go @@ -21,7 +21,7 @@ limitations under the License. // +k8s:deepcopy-gen=package,register // +k8s:conversion-gen=sigs.k8s.io/controller-tools/test/pkg/apis/crew // +k8s:defaulter-gen=TypeMeta -// +groupName=crew.k8s.io +// +groupName=crew.testproject.org package v1 import ( @@ -31,7 +31,7 @@ import ( var ( // SchemeGroupVersion is group version used to register these objects - SchemeGroupVersion = schema.GroupVersion{Group: "crew.k8s.io", Version: "v1"} + SchemeGroupVersion = schema.GroupVersion{Group: "crew.testproject.org", Version: "v1"} // SchemeBuilder is used to add go types to the GroupVersionKind scheme SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion} diff --git a/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/apis/policy/group.go b/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/apis/policy/group.go new file mode 100644 index 0000000000..38489bbdb9 --- /dev/null +++ b/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/apis/policy/group.go @@ -0,0 +1,18 @@ +/* +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 policy contains policy API versions +package policy diff --git a/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/apis/policy/v1beta1/doc.go b/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/apis/policy/v1beta1/doc.go new file mode 100644 index 0000000000..de9987bbf8 --- /dev/null +++ b/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/apis/policy/v1beta1/doc.go @@ -0,0 +1,23 @@ +/* +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 v1beta1 contains API Schema definitions for the policy v1beta1 API group +// +k8s:openapi-gen=true +// +k8s:deepcopy-gen=package,register +// +k8s:conversion-gen=sigs.k8s.io/controller-tools/test/pkg/apis/policy +// +k8s:defaulter-gen=TypeMeta +// +groupName=policy.testproject.org +package v1beta1 diff --git a/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/apis/policy/v1beta1/healthcheckpolicy_types.go b/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/apis/policy/v1beta1/healthcheckpolicy_types.go new file mode 100644 index 0000000000..23cd7ba7d3 --- /dev/null +++ b/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/apis/policy/v1beta1/healthcheckpolicy_types.go @@ -0,0 +1,64 @@ +/* +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 v1beta1 + +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. + +// HealthCheckPolicySpec defines the desired state of HealthCheckPolicy +type HealthCheckPolicySpec struct { + // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster + // Important: Run "make" to regenerate code after modifying this file +} + +// HealthCheckPolicyStatus defines the observed state of HealthCheckPolicy +type HealthCheckPolicyStatus struct { + // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster + // Important: Run "make" to regenerate code after modifying this file +} + +// +genclient +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +// +genclient:nonNamespaced + +// HealthCheckPolicy is the Schema for the healthcheckpolicies API +// +k8s:openapi-gen=true +type HealthCheckPolicy struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec HealthCheckPolicySpec `json:"spec,omitempty"` + Status HealthCheckPolicyStatus `json:"status,omitempty"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +// +genclient:nonNamespaced + +// HealthCheckPolicyList contains a list of HealthCheckPolicy +type HealthCheckPolicyList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []HealthCheckPolicy `json:"items"` +} + +func init() { + SchemeBuilder.Register(&HealthCheckPolicy{}, &HealthCheckPolicyList{}) +} diff --git a/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/apis/policy/v1beta1/register.go b/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/apis/policy/v1beta1/register.go new file mode 100644 index 0000000000..97aed5549d --- /dev/null +++ b/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/apis/policy/v1beta1/register.go @@ -0,0 +1,38 @@ +/* +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. +*/ + +// NOTE: Boilerplate only. Ignore this file. + +// Package v1beta1 contains API Schema definitions for the policy v1beta1 API group +// +k8s:openapi-gen=true +// +k8s:deepcopy-gen=package,register +// +k8s:conversion-gen=sigs.k8s.io/controller-tools/test/pkg/apis/policy +// +k8s:defaulter-gen=TypeMeta +// +groupName=policy.testproject.org +package v1beta1 + +import ( + "k8s.io/apimachinery/pkg/runtime/schema" + "sigs.k8s.io/controller-runtime/pkg/runtime/scheme" +) + +var ( + // SchemeGroupVersion is group version used to register these objects + SchemeGroupVersion = schema.GroupVersion{Group: "policy.testproject.org", Version: "v1beta1"} + + // SchemeBuilder is used to add go types to the GroupVersionKind scheme + SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion} +) diff --git a/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/apis/ship/v1beta1/doc.go b/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/apis/ship/v1beta1/doc.go index 8a42f5698d..a4f24d0706 100644 --- a/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/apis/ship/v1beta1/doc.go +++ b/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/apis/ship/v1beta1/doc.go @@ -19,5 +19,5 @@ limitations under the License. // +k8s:deepcopy-gen=package,register // +k8s:conversion-gen=sigs.k8s.io/controller-tools/test/pkg/apis/ship // +k8s:defaulter-gen=TypeMeta -// +groupName=ship.k8s.io +// +groupName=ship.testproject.org package v1beta1 diff --git a/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/apis/ship/v1beta1/register.go b/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/apis/ship/v1beta1/register.go index c8d5eb64ca..7a487bd2e4 100644 --- a/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/apis/ship/v1beta1/register.go +++ b/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/apis/ship/v1beta1/register.go @@ -21,7 +21,7 @@ limitations under the License. // +k8s:deepcopy-gen=package,register // +k8s:conversion-gen=sigs.k8s.io/controller-tools/test/pkg/apis/ship // +k8s:defaulter-gen=TypeMeta -// +groupName=ship.k8s.io +// +groupName=ship.testproject.org package v1beta1 import ( @@ -31,7 +31,7 @@ import ( var ( // SchemeGroupVersion is group version used to register these objects - SchemeGroupVersion = schema.GroupVersion{Group: "ship.k8s.io", Version: "v1beta1"} + SchemeGroupVersion = schema.GroupVersion{Group: "ship.testproject.org", Version: "v1beta1"} // SchemeBuilder is used to add go types to the GroupVersionKind scheme SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion} diff --git a/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/controller/add_healthcheckpolicy.go b/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/controller/add_healthcheckpolicy.go new file mode 100644 index 0000000000..4b80ba5d4e --- /dev/null +++ b/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/controller/add_healthcheckpolicy.go @@ -0,0 +1,26 @@ +/* +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 controller + +import ( + "sigs.k8s.io/controller-tools/test/pkg/controller/healthcheckpolicy" +) + +func init() { + // AddToManagerFuncs is a list of functions to create controllers and add them to a manager. + AddToManagerFuncs = append(AddToManagerFuncs, healthcheckpolicy.Add) +} diff --git a/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/controller/firstmate/firstmate_controller.go b/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/controller/firstmate/firstmate_controller.go index 288e9ccc8a..606d3bb554 100644 --- a/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/controller/firstmate/firstmate_controller.go +++ b/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/controller/firstmate/firstmate_controller.go @@ -95,7 +95,7 @@ type ReconcileFirstMate struct { // a Deployment as an example // Automatically generate RBAC rules to allow the Controller to read and write Deployments // +kubebuilder:rbac:groups=apps,resources=deployments,verbs=get;list;watch;create;update;patch;delete -// +kubebuilder:rbac:groups=crew.k8s.io,resources=firstmates,verbs=get;list;watch;create;update;patch;delete +// +kubebuilder:rbac:groups=crew.testproject.org,resources=firstmates,verbs=get;list;watch;create;update;patch;delete func (r *ReconcileFirstMate) Reconcile(request reconcile.Request) (reconcile.Result, error) { // Fetch the FirstMate instance instance := &crewv1.FirstMate{} diff --git a/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/controller/frigate/frigate_controller.go b/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/controller/frigate/frigate_controller.go index 5dcdf563e6..c360f64a9c 100644 --- a/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/controller/frigate/frigate_controller.go +++ b/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/controller/frigate/frigate_controller.go @@ -87,7 +87,7 @@ type ReconcileFrigate struct { // and what is in the Frigate.Spec // TODO(user): Modify this Reconcile function to implement your Controller logic. The scaffolding writes // a Deployment as an example -// +kubebuilder:rbac:groups=ship.k8s.io,resources=frigates,verbs=get;list;watch;create;update;patch;delete +// +kubebuilder:rbac:groups=ship.testproject.org,resources=frigates,verbs=get;list;watch;create;update;patch;delete func (r *ReconcileFrigate) Reconcile(request reconcile.Request) (reconcile.Result, error) { // Fetch the Frigate instance instance := &shipv1beta1.Frigate{} diff --git a/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/controller/healthcheckpolicy/healthcheckpolicy_controller.go b/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/controller/healthcheckpolicy/healthcheckpolicy_controller.go new file mode 100644 index 0000000000..c310f620af --- /dev/null +++ b/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/controller/healthcheckpolicy/healthcheckpolicy_controller.go @@ -0,0 +1,106 @@ +/* +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 healthcheckpolicy + +import ( + "context" + + appsv1 "k8s.io/api/apps/v1" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/runtime" + "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/controller" + "sigs.k8s.io/controller-runtime/pkg/handler" + "sigs.k8s.io/controller-runtime/pkg/manager" + "sigs.k8s.io/controller-runtime/pkg/reconcile" + "sigs.k8s.io/controller-runtime/pkg/source" + policyv1beta1 "sigs.k8s.io/controller-tools/test/pkg/apis/policy/v1beta1" +) + +/** +* USER ACTION REQUIRED: This is a scaffold file intended for the user to modify with their own Controller +* business logic. Delete these comments after modifying this file.* + */ + +// Add creates a new HealthCheckPolicy Controller and adds it to the Manager with default RBAC. The Manager will set fields on the Controller +// and Start it when the Manager is Started. +// USER ACTION REQUIRED: update cmd/manager/main.go to call this policy.Add(mgr) to install this Controller +func Add(mgr manager.Manager) error { + return add(mgr, newReconciler(mgr)) +} + +// newReconciler returns a new reconcile.Reconciler +func newReconciler(mgr manager.Manager) reconcile.Reconciler { + return &ReconcileHealthCheckPolicy{Client: mgr.GetClient(), scheme: mgr.GetScheme()} +} + +// add adds a new Controller to mgr with r as the reconcile.Reconciler +func add(mgr manager.Manager, r reconcile.Reconciler) error { + // Create a new controller + c, err := controller.New("healthcheckpolicy-controller", mgr, controller.Options{Reconciler: r}) + if err != nil { + return err + } + + // Watch for changes to HealthCheckPolicy + err = c.Watch(&source.Kind{Type: &policyv1beta1.HealthCheckPolicy{}}, &handler.EnqueueRequestForObject{}) + if err != nil { + return err + } + + // TODO(user): Modify this to be the types you create + // Uncomment watch a Deployment created by HealthCheckPolicy - change this for objects you create + err = c.Watch(&source.Kind{Type: &appsv1.Deployment{}}, &handler.EnqueueRequestForOwner{ + IsController: true, + OwnerType: &policyv1beta1.HealthCheckPolicy{}, + }) + if err != nil { + return err + } + + return nil +} + +var _ reconcile.Reconciler = &ReconcileHealthCheckPolicy{} + +// ReconcileHealthCheckPolicy reconciles a HealthCheckPolicy object +type ReconcileHealthCheckPolicy struct { + client.Client + scheme *runtime.Scheme +} + +// Reconcile reads that state of the cluster for a HealthCheckPolicy object and makes changes based on the state read +// and what is in the HealthCheckPolicy.Spec +// TODO(user): Modify this Reconcile function to implement your Controller logic. The scaffolding writes +// a Deployment as an example +// +kubebuilder:rbac:groups=policy.testproject.org,resources=healthcheckpolicies,verbs=get;list;watch;create;update;patch;delete +func (r *ReconcileHealthCheckPolicy) Reconcile(request reconcile.Request) (reconcile.Result, error) { + // Fetch the HealthCheckPolicy instance + instance := &policyv1beta1.HealthCheckPolicy{} + err := r.Get(context.TODO(), request.NamespacedName, instance) + if err != nil { + if errors.IsNotFound(err) { + // Object not found, return. Created objects are automatically garbage collected. + // For additional cleanup logic use finalizers. + return reconcile.Result{}, nil + } + // Error reading the object - requeue the request. + return reconcile.Result{}, err + } + + return reconcile.Result{}, nil +} diff --git a/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/controller/kraken/kraken_controller.go b/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/controller/kraken/kraken_controller.go index e913e66d04..d9e23993ab 100644 --- a/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/controller/kraken/kraken_controller.go +++ b/cmd/vendor/sigs.k8s.io/controller-tools/test/pkg/controller/kraken/kraken_controller.go @@ -87,7 +87,7 @@ type ReconcileKraken struct { // and what is in the Kraken.Spec // TODO(user): Modify this Reconcile function to implement your Controller logic. The scaffolding writes // a Deployment as an example -// +kubebuilder:rbac:groups=creatures.k8s.io,resources=krakens,verbs=get;list;watch;create;update;patch;delete +// +kubebuilder:rbac:groups=creatures.testproject.org,resources=krakens,verbs=get;list;watch;create;update;patch;delete func (r *ReconcileKraken) Reconcile(request reconcile.Request) (reconcile.Result, error) { // Fetch the Kraken instance instance := &creaturesv2alpha1.Kraken{}