github.phpd.cn/cilium/cilium@v1.6.12/pkg/k8s/client/clientset/versioned/clientset.go (about) 1 // Copyright 2017-2019 Authors of Cilium 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 22 ciliumv2 "github.com/cilium/cilium/pkg/k8s/client/clientset/versioned/typed/cilium.io/v2" 23 discovery "k8s.io/client-go/discovery" 24 rest "k8s.io/client-go/rest" 25 flowcontrol "k8s.io/client-go/util/flowcontrol" 26 ) 27 28 type Interface interface { 29 Discovery() discovery.DiscoveryInterface 30 CiliumV2() ciliumv2.CiliumV2Interface 31 } 32 33 // Clientset contains the clients for groups. Each group has exactly one 34 // version included in a Clientset. 35 type Clientset struct { 36 *discovery.DiscoveryClient 37 ciliumV2 *ciliumv2.CiliumV2Client 38 } 39 40 // CiliumV2 retrieves the CiliumV2Client 41 func (c *Clientset) CiliumV2() ciliumv2.CiliumV2Interface { 42 return c.ciliumV2 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 func NewForConfig(c *rest.Config) (*Clientset, error) { 57 configShallowCopy := *c 58 if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 { 59 if configShallowCopy.Burst <= 0 { 60 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") 61 } 62 configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst) 63 } 64 var cs Clientset 65 var err error 66 cs.ciliumV2, err = ciliumv2.NewForConfig(&configShallowCopy) 67 if err != nil { 68 return nil, err 69 } 70 71 cs.DiscoveryClient, err = discovery.NewDiscoveryClientForConfig(&configShallowCopy) 72 if err != nil { 73 return nil, err 74 } 75 return &cs, nil 76 } 77 78 // NewForConfigOrDie creates a new Clientset for the given config and 79 // panics if there is an error in the config. 80 func NewForConfigOrDie(c *rest.Config) *Clientset { 81 var cs Clientset 82 cs.ciliumV2 = ciliumv2.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.ciliumV2 = ciliumv2.New(c) 92 93 cs.DiscoveryClient = discovery.NewDiscoveryClient(c) 94 return &cs 95 }