Skip to content

Commit 63f0cea

Browse files
cluster: support HPA for all cluster CRs storage
1 parent c988d06 commit 63f0cea

File tree

14 files changed

+2034
-6
lines changed

14 files changed

+2034
-6
lines changed

api/operator/v1/vlcluster_types.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,11 @@ type VLStorage struct {
526526
// ClaimTemplates allows adding additional VolumeClaimTemplates for StatefulSet
527527
ClaimTemplates []corev1.PersistentVolumeClaim `json:"claimTemplates,omitempty"`
528528

529+
// Configures horizontal pod autoscaling.
530+
// Note, downscaling is not supported.
531+
// +optional
532+
HPA *vmv1beta1.EmbeddedHPA `json:"hpa,omitempty"`
533+
529534
// StorageDataPath - path to storage data
530535
// +optional
531536
StorageDataPath string `json:"storageDataPath,omitempty"`
@@ -697,6 +702,9 @@ func (cr *VLCluster) Validate() error {
697702
if vls.ServiceSpec != nil && vls.ServiceSpec.Name == name {
698703
return fmt.Errorf(".serviceSpec.Name cannot be equal to prefixed name=%q", name)
699704
}
705+
if vls.HPA != nil && vls.HPA.Behaviour != nil && vls.HPA.Behaviour.ScaleDown != nil {
706+
return fmt.Errorf("vlstorage scaledown HPA behavior is not supported")
707+
}
700708
}
701709
if cr.Spec.RequestsLoadBalancer.Enabled {
702710
rlb := cr.Spec.RequestsLoadBalancer.Spec

api/operator/v1/vtcluster_types.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,11 @@ type VTStorage struct {
441441
// ClaimTemplates allows adding additional VolumeClaimTemplates for StatefulSet
442442
ClaimTemplates []corev1.PersistentVolumeClaim `json:"claimTemplates,omitempty"`
443443

444+
// Configures horizontal pod autoscaling.
445+
// Note, downscaling is not supported.
446+
// +optional
447+
HPA *vmv1beta1.EmbeddedHPA `json:"hpa,omitempty"`
448+
444449
// StorageDataPath - path to storage data
445450
// +optional
446451
StorageDataPath string `json:"storageDataPath,omitempty"`
@@ -612,6 +617,9 @@ func (cr *VTCluster) Validate() error {
612617
if vts.ServiceSpec != nil && vts.ServiceSpec.Name == name {
613618
return fmt.Errorf(".serviceSpec.Name cannot be equal to prefixed name=%q", name)
614619
}
620+
if vts.HPA != nil && vts.HPA.Behaviour != nil && vts.HPA.Behaviour.ScaleDown != nil {
621+
return fmt.Errorf("vtstorage scaledown HPA behavior is not supported")
622+
}
615623
}
616624
if cr.Spec.RequestsLoadBalancer.Enabled {
617625
rlb := cr.Spec.RequestsLoadBalancer.Spec

api/operator/v1/zz_generated.deepcopy.go

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/operator/v1beta1/vmcluster_types.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,11 @@ type VMStorage struct {
445445
// +optional
446446
PersistentVolumeClaimRetentionPolicy *appsv1.StatefulSetPersistentVolumeClaimRetentionPolicy `json:"persistentVolumeClaimRetentionPolicy,omitempty"`
447447

448+
// Configures horizontal pod autoscaling.
449+
// Note, downscaling is not supported.
450+
// +optional
451+
HPA *EmbeddedHPA `json:"hpa,omitempty"`
452+
448453
// VMInsertPort for VMInsert connections
449454
// +optional
450455
VMInsertPort string `json:"vmInsertPort,omitempty"`
@@ -670,6 +675,9 @@ func (cr *VMCluster) Validate() error {
670675
return fmt.Errorf("vmstorage: %w", err)
671676
}
672677
}
678+
if vms.HPA != nil && vms.HPA.Behaviour != nil && vms.HPA.Behaviour.ScaleDown != nil {
679+
return fmt.Errorf("vmstorage scaledown HPA behavior is not supported")
680+
}
673681
}
674682
if cr.Spec.RequestsLoadBalancer.Enabled {
675683
rlb := cr.Spec.RequestsLoadBalancer.Spec

api/operator/v1beta1/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/overlay/crd.yaml

Lines changed: 1893 additions & 0 deletions
Large diffs are not rendered by default.

docs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ aliases:
1515

1616
* FEATURE: [vmagent](https://docs.victoriametrics.com/operator/resources/vmagent/): support `namespace` parameter in `attach_metadata` section for all scrape configurations. See [#1654](https://github.com/VictoriaMetrics/operator/issues/1654).
1717
* FEATURE: [vlagent](https://docs.victoriametrics.com/operator/resources/vlagent): support logs collection. See [#1501](https://github.com/VictoriaMetrics/operator/issues/1501).
18+
* FEATURE: [vmoperator](https://docs.victoriametrics.com/operator/): added HPA support for all cluster CR storage. See [#1678](https://github.com/VictoriaMetrics/operator/issues/1678).
1819

1920
## [v0.66.1](https://github.com/VictoriaMetrics/operator/releases/tag/v0.66.1)
2021

docs/api.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,7 @@ Appears in: [VLClusterSpec](#vlclusterspec)
561561
| hostAliases<a href="#vlstorage-hostaliases" id="vlstorage-hostaliases">#</a><br/>_[HostAlias](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30/#hostalias-v1-core) array_ | _(Optional)_<br/>HostAliases provides mapping for ip and hostname,<br />that would be propagated to pod,<br />cannot be used with HostNetwork. |
562562
| hostNetwork<a href="#vlstorage-hostnetwork" id="vlstorage-hostnetwork">#</a><br/>_boolean_ | _(Optional)_<br/>HostNetwork controls whether the pod may use the node network namespace |
563563
| host_aliases<a href="#vlstorage-host_aliases" id="vlstorage-host_aliases">#</a><br/>_[HostAlias](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30/#hostalias-v1-core) array_ | _(Optional)_<br/>HostAliasesUnderScore provides mapping for ip and hostname,<br />that would be propagated to pod,<br />cannot be used with HostNetwork.<br />Has Priority over hostAliases field |
564+
| hpa<a href="#vlstorage-hpa" id="vlstorage-hpa">#</a><br/>_[EmbeddedHPA](#embeddedhpa)_ | _(Optional)_<br/>Configures horizontal pod autoscaling.<br />Note, downscaling is not supported. |
564565
| image<a href="#vlstorage-image" id="vlstorage-image">#</a><br/>_[Image](#image)_ | _(Optional)_<br/>Image - docker image settings<br />if no specified operator uses default version from operator config |
565566
| imagePullSecrets<a href="#vlstorage-imagepullsecrets" id="vlstorage-imagepullsecrets">#</a><br/>_[LocalObjectReference](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30/#localobjectreference-v1-core) array_ | _(Optional)_<br/>ImagePullSecrets An optional list of references to secrets in the same namespace<br />to use for pulling images from registries<br />see https://kubernetes.io/docs/concepts/containers/images/#referring-to-an-imagepullsecrets-on-a-pod |
566567
| initContainers<a href="#vlstorage-initcontainers" id="vlstorage-initcontainers">#</a><br/>_[Container](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30/#container-v1-core) array_ | _(Optional)_<br/>InitContainers allows adding initContainers to the pod definition.<br />Any errors during the execution of an initContainer will lead to a restart of the Pod.<br />More info: https://kubernetes.io/docs/concepts/workloads/pods/init-containers/ |
@@ -1094,6 +1095,7 @@ Appears in: [VTClusterSpec](#vtclusterspec)
10941095
| hostAliases<a href="#vtstorage-hostaliases" id="vtstorage-hostaliases">#</a><br/>_[HostAlias](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30/#hostalias-v1-core) array_ | _(Optional)_<br/>HostAliases provides mapping for ip and hostname,<br />that would be propagated to pod,<br />cannot be used with HostNetwork. |
10951096
| hostNetwork<a href="#vtstorage-hostnetwork" id="vtstorage-hostnetwork">#</a><br/>_boolean_ | _(Optional)_<br/>HostNetwork controls whether the pod may use the node network namespace |
10961097
| host_aliases<a href="#vtstorage-host_aliases" id="vtstorage-host_aliases">#</a><br/>_[HostAlias](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30/#hostalias-v1-core) array_ | _(Optional)_<br/>HostAliasesUnderScore provides mapping for ip and hostname,<br />that would be propagated to pod,<br />cannot be used with HostNetwork.<br />Has Priority over hostAliases field |
1098+
| hpa<a href="#vtstorage-hpa" id="vtstorage-hpa">#</a><br/>_[EmbeddedHPA](#embeddedhpa)_ | _(Optional)_<br/>Configures horizontal pod autoscaling.<br />Note, downscaling is not supported. |
10971099
| image<a href="#vtstorage-image" id="vtstorage-image">#</a><br/>_[Image](#image)_ | _(Optional)_<br/>Image - docker image settings<br />if no specified operator uses default version from operator config |
10981100
| imagePullSecrets<a href="#vtstorage-imagepullsecrets" id="vtstorage-imagepullsecrets">#</a><br/>_[LocalObjectReference](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30/#localobjectreference-v1-core) array_ | _(Optional)_<br/>ImagePullSecrets An optional list of references to secrets in the same namespace<br />to use for pulling images from registries<br />see https://kubernetes.io/docs/concepts/containers/images/#referring-to-an-imagepullsecrets-on-a-pod |
10991101
| initContainers<a href="#vtstorage-initcontainers" id="vtstorage-initcontainers">#</a><br/>_[Container](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30/#container-v1-core) array_ | _(Optional)_<br/>InitContainers allows adding initContainers to the pod definition.<br />Any errors during the execution of an initContainer will lead to a restart of the Pod.<br />More info: https://kubernetes.io/docs/concepts/workloads/pods/init-containers/ |
@@ -1718,7 +1720,7 @@ Appears in: [Receiver](#receiver)
17181720
EmbeddedHPA embeds HorizontalPodAutoScaler spec v2.
17191721
https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/horizontal-pod-autoscaler-v2/
17201722

1721-
Appears in: [VLInsert](#vlinsert), [VLSelect](#vlselect), [VMAuthSpec](#vmauthspec), [VMInsert](#vminsert), [VMSelect](#vmselect), [VTInsert](#vtinsert), [VTSelect](#vtselect)
1723+
Appears in: [VLInsert](#vlinsert), [VLSelect](#vlselect), [VLStorage](#vlstorage), [VMAuthSpec](#vmauthspec), [VMInsert](#vminsert), [VMSelect](#vmselect), [VMStorage](#vmstorage), [VTInsert](#vtinsert), [VTSelect](#vtselect), [VTStorage](#vtstorage)
17221724

17231725
| Field | Description |
17241726
| --- | --- |
@@ -4826,6 +4828,7 @@ Appears in: [VMClusterSpec](#vmclusterspec)
48264828
| hostAliases<a href="#vmstorage-hostaliases" id="vmstorage-hostaliases">#</a><br/>_[HostAlias](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30/#hostalias-v1-core) array_ | _(Optional)_<br/>HostAliases provides mapping for ip and hostname,<br />that would be propagated to pod,<br />cannot be used with HostNetwork. |
48274829
| hostNetwork<a href="#vmstorage-hostnetwork" id="vmstorage-hostnetwork">#</a><br/>_boolean_ | _(Optional)_<br/>HostNetwork controls whether the pod may use the node network namespace |
48284830
| host_aliases<a href="#vmstorage-host_aliases" id="vmstorage-host_aliases">#</a><br/>_[HostAlias](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30/#hostalias-v1-core) array_ | _(Optional)_<br/>HostAliasesUnderScore provides mapping for ip and hostname,<br />that would be propagated to pod,<br />cannot be used with HostNetwork.<br />Has Priority over hostAliases field |
4831+
| hpa<a href="#vmstorage-hpa" id="vmstorage-hpa">#</a><br/>_[EmbeddedHPA](#embeddedhpa)_ | _(Optional)_<br/>Configures horizontal pod autoscaling.<br />Note, downscaling is not supported. |
48294832
| image<a href="#vmstorage-image" id="vmstorage-image">#</a><br/>_[Image](#image)_ | _(Optional)_<br/>Image - docker image settings<br />if no specified operator uses default version from operator config |
48304833
| imagePullSecrets<a href="#vmstorage-imagepullsecrets" id="vmstorage-imagepullsecrets">#</a><br/>_[LocalObjectReference](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30/#localobjectreference-v1-core) array_ | _(Optional)_<br/>ImagePullSecrets An optional list of references to secrets in the same namespace<br />to use for pulling images from registries<br />see https://kubernetes.io/docs/concepts/containers/images/#referring-to-an-imagepullsecrets-on-a-pod |
48314834
| initContainers<a href="#vmstorage-initcontainers" id="vmstorage-initcontainers">#</a><br/>_[Container](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30/#container-v1-core) array_ | _(Optional)_<br/>InitContainers allows adding initContainers to the pod definition.<br />Any errors during the execution of an initContainer will lead to a restart of the Pod.<br />More info: https://kubernetes.io/docs/concepts/workloads/pods/init-containers/ |

internal/controller/operator/factory/finalize/cluster.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ func OnStorageDelete(ctx context.Context, rclient client.Client, cr build.Parent
106106
objsToRemove := []client.Object{
107107
&appsv1.StatefulSet{ObjectMeta: objMeta},
108108
&policyv1.PodDisruptionBudget{ObjectMeta: objMeta},
109+
&autoscalingv2.HorizontalPodAutoscaler{ObjectMeta: objMeta},
109110
&vmv1beta1.VMServiceScrape{ObjectMeta: objMeta},
110111
}
111112
owner := cr.AsOwner()

internal/controller/operator/factory/vlcluster/vlcluster.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ func deleteOrphaned(ctx context.Context, rclient client.Client, cr *vmv1.VLClust
8282
if newStorage.PodDisruptionBudget != nil {
8383
cc.KeepPDB(commonName)
8484
}
85+
if newStorage.HPA != nil {
86+
cc.KeepHPA(commonName)
87+
}
8588
if !ptr.Deref(newStorage.DisableSelfServiceScrape, disableSelfScrape) {
8689
cc.KeepScrape(commonName)
8790
}

0 commit comments

Comments
 (0)