From 0f6c086c50718c5c0096cd6829dfce286b2bf980 Mon Sep 17 00:00:00 2001 From: yandongxiao Date: Thu, 12 Oct 2023 13:56:32 +0800 Subject: [PATCH] [Feature] allow to config the terminationGracePeriodSeconds Signed-off-by: yandongxiao --- .../starrocks.com_starrocksclusters.yaml | 39 +++++++++++++++++++ deploy/starrocks.com_starrocksclusters.yaml | 9 +++++ .../starrocks/templates/starrockscluster.yaml | 3 ++ .../charts/starrocks/values.yaml | 6 +++ pkg/apis/starrocks/v1/component_type.go | 19 +++++++++ pkg/apis/starrocks/v1/load_type.go | 4 +- .../starrocks/v1/starrockscluster_types.go | 8 ++++ .../starrocks/v1/zz_generated.deepcopy.go | 5 +++ pkg/k8sutils/templates/pod/spec.go | 2 +- 9 files changed, 93 insertions(+), 2 deletions(-) diff --git a/config/crd/bases/starrocks.com_starrocksclusters.yaml b/config/crd/bases/starrocks.com_starrocksclusters.yaml index 0c55f060..fad6b86c 100644 --- a/config/crd/bases/starrocks.com_starrocksclusters.yaml +++ b/config/crd/bases/starrocks.com_starrocksclusters.yaml @@ -1273,6 +1273,19 @@ spec: - storageSize type: object type: array + terminationGracePeriodSeconds: + description: TerminationGracePeriodSeconds defines duration in + seconds the pod needs to terminate gracefully. May be decreased + in delete request. Value must be non-negative integer. The value + zero indicates stop immediately via the kill signal (no opportunity + to shut down). If this value is nil, the default grace period + will be used instead. The grace period is the duration in seconds + after the processes running in the pod are sent a termination + signal and the time when the processes are forcibly halted with + a kill signal. Set this value longer than the expected cleanup + time for your process. Defaults to 120 seconds. + format: int64 + type: integer tolerations: description: (Optional) Tolerations for scheduling pods onto some dedicated nodes @@ -3218,6 +3231,19 @@ spec: - storageSize type: object type: array + terminationGracePeriodSeconds: + description: TerminationGracePeriodSeconds defines duration in + seconds the pod needs to terminate gracefully. May be decreased + in delete request. Value must be non-negative integer. The value + zero indicates stop immediately via the kill signal (no opportunity + to shut down). If this value is nil, the default grace period + will be used instead. The grace period is the duration in seconds + after the processes running in the pod are sent a termination + signal and the time when the processes are forcibly halted with + a kill signal. Set this value longer than the expected cleanup + time for your process. Defaults to 120 seconds. + format: int64 + type: integer tolerations: description: (Optional) Tolerations for scheduling pods onto some dedicated nodes @@ -5575,6 +5601,19 @@ spec: - storageSize type: object type: array + terminationGracePeriodSeconds: + description: TerminationGracePeriodSeconds defines duration in + seconds the pod needs to terminate gracefully. May be decreased + in delete request. Value must be non-negative integer. The value + zero indicates stop immediately via the kill signal (no opportunity + to shut down). If this value is nil, the default grace period + will be used instead. The grace period is the duration in seconds + after the processes running in the pod are sent a termination + signal and the time when the processes are forcibly halted with + a kill signal. Set this value longer than the expected cleanup + time for your process. Defaults to 120 seconds. + format: int64 + type: integer tolerations: description: (Optional) Tolerations for scheduling pods onto some dedicated nodes diff --git a/deploy/starrocks.com_starrocksclusters.yaml b/deploy/starrocks.com_starrocksclusters.yaml index 2eb321e7..246c45a5 100644 --- a/deploy/starrocks.com_starrocksclusters.yaml +++ b/deploy/starrocks.com_starrocksclusters.yaml @@ -596,6 +596,9 @@ spec: - storageSize type: object type: array + terminationGracePeriodSeconds: + format: int64 + type: integer tolerations: items: properties: @@ -1496,6 +1499,9 @@ spec: - storageSize type: object type: array + terminationGracePeriodSeconds: + format: int64 + type: integer tolerations: items: properties: @@ -2547,6 +2553,9 @@ spec: - storageSize type: object type: array + terminationGracePeriodSeconds: + format: int64 + type: integer tolerations: items: properties: diff --git a/helm-charts/charts/kube-starrocks/charts/starrocks/templates/starrockscluster.yaml b/helm-charts/charts/kube-starrocks/charts/starrocks/templates/starrockscluster.yaml index c3ec19ca..8eabcb74 100644 --- a/helm-charts/charts/kube-starrocks/charts/starrocks/templates/starrockscluster.yaml +++ b/helm-charts/charts/kube-starrocks/charts/starrocks/templates/starrockscluster.yaml @@ -105,6 +105,7 @@ spec: tolerations: {{toYaml .Values.starrocksFESpec.tolerations | indent 4 }} {{- end }} + terminationGracePeriodSeconds: {{ .Values.starrocksFESpec.terminationGracePeriodSeconds }} {{- if .Values.starrocksFESpec.secrets }} secrets: {{- range .Values.starrocksFESpec.secrets }} @@ -241,6 +242,7 @@ spec: tolerations: {{toYaml .Values.starrocksBeSpec.tolerations | indent 4 }} {{- end }} + terminationGracePeriodSeconds: {{ .Values.starrocksBeSpec.terminationGracePeriodSeconds }} {{- if .Values.starrocksBeSpec.secrets }} secrets: {{- range .Values.starrocksBeSpec.secrets }} @@ -333,6 +335,7 @@ spec: tolerations: {{toYaml .Values.starrocksCnSpec.tolerations | indent 4 }} {{- end }} + terminationGracePeriodSeconds: {{ .Values.starrocksCnSpec.terminationGracePeriodSeconds }} {{- if and .Values.starrocksCluster.enabledCn .Values.starrocksCnSpec.autoScalingPolicy }} autoScalingPolicy: {{ toYaml .Values.starrocksCnSpec.autoScalingPolicy | indent 6 }} diff --git a/helm-charts/charts/kube-starrocks/charts/starrocks/values.yaml b/helm-charts/charts/kube-starrocks/charts/starrocks/values.yaml index 10dbacd6..01a93109 100644 --- a/helm-charts/charts/kube-starrocks/charts/starrocks/values.yaml +++ b/helm-charts/charts/kube-starrocks/charts/starrocks/values.yaml @@ -177,6 +177,8 @@ starrocksFESpec: # - name: my-configmap # mountPath: /etc/my-configmap # subPath: "" + # terminationGracePeriodSeconds defines duration in seconds the FE pod needs to terminate gracefully. + terminationGracePeriodSeconds: 120 # spec for compute node, compute node provide compute function. starrocksCnSpec: @@ -336,6 +338,8 @@ starrocksCnSpec: # - name: my-configmap # mountPath: /etc/my-configmap # subPath: "" + # terminationGracePeriodSeconds defines duration in seconds the CN pod needs to terminate gracefully. + terminationGracePeriodSeconds: 120 # spec for component be, provide storage and compute function. starrocksBeSpec: @@ -459,6 +463,8 @@ starrocksBeSpec: # - name: my-configmap # mountPath: /etc/my-configmap # subPath: "" + # terminationGracePeriodSeconds defines duration in seconds the BE pod needs to terminate gracefully. + terminationGracePeriodSeconds: 120 # create secrets if necessary. secrets: [] diff --git a/pkg/apis/starrocks/v1/component_type.go b/pkg/apis/starrocks/v1/component_type.go index 77790b51..73d2cd7e 100644 --- a/pkg/apis/starrocks/v1/component_type.go +++ b/pkg/apis/starrocks/v1/component_type.go @@ -38,6 +38,17 @@ type StarRocksComponentSpec struct { // file if specified. This is only valid for non-hostNetwork pods. // +optional HostAliases []corev1.HostAlias `json:"hostAliases,omitempty"` + + // TerminationGracePeriodSeconds defines duration in seconds the pod needs to terminate gracefully. May be decreased in delete request. + // Value must be non-negative integer. The value zero indicates stop immediately via + // the kill signal (no opportunity to shut down). + // If this value is nil, the default grace period will be used instead. + // The grace period is the duration in seconds after the processes running in the pod are sent + // a termination signal and the time when the processes are forcibly halted with a kill signal. + // Set this value longer than the expected cleanup time for your process. + // Defaults to 120 seconds. + // +optional + TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty"` } // StarRocksComponentStatus represents the status of a starrocks component. @@ -106,3 +117,11 @@ func (spec *StarRocksComponentSpec) GetRunAsNonRoot() (*int64, *int64) { groupId := int64(1000) return &userId, &groupId } + +func (spec *StarRocksComponentSpec) GetTerminationGracePeriodSeconds() *int64 { + if spec.TerminationGracePeriodSeconds == nil { + v := int64(120) + return &v + } + return spec.TerminationGracePeriodSeconds +} diff --git a/pkg/apis/starrocks/v1/load_type.go b/pkg/apis/starrocks/v1/load_type.go index feaf23b1..cd7cb7eb 100644 --- a/pkg/apis/starrocks/v1/load_type.go +++ b/pkg/apis/starrocks/v1/load_type.go @@ -1,6 +1,8 @@ package v1 -import corev1 "k8s.io/api/core/v1" +import ( + corev1 "k8s.io/api/core/v1" +) type loadInterface interface { GetAnnotations() map[string]string diff --git a/pkg/apis/starrocks/v1/starrockscluster_types.go b/pkg/apis/starrocks/v1/starrockscluster_types.go index f6f3c2d9..ad33c7b7 100644 --- a/pkg/apis/starrocks/v1/starrockscluster_types.go +++ b/pkg/apis/starrocks/v1/starrockscluster_types.go @@ -68,6 +68,7 @@ type SpecInterface interface { loadInterface GetHostAliases() []corev1.HostAlias GetRunAsNonRoot() (*int64, *int64) + GetTerminationGracePeriodSeconds() *int64 } var _ SpecInterface = &StarRocksFeSpec{} @@ -181,6 +182,13 @@ func (spec *StarRocksFeProxySpec) GetRunAsNonRoot() (*int64, *int64) { return nil, nil } +// GetTerminationGracePeriodSeconds +// fe proxy does not have field TerminationGracePeriodSeconds, the reason why implementing this method is +// that StarRocksFeProxySpec needs to implement SpecInterface interface +func (spec *StarRocksFeProxySpec) GetTerminationGracePeriodSeconds() *int64 { + return nil +} + // ClusterPhase represent the cluster phase. the possible value for cluster phase are: running, failed, pending. type ClusterPhase string diff --git a/pkg/apis/starrocks/v1/zz_generated.deepcopy.go b/pkg/apis/starrocks/v1/zz_generated.deepcopy.go index a2d45430..b31b4fa4 100644 --- a/pkg/apis/starrocks/v1/zz_generated.deepcopy.go +++ b/pkg/apis/starrocks/v1/zz_generated.deepcopy.go @@ -652,6 +652,11 @@ func (in *StarRocksComponentSpec) DeepCopyInto(out *StarRocksComponentSpec) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + if in.TerminationGracePeriodSeconds != nil { + in, out := &in.TerminationGracePeriodSeconds, &out.TerminationGracePeriodSeconds + *out = new(int64) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StarRocksComponentSpec. diff --git a/pkg/k8sutils/templates/pod/spec.go b/pkg/k8sutils/templates/pod/spec.go index b42a21a0..6671bd6d 100644 --- a/pkg/k8sutils/templates/pod/spec.go +++ b/pkg/k8sutils/templates/pod/spec.go @@ -384,7 +384,7 @@ func Spec(spec v1.SpecInterface, defaultServiceAccount string, container corev1. Containers: []corev1.Container{container}, Volumes: volumes, ServiceAccountName: spec.GetServiceAccount(), - TerminationGracePeriodSeconds: rutils.GetInt64ptr(int64(120)), + TerminationGracePeriodSeconds: spec.GetTerminationGracePeriodSeconds(), Affinity: spec.GetAffinity(), Tolerations: spec.GetTolerations(), ImagePullSecrets: spec.GetImagePullSecrets(),