github.com/AliyunContainerService/cli@v0.0.0-20181009023821-814ced4b30d0/kubernetes/client/clientset/clientset.go (about) 1 package clientset 2 3 import ( 4 composev1beta1 "github.com/docker/cli/kubernetes/client/clientset/typed/compose/v1beta1" 5 composev1beta2 "github.com/docker/cli/kubernetes/client/clientset/typed/compose/v1beta2" 6 "github.com/golang/glog" 7 "k8s.io/client-go/discovery" 8 "k8s.io/client-go/rest" 9 "k8s.io/client-go/util/flowcontrol" 10 ) 11 12 // Interface defines the methods a compose kube client should have 13 // FIXME(vdemeester) is it required ? 14 type Interface interface { 15 Discovery() discovery.DiscoveryInterface 16 ComposeV1beta2() composev1beta2.ComposeV1beta2Interface 17 ComposeV1beta1() composev1beta1.ComposeV1beta1Interface 18 } 19 20 // Clientset contains the clients for groups. Each group has exactly one 21 // version included in a Clientset. 22 type Clientset struct { 23 *discovery.DiscoveryClient 24 *composev1beta2.ComposeV1beta2Client 25 *composev1beta1.ComposeV1beta1Client 26 } 27 28 // ComposeV1beta2 retrieves the ComposeV1beta2Client 29 func (c *Clientset) ComposeV1beta2() composev1beta2.ComposeV1beta2Interface { 30 if c == nil { 31 return nil 32 } 33 return c.ComposeV1beta2Client 34 } 35 36 // ComposeV1beta1 retrieves the ComposeV1beta1Client 37 func (c *Clientset) ComposeV1beta1() composev1beta1.ComposeV1beta1Interface { 38 if c == nil { 39 return nil 40 } 41 return c.ComposeV1beta1Client 42 } 43 44 // Discovery retrieves the DiscoveryClient 45 func (c *Clientset) Discovery() discovery.DiscoveryInterface { 46 if c == nil { 47 return nil 48 } 49 return c.DiscoveryClient 50 } 51 52 // NewForConfig creates a new Clientset for the given config. 53 func NewForConfig(c *rest.Config) (*Clientset, error) { 54 configShallowCopy := *c 55 if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 { 56 configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst) 57 } 58 var cs Clientset 59 var err error 60 cs.ComposeV1beta2Client, err = composev1beta2.NewForConfig(&configShallowCopy) 61 if err != nil { 62 return nil, err 63 } 64 cs.ComposeV1beta1Client, err = composev1beta1.NewForConfig(&configShallowCopy) 65 if err != nil { 66 return nil, err 67 } 68 69 cs.DiscoveryClient, err = discovery.NewDiscoveryClientForConfig(&configShallowCopy) 70 if err != nil { 71 glog.Errorf("failed to create the DiscoveryClient: %v", err) 72 return nil, err 73 } 74 return &cs, nil 75 } 76 77 // NewForConfigOrDie creates a new Clientset for the given config and 78 // panics if there is an error in the config. 79 func NewForConfigOrDie(c *rest.Config) *Clientset { 80 var cs Clientset 81 cs.ComposeV1beta2Client = composev1beta2.NewForConfigOrDie(c) 82 cs.ComposeV1beta1Client = composev1beta1.NewForConfigOrDie(c) 83 84 cs.DiscoveryClient = discovery.NewDiscoveryClientForConfigOrDie(c) 85 return &cs 86 } 87 88 // New creates a new Clientset for the given RESTClient. 89 func New(c rest.Interface) *Clientset { 90 var cs Clientset 91 cs.ComposeV1beta2Client = composev1beta2.New(c) 92 cs.ComposeV1beta1Client = composev1beta1.New(c) 93 94 cs.DiscoveryClient = discovery.NewDiscoveryClient(c) 95 return &cs 96 }