1
0
mirror of https://github.com/rancher/types.git synced 2025-07-12 04:47:59 +00:00

add serviceaccount generated type

This commit is contained in:
Aiwantaozi 2018-02-09 05:19:44 +08:00 committed by Darren Shepherd
parent 0de22e2129
commit 509188b263
5 changed files with 360 additions and 0 deletions

View File

@ -50,6 +50,10 @@ func RegisterDeepCopies(scheme *runtime.Scheme) error {
in.(*SecretList).DeepCopyInto(out.(*SecretList))
return nil
}, InType: reflect.TypeOf(&SecretList{})},
conversion.GeneratedDeepCopyFunc{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*ServiceAccountList).DeepCopyInto(out.(*ServiceAccountList))
return nil
}, InType: reflect.TypeOf(&ServiceAccountList{})},
conversion.GeneratedDeepCopyFunc{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*ServiceList).DeepCopyInto(out.(*ServiceList))
return nil
@ -329,6 +333,40 @@ func (in *SecretList) DeepCopyObject() runtime.Object {
}
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ServiceAccountList) DeepCopyInto(out *ServiceAccountList) {
*out = *in
out.TypeMeta = in.TypeMeta
out.ListMeta = in.ListMeta
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]core_v1.ServiceAccount, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServiceAccountList.
func (in *ServiceAccountList) DeepCopy() *ServiceAccountList {
if in == nil {
return nil
}
out := new(ServiceAccountList)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *ServiceAccountList) 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 *ServiceList) DeepCopyInto(out *ServiceList) {
*out = *in

View File

@ -23,6 +23,7 @@ type Interface interface {
ServicesGetter
SecretsGetter
ConfigMapsGetter
ServiceAccountsGetter
}
type Client struct {
@ -39,6 +40,7 @@ type Client struct {
serviceControllers map[string]ServiceController
secretControllers map[string]SecretController
configMapControllers map[string]ConfigMapController
serviceAccountControllers map[string]ServiceAccountController
}
func NewForConfig(config rest.Config) (Interface, error) {
@ -64,6 +66,7 @@ func NewForConfig(config rest.Config) (Interface, error) {
serviceControllers: map[string]ServiceController{},
secretControllers: map[string]SecretController{},
configMapControllers: map[string]ConfigMapController{},
serviceAccountControllers: map[string]ServiceAccountController{},
}, nil
}
@ -195,3 +198,16 @@ func (c *Client) ConfigMaps(namespace string) ConfigMapInterface {
objectClient: objectClient,
}
}
type ServiceAccountsGetter interface {
ServiceAccounts(namespace string) ServiceAccountInterface
}
func (c *Client) ServiceAccounts(namespace string) ServiceAccountInterface {
objectClient := clientbase.NewObjectClient(namespace, c.restClient, &ServiceAccountResource, ServiceAccountGroupVersionKind, serviceAccountFactory{})
return &serviceAccountClient{
ns: namespace,
client: c,
objectClient: objectClient,
}
}

View File

@ -42,6 +42,7 @@ func addKnownTypes(scheme *runtime.Scheme) error {
&ServiceList{},
&SecretList{},
&ConfigMapList{},
&ServiceAccountList{},
)
return nil
}

View File

@ -0,0 +1,253 @@
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 (
ServiceAccountGroupVersionKind = schema.GroupVersionKind{
Version: Version,
Group: GroupName,
Kind: "ServiceAccount",
}
ServiceAccountResource = metav1.APIResource{
Name: "serviceaccounts",
SingularName: "serviceaccount",
Namespaced: true,
Kind: ServiceAccountGroupVersionKind.Kind,
}
)
type ServiceAccountList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []v1.ServiceAccount
}
type ServiceAccountHandlerFunc func(key string, obj *v1.ServiceAccount) error
type ServiceAccountLister interface {
List(namespace string, selector labels.Selector) (ret []*v1.ServiceAccount, err error)
Get(namespace, name string) (*v1.ServiceAccount, error)
}
type ServiceAccountController interface {
Informer() cache.SharedIndexInformer
Lister() ServiceAccountLister
AddHandler(name string, handler ServiceAccountHandlerFunc)
AddClusterScopedHandler(name, clusterName string, handler ServiceAccountHandlerFunc)
Enqueue(namespace, name string)
Sync(ctx context.Context) error
Start(ctx context.Context, threadiness int) error
}
type ServiceAccountInterface interface {
ObjectClient() *clientbase.ObjectClient
Create(*v1.ServiceAccount) (*v1.ServiceAccount, error)
GetNamespaced(namespace, name string, opts metav1.GetOptions) (*v1.ServiceAccount, error)
Get(name string, opts metav1.GetOptions) (*v1.ServiceAccount, error)
Update(*v1.ServiceAccount) (*v1.ServiceAccount, error)
Delete(name string, options *metav1.DeleteOptions) error
DeleteNamespaced(namespace, name string, options *metav1.DeleteOptions) error
List(opts metav1.ListOptions) (*ServiceAccountList, error)
Watch(opts metav1.ListOptions) (watch.Interface, error)
DeleteCollection(deleteOpts *metav1.DeleteOptions, listOpts metav1.ListOptions) error
Controller() ServiceAccountController
AddHandler(name string, sync ServiceAccountHandlerFunc)
AddLifecycle(name string, lifecycle ServiceAccountLifecycle)
AddClusterScopedHandler(name, clusterName string, sync ServiceAccountHandlerFunc)
AddClusterScopedLifecycle(name, clusterName string, lifecycle ServiceAccountLifecycle)
}
type serviceAccountLister struct {
controller *serviceAccountController
}
func (l *serviceAccountLister) List(namespace string, selector labels.Selector) (ret []*v1.ServiceAccount, err error) {
err = cache.ListAllByNamespace(l.controller.Informer().GetIndexer(), namespace, selector, func(obj interface{}) {
ret = append(ret, obj.(*v1.ServiceAccount))
})
return
}
func (l *serviceAccountLister) Get(namespace, name string) (*v1.ServiceAccount, error) {
var key string
if namespace != "" {
key = namespace + "/" + name
} else {
key = name
}
obj, exists, err := l.controller.Informer().GetIndexer().GetByKey(key)
if err != nil {
return nil, err
}
if !exists {
return nil, errors.NewNotFound(schema.GroupResource{
Group: ServiceAccountGroupVersionKind.Group,
Resource: "serviceAccount",
}, name)
}
return obj.(*v1.ServiceAccount), nil
}
type serviceAccountController struct {
controller.GenericController
}
func (c *serviceAccountController) Lister() ServiceAccountLister {
return &serviceAccountLister{
controller: c,
}
}
func (c *serviceAccountController) AddHandler(name string, handler ServiceAccountHandlerFunc) {
c.GenericController.AddHandler(name, 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.ServiceAccount))
})
}
func (c *serviceAccountController) AddClusterScopedHandler(name, cluster string, handler ServiceAccountHandlerFunc) {
c.GenericController.AddHandler(name, func(key string) error {
obj, exists, err := c.Informer().GetStore().GetByKey(key)
if err != nil {
return err
}
if !exists {
return handler(key, nil)
}
if !controller.ObjectInCluster(cluster, obj) {
return nil
}
return handler(key, obj.(*v1.ServiceAccount))
})
}
type serviceAccountFactory struct {
}
func (c serviceAccountFactory) Object() runtime.Object {
return &v1.ServiceAccount{}
}
func (c serviceAccountFactory) List() runtime.Object {
return &ServiceAccountList{}
}
func (s *serviceAccountClient) Controller() ServiceAccountController {
s.client.Lock()
defer s.client.Unlock()
c, ok := s.client.serviceAccountControllers[s.ns]
if ok {
return c
}
genericController := controller.NewGenericController(ServiceAccountGroupVersionKind.Kind+"Controller",
s.objectClient)
c = &serviceAccountController{
GenericController: genericController,
}
s.client.serviceAccountControllers[s.ns] = c
s.client.starters = append(s.client.starters, c)
return c
}
type serviceAccountClient struct {
client *Client
ns string
objectClient *clientbase.ObjectClient
controller ServiceAccountController
}
func (s *serviceAccountClient) ObjectClient() *clientbase.ObjectClient {
return s.objectClient
}
func (s *serviceAccountClient) Create(o *v1.ServiceAccount) (*v1.ServiceAccount, error) {
obj, err := s.objectClient.Create(o)
return obj.(*v1.ServiceAccount), err
}
func (s *serviceAccountClient) Get(name string, opts metav1.GetOptions) (*v1.ServiceAccount, error) {
obj, err := s.objectClient.Get(name, opts)
return obj.(*v1.ServiceAccount), err
}
func (s *serviceAccountClient) GetNamespaced(namespace, name string, opts metav1.GetOptions) (*v1.ServiceAccount, error) {
obj, err := s.objectClient.GetNamespaced(namespace, name, opts)
return obj.(*v1.ServiceAccount), err
}
func (s *serviceAccountClient) Update(o *v1.ServiceAccount) (*v1.ServiceAccount, error) {
obj, err := s.objectClient.Update(o.Name, o)
return obj.(*v1.ServiceAccount), err
}
func (s *serviceAccountClient) Delete(name string, options *metav1.DeleteOptions) error {
return s.objectClient.Delete(name, options)
}
func (s *serviceAccountClient) DeleteNamespaced(namespace, name string, options *metav1.DeleteOptions) error {
return s.objectClient.DeleteNamespaced(namespace, name, options)
}
func (s *serviceAccountClient) List(opts metav1.ListOptions) (*ServiceAccountList, error) {
obj, err := s.objectClient.List(opts)
return obj.(*ServiceAccountList), err
}
func (s *serviceAccountClient) Watch(opts metav1.ListOptions) (watch.Interface, error) {
return s.objectClient.Watch(opts)
}
// Patch applies the patch and returns the patched deployment.
func (s *serviceAccountClient) Patch(o *v1.ServiceAccount, data []byte, subresources ...string) (*v1.ServiceAccount, error) {
obj, err := s.objectClient.Patch(o.Name, o, data, subresources...)
return obj.(*v1.ServiceAccount), err
}
func (s *serviceAccountClient) DeleteCollection(deleteOpts *metav1.DeleteOptions, listOpts metav1.ListOptions) error {
return s.objectClient.DeleteCollection(deleteOpts, listOpts)
}
func (s *serviceAccountClient) AddHandler(name string, sync ServiceAccountHandlerFunc) {
s.Controller().AddHandler(name, sync)
}
func (s *serviceAccountClient) AddLifecycle(name string, lifecycle ServiceAccountLifecycle) {
sync := NewServiceAccountLifecycleAdapter(name, false, s, lifecycle)
s.AddHandler(name, sync)
}
func (s *serviceAccountClient) AddClusterScopedHandler(name, clusterName string, sync ServiceAccountHandlerFunc) {
s.Controller().AddClusterScopedHandler(name, clusterName, sync)
}
func (s *serviceAccountClient) AddClusterScopedLifecycle(name, clusterName string, lifecycle ServiceAccountLifecycle) {
sync := NewServiceAccountLifecycleAdapter(name+"_"+clusterName, true, s, lifecycle)
s.AddClusterScopedHandler(name, clusterName, sync)
}

View File

@ -0,0 +1,52 @@
package v1
import (
"github.com/rancher/norman/lifecycle"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
)
type ServiceAccountLifecycle interface {
Create(obj *v1.ServiceAccount) (*v1.ServiceAccount, error)
Remove(obj *v1.ServiceAccount) (*v1.ServiceAccount, error)
Updated(obj *v1.ServiceAccount) (*v1.ServiceAccount, error)
}
type serviceAccountLifecycleAdapter struct {
lifecycle ServiceAccountLifecycle
}
func (w *serviceAccountLifecycleAdapter) Create(obj runtime.Object) (runtime.Object, error) {
o, err := w.lifecycle.Create(obj.(*v1.ServiceAccount))
if o == nil {
return nil, err
}
return o, err
}
func (w *serviceAccountLifecycleAdapter) Finalize(obj runtime.Object) (runtime.Object, error) {
o, err := w.lifecycle.Remove(obj.(*v1.ServiceAccount))
if o == nil {
return nil, err
}
return o, err
}
func (w *serviceAccountLifecycleAdapter) Updated(obj runtime.Object) (runtime.Object, error) {
o, err := w.lifecycle.Updated(obj.(*v1.ServiceAccount))
if o == nil {
return nil, err
}
return o, err
}
func NewServiceAccountLifecycleAdapter(name string, clusterScoped bool, client ServiceAccountInterface, l ServiceAccountLifecycle) ServiceAccountHandlerFunc {
adapter := &serviceAccountLifecycleAdapter{lifecycle: l}
syncFn := lifecycle.NewObjectLifecycleAdapter(name, clusterScoped, adapter, client.ObjectClient())
return func(key string, obj *v1.ServiceAccount) error {
if obj == nil {
return syncFn(key, nil)
}
return syncFn(key, obj)
}
}