Skip to content

Commit f8a1de6

Browse files
committed
add resource limit to pod
1 parent da9b09c commit f8a1de6

File tree

11 files changed

+125
-18
lines changed

11 files changed

+125
-18
lines changed

api/disaggregated/v1/types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ type ComputeGroup struct {
121121
// Default System Init means that the container must be started in privileged mode.
122122
// Default System Init configuration is implemented through the initContainers of the pod, so changes to this configuration may be ignored by k8s when it is not the first deployment.
123123
SkipDefaultSystemInit bool `json:"skipDefaultSystemInit,omitempty"`
124+
125+
// AutoResolveLimitCPU indicates whether to automatically set the CPU limit to doris BE config.
126+
// Default value is 'false'. This means that the Doris BE is unaware of the CPU configuration of resources.
127+
// Enabling this configuration means injecting an ENV named BE_CPU_LIMIT with the value requests.cpu into the pod. This configuration will also appear in the 'be.conf' file inside the BE container.
128+
// Changing this configuration will cause a BE rolling restart.
129+
AutoResolveLimitCPU bool `json:"autoResolveLimitCPU,omitempty"`
124130
}
125131

126132
type CommonSpec struct {

api/doris/v1/types.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import (
2323
)
2424

2525
var (
26-
AnnotationDebugKey = "selectdb.com.doris/runmode"
27-
AnnotationDebugValue = "debug"
26+
AnnotationDebugKey = "selectdb.com.doris/runmode"
27+
AnnotationDebugValue = "debug"
2828
AnnotationDebugDorisKey = "apache.com.doris/runmode"
2929
)
3030

@@ -129,6 +129,12 @@ type BeSpec struct {
129129
//EnableFeAffinity schedule the be pod on the hosts that have fe pod. when in test situation or have 3 fe and 3 be nodes, and wants one fe and one be in same host.
130130
//the weight of antiAffinity in same node is greater than this affinity.
131131
EnableFeAffinity bool `json:"enableFeAffinity,omitempty"`
132+
133+
// AutoResolveLimitCPU indicates whether to automatically set the CPU limit to doris BE config.
134+
// Default value is 'false'. This means that the Doris BE is unaware of the CPU configuration of resources.
135+
// Enabling this configuration means injecting an ENV named BE_CPU_LIMIT with the value requests.cpu into the pod. This configuration will also appear in the 'be.conf' file inside the BE container.
136+
// Changing this configuration will cause a BE rolling restart.
137+
AutoResolveLimitCPU bool `json:"autoResolveLimitCPU,omitempty"`
132138
}
133139

134140
// FeAddress specify the fe address, please set it when you deploy fe outside k8s or deploy components use crd except fe, if not set .
@@ -158,6 +164,12 @@ type CnSpec struct {
158164

159165
//AutoScalingPolicy auto scaling strategy
160166
AutoScalingPolicy *AutoScalingPolicy `json:"autoScalingPolicy,omitempty"`
167+
168+
// AutoResolveLimitCPU indicates whether to automatically set the CPU limit to doris BE config.
169+
// Default value is 'false'. This means that the Doris BE is unaware of the CPU configuration of resources.
170+
// Enabling this configuration means injecting an ENV named BE_CPU_LIMIT with the value requests.cpu into the pod. This configuration will also appear in the 'be.conf' file inside the BE container.
171+
// Changing this configuration will cause a BE rolling restart.
172+
AutoResolveLimitCPU bool `json:"autoResolveLimitCPU,omitempty"`
161173
}
162174

163175
// BrokerSpec describes a template for creating copies of a broker software service, if deploy broker we recommend you add affinity for deploy with be pod.

config/crd/bases/crds.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,13 @@ spec:
10081008
description: annotation for fe pods. user can config monitor annotation
10091009
for collect to monitor system.
10101010
type: object
1011+
autoResolveLimitCPU:
1012+
description: |-
1013+
AutoResolveLimitCPU indicates whether to automatically set the CPU limit to doris BE config.
1014+
Default value is 'false'. This means that the Doris BE is unaware of the CPU configuration of resources.
1015+
Enabling this configuration means injecting an ENV named BE_CPU_LIMIT with the value requests.cpu into the pod. This configuration will also appear in the 'be.conf' file inside the BE container.
1016+
Changing this configuration will cause a BE rolling restart.
1017+
type: boolean
10111018
claims:
10121019
description: |-
10131020
Claims lists the names of resources, defined in spec.resourceClaims,
@@ -5093,6 +5100,13 @@ spec:
50935100
description: annotation for fe pods. user can config monitor annotation
50945101
for collect to monitor system.
50955102
type: object
5103+
autoResolveLimitCPU:
5104+
description: |-
5105+
AutoResolveLimitCPU indicates whether to automatically set the CPU limit to doris BE config.
5106+
Default value is 'false'. This means that the Doris BE is unaware of the CPU configuration of resources.
5107+
Enabling this configuration means injecting an ENV named BE_CPU_LIMIT with the value requests.cpu into the pod. This configuration will also appear in the 'be.conf' file inside the BE container.
5108+
Changing this configuration will cause a BE rolling restart.
5109+
type: boolean
50965110
autoScalingPolicy:
50975111
description: AutoScalingPolicy auto scaling strategy
50985112
properties:
@@ -10146,6 +10160,13 @@ spec:
1014610160
Annotations is an unstructured key value map stored with a resource that may be
1014710161
set by external tools to store and retrieve arbitrary metadata.
1014810162
type: object
10163+
autoResolveLimitCPU:
10164+
description: |-
10165+
AutoResolveLimitCPU indicates whether to automatically set the CPU limit to doris BE config.
10166+
Default value is 'false'. This means that the Doris BE is unaware of the CPU configuration of resources.
10167+
Enabling this configuration means injecting an ENV named BE_CPU_LIMIT with the value requests.cpu into the pod. This configuration will also appear in the 'be.conf' file inside the BE container.
10168+
Changing this configuration will cause a BE rolling restart.
10169+
type: boolean
1014910170
claims:
1015010171
description: |-
1015110172
Claims lists the names of resources, defined in spec.resourceClaims,

config/crd/bases/disaggregated.cluster.doris.com_dorisdisaggregatedclusters.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,13 @@ spec:
10191019
Annotations is an unstructured key value map stored with a resource that may be
10201020
set by external tools to store and retrieve arbitrary metadata.
10211021
type: object
1022+
autoResolveLimitCPU:
1023+
description: |-
1024+
AutoResolveLimitCPU indicates whether to automatically set the CPU limit to doris BE config.
1025+
Default value is 'false'. This means that the Doris BE is unaware of the CPU configuration of resources.
1026+
Enabling this configuration means injecting an ENV named BE_CPU_LIMIT with the value requests.cpu into the pod. This configuration will also appear in the 'be.conf' file inside the BE container.
1027+
Changing this configuration will cause a BE rolling restart.
1028+
type: boolean
10221029
claims:
10231030
description: |-
10241031
Claims lists the names of resources, defined in spec.resourceClaims,

config/crd/bases/doris.apache.com_dorisclusters.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,13 @@ spec:
10081008
description: annotation for fe pods. user can config monitor annotation
10091009
for collect to monitor system.
10101010
type: object
1011+
autoResolveLimitCPU:
1012+
description: |-
1013+
AutoResolveLimitCPU indicates whether to automatically set the CPU limit to doris BE config.
1014+
Default value is 'false'. This means that the Doris BE is unaware of the CPU configuration of resources.
1015+
Enabling this configuration means injecting an ENV named BE_CPU_LIMIT with the value requests.cpu into the pod. This configuration will also appear in the 'be.conf' file inside the BE container.
1016+
Changing this configuration will cause a BE rolling restart.
1017+
type: boolean
10111018
claims:
10121019
description: |-
10131020
Claims lists the names of resources, defined in spec.resourceClaims,
@@ -5093,6 +5100,13 @@ spec:
50935100
description: annotation for fe pods. user can config monitor annotation
50945101
for collect to monitor system.
50955102
type: object
5103+
autoResolveLimitCPU:
5104+
description: |-
5105+
AutoResolveLimitCPU indicates whether to automatically set the CPU limit to doris BE config.
5106+
Default value is 'false'. This means that the Doris BE is unaware of the CPU configuration of resources.
5107+
Enabling this configuration means injecting an ENV named BE_CPU_LIMIT with the value requests.cpu into the pod. This configuration will also appear in the 'be.conf' file inside the BE container.
5108+
Changing this configuration will cause a BE rolling restart.
5109+
type: boolean
50965110
autoScalingPolicy:
50975111
description: AutoScalingPolicy auto scaling strategy
50985112
properties:

config/crd/bases/doris.selectdb.com_dorisclusters.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,13 @@ spec:
10081008
description: annotation for fe pods. user can config monitor annotation
10091009
for collect to monitor system.
10101010
type: object
1011+
autoResolveLimitCPU:
1012+
description: |-
1013+
AutoResolveLimitCPU indicates whether to automatically set the CPU limit to doris BE config.
1014+
Default value is 'false'. This means that the Doris BE is unaware of the CPU configuration of resources.
1015+
Enabling this configuration means injecting an ENV named BE_CPU_LIMIT with the value requests.cpu into the pod. This configuration will also appear in the 'be.conf' file inside the BE container.
1016+
Changing this configuration will cause a BE rolling restart.
1017+
type: boolean
10111018
claims:
10121019
description: |-
10131020
Claims lists the names of resources, defined in spec.resourceClaims,
@@ -5093,6 +5100,13 @@ spec:
50935100
description: annotation for fe pods. user can config monitor annotation
50945101
for collect to monitor system.
50955102
type: object
5103+
autoResolveLimitCPU:
5104+
description: |-
5105+
AutoResolveLimitCPU indicates whether to automatically set the CPU limit to doris BE config.
5106+
Default value is 'false'. This means that the Doris BE is unaware of the CPU configuration of resources.
5107+
Enabling this configuration means injecting an ENV named BE_CPU_LIMIT with the value requests.cpu into the pod. This configuration will also appear in the 'be.conf' file inside the BE container.
5108+
Changing this configuration will cause a BE rolling restart.
5109+
type: boolean
50965110
autoScalingPolicy:
50975111
description: AutoScalingPolicy auto scaling strategy
50985112
properties:

go.sum

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,7 @@ golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43/go.mod h1:KelEdhl1UZF7XfJ
379379
golang.org/x/oauth2 v0.0.0-20201109201403-9fd604954f58/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
380380
golang.org/x/oauth2 v0.0.0-20201208152858-08078c50e5b5/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
381381
golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
382-
golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs=
383-
golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
382+
golang.org/x/oauth2 v0.27.0 h1:da9Vo7/tDv5RH/7nZDz1eMGS/q1Vv1N/7FCrBhI9I3M=
384383
golang.org/x/oauth2 v0.27.0/go.mod h1:onh5ek6nERTohokkhCD/y2cV4Do3fxFHFuAejCkRWT8=
385384
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
386385
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=

helm-charts/doris-operator/crds/disaggregated.cluster.doris.com_dorisdisaggregatedclusters.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,13 @@ spec:
10191019
Annotations is an unstructured key value map stored with a resource that may be
10201020
set by external tools to store and retrieve arbitrary metadata.
10211021
type: object
1022+
autoResolveLimitCPU:
1023+
description: |-
1024+
AutoResolveLimitCPU indicates whether to automatically set the CPU limit to doris BE config.
1025+
Default value is 'false'. This means that the Doris BE is unaware of the CPU configuration of resources.
1026+
Enabling this configuration means injecting an ENV named BE_CPU_LIMIT with the value requests.cpu into the pod. This configuration will also appear in the 'be.conf' file inside the BE container.
1027+
Changing this configuration will cause a BE rolling restart.
1028+
type: boolean
10221029
claims:
10231030
description: |-
10241031
Claims lists the names of resources, defined in spec.resourceClaims,

helm-charts/doris-operator/crds/doris.apache.com_dorisclusters.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,13 @@ spec:
10081008
description: annotation for fe pods. user can config monitor annotation
10091009
for collect to monitor system.
10101010
type: object
1011+
autoResolveLimitCPU:
1012+
description: |-
1013+
AutoResolveLimitCPU indicates whether to automatically set the CPU limit to doris BE config.
1014+
Default value is 'false'. This means that the Doris BE is unaware of the CPU configuration of resources.
1015+
Enabling this configuration means injecting an ENV named BE_CPU_LIMIT with the value requests.cpu into the pod. This configuration will also appear in the 'be.conf' file inside the BE container.
1016+
Changing this configuration will cause a BE rolling restart.
1017+
type: boolean
10111018
claims:
10121019
description: |-
10131020
Claims lists the names of resources, defined in spec.resourceClaims,
@@ -5093,6 +5100,13 @@ spec:
50935100
description: annotation for fe pods. user can config monitor annotation
50945101
for collect to monitor system.
50955102
type: object
5103+
autoResolveLimitCPU:
5104+
description: |-
5105+
AutoResolveLimitCPU indicates whether to automatically set the CPU limit to doris BE config.
5106+
Default value is 'false'. This means that the Doris BE is unaware of the CPU configuration of resources.
5107+
Enabling this configuration means injecting an ENV named BE_CPU_LIMIT with the value requests.cpu into the pod. This configuration will also appear in the 'be.conf' file inside the BE container.
5108+
Changing this configuration will cause a BE rolling restart.
5109+
type: boolean
50965110
autoScalingPolicy:
50975111
description: AutoScalingPolicy auto scaling strategy
50985112
properties:

pkg/common/utils/resource/pod.go

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
package resource
1919

2020
import (
21+
"strconv"
22+
"strings"
23+
2124
dv1 "github.com/apache/doris-operator/api/disaggregated/v1"
2225
v1 "github.com/apache/doris-operator/api/doris/v1"
2326
"github.com/apache/doris-operator/pkg/common/utils/kerberos"
@@ -26,8 +29,6 @@ import (
2629
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2730
"k8s.io/apimachinery/pkg/util/intstr"
2831
"k8s.io/klog/v2"
29-
"strconv"
30-
"strings"
3132
)
3233

3334
const (
@@ -87,7 +88,7 @@ const (
8788

8889
DISAGGREGATED_FE_MAIN_CONTAINER_NAME = "fe"
8990
DISAGGREGATED_BE_MAIN_CONTAINER_NAME = "compute"
90-
DISAGGREGATED_MS_MAIN_CONTAINER_NAME= "metaservice"
91+
DISAGGREGATED_MS_MAIN_CONTAINER_NAME = "metaservice"
9192
)
9293

9394
type ProbeType string
@@ -452,6 +453,14 @@ func NewBaseMainContainer(dcr *v1.DorisCluster, config map[string]interface{}, c
452453
envs = append(envs, corev1.EnvVar{Name: "SKIP_CHECK_ULIMIT", Value: "true"})
453454
}
454455

456+
if componentType == v1.Component_BE && dcr.Spec.BeSpec.AutoResolveLimitCPU && spec.Limits.Cpu() != nil {
457+
envs = append(envs, corev1.EnvVar{Name: "BE_CPU_LIMIT", Value: spec.Limits.Cpu().String()})
458+
}
459+
460+
if componentType == v1.Component_CN && dcr.Spec.CnSpec.AutoResolveLimitCPU && spec.Limits.Cpu() != nil {
461+
envs = append(envs, corev1.EnvVar{Name: "BE_CPU_LIMIT", Value: spec.Limits.Cpu().String()})
462+
}
463+
455464
if len(GetMountConfigMapInfo(spec.ConfigMapInfo)) != 0 {
456465
_, configVolumeMounts := getMultiConfigVolumeAndVolumeMount(&spec.ConfigMapInfo, componentType)
457466
volumeMounts = append(volumeMounts, configVolumeMounts...)
@@ -571,12 +580,12 @@ func buildKerberosEnv(info *v1.KerberosInfo, config map[string]interface{}, comp
571580
return buildKerberosEnvUseSecretMountPath(info.KeytabPath, config, string(componentType))
572581
}
573582

574-
func BuildKerberosEnvForDDC(info *dv1.KerberosInfo, config map[string]interface{}, componentType dv1.DisaggregatedComponentType)[]corev1.EnvVar {
583+
func BuildKerberosEnvForDDC(info *dv1.KerberosInfo, config map[string]interface{}, componentType dv1.DisaggregatedComponentType) []corev1.EnvVar {
575584
if info == nil {
576585
return nil
577586
}
578587

579-
return buildKerberosEnvUseSecretMountPath(info.KeytabPath, config, string(componentType))
588+
return buildKerberosEnvUseSecretMountPath(info.KeytabPath, config, string(componentType))
580589
}
581590

582591
func buildKerberosEnvUseSecretMountPath(keytabPath string, config map[string]interface{}, componentType string) []corev1.EnvVar {
@@ -739,8 +748,7 @@ func getFeDefaultVolumesVolumeMounts() ([]corev1.Volume, []corev1.VolumeMount) {
739748
return volumes, volumMounts
740749
}
741750

742-
//
743-
func GetPodInfoVolumesVolumeMounts() ([]corev1.Volume, []corev1.VolumeMount){
751+
func GetPodInfoVolumesVolumeMounts() ([]corev1.Volume, []corev1.VolumeMount) {
744752
return appendPodInfoVolumesVolumeMounts(nil, nil)
745753
}
746754

@@ -932,16 +940,16 @@ func getKerberosVolumeAndVolumeMount(kerberosInfo *v1.KerberosInfo) ([]corev1.Vo
932940
return getKerberosConfigAndSecretVolumeAndVolumeMount(kerberosInfo.Krb5ConfigMap, kerberosInfo.KeytabSecretName)
933941
}
934942

935-
//get the kerberos volume and mounts to ddc.
936-
func GetDv1KerberosVolumeAndVolumeMount(kerberosInfo *dv1.KerberosInfo)([]corev1.Volume, []corev1.VolumeMount) {
943+
// get the kerberos volume and mounts to ddc.
944+
func GetDv1KerberosVolumeAndVolumeMount(kerberosInfo *dv1.KerberosInfo) ([]corev1.Volume, []corev1.VolumeMount) {
937945
if kerberosInfo == nil {
938946
return []corev1.Volume{}, []corev1.VolumeMount{}
939947
}
940948

941949
return getKerberosConfigAndSecretVolumeAndVolumeMount(kerberosInfo.Krb5ConfigMap, kerberosInfo.KeytabSecretName)
942950
}
943951

944-
//abstract a base function for dcr and ddc used.
952+
// abstract a base function for dcr and ddc used.
945953
func getKerberosConfigAndSecretVolumeAndVolumeMount(configMapName, secretName string) ([]corev1.Volume, []corev1.VolumeMount) {
946954
var volumes []corev1.Volume
947955
var volumeMounts []corev1.VolumeMount
@@ -1226,7 +1234,7 @@ func constructBeDefaultInitContainer(defaultImage string) corev1.Container {
12261234
func UseNewDefaultInitContainerImage(pts *corev1.PodTemplateSpec) {
12271235
var beImage string
12281236
for _, c := range pts.Spec.Containers {
1229-
if c.Name == string(v1.Component_BE) || c.Name == string(DISAGGREGATED_BE_MAIN_CONTAINER_NAME){
1237+
if c.Name == string(v1.Component_BE) || c.Name == string(DISAGGREGATED_BE_MAIN_CONTAINER_NAME) {
12301238
beImage = c.Image
12311239
break
12321240
}

0 commit comments

Comments
 (0)