k8s.io/client-go@v0.31.1/kubernetes/typed/apps/v1/deployment.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  
    26  	v1 "k8s.io/api/apps/v1"
    27  	autoscalingv1 "k8s.io/api/autoscaling/v1"
    28  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    29  	types "k8s.io/apimachinery/pkg/types"
    30  	watch "k8s.io/apimachinery/pkg/watch"
    31  	appsv1 "k8s.io/client-go/applyconfigurations/apps/v1"
    32  	applyconfigurationsautoscalingv1 "k8s.io/client-go/applyconfigurations/autoscaling/v1"
    33  	gentype "k8s.io/client-go/gentype"
    34  	scheme "k8s.io/client-go/kubernetes/scheme"
    35  )
    36  
    37  // DeploymentsGetter has a method to return a DeploymentInterface.
    38  // A group's client should implement this interface.
    39  type DeploymentsGetter interface {
    40  	Deployments(namespace string) DeploymentInterface
    41  }
    42  
    43  // DeploymentInterface has methods to work with Deployment resources.
    44  type DeploymentInterface interface {
    45  	Create(ctx context.Context, deployment *v1.Deployment, opts metav1.CreateOptions) (*v1.Deployment, error)
    46  	Update(ctx context.Context, deployment *v1.Deployment, opts metav1.UpdateOptions) (*v1.Deployment, error)
    47  	// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus().
    48  	UpdateStatus(ctx context.Context, deployment *v1.Deployment, opts metav1.UpdateOptions) (*v1.Deployment, 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.Deployment, error)
    52  	List(ctx context.Context, opts metav1.ListOptions) (*v1.DeploymentList, 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.Deployment, err error)
    55  	Apply(ctx context.Context, deployment *appsv1.DeploymentApplyConfiguration, opts metav1.ApplyOptions) (result *v1.Deployment, err error)
    56  	// Add a +genclient:noStatus comment above the type to avoid generating ApplyStatus().
    57  	ApplyStatus(ctx context.Context, deployment *appsv1.DeploymentApplyConfiguration, opts metav1.ApplyOptions) (result *v1.Deployment, err error)
    58  	GetScale(ctx context.Context, deploymentName string, options metav1.GetOptions) (*autoscalingv1.Scale, error)
    59  	UpdateScale(ctx context.Context, deploymentName string, scale *autoscalingv1.Scale, opts metav1.UpdateOptions) (*autoscalingv1.Scale, error)
    60  	ApplyScale(ctx context.Context, deploymentName string, scale *applyconfigurationsautoscalingv1.ScaleApplyConfiguration, opts metav1.ApplyOptions) (*autoscalingv1.Scale, error)
    61  
    62  	DeploymentExpansion
    63  }
    64  
    65  // deployments implements DeploymentInterface
    66  type deployments struct {
    67  	*gentype.ClientWithListAndApply[*v1.Deployment, *v1.DeploymentList, *appsv1.DeploymentApplyConfiguration]
    68  }
    69  
    70  // newDeployments returns a Deployments
    71  func newDeployments(c *AppsV1Client, namespace string) *deployments {
    72  	return &deployments{
    73  		gentype.NewClientWithListAndApply[*v1.Deployment, *v1.DeploymentList, *appsv1.DeploymentApplyConfiguration](
    74  			"deployments",
    75  			c.RESTClient(),
    76  			scheme.ParameterCodec,
    77  			namespace,
    78  			func() *v1.Deployment { return &v1.Deployment{} },
    79  			func() *v1.DeploymentList { return &v1.DeploymentList{} }),
    80  	}
    81  }
    82  
    83  // GetScale takes name of the deployment, and returns the corresponding autoscalingv1.Scale object, and an error if there is any.
    84  func (c *deployments) GetScale(ctx context.Context, deploymentName string, options metav1.GetOptions) (result *autoscalingv1.Scale, err error) {
    85  	result = &autoscalingv1.Scale{}
    86  	err = c.GetClient().Get().
    87  		Namespace(c.GetNamespace()).
    88  		Resource("deployments").
    89  		Name(deploymentName).
    90  		SubResource("scale").
    91  		VersionedParams(&options, scheme.ParameterCodec).
    92  		Do(ctx).
    93  		Into(result)
    94  	return
    95  }
    96  
    97  // 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.
    98  func (c *deployments) UpdateScale(ctx context.Context, deploymentName string, scale *autoscalingv1.Scale, opts metav1.UpdateOptions) (result *autoscalingv1.Scale, err error) {
    99  	result = &autoscalingv1.Scale{}
   100  	err = c.GetClient().Put().
   101  		Namespace(c.GetNamespace()).
   102  		Resource("deployments").
   103  		Name(deploymentName).
   104  		SubResource("scale").
   105  		VersionedParams(&opts, scheme.ParameterCodec).
   106  		Body(scale).
   107  		Do(ctx).
   108  		Into(result)
   109  	return
   110  }
   111  
   112  // ApplyScale takes top resource name and the apply declarative configuration for scale,
   113  // applies it and returns the applied scale, and an error, if there is any.
   114  func (c *deployments) ApplyScale(ctx context.Context, deploymentName string, scale *applyconfigurationsautoscalingv1.ScaleApplyConfiguration, opts metav1.ApplyOptions) (result *autoscalingv1.Scale, err error) {
   115  	if scale == nil {
   116  		return nil, fmt.Errorf("scale provided to ApplyScale must not be nil")
   117  	}
   118  	patchOpts := opts.ToPatchOptions()
   119  	data, err := json.Marshal(scale)
   120  	if err != nil {
   121  		return nil, err
   122  	}
   123  
   124  	result = &autoscalingv1.Scale{}
   125  	err = c.GetClient().Patch(types.ApplyPatchType).
   126  		Namespace(c.GetNamespace()).
   127  		Resource("deployments").
   128  		Name(deploymentName).
   129  		SubResource("scale").
   130  		VersionedParams(&patchOpts, scheme.ParameterCodec).
   131  		Body(data).
   132  		Do(ctx).
   133  		Into(result)
   134  	return
   135  }