diff --git a/.golangci.yaml b/.golangci.yaml index b307bfe57..4a55daca8 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -131,6 +131,8 @@ linters-settings: pkg: k8s.io/api/storage/v1 - alias: meta pkg: k8s.io/apimachinery/pkg/apis/meta/v1 + - alias: autoscaling + pkg: k8s.io/api/autoscaling/v1 - alias: typedCore pkg: k8s.io/client-go/kubernetes/typed/core/v1 - alias: ugrpc diff --git a/CHANGELOG.md b/CHANGELOG.md index aef9ff628..907f12b23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ - (Feature) (Platform) Storage - (Maintenance) Extract GRPC Client Package - (Feature) (Platform) Chart +- (Feature) (Scheduler) Deployment Scale Functionality ## [1.2.43](https://github.com/arangodb/kube-arangodb/tree/1.2.43) (2024-10-14) - (Feature) ArangoRoute CRD diff --git a/chart/kube-arangodb-arm64/crds/scheduler-deployment.yaml b/chart/kube-arangodb-arm64/crds/scheduler-deployment.yaml index 0178e1c89..00464fb64 100644 --- a/chart/kube-arangodb-arm64/crds/scheduler-deployment.yaml +++ b/chart/kube-arangodb-arm64/crds/scheduler-deployment.yaml @@ -20,3 +20,6 @@ spec: storage: true subresources: status: {} + scale: + specReplicasPath: .spec.replicas + statusReplicasPath: .status.replicas diff --git a/chart/kube-arangodb-enterprise-arm64/crds/scheduler-deployment.yaml b/chart/kube-arangodb-enterprise-arm64/crds/scheduler-deployment.yaml index 0178e1c89..00464fb64 100644 --- a/chart/kube-arangodb-enterprise-arm64/crds/scheduler-deployment.yaml +++ b/chart/kube-arangodb-enterprise-arm64/crds/scheduler-deployment.yaml @@ -20,3 +20,6 @@ spec: storage: true subresources: status: {} + scale: + specReplicasPath: .spec.replicas + statusReplicasPath: .status.replicas diff --git a/chart/kube-arangodb-enterprise/crds/scheduler-deployment.yaml b/chart/kube-arangodb-enterprise/crds/scheduler-deployment.yaml index 0178e1c89..00464fb64 100644 --- a/chart/kube-arangodb-enterprise/crds/scheduler-deployment.yaml +++ b/chart/kube-arangodb-enterprise/crds/scheduler-deployment.yaml @@ -20,3 +20,6 @@ spec: storage: true subresources: status: {} + scale: + specReplicasPath: .spec.replicas + statusReplicasPath: .status.replicas diff --git a/chart/kube-arangodb/crds/scheduler-deployment.yaml b/chart/kube-arangodb/crds/scheduler-deployment.yaml index 0178e1c89..00464fb64 100644 --- a/chart/kube-arangodb/crds/scheduler-deployment.yaml +++ b/chart/kube-arangodb/crds/scheduler-deployment.yaml @@ -20,3 +20,6 @@ spec: storage: true subresources: status: {} + scale: + specReplicasPath: .spec.replicas + statusReplicasPath: .status.replicas diff --git a/pkg/apis/scheduler/v1beta1/types_deployment.go b/pkg/apis/scheduler/v1beta1/types_deployment.go index ea5ffb6c7..35d1470d7 100644 --- a/pkg/apis/scheduler/v1beta1/types_deployment.go +++ b/pkg/apis/scheduler/v1beta1/types_deployment.go @@ -38,6 +38,8 @@ type ArangoSchedulerDeploymentList struct { } // +genclient +// +genclient:method=GetScale,verb=get,subresource=scale,result=k8s.io/api/autoscaling/v1.Scale +// +genclient:method=UpdateScale,verb=update,subresource=scale,input=k8s.io/api/autoscaling/v1.Scale,result=k8s.io/api/autoscaling/v1.Scale // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // ArangoSchedulerDeployment wraps apps. ArangoSchedulerDeployment with profile details diff --git a/pkg/crd/crds/scheduler-deployment.yaml b/pkg/crd/crds/scheduler-deployment.yaml index 0178e1c89..00464fb64 100644 --- a/pkg/crd/crds/scheduler-deployment.yaml +++ b/pkg/crd/crds/scheduler-deployment.yaml @@ -20,3 +20,6 @@ spec: storage: true subresources: status: {} + scale: + specReplicasPath: .spec.replicas + statusReplicasPath: .status.replicas diff --git a/pkg/generated/clientset/versioned/typed/scheduler/v1beta1/arangoschedulerdeployment.go b/pkg/generated/clientset/versioned/typed/scheduler/v1beta1/arangoschedulerdeployment.go index a7becc2aa..702f30e9f 100644 --- a/pkg/generated/clientset/versioned/typed/scheduler/v1beta1/arangoschedulerdeployment.go +++ b/pkg/generated/clientset/versioned/typed/scheduler/v1beta1/arangoschedulerdeployment.go @@ -27,6 +27,7 @@ import ( v1beta1 "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1" scheme "github.com/arangodb/kube-arangodb/pkg/generated/clientset/versioned/scheme" + autoscalingv1 "k8s.io/api/autoscaling/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" watch "k8s.io/apimachinery/pkg/watch" @@ -51,6 +52,9 @@ type ArangoSchedulerDeploymentInterface interface { List(ctx context.Context, opts v1.ListOptions) (*v1beta1.ArangoSchedulerDeploymentList, error) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.ArangoSchedulerDeployment, err error) + GetScale(ctx context.Context, arangoSchedulerDeploymentName string, options v1.GetOptions) (*autoscalingv1.Scale, error) + UpdateScale(ctx context.Context, arangoSchedulerDeploymentName string, scale *autoscalingv1.Scale, opts v1.UpdateOptions) (*autoscalingv1.Scale, error) + ArangoSchedulerDeploymentExpansion } @@ -71,3 +75,32 @@ func newArangoSchedulerDeployments(c *SchedulerV1beta1Client, namespace string) func() *v1beta1.ArangoSchedulerDeploymentList { return &v1beta1.ArangoSchedulerDeploymentList{} }), } } + +// GetScale takes name of the arangoSchedulerDeployment, and returns the corresponding autoscalingv1.Scale object, and an error if there is any. +func (c *arangoSchedulerDeployments) GetScale(ctx context.Context, arangoSchedulerDeploymentName string, options v1.GetOptions) (result *autoscalingv1.Scale, err error) { + result = &autoscalingv1.Scale{} + err = c.GetClient().Get(). + Namespace(c.GetNamespace()). + Resource("arangoschedulerdeployments"). + Name(arangoSchedulerDeploymentName). + SubResource("scale"). + VersionedParams(&options, scheme.ParameterCodec). + Do(ctx). + Into(result) + return +} + +// 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. +func (c *arangoSchedulerDeployments) UpdateScale(ctx context.Context, arangoSchedulerDeploymentName string, scale *autoscalingv1.Scale, opts v1.UpdateOptions) (result *autoscalingv1.Scale, err error) { + result = &autoscalingv1.Scale{} + err = c.GetClient().Put(). + Namespace(c.GetNamespace()). + Resource("arangoschedulerdeployments"). + Name(arangoSchedulerDeploymentName). + SubResource("scale"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(scale). + Do(ctx). + Into(result) + return +} diff --git a/pkg/generated/clientset/versioned/typed/scheduler/v1beta1/fake/fake_arangoschedulerdeployment.go b/pkg/generated/clientset/versioned/typed/scheduler/v1beta1/fake/fake_arangoschedulerdeployment.go index 7a30183df..ba6d76840 100644 --- a/pkg/generated/clientset/versioned/typed/scheduler/v1beta1/fake/fake_arangoschedulerdeployment.go +++ b/pkg/generated/clientset/versioned/typed/scheduler/v1beta1/fake/fake_arangoschedulerdeployment.go @@ -26,6 +26,7 @@ import ( "context" v1beta1 "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1" + autoscalingv1 "k8s.io/api/autoscaling/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" labels "k8s.io/apimachinery/pkg/labels" types "k8s.io/apimachinery/pkg/types" @@ -149,3 +150,27 @@ func (c *FakeArangoSchedulerDeployments) Patch(ctx context.Context, name string, } return obj.(*v1beta1.ArangoSchedulerDeployment), err } + +// GetScale takes name of the arangoSchedulerDeployment, and returns the corresponding scale object, and an error if there is any. +func (c *FakeArangoSchedulerDeployments) GetScale(ctx context.Context, arangoSchedulerDeploymentName string, options v1.GetOptions) (result *autoscalingv1.Scale, err error) { + emptyResult := &autoscalingv1.Scale{} + obj, err := c.Fake. + Invokes(testing.NewGetSubresourceActionWithOptions(arangoschedulerdeploymentsResource, c.ns, "scale", arangoSchedulerDeploymentName, options), emptyResult) + + if obj == nil { + return emptyResult, err + } + return obj.(*autoscalingv1.Scale), err +} + +// UpdateScale takes the representation of a scale and updates it. Returns the server's representation of the scale, and an error, if there is any. +func (c *FakeArangoSchedulerDeployments) UpdateScale(ctx context.Context, arangoSchedulerDeploymentName string, scale *autoscalingv1.Scale, opts v1.UpdateOptions) (result *autoscalingv1.Scale, err error) { + emptyResult := &autoscalingv1.Scale{} + obj, err := c.Fake. + Invokes(testing.NewUpdateSubresourceActionWithOptions(arangoschedulerdeploymentsResource, "scale", c.ns, scale, opts), &autoscalingv1.Scale{}) + + if obj == nil { + return emptyResult, err + } + return obj.(*autoscalingv1.Scale), err +} diff --git a/pkg/util/k8sutil/inspector/generic/mod.go b/pkg/util/k8sutil/inspector/generic/mod.go index 93da1457d..fc5ff1158 100644 --- a/pkg/util/k8sutil/inspector/generic/mod.go +++ b/pkg/util/k8sutil/inspector/generic/mod.go @@ -23,6 +23,7 @@ package generic import ( "context" + autoscaling "k8s.io/api/autoscaling/v1" meta "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" ) @@ -61,6 +62,19 @@ type DeleteInterface[S meta.Object] interface { Delete(ctx context.Context, name string, opts meta.DeleteOptions) error } +type ScaleGet interface { + GetScale(ctx context.Context, name string, options meta.GetOptions) (*autoscaling.Scale, error) +} + +type ScaleUpdate interface { + UpdateScale(ctx context.Context, name string, scale *autoscaling.Scale, opts meta.UpdateOptions) (*autoscaling.Scale, error) +} + +type Scale interface { + ScaleGet + ScaleUpdate +} + type ReadClient[S meta.Object] interface { GetInterface[S] }