| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
package v1 |
| 20 |
|
| 21 |
import ( |
| 22 |
context "context" |
| 23 |
fmt "fmt" |
| 24 |
|
| 25 |
appsv1 "k8s.io/api/apps/v1" |
| 26 |
autoscalingv1 "k8s.io/api/autoscaling/v1" |
| 27 |
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 28 |
types "k8s.io/apimachinery/pkg/types" |
| 29 |
watch "k8s.io/apimachinery/pkg/watch" |
| 30 |
applyconfigurationsappsv1 "k8s.io/client-go/applyconfigurations/apps/v1" |
| 31 |
applyconfigurationsautoscalingv1 "k8s.io/client-go/applyconfigurations/autoscaling/v1" |
| 32 |
gentype "k8s.io/client-go/gentype" |
| 33 |
scheme "k8s.io/client-go/kubernetes/scheme" |
| 34 |
apply "k8s.io/client-go/util/apply" |
| 35 |
) |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
type DeploymentsGetter interface { |
| 40 |
Deployments(namespace string) DeploymentInterface |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
type DeploymentInterface interface { |
| 45 |
Create(ctx context.Context, deployment *appsv1.Deployment, opts metav1.CreateOptions) (*appsv1.Deployment, error) |
| 46 |
Update(ctx context.Context, deployment *appsv1.Deployment, opts metav1.UpdateOptions) (*appsv1.Deployment, error) |
| 47 |
|
| 48 |
UpdateStatus(ctx context.Context, deployment *appsv1.Deployment, opts metav1.UpdateOptions) (*appsv1.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) (*appsv1.Deployment, error) |
| 52 |
List(ctx context.Context, opts metav1.ListOptions) (*appsv1.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 *appsv1.Deployment, err error) |
| 55 |
Apply(ctx context.Context, deployment *applyconfigurationsappsv1.DeploymentApplyConfiguration, opts metav1.ApplyOptions) (result *appsv1.Deployment, err error) |
| 56 |
|
| 57 |
ApplyStatus(ctx context.Context, deployment *applyconfigurationsappsv1.DeploymentApplyConfiguration, opts metav1.ApplyOptions) (result *appsv1.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 |
|
| 66 |
type deployments struct { |
| 67 |
*gentype.ClientWithListAndApply[*appsv1.Deployment, *appsv1.DeploymentList, *applyconfigurationsappsv1.DeploymentApplyConfiguration] |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
func newDeployments(c *AppsV1Client, namespace string) *deployments { |
| 72 |
return &deployments{ |
| 73 |
gentype.NewClientWithListAndApply[*appsv1.Deployment, *appsv1.DeploymentList, *applyconfigurationsappsv1.DeploymentApplyConfiguration]( |
| 74 |
"deployments", |
| 75 |
c.RESTClient(), |
| 76 |
scheme.ParameterCodec, |
| 77 |
namespace, |
| 78 |
func() *appsv1.Deployment { return &appsv1.Deployment{} }, |
| 79 |
func() *appsv1.DeploymentList { return &appsv1.DeploymentList{} }, |
| 80 |
gentype.PrefersProtobuf[*appsv1.Deployment](), |
| 81 |
), |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
func (c *deployments) GetScale(ctx context.Context, deploymentName string, options metav1.GetOptions) (result *autoscalingv1.Scale, err error) { |
| 87 |
result = &autoscalingv1.Scale{} |
| 88 |
err = c.GetClient().Get(). |
| 89 |
UseProtobufAsDefault(). |
| 90 |
Namespace(c.GetNamespace()). |
| 91 |
Resource("deployments"). |
| 92 |
Name(deploymentName). |
| 93 |
SubResource("scale"). |
| 94 |
VersionedParams(&options, scheme.ParameterCodec). |
| 95 |
Do(ctx). |
| 96 |
Into(result) |
| 97 |
return |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
func (c *deployments) UpdateScale(ctx context.Context, deploymentName string, scale *autoscalingv1.Scale, opts metav1.UpdateOptions) (result *autoscalingv1.Scale, err error) { |
| 102 |
result = &autoscalingv1.Scale{} |
| 103 |
err = c.GetClient().Put(). |
| 104 |
UseProtobufAsDefault(). |
| 105 |
Namespace(c.GetNamespace()). |
| 106 |
Resource("deployments"). |
| 107 |
Name(deploymentName). |
| 108 |
SubResource("scale"). |
| 109 |
VersionedParams(&opts, scheme.ParameterCodec). |
| 110 |
Body(scale). |
| 111 |
Do(ctx). |
| 112 |
Into(result) |
| 113 |
return |
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
func (c *deployments) ApplyScale(ctx context.Context, deploymentName string, scale *applyconfigurationsautoscalingv1.ScaleApplyConfiguration, opts metav1.ApplyOptions) (result *autoscalingv1.Scale, err error) { |
| 119 |
if scale == nil { |
| 120 |
return nil, fmt.Errorf("scale provided to ApplyScale must not be nil") |
| 121 |
} |
| 122 |
patchOpts := opts.ToPatchOptions() |
| 123 |
request, err := apply.NewRequest(c.GetClient(), scale) |
| 124 |
if err != nil { |
| 125 |
return nil, err |
| 126 |
} |
| 127 |
|
| 128 |
result = &autoscalingv1.Scale{} |
| 129 |
err = request. |
| 130 |
UseProtobufAsDefault(). |
| 131 |
Namespace(c.GetNamespace()). |
| 132 |
Resource("deployments"). |
| 133 |
Name(deploymentName). |
| 134 |
SubResource("scale"). |
| 135 |
VersionedParams(&patchOpts, scheme.ParameterCodec). |
| 136 |
Do(ctx). |
| 137 |
Into(result) |
| 138 |
return |
| 139 |
} |