github.com/GoogleContainerTools/kpt/porch/api@v0.0.0-20240427025202-5cbd3cbd9237/generated/clientset/versioned/clientset.go (about)

     1  // Copyright 2023 The kpt 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  	porchv1alpha1 "github.com/GoogleContainerTools/kpt/porch/api/generated/clientset/versioned/typed/porch/v1alpha1"
    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  	PorchV1alpha1() porchv1alpha1.PorchV1alpha1Interface
    32  }
    33  
    34  // Clientset contains the clients for groups. Each group has exactly one
    35  // version included in a Clientset.
    36  type Clientset struct {
    37  	*discovery.DiscoveryClient
    38  	porchV1alpha1 *porchv1alpha1.PorchV1alpha1Client
    39  }
    40  
    41  // PorchV1alpha1 retrieves the PorchV1alpha1Client
    42  func (c *Clientset) PorchV1alpha1() porchv1alpha1.PorchV1alpha1Interface {
    43  	return c.porchV1alpha1
    44  }
    45  
    46  // Discovery retrieves the DiscoveryClient
    47  func (c *Clientset) Discovery() discovery.DiscoveryInterface {
    48  	if c == nil {
    49  		return nil
    50  	}
    51  	return c.DiscoveryClient
    52  }
    53  
    54  // NewForConfig creates a new Clientset for the given config.
    55  // If config's RateLimiter is not set and QPS and Burst are acceptable,
    56  // NewForConfig will generate a rate-limiter in configShallowCopy.
    57  // NewForConfig is equivalent to NewForConfigAndClient(c, httpClient),
    58  // where httpClient was generated with rest.HTTPClientFor(c).
    59  func NewForConfig(c *rest.Config) (*Clientset, error) {
    60  	configShallowCopy := *c
    61  
    62  	// share the transport between all clients
    63  	httpClient, err := rest.HTTPClientFor(&configShallowCopy)
    64  	if err != nil {
    65  		return nil, err
    66  	}
    67  
    68  	return NewForConfigAndClient(&configShallowCopy, httpClient)
    69  }
    70  
    71  // NewForConfigAndClient creates a new Clientset for the given config and http client.
    72  // Note the http client provided takes precedence over the configured transport values.
    73  // If config's RateLimiter is not set and QPS and Burst are acceptable,
    74  // NewForConfigAndClient will generate a rate-limiter in configShallowCopy.
    75  func NewForConfigAndClient(c *rest.Config, httpClient *http.Client) (*Clientset, error) {
    76  	configShallowCopy := *c
    77  	if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 {
    78  		if configShallowCopy.Burst <= 0 {
    79  			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")
    80  		}
    81  		configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst)
    82  	}
    83  
    84  	var cs Clientset
    85  	var err error
    86  	cs.porchV1alpha1, err = porchv1alpha1.NewForConfigAndClient(&configShallowCopy, httpClient)
    87  	if err != nil {
    88  		return nil, err
    89  	}
    90  
    91  	cs.DiscoveryClient, err = discovery.NewDiscoveryClientForConfigAndClient(&configShallowCopy, httpClient)
    92  	if err != nil {
    93  		return nil, err
    94  	}
    95  	return &cs, nil
    96  }
    97  
    98  // NewForConfigOrDie creates a new Clientset for the given config and
    99  // panics if there is an error in the config.
   100  func NewForConfigOrDie(c *rest.Config) *Clientset {
   101  	cs, err := NewForConfig(c)
   102  	if err != nil {
   103  		panic(err)
   104  	}
   105  	return cs
   106  }
   107  
   108  // New creates a new Clientset for the given RESTClient.
   109  func New(c rest.Interface) *Clientset {
   110  	var cs Clientset
   111  	cs.porchV1alpha1 = porchv1alpha1.New(c)
   112  
   113  	cs.DiscoveryClient = discovery.NewDiscoveryClient(c)
   114  	return &cs
   115  }