1
0
mirror of https://github.com/rancher/types.git synced 2025-08-31 21:00:16 +00:00

generated changes

This commit is contained in:
Daishan Peng
2018-02-01 15:14:49 -07:00
committed by Darren Shepherd
parent bb5aa0187b
commit 3c50ca8493
15 changed files with 650 additions and 604 deletions

View File

@@ -0,0 +1,252 @@
package v3
import (
"context"
"github.com/rancher/norman/clientbase"
"github.com/rancher/norman/controller"
"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 (
AppGroupVersionKind = schema.GroupVersionKind{
Version: Version,
Group: GroupName,
Kind: "App",
}
AppResource = metav1.APIResource{
Name: "apps",
SingularName: "app",
Namespaced: true,
Kind: AppGroupVersionKind.Kind,
}
)
type AppList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []App
}
type AppHandlerFunc func(key string, obj *App) error
type AppLister interface {
List(namespace string, selector labels.Selector) (ret []*App, err error)
Get(namespace, name string) (*App, error)
}
type AppController interface {
Informer() cache.SharedIndexInformer
Lister() AppLister
AddHandler(name string, handler AppHandlerFunc)
AddClusterScopedHandler(name, clusterName string, handler AppHandlerFunc)
Enqueue(namespace, name string)
Sync(ctx context.Context) error
Start(ctx context.Context, threadiness int) error
}
type AppInterface interface {
ObjectClient() *clientbase.ObjectClient
Create(*App) (*App, error)
GetNamespaced(namespace, name string, opts metav1.GetOptions) (*App, error)
Get(name string, opts metav1.GetOptions) (*App, error)
Update(*App) (*App, error)
Delete(name string, options *metav1.DeleteOptions) error
DeleteNamespaced(namespace, name string, options *metav1.DeleteOptions) error
List(opts metav1.ListOptions) (*AppList, error)
Watch(opts metav1.ListOptions) (watch.Interface, error)
DeleteCollection(deleteOpts *metav1.DeleteOptions, listOpts metav1.ListOptions) error
Controller() AppController
AddHandler(name string, sync AppHandlerFunc)
AddLifecycle(name string, lifecycle AppLifecycle)
AddClusterScopedHandler(name, clusterName string, sync AppHandlerFunc)
AddClusterScopedLifecycle(name, clusterName string, lifecycle AppLifecycle)
}
type appLister struct {
controller *appController
}
func (l *appLister) List(namespace string, selector labels.Selector) (ret []*App, err error) {
err = cache.ListAllByNamespace(l.controller.Informer().GetIndexer(), namespace, selector, func(obj interface{}) {
ret = append(ret, obj.(*App))
})
return
}
func (l *appLister) Get(namespace, name string) (*App, 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: AppGroupVersionKind.Group,
Resource: "app",
}, name)
}
return obj.(*App), nil
}
type appController struct {
controller.GenericController
}
func (c *appController) Lister() AppLister {
return &appLister{
controller: c,
}
}
func (c *appController) AddHandler(name string, handler AppHandlerFunc) {
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.(*App))
})
}
func (c *appController) AddClusterScopedHandler(name, cluster string, handler AppHandlerFunc) {
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.(*App))
})
}
type appFactory struct {
}
func (c appFactory) Object() runtime.Object {
return &App{}
}
func (c appFactory) List() runtime.Object {
return &AppList{}
}
func (s *appClient) Controller() AppController {
s.client.Lock()
defer s.client.Unlock()
c, ok := s.client.appControllers[s.ns]
if ok {
return c
}
genericController := controller.NewGenericController(AppGroupVersionKind.Kind+"Controller",
s.objectClient)
c = &appController{
GenericController: genericController,
}
s.client.appControllers[s.ns] = c
s.client.starters = append(s.client.starters, c)
return c
}
type appClient struct {
client *Client
ns string
objectClient *clientbase.ObjectClient
controller AppController
}
func (s *appClient) ObjectClient() *clientbase.ObjectClient {
return s.objectClient
}
func (s *appClient) Create(o *App) (*App, error) {
obj, err := s.objectClient.Create(o)
return obj.(*App), err
}
func (s *appClient) Get(name string, opts metav1.GetOptions) (*App, error) {
obj, err := s.objectClient.Get(name, opts)
return obj.(*App), err
}
func (s *appClient) GetNamespaced(namespace, name string, opts metav1.GetOptions) (*App, error) {
obj, err := s.objectClient.GetNamespaced(namespace, name, opts)
return obj.(*App), err
}
func (s *appClient) Update(o *App) (*App, error) {
obj, err := s.objectClient.Update(o.Name, o)
return obj.(*App), err
}
func (s *appClient) Delete(name string, options *metav1.DeleteOptions) error {
return s.objectClient.Delete(name, options)
}
func (s *appClient) DeleteNamespaced(namespace, name string, options *metav1.DeleteOptions) error {
return s.objectClient.DeleteNamespaced(namespace, name, options)
}
func (s *appClient) List(opts metav1.ListOptions) (*AppList, error) {
obj, err := s.objectClient.List(opts)
return obj.(*AppList), err
}
func (s *appClient) Watch(opts metav1.ListOptions) (watch.Interface, error) {
return s.objectClient.Watch(opts)
}
// Patch applies the patch and returns the patched deployment.
func (s *appClient) Patch(o *App, data []byte, subresources ...string) (*App, error) {
obj, err := s.objectClient.Patch(o.Name, o, data, subresources...)
return obj.(*App), err
}
func (s *appClient) DeleteCollection(deleteOpts *metav1.DeleteOptions, listOpts metav1.ListOptions) error {
return s.objectClient.DeleteCollection(deleteOpts, listOpts)
}
func (s *appClient) AddHandler(name string, sync AppHandlerFunc) {
s.Controller().AddHandler(name, sync)
}
func (s *appClient) AddLifecycle(name string, lifecycle AppLifecycle) {
sync := NewAppLifecycleAdapter(name, false, s, lifecycle)
s.AddHandler(name, sync)
}
func (s *appClient) AddClusterScopedHandler(name, clusterName string, sync AppHandlerFunc) {
s.Controller().AddClusterScopedHandler(name, clusterName, sync)
}
func (s *appClient) AddClusterScopedLifecycle(name, clusterName string, lifecycle AppLifecycle) {
sync := NewAppLifecycleAdapter(name+"_"+clusterName, true, s, lifecycle)
s.AddClusterScopedHandler(name, clusterName, sync)
}

View File

@@ -0,0 +1,51 @@
package v3
import (
"github.com/rancher/norman/lifecycle"
"k8s.io/apimachinery/pkg/runtime"
)
type AppLifecycle interface {
Create(obj *App) (*App, error)
Remove(obj *App) (*App, error)
Updated(obj *App) (*App, error)
}
type appLifecycleAdapter struct {
lifecycle AppLifecycle
}
func (w *appLifecycleAdapter) Create(obj runtime.Object) (runtime.Object, error) {
o, err := w.lifecycle.Create(obj.(*App))
if o == nil {
return nil, err
}
return o, err
}
func (w *appLifecycleAdapter) Finalize(obj runtime.Object) (runtime.Object, error) {
o, err := w.lifecycle.Remove(obj.(*App))
if o == nil {
return nil, err
}
return o, err
}
func (w *appLifecycleAdapter) Updated(obj runtime.Object) (runtime.Object, error) {
o, err := w.lifecycle.Updated(obj.(*App))
if o == nil {
return nil, err
}
return o, err
}
func NewAppLifecycleAdapter(name string, clusterScoped bool, client AppInterface, l AppLifecycle) AppHandlerFunc {
adapter := &appLifecycleAdapter{lifecycle: l}
syncFn := lifecycle.NewObjectLifecycleAdapter(name, clusterScoped, adapter, client.ObjectClient())
return func(key string, obj *App) error {
if obj == nil {
return syncFn(key, nil)
}
return syncFn(key, obj)
}
}

View File

@@ -23,6 +23,22 @@ func RegisterDeepCopies(scheme *runtime.Scheme) error {
in.(*Action).DeepCopyInto(out.(*Action))
return nil
}, InType: reflect.TypeOf(&Action{})},
conversion.GeneratedDeepCopyFunc{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*App).DeepCopyInto(out.(*App))
return nil
}, InType: reflect.TypeOf(&App{})},
conversion.GeneratedDeepCopyFunc{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*AppList).DeepCopyInto(out.(*AppList))
return nil
}, InType: reflect.TypeOf(&AppList{})},
conversion.GeneratedDeepCopyFunc{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*AppSpec).DeepCopyInto(out.(*AppSpec))
return nil
}, InType: reflect.TypeOf(&AppSpec{})},
conversion.GeneratedDeepCopyFunc{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*AppStatus).DeepCopyInto(out.(*AppStatus))
return nil
}, InType: reflect.TypeOf(&AppStatus{})},
conversion.GeneratedDeepCopyFunc{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*AuthConfig).DeepCopyInto(out.(*AuthConfig))
return nil
@@ -495,22 +511,6 @@ func RegisterDeepCopies(scheme *runtime.Scheme) error {
in.(*SplunkConfig).DeepCopyInto(out.(*SplunkConfig))
return nil
}, InType: reflect.TypeOf(&SplunkConfig{})},
conversion.GeneratedDeepCopyFunc{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*Stack).DeepCopyInto(out.(*Stack))
return nil
}, InType: reflect.TypeOf(&Stack{})},
conversion.GeneratedDeepCopyFunc{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*StackList).DeepCopyInto(out.(*StackList))
return nil
}, InType: reflect.TypeOf(&StackList{})},
conversion.GeneratedDeepCopyFunc{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*StackSpec).DeepCopyInto(out.(*StackSpec))
return nil
}, InType: reflect.TypeOf(&StackSpec{})},
conversion.GeneratedDeepCopyFunc{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*StackStatus).DeepCopyInto(out.(*StackStatus))
return nil
}, InType: reflect.TypeOf(&StackStatus{})},
conversion.GeneratedDeepCopyFunc{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*SyslogConfig).DeepCopyInto(out.(*SyslogConfig))
return nil
@@ -567,6 +567,10 @@ func RegisterDeepCopies(scheme *runtime.Scheme) error {
in.(*Values).DeepCopyInto(out.(*Values))
return nil
}, InType: reflect.TypeOf(&Values{})},
conversion.GeneratedDeepCopyFunc{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*VersionCommits).DeepCopyInto(out.(*VersionCommits))
return nil
}, InType: reflect.TypeOf(&VersionCommits{})},
conversion.GeneratedDeepCopyFunc{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*Zookeeper).DeepCopyInto(out.(*Zookeeper))
return nil
@@ -590,6 +594,133 @@ func (in *Action) DeepCopy() *Action {
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *App) DeepCopyInto(out *App) {
*out = *in
out.Namespaced = in.Namespaced
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
in.Spec.DeepCopyInto(&out.Spec)
in.Status.DeepCopyInto(&out.Status)
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new App.
func (in *App) DeepCopy() *App {
if in == nil {
return nil
}
out := new(App)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *App) 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 *AppList) DeepCopyInto(out *AppList) {
*out = *in
out.TypeMeta = in.TypeMeta
out.ListMeta = in.ListMeta
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]App, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AppList.
func (in *AppList) DeepCopy() *AppList {
if in == nil {
return nil
}
out := new(AppList)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *AppList) 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 *AppSpec) DeepCopyInto(out *AppSpec) {
*out = *in
if in.Templates != nil {
in, out := &in.Templates, &out.Templates
*out = make(map[string]string, len(*in))
for key, val := range *in {
(*out)[key] = val
}
}
if in.Answers != nil {
in, out := &in.Answers, &out.Answers
*out = make(map[string]string, len(*in))
for key, val := range *in {
(*out)[key] = val
}
}
if in.Tag != nil {
in, out := &in.Tag, &out.Tag
*out = make(map[string]string, len(*in))
for key, val := range *in {
(*out)[key] = val
}
}
if in.Groups != nil {
in, out := &in.Groups, &out.Groups
*out = make([]string, len(*in))
copy(*out, *in)
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AppSpec.
func (in *AppSpec) DeepCopy() *AppSpec {
if in == nil {
return nil
}
out := new(AppSpec)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *AppStatus) DeepCopyInto(out *AppStatus) {
*out = *in
if in.Releases != nil {
in, out := &in.Releases, &out.Releases
*out = make([]ReleaseInfo, len(*in))
copy(*out, *in)
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AppStatus.
func (in *AppStatus) DeepCopy() *AppStatus {
if in == nil {
return nil
}
out := new(AppStatus)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *AuthConfig) DeepCopyInto(out *AuthConfig) {
*out = *in
@@ -770,7 +901,7 @@ func (in *Catalog) DeepCopyInto(out *Catalog) {
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
out.Spec = in.Spec
out.Status = in.Status
in.Status.DeepCopyInto(&out.Status)
return
}
@@ -846,6 +977,13 @@ func (in *CatalogSpec) DeepCopy() *CatalogSpec {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *CatalogStatus) DeepCopyInto(out *CatalogStatus) {
*out = *in
if in.HelmVersionCommits != nil {
in, out := &in.HelmVersionCommits, &out.HelmVersionCommits
*out = make(map[string]VersionCommits, len(*in))
for key, val := range *in {
(*out)[key] = *val.DeepCopy()
}
}
return
}
@@ -3774,133 +3912,6 @@ func (in *SplunkConfig) DeepCopy() *SplunkConfig {
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Stack) DeepCopyInto(out *Stack) {
*out = *in
out.Namespaced = in.Namespaced
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
in.Spec.DeepCopyInto(&out.Spec)
in.Status.DeepCopyInto(&out.Status)
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Stack.
func (in *Stack) DeepCopy() *Stack {
if in == nil {
return nil
}
out := new(Stack)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *Stack) 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 *StackList) DeepCopyInto(out *StackList) {
*out = *in
out.TypeMeta = in.TypeMeta
out.ListMeta = in.ListMeta
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]Stack, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StackList.
func (in *StackList) DeepCopy() *StackList {
if in == nil {
return nil
}
out := new(StackList)
in.DeepCopyInto(out)
return out
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *StackList) 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 *StackSpec) DeepCopyInto(out *StackSpec) {
*out = *in
if in.Templates != nil {
in, out := &in.Templates, &out.Templates
*out = make(map[string]string, len(*in))
for key, val := range *in {
(*out)[key] = val
}
}
if in.Answers != nil {
in, out := &in.Answers, &out.Answers
*out = make(map[string]string, len(*in))
for key, val := range *in {
(*out)[key] = val
}
}
if in.Tag != nil {
in, out := &in.Tag, &out.Tag
*out = make(map[string]string, len(*in))
for key, val := range *in {
(*out)[key] = val
}
}
if in.Groups != nil {
in, out := &in.Groups, &out.Groups
*out = make([]string, len(*in))
copy(*out, *in)
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StackSpec.
func (in *StackSpec) DeepCopy() *StackSpec {
if in == nil {
return nil
}
out := new(StackSpec)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *StackStatus) DeepCopyInto(out *StackStatus) {
*out = *in
if in.Releases != nil {
in, out := &in.Releases, &out.Releases
*out = make([]ReleaseInfo, len(*in))
copy(*out, *in)
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StackStatus.
func (in *StackStatus) DeepCopy() *StackStatus {
if in == nil {
return nil
}
out := new(StackStatus)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *SyslogConfig) DeepCopyInto(out *SyslogConfig) {
*out = *in
@@ -4310,6 +4321,29 @@ func (in *Values) DeepCopy() *Values {
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *VersionCommits) DeepCopyInto(out *VersionCommits) {
*out = *in
if in.Value != nil {
in, out := &in.Value, &out.Value
*out = make(map[string]string, len(*in))
for key, val := range *in {
(*out)[key] = val
}
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new VersionCommits.
func (in *VersionCommits) DeepCopy() *VersionCommits {
if in == nil {
return nil
}
out := new(VersionCommits)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Zookeeper) DeepCopyInto(out *Zookeeper) {
*out = *in

View File

@@ -37,7 +37,7 @@ type Interface interface {
AuthConfigsGetter
TokensGetter
DynamicSchemasGetter
StacksGetter
AppsGetter
PreferencesGetter
ClusterLoggingsGetter
ProjectLoggingsGetter
@@ -73,7 +73,7 @@ type Client struct {
authConfigControllers map[string]AuthConfigController
tokenControllers map[string]TokenController
dynamicSchemaControllers map[string]DynamicSchemaController
stackControllers map[string]StackController
appControllers map[string]AppController
preferenceControllers map[string]PreferenceController
clusterLoggingControllers map[string]ClusterLoggingController
projectLoggingControllers map[string]ProjectLoggingController
@@ -118,7 +118,7 @@ func NewForConfig(config rest.Config) (Interface, error) {
authConfigControllers: map[string]AuthConfigController{},
tokenControllers: map[string]TokenController{},
dynamicSchemaControllers: map[string]DynamicSchemaController{},
stackControllers: map[string]StackController{},
appControllers: map[string]AppController{},
preferenceControllers: map[string]PreferenceController{},
clusterLoggingControllers: map[string]ClusterLoggingController{},
projectLoggingControllers: map[string]ProjectLoggingController{},
@@ -438,13 +438,13 @@ func (c *Client) DynamicSchemas(namespace string) DynamicSchemaInterface {
}
}
type StacksGetter interface {
Stacks(namespace string) StackInterface
type AppsGetter interface {
Apps(namespace string) AppInterface
}
func (c *Client) Stacks(namespace string) StackInterface {
objectClient := clientbase.NewObjectClient(namespace, c.restClient, &StackResource, StackGroupVersionKind, stackFactory{})
return &stackClient{
func (c *Client) Apps(namespace string) AppInterface {
objectClient := clientbase.NewObjectClient(namespace, c.restClient, &AppResource, AppGroupVersionKind, appFactory{})
return &appClient{
ns: namespace,
client: c,
objectClient: objectClient,

View File

@@ -79,8 +79,8 @@ func addKnownTypes(scheme *runtime.Scheme) error {
&TokenList{},
&DynamicSchema{},
&DynamicSchemaList{},
&Stack{},
&StackList{},
&App{},
&AppList{},
&Preference{},
&PreferenceList{},
&ClusterLogging{},

View File

@@ -1,252 +0,0 @@
package v3
import (
"context"
"github.com/rancher/norman/clientbase"
"github.com/rancher/norman/controller"
"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 (
StackGroupVersionKind = schema.GroupVersionKind{
Version: Version,
Group: GroupName,
Kind: "Stack",
}
StackResource = metav1.APIResource{
Name: "stacks",
SingularName: "stack",
Namespaced: true,
Kind: StackGroupVersionKind.Kind,
}
)
type StackList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Stack
}
type StackHandlerFunc func(key string, obj *Stack) error
type StackLister interface {
List(namespace string, selector labels.Selector) (ret []*Stack, err error)
Get(namespace, name string) (*Stack, error)
}
type StackController interface {
Informer() cache.SharedIndexInformer
Lister() StackLister
AddHandler(name string, handler StackHandlerFunc)
AddClusterScopedHandler(name, clusterName string, handler StackHandlerFunc)
Enqueue(namespace, name string)
Sync(ctx context.Context) error
Start(ctx context.Context, threadiness int) error
}
type StackInterface interface {
ObjectClient() *clientbase.ObjectClient
Create(*Stack) (*Stack, error)
GetNamespaced(namespace, name string, opts metav1.GetOptions) (*Stack, error)
Get(name string, opts metav1.GetOptions) (*Stack, error)
Update(*Stack) (*Stack, error)
Delete(name string, options *metav1.DeleteOptions) error
DeleteNamespaced(namespace, name string, options *metav1.DeleteOptions) error
List(opts metav1.ListOptions) (*StackList, error)
Watch(opts metav1.ListOptions) (watch.Interface, error)
DeleteCollection(deleteOpts *metav1.DeleteOptions, listOpts metav1.ListOptions) error
Controller() StackController
AddHandler(name string, sync StackHandlerFunc)
AddLifecycle(name string, lifecycle StackLifecycle)
AddClusterScopedHandler(name, clusterName string, sync StackHandlerFunc)
AddClusterScopedLifecycle(name, clusterName string, lifecycle StackLifecycle)
}
type stackLister struct {
controller *stackController
}
func (l *stackLister) List(namespace string, selector labels.Selector) (ret []*Stack, err error) {
err = cache.ListAllByNamespace(l.controller.Informer().GetIndexer(), namespace, selector, func(obj interface{}) {
ret = append(ret, obj.(*Stack))
})
return
}
func (l *stackLister) Get(namespace, name string) (*Stack, 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: StackGroupVersionKind.Group,
Resource: "stack",
}, name)
}
return obj.(*Stack), nil
}
type stackController struct {
controller.GenericController
}
func (c *stackController) Lister() StackLister {
return &stackLister{
controller: c,
}
}
func (c *stackController) AddHandler(name string, handler StackHandlerFunc) {
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.(*Stack))
})
}
func (c *stackController) AddClusterScopedHandler(name, cluster string, handler StackHandlerFunc) {
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.(*Stack))
})
}
type stackFactory struct {
}
func (c stackFactory) Object() runtime.Object {
return &Stack{}
}
func (c stackFactory) List() runtime.Object {
return &StackList{}
}
func (s *stackClient) Controller() StackController {
s.client.Lock()
defer s.client.Unlock()
c, ok := s.client.stackControllers[s.ns]
if ok {
return c
}
genericController := controller.NewGenericController(StackGroupVersionKind.Kind+"Controller",
s.objectClient)
c = &stackController{
GenericController: genericController,
}
s.client.stackControllers[s.ns] = c
s.client.starters = append(s.client.starters, c)
return c
}
type stackClient struct {
client *Client
ns string
objectClient *clientbase.ObjectClient
controller StackController
}
func (s *stackClient) ObjectClient() *clientbase.ObjectClient {
return s.objectClient
}
func (s *stackClient) Create(o *Stack) (*Stack, error) {
obj, err := s.objectClient.Create(o)
return obj.(*Stack), err
}
func (s *stackClient) Get(name string, opts metav1.GetOptions) (*Stack, error) {
obj, err := s.objectClient.Get(name, opts)
return obj.(*Stack), err
}
func (s *stackClient) GetNamespaced(namespace, name string, opts metav1.GetOptions) (*Stack, error) {
obj, err := s.objectClient.GetNamespaced(namespace, name, opts)
return obj.(*Stack), err
}
func (s *stackClient) Update(o *Stack) (*Stack, error) {
obj, err := s.objectClient.Update(o.Name, o)
return obj.(*Stack), err
}
func (s *stackClient) Delete(name string, options *metav1.DeleteOptions) error {
return s.objectClient.Delete(name, options)
}
func (s *stackClient) DeleteNamespaced(namespace, name string, options *metav1.DeleteOptions) error {
return s.objectClient.DeleteNamespaced(namespace, name, options)
}
func (s *stackClient) List(opts metav1.ListOptions) (*StackList, error) {
obj, err := s.objectClient.List(opts)
return obj.(*StackList), err
}
func (s *stackClient) Watch(opts metav1.ListOptions) (watch.Interface, error) {
return s.objectClient.Watch(opts)
}
// Patch applies the patch and returns the patched deployment.
func (s *stackClient) Patch(o *Stack, data []byte, subresources ...string) (*Stack, error) {
obj, err := s.objectClient.Patch(o.Name, o, data, subresources...)
return obj.(*Stack), err
}
func (s *stackClient) DeleteCollection(deleteOpts *metav1.DeleteOptions, listOpts metav1.ListOptions) error {
return s.objectClient.DeleteCollection(deleteOpts, listOpts)
}
func (s *stackClient) AddHandler(name string, sync StackHandlerFunc) {
s.Controller().AddHandler(name, sync)
}
func (s *stackClient) AddLifecycle(name string, lifecycle StackLifecycle) {
sync := NewStackLifecycleAdapter(name, false, s, lifecycle)
s.AddHandler(name, sync)
}
func (s *stackClient) AddClusterScopedHandler(name, clusterName string, sync StackHandlerFunc) {
s.Controller().AddClusterScopedHandler(name, clusterName, sync)
}
func (s *stackClient) AddClusterScopedLifecycle(name, clusterName string, lifecycle StackLifecycle) {
sync := NewStackLifecycleAdapter(name+"_"+clusterName, true, s, lifecycle)
s.AddClusterScopedHandler(name, clusterName, sync)
}

View File

@@ -1,51 +0,0 @@
package v3
import (
"github.com/rancher/norman/lifecycle"
"k8s.io/apimachinery/pkg/runtime"
)
type StackLifecycle interface {
Create(obj *Stack) (*Stack, error)
Remove(obj *Stack) (*Stack, error)
Updated(obj *Stack) (*Stack, error)
}
type stackLifecycleAdapter struct {
lifecycle StackLifecycle
}
func (w *stackLifecycleAdapter) Create(obj runtime.Object) (runtime.Object, error) {
o, err := w.lifecycle.Create(obj.(*Stack))
if o == nil {
return nil, err
}
return o, err
}
func (w *stackLifecycleAdapter) Finalize(obj runtime.Object) (runtime.Object, error) {
o, err := w.lifecycle.Remove(obj.(*Stack))
if o == nil {
return nil, err
}
return o, err
}
func (w *stackLifecycleAdapter) Updated(obj runtime.Object) (runtime.Object, error) {
o, err := w.lifecycle.Updated(obj.(*Stack))
if o == nil {
return nil, err
}
return o, err
}
func NewStackLifecycleAdapter(name string, clusterScoped bool, client StackInterface, l StackLifecycle) StackHandlerFunc {
adapter := &stackLifecycleAdapter{lifecycle: l}
syncFn := lifecycle.NewObjectLifecycleAdapter(name, clusterScoped, adapter, client.ObjectClient())
return func(key string, obj *Stack) error {
if obj == nil {
return syncFn(key, nil)
}
return syncFn(key, obj)
}
}