github.com/operator-framework/operator-lifecycle-manager@v0.30.0/pkg/package-server/client/clientset/internalversion/clientset.go (about) 1 /* 2 Copyright Red Hat, Inc. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 // Code generated by client-gen. DO NOT EDIT. 18 19 package internalversion 20 21 import ( 22 "fmt" 23 "net/http" 24 25 operatorsinternalversion "github.com/operator-framework/operator-lifecycle-manager/pkg/package-server/client/clientset/internalversion/typed/operators/internalversion" 26 discovery "k8s.io/client-go/discovery" 27 rest "k8s.io/client-go/rest" 28 flowcontrol "k8s.io/client-go/util/flowcontrol" 29 ) 30 31 type Interface interface { 32 Discovery() discovery.DiscoveryInterface 33 Operators() operatorsinternalversion.OperatorsInterface 34 } 35 36 // Clientset contains the clients for groups. 37 type Clientset struct { 38 *discovery.DiscoveryClient 39 operators *operatorsinternalversion.OperatorsClient 40 } 41 42 // Operators retrieves the OperatorsClient 43 func (c *Clientset) Operators() operatorsinternalversion.OperatorsInterface { 44 return c.operators 45 } 46 47 // Discovery retrieves the DiscoveryClient 48 func (c *Clientset) Discovery() discovery.DiscoveryInterface { 49 if c == nil { 50 return nil 51 } 52 return c.DiscoveryClient 53 } 54 55 // NewForConfig creates a new Clientset for the given config. 56 // If config's RateLimiter is not set and QPS and Burst are acceptable, 57 // NewForConfig will generate a rate-limiter in configShallowCopy. 58 // NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), 59 // where httpClient was generated with rest.HTTPClientFor(c). 60 func NewForConfig(c *rest.Config) (*Clientset, error) { 61 configShallowCopy := *c 62 63 if configShallowCopy.UserAgent == "" { 64 configShallowCopy.UserAgent = rest.DefaultKubernetesUserAgent() 65 } 66 67 // share the transport between all clients 68 httpClient, err := rest.HTTPClientFor(&configShallowCopy) 69 if err != nil { 70 return nil, err 71 } 72 73 return NewForConfigAndClient(&configShallowCopy, httpClient) 74 } 75 76 // NewForConfigAndClient creates a new Clientset for the given config and http client. 77 // Note the http client provided takes precedence over the configured transport values. 78 // If config's RateLimiter is not set and QPS and Burst are acceptable, 79 // NewForConfigAndClient will generate a rate-limiter in configShallowCopy. 80 func NewForConfigAndClient(c *rest.Config, httpClient *http.Client) (*Clientset, error) { 81 configShallowCopy := *c 82 if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 { 83 if configShallowCopy.Burst <= 0 { 84 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") 85 } 86 configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst) 87 } 88 89 var cs Clientset 90 var err error 91 cs.operators, err = operatorsinternalversion.NewForConfigAndClient(&configShallowCopy, httpClient) 92 if err != nil { 93 return nil, err 94 } 95 96 cs.DiscoveryClient, err = discovery.NewDiscoveryClientForConfigAndClient(&configShallowCopy, httpClient) 97 if err != nil { 98 return nil, err 99 } 100 return &cs, nil 101 } 102 103 // NewForConfigOrDie creates a new Clientset for the given config and 104 // panics if there is an error in the config. 105 func NewForConfigOrDie(c *rest.Config) *Clientset { 106 cs, err := NewForConfig(c) 107 if err != nil { 108 panic(err) 109 } 110 return cs 111 } 112 113 // New creates a new Clientset for the given RESTClient. 114 func New(c rest.Interface) *Clientset { 115 var cs Clientset 116 cs.operators = operatorsinternalversion.New(c) 117 118 cs.DiscoveryClient = discovery.NewDiscoveryClient(c) 119 return &cs 120 }