k8s.io/client-go@v0.22.2/kubernetes/typed/apps/v1/statefulset.go (about) 1 /* 2 Copyright The Kubernetes 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 // Code generated by client-gen. DO NOT EDIT. 18 19 package v1 20 21 import ( 22 "context" 23 json "encoding/json" 24 "fmt" 25 "time" 26 27 v1 "k8s.io/api/apps/v1" 28 autoscalingv1 "k8s.io/api/autoscaling/v1" 29 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 30 types "k8s.io/apimachinery/pkg/types" 31 watch "k8s.io/apimachinery/pkg/watch" 32 appsv1 "k8s.io/client-go/applyconfigurations/apps/v1" 33 applyconfigurationsautoscalingv1 "k8s.io/client-go/applyconfigurations/autoscaling/v1" 34 scheme "k8s.io/client-go/kubernetes/scheme" 35 rest "k8s.io/client-go/rest" 36 ) 37 38 // StatefulSetsGetter has a method to return a StatefulSetInterface. 39 // A group's client should implement this interface. 40 type StatefulSetsGetter interface { 41 StatefulSets(namespace string) StatefulSetInterface 42 } 43 44 // StatefulSetInterface has methods to work with StatefulSet resources. 45 type StatefulSetInterface interface { 46 Create(ctx context.Context, statefulSet *v1.StatefulSet, opts metav1.CreateOptions) (*v1.StatefulSet, error) 47 Update(ctx context.Context, statefulSet *v1.StatefulSet, opts metav1.UpdateOptions) (*v1.StatefulSet, error) 48 UpdateStatus(ctx context.Context, statefulSet *v1.StatefulSet, opts metav1.UpdateOptions) (*v1.StatefulSet, error) 49 Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error 50 DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error 51 Get(ctx context.Context, name string, opts metav1.GetOptions) (*v1.StatefulSet, error) 52 List(ctx context.Context, opts metav1.ListOptions) (*v1.StatefulSetList, error) 53 Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) 54 Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.StatefulSet, err error) 55 Apply(ctx context.Context, statefulSet *appsv1.StatefulSetApplyConfiguration, opts metav1.ApplyOptions) (result *v1.StatefulSet, err error) 56 ApplyStatus(ctx context.Context, statefulSet *appsv1.StatefulSetApplyConfiguration, opts metav1.ApplyOptions) (result *v1.StatefulSet, err error) 57 GetScale(ctx context.Context, statefulSetName string, options metav1.GetOptions) (*autoscalingv1.Scale, error) 58 UpdateScale(ctx context.Context, statefulSetName string, scale *autoscalingv1.Scale, opts metav1.UpdateOptions) (*autoscalingv1.Scale, error) 59 ApplyScale(ctx context.Context, statefulSetName string, scale *applyconfigurationsautoscalingv1.ScaleApplyConfiguration, opts metav1.ApplyOptions) (*autoscalingv1.Scale, error) 60 61 StatefulSetExpansion 62 } 63 64 // statefulSets implements StatefulSetInterface 65 type statefulSets struct { 66 client rest.Interface 67 ns string 68 } 69 70 // newStatefulSets returns a StatefulSets 71 func newStatefulSets(c *AppsV1Client, namespace string) *statefulSets { 72 return &statefulSets{ 73 client: c.RESTClient(), 74 ns: namespace, 75 } 76 } 77 78 // Get takes name of the statefulSet, and returns the corresponding statefulSet object, and an error if there is any. 79 func (c *statefulSets) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.StatefulSet, err error) { 80 result = &v1.StatefulSet{} 81 err = c.client.Get(). 82 Namespace(c.ns). 83 Resource("statefulsets"). 84 Name(name). 85 VersionedParams(&options, scheme.ParameterCodec). 86 Do(ctx). 87 Into(result) 88 return 89 } 90 91 // List takes label and field selectors, and returns the list of StatefulSets that match those selectors. 92 func (c *statefulSets) List(ctx context.Context, opts metav1.ListOptions) (result *v1.StatefulSetList, err error) { 93 var timeout time.Duration 94 if opts.TimeoutSeconds != nil { 95 timeout = time.Duration(*opts.TimeoutSeconds) * time.Second 96 } 97 result = &v1.StatefulSetList{} 98 err = c.client.Get(). 99 Namespace(c.ns). 100 Resource("statefulsets"). 101 VersionedParams(&opts, scheme.ParameterCodec). 102 Timeout(timeout). 103 Do(ctx). 104 Into(result) 105 return 106 } 107 108 // Watch returns a watch.Interface that watches the requested statefulSets. 109 func (c *statefulSets) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { 110 var timeout time.Duration 111 if opts.TimeoutSeconds != nil { 112 timeout = time.Duration(*opts.TimeoutSeconds) * time.Second 113 } 114 opts.Watch = true 115 return c.client.Get(). 116 Namespace(c.ns). 117 Resource("statefulsets"). 118 VersionedParams(&opts, scheme.ParameterCodec). 119 Timeout(timeout). 120 Watch(ctx) 121 } 122 123 // Create takes the representation of a statefulSet and creates it. Returns the server's representation of the statefulSet, and an error, if there is any. 124 func (c *statefulSets) Create(ctx context.Context, statefulSet *v1.StatefulSet, opts metav1.CreateOptions) (result *v1.StatefulSet, err error) { 125 result = &v1.StatefulSet{} 126 err = c.client.Post(). 127 Namespace(c.ns). 128 Resource("statefulsets"). 129 VersionedParams(&opts, scheme.ParameterCodec). 130 Body(statefulSet). 131 Do(ctx). 132 Into(result) 133 return 134 } 135 136 // Update takes the representation of a statefulSet and updates it. Returns the server's representation of the statefulSet, and an error, if there is any. 137 func (c *statefulSets) Update(ctx context.Context, statefulSet *v1.StatefulSet, opts metav1.UpdateOptions) (result *v1.StatefulSet, err error) { 138 result = &v1.StatefulSet{} 139 err = c.client.Put(). 140 Namespace(c.ns). 141 Resource("statefulsets"). 142 Name(statefulSet.Name). 143 VersionedParams(&opts, scheme.ParameterCodec). 144 Body(statefulSet). 145 Do(ctx). 146 Into(result) 147 return 148 } 149 150 // UpdateStatus was generated because the type contains a Status member. 151 // Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). 152 func (c *statefulSets) UpdateStatus(ctx context.Context, statefulSet *v1.StatefulSet, opts metav1.UpdateOptions) (result *v1.StatefulSet, err error) { 153 result = &v1.StatefulSet{} 154 err = c.client.Put(). 155 Namespace(c.ns). 156 Resource("statefulsets"). 157 Name(statefulSet.Name). 158 SubResource("status"). 159 VersionedParams(&opts, scheme.ParameterCodec). 160 Body(statefulSet). 161 Do(ctx). 162 Into(result) 163 return 164 } 165 166 // Delete takes name of the statefulSet and deletes it. Returns an error if one occurs. 167 func (c *statefulSets) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { 168 return c.client.Delete(). 169 Namespace(c.ns). 170 Resource("statefulsets"). 171 Name(name). 172 Body(&opts). 173 Do(ctx). 174 Error() 175 } 176 177 // DeleteCollection deletes a collection of objects. 178 func (c *statefulSets) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { 179 var timeout time.Duration 180 if listOpts.TimeoutSeconds != nil { 181 timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second 182 } 183 return c.client.Delete(). 184 Namespace(c.ns). 185 Resource("statefulsets"). 186 VersionedParams(&listOpts, scheme.ParameterCodec). 187 Timeout(timeout). 188 Body(&opts). 189 Do(ctx). 190 Error() 191 } 192 193 // Patch applies the patch and returns the patched statefulSet. 194 func (c *statefulSets) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.StatefulSet, err error) { 195 result = &v1.StatefulSet{} 196 err = c.client.Patch(pt). 197 Namespace(c.ns). 198 Resource("statefulsets"). 199 Name(name). 200 SubResource(subresources...). 201 VersionedParams(&opts, scheme.ParameterCodec). 202 Body(data). 203 Do(ctx). 204 Into(result) 205 return 206 } 207 208 // Apply takes the given apply declarative configuration, applies it and returns the applied statefulSet. 209 func (c *statefulSets) Apply(ctx context.Context, statefulSet *appsv1.StatefulSetApplyConfiguration, opts metav1.ApplyOptions) (result *v1.StatefulSet, err error) { 210 if statefulSet == nil { 211 return nil, fmt.Errorf("statefulSet provided to Apply must not be nil") 212 } 213 patchOpts := opts.ToPatchOptions() 214 data, err := json.Marshal(statefulSet) 215 if err != nil { 216 return nil, err 217 } 218 name := statefulSet.Name 219 if name == nil { 220 return nil, fmt.Errorf("statefulSet.Name must be provided to Apply") 221 } 222 result = &v1.StatefulSet{} 223 err = c.client.Patch(types.ApplyPatchType). 224 Namespace(c.ns). 225 Resource("statefulsets"). 226 Name(*name). 227 VersionedParams(&patchOpts, scheme.ParameterCodec). 228 Body(data). 229 Do(ctx). 230 Into(result) 231 return 232 } 233 234 // ApplyStatus was generated because the type contains a Status member. 235 // Add a +genclient:noStatus comment above the type to avoid generating ApplyStatus(). 236 func (c *statefulSets) ApplyStatus(ctx context.Context, statefulSet *appsv1.StatefulSetApplyConfiguration, opts metav1.ApplyOptions) (result *v1.StatefulSet, err error) { 237 if statefulSet == nil { 238 return nil, fmt.Errorf("statefulSet provided to Apply must not be nil") 239 } 240 patchOpts := opts.ToPatchOptions() 241 data, err := json.Marshal(statefulSet) 242 if err != nil { 243 return nil, err 244 } 245 246 name := statefulSet.Name 247 if name == nil { 248 return nil, fmt.Errorf("statefulSet.Name must be provided to Apply") 249 } 250 251 result = &v1.StatefulSet{} 252 err = c.client.Patch(types.ApplyPatchType). 253 Namespace(c.ns). 254 Resource("statefulsets"). 255 Name(*name). 256 SubResource("status"). 257 VersionedParams(&patchOpts, scheme.ParameterCodec). 258 Body(data). 259 Do(ctx). 260 Into(result) 261 return 262 } 263 264 // GetScale takes name of the statefulSet, and returns the corresponding autoscalingv1.Scale object, and an error if there is any. 265 func (c *statefulSets) GetScale(ctx context.Context, statefulSetName string, options metav1.GetOptions) (result *autoscalingv1.Scale, err error) { 266 result = &autoscalingv1.Scale{} 267 err = c.client.Get(). 268 Namespace(c.ns). 269 Resource("statefulsets"). 270 Name(statefulSetName). 271 SubResource("scale"). 272 VersionedParams(&options, scheme.ParameterCodec). 273 Do(ctx). 274 Into(result) 275 return 276 } 277 278 // UpdateScale takes the top resource name and the representation of a scale and updates it. Returns the server's representation of the scale, and an error, if there is any. 279 func (c *statefulSets) UpdateScale(ctx context.Context, statefulSetName string, scale *autoscalingv1.Scale, opts metav1.UpdateOptions) (result *autoscalingv1.Scale, err error) { 280 result = &autoscalingv1.Scale{} 281 err = c.client.Put(). 282 Namespace(c.ns). 283 Resource("statefulsets"). 284 Name(statefulSetName). 285 SubResource("scale"). 286 VersionedParams(&opts, scheme.ParameterCodec). 287 Body(scale). 288 Do(ctx). 289 Into(result) 290 return 291 } 292 293 // ApplyScale takes top resource name and the apply declarative configuration for scale, 294 // applies it and returns the applied scale, and an error, if there is any. 295 func (c *statefulSets) ApplyScale(ctx context.Context, statefulSetName string, scale *applyconfigurationsautoscalingv1.ScaleApplyConfiguration, opts metav1.ApplyOptions) (result *autoscalingv1.Scale, err error) { 296 if scale == nil { 297 return nil, fmt.Errorf("scale provided to ApplyScale must not be nil") 298 } 299 patchOpts := opts.ToPatchOptions() 300 data, err := json.Marshal(scale) 301 if err != nil { 302 return nil, err 303 } 304 305 result = &autoscalingv1.Scale{} 306 err = c.client.Patch(types.ApplyPatchType). 307 Namespace(c.ns). 308 Resource("statefulsets"). 309 Name(statefulSetName). 310 SubResource("scale"). 311 VersionedParams(&patchOpts, scheme.ParameterCodec). 312 Body(data). 313 Do(ctx). 314 Into(result) 315 return 316 }