github.com/verrazzano/verrazzano@v1.7.0/cluster-operator/clientset/versioned/clientset.go (about) 1 // Copyright (c) 2022, 2023, Oracle and/or its affiliates. 2 // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 3 4 // Code generated by client-gen. DO NOT EDIT. 5 6 package versioned 7 8 import ( 9 "fmt" 10 "net/http" 11 12 clustersv1alpha1 "github.com/verrazzano/verrazzano/cluster-operator/clientset/versioned/typed/clusters/v1alpha1" 13 discovery "k8s.io/client-go/discovery" 14 rest "k8s.io/client-go/rest" 15 flowcontrol "k8s.io/client-go/util/flowcontrol" 16 ) 17 18 type Interface interface { 19 Discovery() discovery.DiscoveryInterface 20 ClustersV1alpha1() clustersv1alpha1.ClustersV1alpha1Interface 21 } 22 23 // Clientset contains the clients for groups. Each group has exactly one 24 // version included in a Clientset. 25 type Clientset struct { 26 *discovery.DiscoveryClient 27 clustersV1alpha1 *clustersv1alpha1.ClustersV1alpha1Client 28 } 29 30 // ClustersV1alpha1 retrieves the ClustersV1alpha1Client 31 func (c *Clientset) ClustersV1alpha1() clustersv1alpha1.ClustersV1alpha1Interface { 32 return c.clustersV1alpha1 33 } 34 35 // Discovery retrieves the DiscoveryClient 36 func (c *Clientset) Discovery() discovery.DiscoveryInterface { 37 if c == nil { 38 return nil 39 } 40 return c.DiscoveryClient 41 } 42 43 // NewForConfig creates a new Clientset for the given config. 44 // If config's RateLimiter is not set and QPS and Burst are acceptable, 45 // NewForConfig will generate a rate-limiter in configShallowCopy. 46 // NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), 47 // where httpClient was generated with rest.HTTPClientFor(c). 48 func NewForConfig(c *rest.Config) (*Clientset, error) { 49 configShallowCopy := *c 50 51 if configShallowCopy.UserAgent == "" { 52 configShallowCopy.UserAgent = rest.DefaultKubernetesUserAgent() 53 } 54 55 // share the transport between all clients 56 httpClient, err := rest.HTTPClientFor(&configShallowCopy) 57 if err != nil { 58 return nil, err 59 } 60 61 return NewForConfigAndClient(&configShallowCopy, httpClient) 62 } 63 64 // NewForConfigAndClient creates a new Clientset for the given config and http client. 65 // Note the http client provided takes precedence over the configured transport values. 66 // If config's RateLimiter is not set and QPS and Burst are acceptable, 67 // NewForConfigAndClient will generate a rate-limiter in configShallowCopy. 68 func NewForConfigAndClient(c *rest.Config, httpClient *http.Client) (*Clientset, error) { 69 configShallowCopy := *c 70 if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 { 71 if configShallowCopy.Burst <= 0 { 72 return nil, fmt.Errorf("burst is required to be greater than 0 when RateLimiter is not set and QPS is set to greater than 0") 73 } 74 configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst) 75 } 76 77 var cs Clientset 78 var err error 79 cs.clustersV1alpha1, err = clustersv1alpha1.NewForConfigAndClient(&configShallowCopy, httpClient) 80 if err != nil { 81 return nil, err 82 } 83 84 cs.DiscoveryClient, err = discovery.NewDiscoveryClientForConfigAndClient(&configShallowCopy, httpClient) 85 if err != nil { 86 return nil, err 87 } 88 return &cs, nil 89 } 90 91 // NewForConfigOrDie creates a new Clientset for the given config and 92 // panics if there is an error in the config. 93 func NewForConfigOrDie(c *rest.Config) *Clientset { 94 cs, err := NewForConfig(c) 95 if err != nil { 96 panic(err) 97 } 98 return cs 99 } 100 101 // New creates a new Clientset for the given RESTClient. 102 func New(c rest.Interface) *Clientset { 103 var cs Clientset 104 cs.clustersV1alpha1 = clustersv1alpha1.New(c) 105 106 cs.DiscoveryClient = discovery.NewDiscoveryClient(c) 107 return &cs 108 }