|
| 1 | +/* |
| 2 | +Copyright 2021 clusterpedia Authors |
| 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 | +package v1beta1 |
| 18 | + |
| 19 | +import ( |
| 20 | + "context" |
| 21 | + "net/http" |
| 22 | + "time" |
| 23 | + |
| 24 | + clusterpediav1beta1 "github.com/clusterpedia-io/api/clusterpedia/v1beta1" |
| 25 | + scheme "github.com/clusterpedia-io/client-go/clusterpediaclient/scheme" |
| 26 | + |
| 27 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 28 | + "k8s.io/client-go/rest" |
| 29 | +) |
| 30 | + |
| 31 | +type ClusterPediaV1beta1 interface { |
| 32 | + CollectionResource() CollectionResourceInterface |
| 33 | +} |
| 34 | + |
| 35 | +type ClusterPediaV1beta1Client struct { |
| 36 | + restClient rest.Interface |
| 37 | +} |
| 38 | + |
| 39 | +// New creates a new CoreV1Client for the given RESTClient. |
| 40 | +func NewForConfig(c *rest.Config) (*ClusterPediaV1beta1Client, error) { |
| 41 | + config := *c |
| 42 | + if err := setConfigDefaults(&config); err != nil { |
| 43 | + return nil, err |
| 44 | + } |
| 45 | + httpClient, err := rest.HTTPClientFor(&config) |
| 46 | + if err != nil { |
| 47 | + return nil, err |
| 48 | + } |
| 49 | + return NewForConfigAndClient(&config, httpClient) |
| 50 | +} |
| 51 | + |
| 52 | +func NewForConfigAndClient(c *rest.Config, h *http.Client) (*ClusterPediaV1beta1Client, error) { |
| 53 | + config := *c |
| 54 | + if err := setConfigDefaults(&config); err != nil { |
| 55 | + return nil, err |
| 56 | + } |
| 57 | + client, err := rest.RESTClientForConfigAndClient(&config, h) |
| 58 | + if err != nil { |
| 59 | + return nil, err |
| 60 | + } |
| 61 | + return &ClusterPediaV1beta1Client{client}, nil |
| 62 | +} |
| 63 | + |
| 64 | +func setConfigDefaults(config *rest.Config) error { |
| 65 | + gv := clusterpediav1beta1.SchemeGroupVersion |
| 66 | + config.GroupVersion = &gv |
| 67 | + config.APIPath = "/apis" |
| 68 | + config.NegotiatedSerializer = scheme.Codecs.WithoutConversion() |
| 69 | + |
| 70 | + if config.UserAgent == "" { |
| 71 | + config.UserAgent = rest.DefaultKubernetesUserAgent() |
| 72 | + } |
| 73 | + |
| 74 | + return nil |
| 75 | +} |
| 76 | + |
| 77 | +func (c *ClusterPediaV1beta1Client) CollectionResource() CollectionResourceInterface { |
| 78 | + return &CollectionResource{c.restClient} |
| 79 | +} |
| 80 | + |
| 81 | +type CollectionResourceInterface interface { |
| 82 | + Get(ctx context.Context, name string, opts metav1.GetOptions) (*clusterpediav1beta1.CollectionResource, error) |
| 83 | + List(ctx context.Context, opts metav1.ListOptions) (*clusterpediav1beta1.CollectionResourceList, error) |
| 84 | + Fetch(ctx context.Context, name string, opts metav1.ListOptions, params map[string]string) (*clusterpediav1beta1.CollectionResource, error) |
| 85 | +} |
| 86 | + |
| 87 | +type CollectionResource struct { |
| 88 | + client rest.Interface |
| 89 | +} |
| 90 | + |
| 91 | +func (c *CollectionResource) Get(ctx context.Context, name string, opts metav1.GetOptions) (result *clusterpediav1beta1.CollectionResource, err error) { |
| 92 | + result = &clusterpediav1beta1.CollectionResource{} |
| 93 | + err = c.client.Get(). |
| 94 | + Resource("collectionresources"). |
| 95 | + Name(name). |
| 96 | + VersionedParams(&opts, scheme.ParameterCodec). |
| 97 | + Do(ctx). |
| 98 | + Into(result) |
| 99 | + return |
| 100 | +} |
| 101 | + |
| 102 | +func (c *CollectionResource) List(ctx context.Context, opts metav1.ListOptions) (result *clusterpediav1beta1.CollectionResourceList, err error) { |
| 103 | + var timeout time.Duration |
| 104 | + if opts.TimeoutSeconds != nil { |
| 105 | + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second |
| 106 | + } |
| 107 | + result = &clusterpediav1beta1.CollectionResourceList{} |
| 108 | + err = c.client.Get(). |
| 109 | + Resource("collectionresources"). |
| 110 | + VersionedParams(&opts, scheme.ParameterCodec). |
| 111 | + Timeout(timeout). |
| 112 | + Do(ctx). |
| 113 | + Into(result) |
| 114 | + return |
| 115 | +} |
| 116 | + |
| 117 | +func (c *CollectionResource) Fetch(ctx context.Context, name string, opts metav1.ListOptions, params map[string]string) (result *clusterpediav1beta1.CollectionResource, err error) { |
| 118 | + request := c.client.Get(). |
| 119 | + Resource("collectionresources"). |
| 120 | + Name(name). |
| 121 | + VersionedParams(&opts, scheme.ParameterCodec) |
| 122 | + |
| 123 | + for p, v := range params { |
| 124 | + request.Param(p, v) |
| 125 | + } |
| 126 | + |
| 127 | + result = &clusterpediav1beta1.CollectionResource{} |
| 128 | + request.Do(ctx).Into(result) |
| 129 | + return |
| 130 | +} |
0 commit comments