From e77815f156e92d0421e9a4dd8ca20e190c4d7ea9 Mon Sep 17 00:00:00 2001 From: Craig Jellick Date: Sat, 9 Dec 2017 09:19:33 -0700 Subject: [PATCH] Add native types for their listers --- apis/core/v1/zz_generated_deepcopy.go | 34 ++++ apis/core/v1/zz_generated_k8s_client.go | 16 ++ .../v1/zz_generated_namespace_controller.go | 188 ++++++++++++++++++ ...z_generated_namespace_lifecycle_adapter.go | 40 ++++ .../v1beta1/zz_generated_deepcopy.go | 40 ++++ .../v1beta1/zz_generated_k8s_client.go | 69 +++++++ ...enerated_pod_security_policy_controller.go | 188 ++++++++++++++++++ ...d_pod_security_policy_lifecycle_adapter.go | 40 ++++ ...nerated_cluster_role_binding_controller.go | 188 ++++++++++++++++++ ..._cluster_role_binding_lifecycle_adapter.go | 40 ++++ .../zz_generated_cluster_role_controller.go | 188 ++++++++++++++++++ ...enerated_cluster_role_lifecycle_adapter.go | 40 ++++ apis/rbac/v1/zz_generated_deepcopy.go | 108 ++++++++++ apis/rbac/v1/zz_generated_k8s_client.go | 101 ++++++++++ .../zz_generated_role_binding_controller.go | 188 ++++++++++++++++++ ...enerated_role_binding_lifecycle_adapter.go | 40 ++++ config/context.go | 22 +- main.go | 6 +- 18 files changed, 1532 insertions(+), 4 deletions(-) create mode 100644 apis/core/v1/zz_generated_namespace_controller.go create mode 100644 apis/core/v1/zz_generated_namespace_lifecycle_adapter.go create mode 100644 apis/extensions/v1beta1/zz_generated_deepcopy.go create mode 100644 apis/extensions/v1beta1/zz_generated_k8s_client.go create mode 100644 apis/extensions/v1beta1/zz_generated_pod_security_policy_controller.go create mode 100644 apis/extensions/v1beta1/zz_generated_pod_security_policy_lifecycle_adapter.go create mode 100644 apis/rbac/v1/zz_generated_cluster_role_binding_controller.go create mode 100644 apis/rbac/v1/zz_generated_cluster_role_binding_lifecycle_adapter.go create mode 100644 apis/rbac/v1/zz_generated_cluster_role_controller.go create mode 100644 apis/rbac/v1/zz_generated_cluster_role_lifecycle_adapter.go create mode 100644 apis/rbac/v1/zz_generated_deepcopy.go create mode 100644 apis/rbac/v1/zz_generated_k8s_client.go create mode 100644 apis/rbac/v1/zz_generated_role_binding_controller.go create mode 100644 apis/rbac/v1/zz_generated_role_binding_lifecycle_adapter.go diff --git a/apis/core/v1/zz_generated_deepcopy.go b/apis/core/v1/zz_generated_deepcopy.go index 3d8bdbb4..0c1e061a 100644 --- a/apis/core/v1/zz_generated_deepcopy.go +++ b/apis/core/v1/zz_generated_deepcopy.go @@ -39,6 +39,40 @@ func (in *ComponentStatusList) DeepCopyObject() runtime.Object { } } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *NamespaceList) DeepCopyInto(out *NamespaceList) { + *out = *in + out.TypeMeta = in.TypeMeta + out.ListMeta = in.ListMeta + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]core_v1.Namespace, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NamespaceList. +func (in *NamespaceList) DeepCopy() *NamespaceList { + if in == nil { + return nil + } + out := new(NamespaceList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *NamespaceList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } else { + return nil + } +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *NodeList) DeepCopyInto(out *NodeList) { *out = *in diff --git a/apis/core/v1/zz_generated_k8s_client.go b/apis/core/v1/zz_generated_k8s_client.go index 3ec1b138..85df5f94 100644 --- a/apis/core/v1/zz_generated_k8s_client.go +++ b/apis/core/v1/zz_generated_k8s_client.go @@ -17,6 +17,7 @@ type Interface interface { PodsGetter NodesGetter ComponentStatusesGetter + NamespacesGetter } type Client struct { @@ -27,6 +28,7 @@ type Client struct { podControllers map[string]PodController nodeControllers map[string]NodeController componentStatusControllers map[string]ComponentStatusController + namespaceControllers map[string]NamespaceController } func NewForConfig(config rest.Config) (Interface, error) { @@ -46,6 +48,7 @@ func NewForConfig(config rest.Config) (Interface, error) { podControllers: map[string]PodController{}, nodeControllers: map[string]NodeController{}, componentStatusControllers: map[string]ComponentStatusController{}, + namespaceControllers: map[string]NamespaceController{}, }, nil } @@ -99,3 +102,16 @@ func (c *Client) ComponentStatuses(namespace string) ComponentStatusInterface { objectClient: objectClient, } } + +type NamespacesGetter interface { + Namespaces(namespace string) NamespaceInterface +} + +func (c *Client) Namespaces(namespace string) NamespaceInterface { + objectClient := clientbase.NewObjectClient(namespace, c.restClient, &NamespaceResource, NamespaceGroupVersionKind, namespaceFactory{}) + return &namespaceClient{ + ns: namespace, + client: c, + objectClient: objectClient, + } +} diff --git a/apis/core/v1/zz_generated_namespace_controller.go b/apis/core/v1/zz_generated_namespace_controller.go new file mode 100644 index 00000000..6e25f5a6 --- /dev/null +++ b/apis/core/v1/zz_generated_namespace_controller.go @@ -0,0 +1,188 @@ +package v1 + +import ( + "context" + + "github.com/rancher/norman/clientbase" + "github.com/rancher/norman/controller" + "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/watch" + "k8s.io/client-go/tools/cache" +) + +var ( + NamespaceGroupVersionKind = schema.GroupVersionKind{ + Version: "v1", + Group: "", + Kind: "Namespace", + } + NamespaceResource = metav1.APIResource{ + Name: "namespaces", + SingularName: "namespace", + Namespaced: false, + Kind: NamespaceGroupVersionKind.Kind, + } +) + +type NamespaceList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []v1.Namespace +} + +type NamespaceHandlerFunc func(key string, obj *v1.Namespace) error + +type NamespaceLister interface { + List(namespace string, selector labels.Selector) (ret []*v1.Namespace, err error) + Get(namespace, name string) (*v1.Namespace, error) +} + +type NamespaceController interface { + Informer() cache.SharedIndexInformer + Lister() NamespaceLister + AddHandler(handler NamespaceHandlerFunc) + Enqueue(namespace, name string) + Sync(ctx context.Context) error + Start(ctx context.Context, threadiness int) error +} + +type NamespaceInterface interface { + ObjectClient() *clientbase.ObjectClient + Create(*v1.Namespace) (*v1.Namespace, error) + Get(name string, opts metav1.GetOptions) (*v1.Namespace, error) + Update(*v1.Namespace) (*v1.Namespace, error) + Delete(name string, options *metav1.DeleteOptions) error + List(opts metav1.ListOptions) (*NamespaceList, error) + Watch(opts metav1.ListOptions) (watch.Interface, error) + DeleteCollection(deleteOpts *metav1.DeleteOptions, listOpts metav1.ListOptions) error + Controller() NamespaceController +} + +type namespaceLister struct { + controller *namespaceController +} + +func (l *namespaceLister) List(namespace string, selector labels.Selector) (ret []*v1.Namespace, err error) { + err = cache.ListAllByNamespace(l.controller.Informer().GetIndexer(), namespace, selector, func(obj interface{}) { + ret = append(ret, obj.(*v1.Namespace)) + }) + return +} + +func (l *namespaceLister) Get(namespace, name string) (*v1.Namespace, error) { + obj, exists, err := l.controller.Informer().GetIndexer().GetByKey(namespace + "/" + name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(schema.GroupResource{ + Group: NamespaceGroupVersionKind.Group, + Resource: "namespace", + }, name) + } + return obj.(*v1.Namespace), nil +} + +type namespaceController struct { + controller.GenericController +} + +func (c *namespaceController) Lister() NamespaceLister { + return &namespaceLister{ + controller: c, + } +} + +func (c *namespaceController) AddHandler(handler NamespaceHandlerFunc) { + c.GenericController.AddHandler(func(key string) error { + obj, exists, err := c.Informer().GetStore().GetByKey(key) + if err != nil { + return err + } + if !exists { + return handler(key, nil) + } + return handler(key, obj.(*v1.Namespace)) + }) +} + +type namespaceFactory struct { +} + +func (c namespaceFactory) Object() runtime.Object { + return &v1.Namespace{} +} + +func (c namespaceFactory) List() runtime.Object { + return &NamespaceList{} +} + +func (s *namespaceClient) Controller() NamespaceController { + s.client.Lock() + defer s.client.Unlock() + + c, ok := s.client.namespaceControllers[s.ns] + if ok { + return c + } + + genericController := controller.NewGenericController(NamespaceGroupVersionKind.Kind+"Controller", + s.objectClient) + + c = &namespaceController{ + GenericController: genericController, + } + + s.client.namespaceControllers[s.ns] = c + s.client.starters = append(s.client.starters, c) + + return c +} + +type namespaceClient struct { + client *Client + ns string + objectClient *clientbase.ObjectClient + controller NamespaceController +} + +func (s *namespaceClient) ObjectClient() *clientbase.ObjectClient { + return s.objectClient +} + +func (s *namespaceClient) Create(o *v1.Namespace) (*v1.Namespace, error) { + obj, err := s.objectClient.Create(o) + return obj.(*v1.Namespace), err +} + +func (s *namespaceClient) Get(name string, opts metav1.GetOptions) (*v1.Namespace, error) { + obj, err := s.objectClient.Get(name, opts) + return obj.(*v1.Namespace), err +} + +func (s *namespaceClient) Update(o *v1.Namespace) (*v1.Namespace, error) { + obj, err := s.objectClient.Update(o.Name, o) + return obj.(*v1.Namespace), err +} + +func (s *namespaceClient) Delete(name string, options *metav1.DeleteOptions) error { + return s.objectClient.Delete(name, options) +} + +func (s *namespaceClient) List(opts metav1.ListOptions) (*NamespaceList, error) { + obj, err := s.objectClient.List(opts) + return obj.(*NamespaceList), err +} + +func (s *namespaceClient) Watch(opts metav1.ListOptions) (watch.Interface, error) { + return s.objectClient.Watch(opts) +} + +func (s *namespaceClient) DeleteCollection(deleteOpts *metav1.DeleteOptions, listOpts metav1.ListOptions) error { + return s.objectClient.DeleteCollection(deleteOpts, listOpts) +} diff --git a/apis/core/v1/zz_generated_namespace_lifecycle_adapter.go b/apis/core/v1/zz_generated_namespace_lifecycle_adapter.go new file mode 100644 index 00000000..476fdd83 --- /dev/null +++ b/apis/core/v1/zz_generated_namespace_lifecycle_adapter.go @@ -0,0 +1,40 @@ +package v1 + +import ( + "github.com/rancher/norman/lifecycle" + "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/runtime" +) + +type NamespaceLifecycle interface { + Create(obj *v1.Namespace) error + Remove(obj *v1.Namespace) error + Updated(obj *v1.Namespace) error +} + +type namespaceLifecycleAdapter struct { + lifecycle NamespaceLifecycle +} + +func (w *namespaceLifecycleAdapter) Create(obj runtime.Object) error { + return w.lifecycle.Create(obj.(*v1.Namespace)) +} + +func (w *namespaceLifecycleAdapter) Finalize(obj runtime.Object) error { + return w.lifecycle.Remove(obj.(*v1.Namespace)) +} + +func (w *namespaceLifecycleAdapter) Updated(obj runtime.Object) error { + return w.lifecycle.Updated(obj.(*v1.Namespace)) +} + +func NewNamespaceLifecycleAdapter(name string, client NamespaceInterface, l NamespaceLifecycle) NamespaceHandlerFunc { + adapter := &namespaceLifecycleAdapter{lifecycle: l} + syncFn := lifecycle.NewObjectLifecycleAdapter(name, adapter, client.ObjectClient()) + return func(key string, obj *v1.Namespace) error { + if obj == nil { + return syncFn(key, nil) + } + return syncFn(key, obj) + } +} diff --git a/apis/extensions/v1beta1/zz_generated_deepcopy.go b/apis/extensions/v1beta1/zz_generated_deepcopy.go new file mode 100644 index 00000000..10599437 --- /dev/null +++ b/apis/extensions/v1beta1/zz_generated_deepcopy.go @@ -0,0 +1,40 @@ +package v1beta1 + +import ( + extensions_v1beta1 "k8s.io/api/extensions/v1beta1" + runtime "k8s.io/apimachinery/pkg/runtime" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PodSecurityPolicyList) DeepCopyInto(out *PodSecurityPolicyList) { + *out = *in + out.TypeMeta = in.TypeMeta + out.ListMeta = in.ListMeta + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]extensions_v1beta1.PodSecurityPolicy, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PodSecurityPolicyList. +func (in *PodSecurityPolicyList) DeepCopy() *PodSecurityPolicyList { + if in == nil { + return nil + } + out := new(PodSecurityPolicyList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *PodSecurityPolicyList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } else { + return nil + } +} diff --git a/apis/extensions/v1beta1/zz_generated_k8s_client.go b/apis/extensions/v1beta1/zz_generated_k8s_client.go new file mode 100644 index 00000000..bcfb74d7 --- /dev/null +++ b/apis/extensions/v1beta1/zz_generated_k8s_client.go @@ -0,0 +1,69 @@ +package v1beta1 + +import ( + "context" + "sync" + + "github.com/rancher/norman/clientbase" + "github.com/rancher/norman/controller" + "k8s.io/client-go/dynamic" + "k8s.io/client-go/rest" +) + +type Interface interface { + RESTClient() rest.Interface + controller.Starter + + PodSecurityPoliciesGetter +} + +type Client struct { + sync.Mutex + restClient rest.Interface + starters []controller.Starter + + podSecurityPolicyControllers map[string]PodSecurityPolicyController +} + +func NewForConfig(config rest.Config) (Interface, error) { + if config.NegotiatedSerializer == nil { + configConfig := dynamic.ContentConfig() + config.NegotiatedSerializer = configConfig.NegotiatedSerializer + } + + restClient, err := rest.UnversionedRESTClientFor(&config) + if err != nil { + return nil, err + } + + return &Client{ + restClient: restClient, + + podSecurityPolicyControllers: map[string]PodSecurityPolicyController{}, + }, nil +} + +func (c *Client) RESTClient() rest.Interface { + return c.restClient +} + +func (c *Client) Sync(ctx context.Context) error { + return controller.Sync(ctx, c.starters...) +} + +func (c *Client) Start(ctx context.Context, threadiness int) error { + return controller.Start(ctx, threadiness, c.starters...) +} + +type PodSecurityPoliciesGetter interface { + PodSecurityPolicies(namespace string) PodSecurityPolicyInterface +} + +func (c *Client) PodSecurityPolicies(namespace string) PodSecurityPolicyInterface { + objectClient := clientbase.NewObjectClient(namespace, c.restClient, &PodSecurityPolicyResource, PodSecurityPolicyGroupVersionKind, podSecurityPolicyFactory{}) + return &podSecurityPolicyClient{ + ns: namespace, + client: c, + objectClient: objectClient, + } +} diff --git a/apis/extensions/v1beta1/zz_generated_pod_security_policy_controller.go b/apis/extensions/v1beta1/zz_generated_pod_security_policy_controller.go new file mode 100644 index 00000000..c40488de --- /dev/null +++ b/apis/extensions/v1beta1/zz_generated_pod_security_policy_controller.go @@ -0,0 +1,188 @@ +package v1beta1 + +import ( + "context" + + "github.com/rancher/norman/clientbase" + "github.com/rancher/norman/controller" + "k8s.io/api/extensions/v1beta1" + "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/watch" + "k8s.io/client-go/tools/cache" +) + +var ( + PodSecurityPolicyGroupVersionKind = schema.GroupVersionKind{ + Version: "v1beta1", + Group: "extensions", + Kind: "PodSecurityPolicy", + } + PodSecurityPolicyResource = metav1.APIResource{ + Name: "podsecuritypolicies", + SingularName: "podsecuritypolicy", + Namespaced: false, + Kind: PodSecurityPolicyGroupVersionKind.Kind, + } +) + +type PodSecurityPolicyList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []v1beta1.PodSecurityPolicy +} + +type PodSecurityPolicyHandlerFunc func(key string, obj *v1beta1.PodSecurityPolicy) error + +type PodSecurityPolicyLister interface { + List(namespace string, selector labels.Selector) (ret []*v1beta1.PodSecurityPolicy, err error) + Get(namespace, name string) (*v1beta1.PodSecurityPolicy, error) +} + +type PodSecurityPolicyController interface { + Informer() cache.SharedIndexInformer + Lister() PodSecurityPolicyLister + AddHandler(handler PodSecurityPolicyHandlerFunc) + Enqueue(namespace, name string) + Sync(ctx context.Context) error + Start(ctx context.Context, threadiness int) error +} + +type PodSecurityPolicyInterface interface { + ObjectClient() *clientbase.ObjectClient + Create(*v1beta1.PodSecurityPolicy) (*v1beta1.PodSecurityPolicy, error) + Get(name string, opts metav1.GetOptions) (*v1beta1.PodSecurityPolicy, error) + Update(*v1beta1.PodSecurityPolicy) (*v1beta1.PodSecurityPolicy, error) + Delete(name string, options *metav1.DeleteOptions) error + List(opts metav1.ListOptions) (*PodSecurityPolicyList, error) + Watch(opts metav1.ListOptions) (watch.Interface, error) + DeleteCollection(deleteOpts *metav1.DeleteOptions, listOpts metav1.ListOptions) error + Controller() PodSecurityPolicyController +} + +type podSecurityPolicyLister struct { + controller *podSecurityPolicyController +} + +func (l *podSecurityPolicyLister) List(namespace string, selector labels.Selector) (ret []*v1beta1.PodSecurityPolicy, err error) { + err = cache.ListAllByNamespace(l.controller.Informer().GetIndexer(), namespace, selector, func(obj interface{}) { + ret = append(ret, obj.(*v1beta1.PodSecurityPolicy)) + }) + return +} + +func (l *podSecurityPolicyLister) Get(namespace, name string) (*v1beta1.PodSecurityPolicy, error) { + obj, exists, err := l.controller.Informer().GetIndexer().GetByKey(namespace + "/" + name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(schema.GroupResource{ + Group: PodSecurityPolicyGroupVersionKind.Group, + Resource: "podSecurityPolicy", + }, name) + } + return obj.(*v1beta1.PodSecurityPolicy), nil +} + +type podSecurityPolicyController struct { + controller.GenericController +} + +func (c *podSecurityPolicyController) Lister() PodSecurityPolicyLister { + return &podSecurityPolicyLister{ + controller: c, + } +} + +func (c *podSecurityPolicyController) AddHandler(handler PodSecurityPolicyHandlerFunc) { + c.GenericController.AddHandler(func(key string) error { + obj, exists, err := c.Informer().GetStore().GetByKey(key) + if err != nil { + return err + } + if !exists { + return handler(key, nil) + } + return handler(key, obj.(*v1beta1.PodSecurityPolicy)) + }) +} + +type podSecurityPolicyFactory struct { +} + +func (c podSecurityPolicyFactory) Object() runtime.Object { + return &v1beta1.PodSecurityPolicy{} +} + +func (c podSecurityPolicyFactory) List() runtime.Object { + return &PodSecurityPolicyList{} +} + +func (s *podSecurityPolicyClient) Controller() PodSecurityPolicyController { + s.client.Lock() + defer s.client.Unlock() + + c, ok := s.client.podSecurityPolicyControllers[s.ns] + if ok { + return c + } + + genericController := controller.NewGenericController(PodSecurityPolicyGroupVersionKind.Kind+"Controller", + s.objectClient) + + c = &podSecurityPolicyController{ + GenericController: genericController, + } + + s.client.podSecurityPolicyControllers[s.ns] = c + s.client.starters = append(s.client.starters, c) + + return c +} + +type podSecurityPolicyClient struct { + client *Client + ns string + objectClient *clientbase.ObjectClient + controller PodSecurityPolicyController +} + +func (s *podSecurityPolicyClient) ObjectClient() *clientbase.ObjectClient { + return s.objectClient +} + +func (s *podSecurityPolicyClient) Create(o *v1beta1.PodSecurityPolicy) (*v1beta1.PodSecurityPolicy, error) { + obj, err := s.objectClient.Create(o) + return obj.(*v1beta1.PodSecurityPolicy), err +} + +func (s *podSecurityPolicyClient) Get(name string, opts metav1.GetOptions) (*v1beta1.PodSecurityPolicy, error) { + obj, err := s.objectClient.Get(name, opts) + return obj.(*v1beta1.PodSecurityPolicy), err +} + +func (s *podSecurityPolicyClient) Update(o *v1beta1.PodSecurityPolicy) (*v1beta1.PodSecurityPolicy, error) { + obj, err := s.objectClient.Update(o.Name, o) + return obj.(*v1beta1.PodSecurityPolicy), err +} + +func (s *podSecurityPolicyClient) Delete(name string, options *metav1.DeleteOptions) error { + return s.objectClient.Delete(name, options) +} + +func (s *podSecurityPolicyClient) List(opts metav1.ListOptions) (*PodSecurityPolicyList, error) { + obj, err := s.objectClient.List(opts) + return obj.(*PodSecurityPolicyList), err +} + +func (s *podSecurityPolicyClient) Watch(opts metav1.ListOptions) (watch.Interface, error) { + return s.objectClient.Watch(opts) +} + +func (s *podSecurityPolicyClient) DeleteCollection(deleteOpts *metav1.DeleteOptions, listOpts metav1.ListOptions) error { + return s.objectClient.DeleteCollection(deleteOpts, listOpts) +} diff --git a/apis/extensions/v1beta1/zz_generated_pod_security_policy_lifecycle_adapter.go b/apis/extensions/v1beta1/zz_generated_pod_security_policy_lifecycle_adapter.go new file mode 100644 index 00000000..362f02be --- /dev/null +++ b/apis/extensions/v1beta1/zz_generated_pod_security_policy_lifecycle_adapter.go @@ -0,0 +1,40 @@ +package v1beta1 + +import ( + "github.com/rancher/norman/lifecycle" + "k8s.io/api/extensions/v1beta1" + "k8s.io/apimachinery/pkg/runtime" +) + +type PodSecurityPolicyLifecycle interface { + Create(obj *v1beta1.PodSecurityPolicy) error + Remove(obj *v1beta1.PodSecurityPolicy) error + Updated(obj *v1beta1.PodSecurityPolicy) error +} + +type podSecurityPolicyLifecycleAdapter struct { + lifecycle PodSecurityPolicyLifecycle +} + +func (w *podSecurityPolicyLifecycleAdapter) Create(obj runtime.Object) error { + return w.lifecycle.Create(obj.(*v1beta1.PodSecurityPolicy)) +} + +func (w *podSecurityPolicyLifecycleAdapter) Finalize(obj runtime.Object) error { + return w.lifecycle.Remove(obj.(*v1beta1.PodSecurityPolicy)) +} + +func (w *podSecurityPolicyLifecycleAdapter) Updated(obj runtime.Object) error { + return w.lifecycle.Updated(obj.(*v1beta1.PodSecurityPolicy)) +} + +func NewPodSecurityPolicyLifecycleAdapter(name string, client PodSecurityPolicyInterface, l PodSecurityPolicyLifecycle) PodSecurityPolicyHandlerFunc { + adapter := &podSecurityPolicyLifecycleAdapter{lifecycle: l} + syncFn := lifecycle.NewObjectLifecycleAdapter(name, adapter, client.ObjectClient()) + return func(key string, obj *v1beta1.PodSecurityPolicy) error { + if obj == nil { + return syncFn(key, nil) + } + return syncFn(key, obj) + } +} diff --git a/apis/rbac/v1/zz_generated_cluster_role_binding_controller.go b/apis/rbac/v1/zz_generated_cluster_role_binding_controller.go new file mode 100644 index 00000000..435839c6 --- /dev/null +++ b/apis/rbac/v1/zz_generated_cluster_role_binding_controller.go @@ -0,0 +1,188 @@ +package v1 + +import ( + "context" + + "github.com/rancher/norman/clientbase" + "github.com/rancher/norman/controller" + "k8s.io/api/rbac/v1" + "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/watch" + "k8s.io/client-go/tools/cache" +) + +var ( + ClusterRoleBindingGroupVersionKind = schema.GroupVersionKind{ + Version: "v1", + Group: "rbac", + Kind: "ClusterRoleBinding", + } + ClusterRoleBindingResource = metav1.APIResource{ + Name: "clusterrolebindings", + SingularName: "clusterrolebinding", + Namespaced: false, + Kind: ClusterRoleBindingGroupVersionKind.Kind, + } +) + +type ClusterRoleBindingList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []v1.ClusterRoleBinding +} + +type ClusterRoleBindingHandlerFunc func(key string, obj *v1.ClusterRoleBinding) error + +type ClusterRoleBindingLister interface { + List(namespace string, selector labels.Selector) (ret []*v1.ClusterRoleBinding, err error) + Get(namespace, name string) (*v1.ClusterRoleBinding, error) +} + +type ClusterRoleBindingController interface { + Informer() cache.SharedIndexInformer + Lister() ClusterRoleBindingLister + AddHandler(handler ClusterRoleBindingHandlerFunc) + Enqueue(namespace, name string) + Sync(ctx context.Context) error + Start(ctx context.Context, threadiness int) error +} + +type ClusterRoleBindingInterface interface { + ObjectClient() *clientbase.ObjectClient + Create(*v1.ClusterRoleBinding) (*v1.ClusterRoleBinding, error) + Get(name string, opts metav1.GetOptions) (*v1.ClusterRoleBinding, error) + Update(*v1.ClusterRoleBinding) (*v1.ClusterRoleBinding, error) + Delete(name string, options *metav1.DeleteOptions) error + List(opts metav1.ListOptions) (*ClusterRoleBindingList, error) + Watch(opts metav1.ListOptions) (watch.Interface, error) + DeleteCollection(deleteOpts *metav1.DeleteOptions, listOpts metav1.ListOptions) error + Controller() ClusterRoleBindingController +} + +type clusterRoleBindingLister struct { + controller *clusterRoleBindingController +} + +func (l *clusterRoleBindingLister) List(namespace string, selector labels.Selector) (ret []*v1.ClusterRoleBinding, err error) { + err = cache.ListAllByNamespace(l.controller.Informer().GetIndexer(), namespace, selector, func(obj interface{}) { + ret = append(ret, obj.(*v1.ClusterRoleBinding)) + }) + return +} + +func (l *clusterRoleBindingLister) Get(namespace, name string) (*v1.ClusterRoleBinding, error) { + obj, exists, err := l.controller.Informer().GetIndexer().GetByKey(namespace + "/" + name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(schema.GroupResource{ + Group: ClusterRoleBindingGroupVersionKind.Group, + Resource: "clusterRoleBinding", + }, name) + } + return obj.(*v1.ClusterRoleBinding), nil +} + +type clusterRoleBindingController struct { + controller.GenericController +} + +func (c *clusterRoleBindingController) Lister() ClusterRoleBindingLister { + return &clusterRoleBindingLister{ + controller: c, + } +} + +func (c *clusterRoleBindingController) AddHandler(handler ClusterRoleBindingHandlerFunc) { + c.GenericController.AddHandler(func(key string) error { + obj, exists, err := c.Informer().GetStore().GetByKey(key) + if err != nil { + return err + } + if !exists { + return handler(key, nil) + } + return handler(key, obj.(*v1.ClusterRoleBinding)) + }) +} + +type clusterRoleBindingFactory struct { +} + +func (c clusterRoleBindingFactory) Object() runtime.Object { + return &v1.ClusterRoleBinding{} +} + +func (c clusterRoleBindingFactory) List() runtime.Object { + return &ClusterRoleBindingList{} +} + +func (s *clusterRoleBindingClient) Controller() ClusterRoleBindingController { + s.client.Lock() + defer s.client.Unlock() + + c, ok := s.client.clusterRoleBindingControllers[s.ns] + if ok { + return c + } + + genericController := controller.NewGenericController(ClusterRoleBindingGroupVersionKind.Kind+"Controller", + s.objectClient) + + c = &clusterRoleBindingController{ + GenericController: genericController, + } + + s.client.clusterRoleBindingControllers[s.ns] = c + s.client.starters = append(s.client.starters, c) + + return c +} + +type clusterRoleBindingClient struct { + client *Client + ns string + objectClient *clientbase.ObjectClient + controller ClusterRoleBindingController +} + +func (s *clusterRoleBindingClient) ObjectClient() *clientbase.ObjectClient { + return s.objectClient +} + +func (s *clusterRoleBindingClient) Create(o *v1.ClusterRoleBinding) (*v1.ClusterRoleBinding, error) { + obj, err := s.objectClient.Create(o) + return obj.(*v1.ClusterRoleBinding), err +} + +func (s *clusterRoleBindingClient) Get(name string, opts metav1.GetOptions) (*v1.ClusterRoleBinding, error) { + obj, err := s.objectClient.Get(name, opts) + return obj.(*v1.ClusterRoleBinding), err +} + +func (s *clusterRoleBindingClient) Update(o *v1.ClusterRoleBinding) (*v1.ClusterRoleBinding, error) { + obj, err := s.objectClient.Update(o.Name, o) + return obj.(*v1.ClusterRoleBinding), err +} + +func (s *clusterRoleBindingClient) Delete(name string, options *metav1.DeleteOptions) error { + return s.objectClient.Delete(name, options) +} + +func (s *clusterRoleBindingClient) List(opts metav1.ListOptions) (*ClusterRoleBindingList, error) { + obj, err := s.objectClient.List(opts) + return obj.(*ClusterRoleBindingList), err +} + +func (s *clusterRoleBindingClient) Watch(opts metav1.ListOptions) (watch.Interface, error) { + return s.objectClient.Watch(opts) +} + +func (s *clusterRoleBindingClient) DeleteCollection(deleteOpts *metav1.DeleteOptions, listOpts metav1.ListOptions) error { + return s.objectClient.DeleteCollection(deleteOpts, listOpts) +} diff --git a/apis/rbac/v1/zz_generated_cluster_role_binding_lifecycle_adapter.go b/apis/rbac/v1/zz_generated_cluster_role_binding_lifecycle_adapter.go new file mode 100644 index 00000000..f7007fc3 --- /dev/null +++ b/apis/rbac/v1/zz_generated_cluster_role_binding_lifecycle_adapter.go @@ -0,0 +1,40 @@ +package v1 + +import ( + "github.com/rancher/norman/lifecycle" + "k8s.io/api/rbac/v1" + "k8s.io/apimachinery/pkg/runtime" +) + +type ClusterRoleBindingLifecycle interface { + Create(obj *v1.ClusterRoleBinding) error + Remove(obj *v1.ClusterRoleBinding) error + Updated(obj *v1.ClusterRoleBinding) error +} + +type clusterRoleBindingLifecycleAdapter struct { + lifecycle ClusterRoleBindingLifecycle +} + +func (w *clusterRoleBindingLifecycleAdapter) Create(obj runtime.Object) error { + return w.lifecycle.Create(obj.(*v1.ClusterRoleBinding)) +} + +func (w *clusterRoleBindingLifecycleAdapter) Finalize(obj runtime.Object) error { + return w.lifecycle.Remove(obj.(*v1.ClusterRoleBinding)) +} + +func (w *clusterRoleBindingLifecycleAdapter) Updated(obj runtime.Object) error { + return w.lifecycle.Updated(obj.(*v1.ClusterRoleBinding)) +} + +func NewClusterRoleBindingLifecycleAdapter(name string, client ClusterRoleBindingInterface, l ClusterRoleBindingLifecycle) ClusterRoleBindingHandlerFunc { + adapter := &clusterRoleBindingLifecycleAdapter{lifecycle: l} + syncFn := lifecycle.NewObjectLifecycleAdapter(name, adapter, client.ObjectClient()) + return func(key string, obj *v1.ClusterRoleBinding) error { + if obj == nil { + return syncFn(key, nil) + } + return syncFn(key, obj) + } +} diff --git a/apis/rbac/v1/zz_generated_cluster_role_controller.go b/apis/rbac/v1/zz_generated_cluster_role_controller.go new file mode 100644 index 00000000..865e7071 --- /dev/null +++ b/apis/rbac/v1/zz_generated_cluster_role_controller.go @@ -0,0 +1,188 @@ +package v1 + +import ( + "context" + + "github.com/rancher/norman/clientbase" + "github.com/rancher/norman/controller" + "k8s.io/api/rbac/v1" + "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/watch" + "k8s.io/client-go/tools/cache" +) + +var ( + ClusterRoleGroupVersionKind = schema.GroupVersionKind{ + Version: "v1", + Group: "rbac", + Kind: "ClusterRole", + } + ClusterRoleResource = metav1.APIResource{ + Name: "clusterroles", + SingularName: "clusterrole", + Namespaced: false, + Kind: ClusterRoleGroupVersionKind.Kind, + } +) + +type ClusterRoleList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []v1.ClusterRole +} + +type ClusterRoleHandlerFunc func(key string, obj *v1.ClusterRole) error + +type ClusterRoleLister interface { + List(namespace string, selector labels.Selector) (ret []*v1.ClusterRole, err error) + Get(namespace, name string) (*v1.ClusterRole, error) +} + +type ClusterRoleController interface { + Informer() cache.SharedIndexInformer + Lister() ClusterRoleLister + AddHandler(handler ClusterRoleHandlerFunc) + Enqueue(namespace, name string) + Sync(ctx context.Context) error + Start(ctx context.Context, threadiness int) error +} + +type ClusterRoleInterface interface { + ObjectClient() *clientbase.ObjectClient + Create(*v1.ClusterRole) (*v1.ClusterRole, error) + Get(name string, opts metav1.GetOptions) (*v1.ClusterRole, error) + Update(*v1.ClusterRole) (*v1.ClusterRole, error) + Delete(name string, options *metav1.DeleteOptions) error + List(opts metav1.ListOptions) (*ClusterRoleList, error) + Watch(opts metav1.ListOptions) (watch.Interface, error) + DeleteCollection(deleteOpts *metav1.DeleteOptions, listOpts metav1.ListOptions) error + Controller() ClusterRoleController +} + +type clusterRoleLister struct { + controller *clusterRoleController +} + +func (l *clusterRoleLister) List(namespace string, selector labels.Selector) (ret []*v1.ClusterRole, err error) { + err = cache.ListAllByNamespace(l.controller.Informer().GetIndexer(), namespace, selector, func(obj interface{}) { + ret = append(ret, obj.(*v1.ClusterRole)) + }) + return +} + +func (l *clusterRoleLister) Get(namespace, name string) (*v1.ClusterRole, error) { + obj, exists, err := l.controller.Informer().GetIndexer().GetByKey(namespace + "/" + name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(schema.GroupResource{ + Group: ClusterRoleGroupVersionKind.Group, + Resource: "clusterRole", + }, name) + } + return obj.(*v1.ClusterRole), nil +} + +type clusterRoleController struct { + controller.GenericController +} + +func (c *clusterRoleController) Lister() ClusterRoleLister { + return &clusterRoleLister{ + controller: c, + } +} + +func (c *clusterRoleController) AddHandler(handler ClusterRoleHandlerFunc) { + c.GenericController.AddHandler(func(key string) error { + obj, exists, err := c.Informer().GetStore().GetByKey(key) + if err != nil { + return err + } + if !exists { + return handler(key, nil) + } + return handler(key, obj.(*v1.ClusterRole)) + }) +} + +type clusterRoleFactory struct { +} + +func (c clusterRoleFactory) Object() runtime.Object { + return &v1.ClusterRole{} +} + +func (c clusterRoleFactory) List() runtime.Object { + return &ClusterRoleList{} +} + +func (s *clusterRoleClient) Controller() ClusterRoleController { + s.client.Lock() + defer s.client.Unlock() + + c, ok := s.client.clusterRoleControllers[s.ns] + if ok { + return c + } + + genericController := controller.NewGenericController(ClusterRoleGroupVersionKind.Kind+"Controller", + s.objectClient) + + c = &clusterRoleController{ + GenericController: genericController, + } + + s.client.clusterRoleControllers[s.ns] = c + s.client.starters = append(s.client.starters, c) + + return c +} + +type clusterRoleClient struct { + client *Client + ns string + objectClient *clientbase.ObjectClient + controller ClusterRoleController +} + +func (s *clusterRoleClient) ObjectClient() *clientbase.ObjectClient { + return s.objectClient +} + +func (s *clusterRoleClient) Create(o *v1.ClusterRole) (*v1.ClusterRole, error) { + obj, err := s.objectClient.Create(o) + return obj.(*v1.ClusterRole), err +} + +func (s *clusterRoleClient) Get(name string, opts metav1.GetOptions) (*v1.ClusterRole, error) { + obj, err := s.objectClient.Get(name, opts) + return obj.(*v1.ClusterRole), err +} + +func (s *clusterRoleClient) Update(o *v1.ClusterRole) (*v1.ClusterRole, error) { + obj, err := s.objectClient.Update(o.Name, o) + return obj.(*v1.ClusterRole), err +} + +func (s *clusterRoleClient) Delete(name string, options *metav1.DeleteOptions) error { + return s.objectClient.Delete(name, options) +} + +func (s *clusterRoleClient) List(opts metav1.ListOptions) (*ClusterRoleList, error) { + obj, err := s.objectClient.List(opts) + return obj.(*ClusterRoleList), err +} + +func (s *clusterRoleClient) Watch(opts metav1.ListOptions) (watch.Interface, error) { + return s.objectClient.Watch(opts) +} + +func (s *clusterRoleClient) DeleteCollection(deleteOpts *metav1.DeleteOptions, listOpts metav1.ListOptions) error { + return s.objectClient.DeleteCollection(deleteOpts, listOpts) +} diff --git a/apis/rbac/v1/zz_generated_cluster_role_lifecycle_adapter.go b/apis/rbac/v1/zz_generated_cluster_role_lifecycle_adapter.go new file mode 100644 index 00000000..fc892f00 --- /dev/null +++ b/apis/rbac/v1/zz_generated_cluster_role_lifecycle_adapter.go @@ -0,0 +1,40 @@ +package v1 + +import ( + "github.com/rancher/norman/lifecycle" + "k8s.io/api/rbac/v1" + "k8s.io/apimachinery/pkg/runtime" +) + +type ClusterRoleLifecycle interface { + Create(obj *v1.ClusterRole) error + Remove(obj *v1.ClusterRole) error + Updated(obj *v1.ClusterRole) error +} + +type clusterRoleLifecycleAdapter struct { + lifecycle ClusterRoleLifecycle +} + +func (w *clusterRoleLifecycleAdapter) Create(obj runtime.Object) error { + return w.lifecycle.Create(obj.(*v1.ClusterRole)) +} + +func (w *clusterRoleLifecycleAdapter) Finalize(obj runtime.Object) error { + return w.lifecycle.Remove(obj.(*v1.ClusterRole)) +} + +func (w *clusterRoleLifecycleAdapter) Updated(obj runtime.Object) error { + return w.lifecycle.Updated(obj.(*v1.ClusterRole)) +} + +func NewClusterRoleLifecycleAdapter(name string, client ClusterRoleInterface, l ClusterRoleLifecycle) ClusterRoleHandlerFunc { + adapter := &clusterRoleLifecycleAdapter{lifecycle: l} + syncFn := lifecycle.NewObjectLifecycleAdapter(name, adapter, client.ObjectClient()) + return func(key string, obj *v1.ClusterRole) error { + if obj == nil { + return syncFn(key, nil) + } + return syncFn(key, obj) + } +} diff --git a/apis/rbac/v1/zz_generated_deepcopy.go b/apis/rbac/v1/zz_generated_deepcopy.go new file mode 100644 index 00000000..88dcb587 --- /dev/null +++ b/apis/rbac/v1/zz_generated_deepcopy.go @@ -0,0 +1,108 @@ +package v1 + +import ( + rbac_v1 "k8s.io/api/rbac/v1" + runtime "k8s.io/apimachinery/pkg/runtime" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ClusterRoleBindingList) DeepCopyInto(out *ClusterRoleBindingList) { + *out = *in + out.TypeMeta = in.TypeMeta + out.ListMeta = in.ListMeta + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]rbac_v1.ClusterRoleBinding, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterRoleBindingList. +func (in *ClusterRoleBindingList) DeepCopy() *ClusterRoleBindingList { + if in == nil { + return nil + } + out := new(ClusterRoleBindingList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ClusterRoleBindingList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } else { + return nil + } +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ClusterRoleList) DeepCopyInto(out *ClusterRoleList) { + *out = *in + out.TypeMeta = in.TypeMeta + out.ListMeta = in.ListMeta + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]rbac_v1.ClusterRole, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterRoleList. +func (in *ClusterRoleList) DeepCopy() *ClusterRoleList { + if in == nil { + return nil + } + out := new(ClusterRoleList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ClusterRoleList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } else { + return nil + } +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *RoleBindingList) DeepCopyInto(out *RoleBindingList) { + *out = *in + out.TypeMeta = in.TypeMeta + out.ListMeta = in.ListMeta + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]rbac_v1.RoleBinding, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RoleBindingList. +func (in *RoleBindingList) DeepCopy() *RoleBindingList { + if in == nil { + return nil + } + out := new(RoleBindingList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *RoleBindingList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } else { + return nil + } +} diff --git a/apis/rbac/v1/zz_generated_k8s_client.go b/apis/rbac/v1/zz_generated_k8s_client.go new file mode 100644 index 00000000..e77e508b --- /dev/null +++ b/apis/rbac/v1/zz_generated_k8s_client.go @@ -0,0 +1,101 @@ +package v1 + +import ( + "context" + "sync" + + "github.com/rancher/norman/clientbase" + "github.com/rancher/norman/controller" + "k8s.io/client-go/dynamic" + "k8s.io/client-go/rest" +) + +type Interface interface { + RESTClient() rest.Interface + controller.Starter + + RoleBindingsGetter + ClusterRoleBindingsGetter + ClusterRolesGetter +} + +type Client struct { + sync.Mutex + restClient rest.Interface + starters []controller.Starter + + roleBindingControllers map[string]RoleBindingController + clusterRoleBindingControllers map[string]ClusterRoleBindingController + clusterRoleControllers map[string]ClusterRoleController +} + +func NewForConfig(config rest.Config) (Interface, error) { + if config.NegotiatedSerializer == nil { + configConfig := dynamic.ContentConfig() + config.NegotiatedSerializer = configConfig.NegotiatedSerializer + } + + restClient, err := rest.UnversionedRESTClientFor(&config) + if err != nil { + return nil, err + } + + return &Client{ + restClient: restClient, + + roleBindingControllers: map[string]RoleBindingController{}, + clusterRoleBindingControllers: map[string]ClusterRoleBindingController{}, + clusterRoleControllers: map[string]ClusterRoleController{}, + }, nil +} + +func (c *Client) RESTClient() rest.Interface { + return c.restClient +} + +func (c *Client) Sync(ctx context.Context) error { + return controller.Sync(ctx, c.starters...) +} + +func (c *Client) Start(ctx context.Context, threadiness int) error { + return controller.Start(ctx, threadiness, c.starters...) +} + +type RoleBindingsGetter interface { + RoleBindings(namespace string) RoleBindingInterface +} + +func (c *Client) RoleBindings(namespace string) RoleBindingInterface { + objectClient := clientbase.NewObjectClient(namespace, c.restClient, &RoleBindingResource, RoleBindingGroupVersionKind, roleBindingFactory{}) + return &roleBindingClient{ + ns: namespace, + client: c, + objectClient: objectClient, + } +} + +type ClusterRoleBindingsGetter interface { + ClusterRoleBindings(namespace string) ClusterRoleBindingInterface +} + +func (c *Client) ClusterRoleBindings(namespace string) ClusterRoleBindingInterface { + objectClient := clientbase.NewObjectClient(namespace, c.restClient, &ClusterRoleBindingResource, ClusterRoleBindingGroupVersionKind, clusterRoleBindingFactory{}) + return &clusterRoleBindingClient{ + ns: namespace, + client: c, + objectClient: objectClient, + } +} + +type ClusterRolesGetter interface { + ClusterRoles(namespace string) ClusterRoleInterface +} + +func (c *Client) ClusterRoles(namespace string) ClusterRoleInterface { + objectClient := clientbase.NewObjectClient(namespace, c.restClient, &ClusterRoleResource, ClusterRoleGroupVersionKind, clusterRoleFactory{}) + return &clusterRoleClient{ + ns: namespace, + client: c, + objectClient: objectClient, + } +} diff --git a/apis/rbac/v1/zz_generated_role_binding_controller.go b/apis/rbac/v1/zz_generated_role_binding_controller.go new file mode 100644 index 00000000..51723c6a --- /dev/null +++ b/apis/rbac/v1/zz_generated_role_binding_controller.go @@ -0,0 +1,188 @@ +package v1 + +import ( + "context" + + "github.com/rancher/norman/clientbase" + "github.com/rancher/norman/controller" + "k8s.io/api/rbac/v1" + "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/watch" + "k8s.io/client-go/tools/cache" +) + +var ( + RoleBindingGroupVersionKind = schema.GroupVersionKind{ + Version: "v1", + Group: "rbac", + Kind: "RoleBinding", + } + RoleBindingResource = metav1.APIResource{ + Name: "rolebindings", + SingularName: "rolebinding", + Namespaced: false, + Kind: RoleBindingGroupVersionKind.Kind, + } +) + +type RoleBindingList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []v1.RoleBinding +} + +type RoleBindingHandlerFunc func(key string, obj *v1.RoleBinding) error + +type RoleBindingLister interface { + List(namespace string, selector labels.Selector) (ret []*v1.RoleBinding, err error) + Get(namespace, name string) (*v1.RoleBinding, error) +} + +type RoleBindingController interface { + Informer() cache.SharedIndexInformer + Lister() RoleBindingLister + AddHandler(handler RoleBindingHandlerFunc) + Enqueue(namespace, name string) + Sync(ctx context.Context) error + Start(ctx context.Context, threadiness int) error +} + +type RoleBindingInterface interface { + ObjectClient() *clientbase.ObjectClient + Create(*v1.RoleBinding) (*v1.RoleBinding, error) + Get(name string, opts metav1.GetOptions) (*v1.RoleBinding, error) + Update(*v1.RoleBinding) (*v1.RoleBinding, error) + Delete(name string, options *metav1.DeleteOptions) error + List(opts metav1.ListOptions) (*RoleBindingList, error) + Watch(opts metav1.ListOptions) (watch.Interface, error) + DeleteCollection(deleteOpts *metav1.DeleteOptions, listOpts metav1.ListOptions) error + Controller() RoleBindingController +} + +type roleBindingLister struct { + controller *roleBindingController +} + +func (l *roleBindingLister) List(namespace string, selector labels.Selector) (ret []*v1.RoleBinding, err error) { + err = cache.ListAllByNamespace(l.controller.Informer().GetIndexer(), namespace, selector, func(obj interface{}) { + ret = append(ret, obj.(*v1.RoleBinding)) + }) + return +} + +func (l *roleBindingLister) Get(namespace, name string) (*v1.RoleBinding, error) { + obj, exists, err := l.controller.Informer().GetIndexer().GetByKey(namespace + "/" + name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(schema.GroupResource{ + Group: RoleBindingGroupVersionKind.Group, + Resource: "roleBinding", + }, name) + } + return obj.(*v1.RoleBinding), nil +} + +type roleBindingController struct { + controller.GenericController +} + +func (c *roleBindingController) Lister() RoleBindingLister { + return &roleBindingLister{ + controller: c, + } +} + +func (c *roleBindingController) AddHandler(handler RoleBindingHandlerFunc) { + c.GenericController.AddHandler(func(key string) error { + obj, exists, err := c.Informer().GetStore().GetByKey(key) + if err != nil { + return err + } + if !exists { + return handler(key, nil) + } + return handler(key, obj.(*v1.RoleBinding)) + }) +} + +type roleBindingFactory struct { +} + +func (c roleBindingFactory) Object() runtime.Object { + return &v1.RoleBinding{} +} + +func (c roleBindingFactory) List() runtime.Object { + return &RoleBindingList{} +} + +func (s *roleBindingClient) Controller() RoleBindingController { + s.client.Lock() + defer s.client.Unlock() + + c, ok := s.client.roleBindingControllers[s.ns] + if ok { + return c + } + + genericController := controller.NewGenericController(RoleBindingGroupVersionKind.Kind+"Controller", + s.objectClient) + + c = &roleBindingController{ + GenericController: genericController, + } + + s.client.roleBindingControllers[s.ns] = c + s.client.starters = append(s.client.starters, c) + + return c +} + +type roleBindingClient struct { + client *Client + ns string + objectClient *clientbase.ObjectClient + controller RoleBindingController +} + +func (s *roleBindingClient) ObjectClient() *clientbase.ObjectClient { + return s.objectClient +} + +func (s *roleBindingClient) Create(o *v1.RoleBinding) (*v1.RoleBinding, error) { + obj, err := s.objectClient.Create(o) + return obj.(*v1.RoleBinding), err +} + +func (s *roleBindingClient) Get(name string, opts metav1.GetOptions) (*v1.RoleBinding, error) { + obj, err := s.objectClient.Get(name, opts) + return obj.(*v1.RoleBinding), err +} + +func (s *roleBindingClient) Update(o *v1.RoleBinding) (*v1.RoleBinding, error) { + obj, err := s.objectClient.Update(o.Name, o) + return obj.(*v1.RoleBinding), err +} + +func (s *roleBindingClient) Delete(name string, options *metav1.DeleteOptions) error { + return s.objectClient.Delete(name, options) +} + +func (s *roleBindingClient) List(opts metav1.ListOptions) (*RoleBindingList, error) { + obj, err := s.objectClient.List(opts) + return obj.(*RoleBindingList), err +} + +func (s *roleBindingClient) Watch(opts metav1.ListOptions) (watch.Interface, error) { + return s.objectClient.Watch(opts) +} + +func (s *roleBindingClient) DeleteCollection(deleteOpts *metav1.DeleteOptions, listOpts metav1.ListOptions) error { + return s.objectClient.DeleteCollection(deleteOpts, listOpts) +} diff --git a/apis/rbac/v1/zz_generated_role_binding_lifecycle_adapter.go b/apis/rbac/v1/zz_generated_role_binding_lifecycle_adapter.go new file mode 100644 index 00000000..d32dca3b --- /dev/null +++ b/apis/rbac/v1/zz_generated_role_binding_lifecycle_adapter.go @@ -0,0 +1,40 @@ +package v1 + +import ( + "github.com/rancher/norman/lifecycle" + "k8s.io/api/rbac/v1" + "k8s.io/apimachinery/pkg/runtime" +) + +type RoleBindingLifecycle interface { + Create(obj *v1.RoleBinding) error + Remove(obj *v1.RoleBinding) error + Updated(obj *v1.RoleBinding) error +} + +type roleBindingLifecycleAdapter struct { + lifecycle RoleBindingLifecycle +} + +func (w *roleBindingLifecycleAdapter) Create(obj runtime.Object) error { + return w.lifecycle.Create(obj.(*v1.RoleBinding)) +} + +func (w *roleBindingLifecycleAdapter) Finalize(obj runtime.Object) error { + return w.lifecycle.Remove(obj.(*v1.RoleBinding)) +} + +func (w *roleBindingLifecycleAdapter) Updated(obj runtime.Object) error { + return w.lifecycle.Updated(obj.(*v1.RoleBinding)) +} + +func NewRoleBindingLifecycleAdapter(name string, client RoleBindingInterface, l RoleBindingLifecycle) RoleBindingHandlerFunc { + adapter := &roleBindingLifecycleAdapter{lifecycle: l} + syncFn := lifecycle.NewObjectLifecycleAdapter(name, adapter, client.ObjectClient()) + return func(key string, obj *v1.RoleBinding) error { + if obj == nil { + return syncFn(key, nil) + } + return syncFn(key, obj) + } +} diff --git a/config/context.go b/config/context.go index 6ed54c33..eaf16a4b 100644 --- a/config/context.go +++ b/config/context.go @@ -7,8 +7,10 @@ import ( "github.com/rancher/norman/signal" appsv1beta2 "github.com/rancher/types/apis/apps/v1beta2" corev1 "github.com/rancher/types/apis/core/v1" + extv1beta1 "github.com/rancher/types/apis/extensions/v1beta1" managementv3 "github.com/rancher/types/apis/management.cattle.io/v3" projectv3 "github.com/rancher/types/apis/project.cattle.io/v3" + rbacv1 "github.com/rancher/types/apis/rbac/v1" "github.com/sirupsen/logrus" "k8s.io/client-go/dynamic" "k8s.io/client-go/kubernetes" @@ -35,9 +37,11 @@ type ClusterContext struct { UnversionedClient rest.Interface K8sClient kubernetes.Interface - Apps appsv1beta2.Interface - Project projectv3.Interface - Core corev1.Interface + Apps appsv1beta2.Interface + Project projectv3.Interface + Core corev1.Interface + RBAC rbacv1.Interface + Extensions extv1beta1.Interface } func (w *ClusterContext) controllers() []controller.Starter { @@ -45,6 +49,8 @@ func (w *ClusterContext) controllers() []controller.Starter { w.Apps, w.Project, w.Core, + w.RBAC, + w.Extensions, } } @@ -118,6 +124,16 @@ func NewClusterContext(clusterConfig, config rest.Config, clusterName string) (* return nil, err } + context.RBAC, err = rbacv1.NewForConfig(config) + if err != nil { + return nil, err + } + + context.Extensions, err = extv1beta1.NewForConfig(config) + if err != nil { + return nil, err + } + dynamicConfig := config if dynamicConfig.NegotiatedSerializer == nil { configConfig := dynamic.ContentConfig() diff --git a/main.go b/main.go index 82523b59..2923de3d 100644 --- a/main.go +++ b/main.go @@ -10,6 +10,8 @@ import ( "github.com/rancher/types/generator" "k8s.io/api/apps/v1beta2" "k8s.io/api/core/v1" + extv1beta1 "k8s.io/api/extensions/v1beta1" + rbacv1 "k8s.io/api/rbac/v1" ) func main() { @@ -17,6 +19,8 @@ func main() { generator.Generate(clusterSchema.Schemas) generator.Generate(projectSchema.Schemas) // Group by API group - generator.GenerateNativeTypes(v1.Pod{}, v1.Node{}, v1.ComponentStatus{}) + generator.GenerateNativeTypes(v1.Pod{}, v1.Node{}, v1.ComponentStatus{}, v1.Namespace{}) generator.GenerateNativeTypes(v1beta2.Deployment{}) + generator.GenerateNativeTypes(rbacv1.RoleBinding{}, rbacv1.ClusterRoleBinding{}, rbacv1.ClusterRole{}) + generator.GenerateNativeTypes(extv1beta1.PodSecurityPolicy{}) }