github.com/projectcalico/api@v0.0.0-20231218190037-9183ab93f33e/pkg/client/clientset_generated/clientset/clientset.go (about)

     1  // Copyright (c) 2023 Tigera, Inc. All rights reserved.
     2  
     3  // Code generated by client-gen. DO NOT EDIT.
     4  
     5  package clientset
     6  
     7  import (
     8  	"fmt"
     9  	"net/http"
    10  
    11  	projectcalicov3 "github.com/projectcalico/api/pkg/client/clientset_generated/clientset/typed/projectcalico/v3"
    12  	discovery "k8s.io/client-go/discovery"
    13  	rest "k8s.io/client-go/rest"
    14  	flowcontrol "k8s.io/client-go/util/flowcontrol"
    15  )
    16  
    17  type Interface interface {
    18  	Discovery() discovery.DiscoveryInterface
    19  	ProjectcalicoV3() projectcalicov3.ProjectcalicoV3Interface
    20  }
    21  
    22  // Clientset contains the clients for groups.
    23  type Clientset struct {
    24  	*discovery.DiscoveryClient
    25  	projectcalicoV3 *projectcalicov3.ProjectcalicoV3Client
    26  }
    27  
    28  // ProjectcalicoV3 retrieves the ProjectcalicoV3Client
    29  func (c *Clientset) ProjectcalicoV3() projectcalicov3.ProjectcalicoV3Interface {
    30  	return c.projectcalicoV3
    31  }
    32  
    33  // Discovery retrieves the DiscoveryClient
    34  func (c *Clientset) Discovery() discovery.DiscoveryInterface {
    35  	if c == nil {
    36  		return nil
    37  	}
    38  	return c.DiscoveryClient
    39  }
    40  
    41  // NewForConfig creates a new Clientset for the given config.
    42  // If config's RateLimiter is not set and QPS and Burst are acceptable,
    43  // NewForConfig will generate a rate-limiter in configShallowCopy.
    44  // NewForConfig is equivalent to NewForConfigAndClient(c, httpClient),
    45  // where httpClient was generated with rest.HTTPClientFor(c).
    46  func NewForConfig(c *rest.Config) (*Clientset, error) {
    47  	configShallowCopy := *c
    48  
    49  	if configShallowCopy.UserAgent == "" {
    50  		configShallowCopy.UserAgent = rest.DefaultKubernetesUserAgent()
    51  	}
    52  
    53  	// share the transport between all clients
    54  	httpClient, err := rest.HTTPClientFor(&configShallowCopy)
    55  	if err != nil {
    56  		return nil, err
    57  	}
    58  
    59  	return NewForConfigAndClient(&configShallowCopy, httpClient)
    60  }
    61  
    62  // NewForConfigAndClient creates a new Clientset for the given config and http client.
    63  // Note the http client provided takes precedence over the configured transport values.
    64  // If config's RateLimiter is not set and QPS and Burst are acceptable,
    65  // NewForConfigAndClient will generate a rate-limiter in configShallowCopy.
    66  func NewForConfigAndClient(c *rest.Config, httpClient *http.Client) (*Clientset, error) {
    67  	configShallowCopy := *c
    68  	if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 {
    69  		if configShallowCopy.Burst <= 0 {
    70  			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")
    71  		}
    72  		configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst)
    73  	}
    74  
    75  	var cs Clientset
    76  	var err error
    77  	cs.projectcalicoV3, err = projectcalicov3.NewForConfigAndClient(&configShallowCopy, httpClient)
    78  	if err != nil {
    79  		return nil, err
    80  	}
    81  
    82  	cs.DiscoveryClient, err = discovery.NewDiscoveryClientForConfigAndClient(&configShallowCopy, httpClient)
    83  	if err != nil {
    84  		return nil, err
    85  	}
    86  	return &cs, nil
    87  }
    88  
    89  // NewForConfigOrDie creates a new Clientset for the given config and
    90  // panics if there is an error in the config.
    91  func NewForConfigOrDie(c *rest.Config) *Clientset {
    92  	cs, err := NewForConfig(c)
    93  	if err != nil {
    94  		panic(err)
    95  	}
    96  	return cs
    97  }
    98  
    99  // New creates a new Clientset for the given RESTClient.
   100  func New(c rest.Interface) *Clientset {
   101  	var cs Clientset
   102  	cs.projectcalicoV3 = projectcalicov3.New(c)
   103  
   104  	cs.DiscoveryClient = discovery.NewDiscoveryClient(c)
   105  	return &cs
   106  }