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