From 2a0dea306345496171cb5447ec9946873a591a2e Mon Sep 17 00:00:00 2001 From: Marco Voelz Date: Wed, 7 Sep 2022 10:50:31 +0200 Subject: [PATCH 1/3] Add EvictionRequirements to types --- .../pkg/apis/autoscaling.k8s.io/v1/types.go | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1/types.go b/vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1/types.go index 0bc2e60f8806..4fc0255de144 100644 --- a/vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1/types.go +++ b/vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1/types.go @@ -106,6 +106,27 @@ type VerticalPodAutoscalerSpec struct { Recommenders []*VerticalPodAutoscalerRecommenderSelector `json:"recommenders,omitempty" protobuf:"bytes,4,opt,name=recommenders"` } +// EvictionChangeRequirement refers to the relationship between the new target recommendation for a Pod and its current requests, what kind of change is necessary for the Pod to be evicted +// +kubebuilder:validation:Enum:=TargetHigherThanRequests;TargetLowerThanRequests +type EvictionChangeRequirement string + +const ( + // TargetHigherThanRequests means the new target recommendation for a Pod is higher than its current requests, i.e. the Pod is scaled up + TargetHigherThanRequests EvictionChangeRequirement = "TargetHigherThanRequests" + // TargetLowerThanRequests means the new target recommendation for a Pod is lower than its current requests, i.e. the Pod is scaled down + TargetLowerThanRequests EvictionChangeRequirement = "TargetLowerThanRequests" +) + +// EvictionRequirement defines a single condition which needs to be true in +// order to evict a Pod +type EvictionRequirement struct { + // Resources is a list of one or more resources that the condition applies + // to. If more than one resource is given, they are combined with OR, not + // with AND. + Resources []v1.ResourceName `json:"resource" protobuf:"bytes,1,name=resources"` + ChangeRequirement EvictionChangeRequirement `json:"changeRequirement" protobuf:"bytes,2,name=changeRequirement"` +} + // PodUpdatePolicy describes the rules on how changes are applied to the pods. type PodUpdatePolicy struct { // Controls when autoscaler applies changes to the pod resources. @@ -118,6 +139,12 @@ type PodUpdatePolicy struct { // allowed. Overrides global '--min-replicas' flag. // +optional MinReplicas *int32 `json:"minReplicas,omitempty" protobuf:"varint,2,opt,name=minReplicas"` + + // EvictionRequirements is a list of EvictionRequirements that need to + // evaluate to true in order for a Pod to be evicted. If more than one + // EvictionRequirement is specified, they are combined with AND. + // +optional + EvictionRequirements []*EvictionRequirement `json:"evictionRequirements,omitempty" protobuf:"bytes,3,opt,name=evictionRequirements"` } // UpdateMode controls when autoscaler applies changes to the pod resources. From 1b35940d4b5cc10d31fdaf232fda8a54f4dacd85 Mon Sep 17 00:00:00 2001 From: Marco Voelz Date: Wed, 15 Mar 2023 10:19:14 +0100 Subject: [PATCH 2/3] Run `generate-crd-yaml.sh` --- .../deploy/vpa-v1-crd-gen.yaml | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/vertical-pod-autoscaler/deploy/vpa-v1-crd-gen.yaml b/vertical-pod-autoscaler/deploy/vpa-v1-crd-gen.yaml index 2442af6db54a..5ea6e7bcd83a 100644 --- a/vertical-pod-autoscaler/deploy/vpa-v1-crd-gen.yaml +++ b/vertical-pod-autoscaler/deploy/vpa-v1-crd-gen.yaml @@ -364,7 +364,7 @@ spec: description: API version of the referent type: string kind: - description: 'Kind of the referent; More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds"' + description: 'Kind of the referent; More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' type: string name: description: 'Name of the referent; More info: http://kubernetes.io/docs/user-guide/identifiers#names' @@ -379,6 +379,38 @@ spec: pods. If not specified, all fields in the `PodUpdatePolicy` are set to their default values. properties: + evictionRequirements: + description: EvictionRequirements is a list of EvictionRequirements + that need to evaluate to true in order for a Pod to be evicted. + If more than one EvictionRequirement is specified, they are + combined with AND. + items: + description: EvictionRequirement defines a single condition + which needs to be true in order to evict a Pod + properties: + changeRequirement: + description: EvictionChangeRequirement refers to the relationship + between the new target recommendation for a Pod and its + current requests, what kind of change is necessary for + the Pod to be evicted + enum: + - TargetHigherThanRequests + - TargetLowerThanRequests + type: string + resource: + description: Resources is a list of one or more resources + that the condition applies to. If more than one resource + is given, they are combined with OR, not with AND. + items: + description: ResourceName is the name identifying various + resources in a ResourceList. + type: string + type: array + required: + - changeRequirement + - resource + type: object + type: array minReplicas: description: Minimal number of replicas which need to be alive for Updater to attempt pod eviction (pending other checks like @@ -607,7 +639,7 @@ spec: description: API version of the referent type: string kind: - description: 'Kind of the referent; More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds"' + description: 'Kind of the referent; More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' type: string name: description: 'Name of the referent; More info: http://kubernetes.io/docs/user-guide/identifiers#names' From 5d7d337ce07d84d3e7d31f21a4582e933378c444 Mon Sep 17 00:00:00 2001 From: Marco Voelz Date: Fri, 28 Jul 2023 09:42:40 +0200 Subject: [PATCH 3/3] Reword AND/OR combinations for more clarity --- vertical-pod-autoscaler/deploy/vpa-v1-crd-gen.yaml | 7 ++++--- .../pkg/apis/autoscaling.k8s.io/v1/types.go | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/vertical-pod-autoscaler/deploy/vpa-v1-crd-gen.yaml b/vertical-pod-autoscaler/deploy/vpa-v1-crd-gen.yaml index 5ea6e7bcd83a..93092ee1e1ee 100644 --- a/vertical-pod-autoscaler/deploy/vpa-v1-crd-gen.yaml +++ b/vertical-pod-autoscaler/deploy/vpa-v1-crd-gen.yaml @@ -382,8 +382,8 @@ spec: evictionRequirements: description: EvictionRequirements is a list of EvictionRequirements that need to evaluate to true in order for a Pod to be evicted. - If more than one EvictionRequirement is specified, they are - combined with AND. + If more than one EvictionRequirement is specified, all of them + need to be fulfilled to allow eviction. items: description: EvictionRequirement defines a single condition which needs to be true in order to evict a Pod @@ -400,7 +400,8 @@ spec: resource: description: Resources is a list of one or more resources that the condition applies to. If more than one resource - is given, they are combined with OR, not with AND. + is given, the EvictionRequirement is fulfilled if at least + one resource meets `changeRequirement`. items: description: ResourceName is the name identifying various resources in a ResourceList. diff --git a/vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1/types.go b/vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1/types.go index 4fc0255de144..575394df724a 100644 --- a/vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1/types.go +++ b/vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1/types.go @@ -121,8 +121,8 @@ const ( // order to evict a Pod type EvictionRequirement struct { // Resources is a list of one or more resources that the condition applies - // to. If more than one resource is given, they are combined with OR, not - // with AND. + // to. If more than one resource is given, the EvictionRequirement is fulfilled + // if at least one resource meets `changeRequirement`. Resources []v1.ResourceName `json:"resource" protobuf:"bytes,1,name=resources"` ChangeRequirement EvictionChangeRequirement `json:"changeRequirement" protobuf:"bytes,2,name=changeRequirement"` } @@ -142,7 +142,7 @@ type PodUpdatePolicy struct { // EvictionRequirements is a list of EvictionRequirements that need to // evaluate to true in order for a Pod to be evicted. If more than one - // EvictionRequirement is specified, they are combined with AND. + // EvictionRequirement is specified, all of them need to be fulfilled to allow eviction. // +optional EvictionRequirements []*EvictionRequirement `json:"evictionRequirements,omitempty" protobuf:"bytes,3,opt,name=evictionRequirements"` }