From ae1cbc5fd260a82f65b8987de5cf942fca891317 Mon Sep 17 00:00:00 2001 From: catpineapple Date: Fri, 27 Dec 2024 15:39:32 +0800 Subject: [PATCH 1/5] add skipSystemInit for be --- api/doris/v1/types.go | 4 ++++ pkg/common/utils/resource/pod.go | 8 +++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/api/doris/v1/types.go b/api/doris/v1/types.go index f07c383d..632687f2 100644 --- a/api/doris/v1/types.go +++ b/api/doris/v1/types.go @@ -95,6 +95,8 @@ type BeSpec struct { // Please confirm whether the host machine and k8s cluster allow it. // Doris workloadgroup reference document: https://doris.apache.org/docs/admin-manual/resource-admin/workload-group EnableWorkloadGroup bool `json:"enableWorkloadGroup,omitempty"` + + SkipDefaultSystemInit bool `json:"skipDefaultSystemInit,omitempty"` } // FeAddress specify the fe address, please set it when you deploy fe outside k8s or deploy components use crd except fe, if not set . @@ -120,6 +122,8 @@ type CnSpec struct { //the foundation spec for creating cn software services. BaseSpec `json:",inline"` + SkipDefaultSystemInit bool `json:"skipDefaultSystemInit,omitempty"` + //AutoScalingPolicy auto scaling strategy AutoScalingPolicy *AutoScalingPolicy `json:"autoScalingPolicy,omitempty"` } diff --git a/pkg/common/utils/resource/pod.go b/pkg/common/utils/resource/pod.go index 4ef21dc6..6b24a3da 100644 --- a/pkg/common/utils/resource/pod.go +++ b/pkg/common/utils/resource/pod.go @@ -155,7 +155,8 @@ func NewPodTemplateSpec(dcr *v1.DorisCluster, componentType v1.ComponentType) co }, } - constructInitContainers(componentType, &pts.Spec, si) + klog.Errorf("111111-----------------") + constructInitContainers(dcr, componentType, &pts.Spec, si) pts.Spec.Affinity = constructAffinity(dcrAffinity, componentType) return pts @@ -220,7 +221,7 @@ func ApplySecurityContext(containers []corev1.Container, securityContext *corev1 return containers } -func constructInitContainers(componentType v1.ComponentType, podSpec *corev1.PodSpec, si *v1.SystemInitialization) { +func constructInitContainers(dcr *v1.DorisCluster, componentType v1.ComponentType, podSpec *corev1.PodSpec, si *v1.SystemInitialization) { defaultImage := "" var defaultInitContains []corev1.Container if si != nil { @@ -230,7 +231,8 @@ func constructInitContainers(componentType v1.ComponentType, podSpec *corev1.Pod } // the init containers have sequence,should confirm use initial is always in the first priority. - if componentType == v1.Component_BE || componentType == v1.Component_CN { + if (componentType == v1.Component_BE && !dcr.Spec.BeSpec.SkipDefaultSystemInit) || (componentType == v1.Component_CN && !dcr.Spec.CnSpec.SkipDefaultSystemInit) { + klog.Errorf("111111-----------------") podSpec.InitContainers = append(podSpec.InitContainers, constructBeDefaultInitContainer(defaultImage)) } podSpec.InitContainers = append(podSpec.InitContainers, defaultInitContains...) From 3e844b5f7ee3098a9678538fe974844a0f30b65d Mon Sep 17 00:00:00 2001 From: catpineapple Date: Fri, 27 Dec 2024 18:33:11 +0800 Subject: [PATCH 2/5] enable skip default system init --- pkg/common/utils/resource/pod.go | 2 -- pkg/controller/sub_controller/be/prepare_modify.go | 3 +-- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/pkg/common/utils/resource/pod.go b/pkg/common/utils/resource/pod.go index 6b24a3da..d96cd065 100644 --- a/pkg/common/utils/resource/pod.go +++ b/pkg/common/utils/resource/pod.go @@ -155,7 +155,6 @@ func NewPodTemplateSpec(dcr *v1.DorisCluster, componentType v1.ComponentType) co }, } - klog.Errorf("111111-----------------") constructInitContainers(dcr, componentType, &pts.Spec, si) pts.Spec.Affinity = constructAffinity(dcrAffinity, componentType) @@ -232,7 +231,6 @@ func constructInitContainers(dcr *v1.DorisCluster, componentType v1.ComponentTyp // the init containers have sequence,should confirm use initial is always in the first priority. if (componentType == v1.Component_BE && !dcr.Spec.BeSpec.SkipDefaultSystemInit) || (componentType == v1.Component_CN && !dcr.Spec.CnSpec.SkipDefaultSystemInit) { - klog.Errorf("111111-----------------") podSpec.InitContainers = append(podSpec.InitContainers, constructBeDefaultInitContainer(defaultImage)) } podSpec.InitContainers = append(podSpec.InitContainers, defaultInitContains...) diff --git a/pkg/controller/sub_controller/be/prepare_modify.go b/pkg/controller/sub_controller/be/prepare_modify.go index dc606e66..34769b14 100644 --- a/pkg/controller/sub_controller/be/prepare_modify.go +++ b/pkg/controller/sub_controller/be/prepare_modify.go @@ -18,12 +18,11 @@ package be import ( - "context" v1 "github.com/apache/doris-operator/api/doris/v1" ) // prepareStatefulsetApply means Pre-operation and status control on the client side -func (be *Controller) prepareStatefulsetApply(ctx context.Context, dcr *v1.DorisCluster, oldStatus v1.ComponentStatus) error { +func (be *Controller) prepareStatefulsetApply(dcr *v1.DorisCluster, oldStatus v1.ComponentStatus) error { // be rolling restart // check 1: be Phase is Available From 18bd54039304ef7249eee43b021d27262069c18b Mon Sep 17 00:00:00 2001 From: catpineapple Date: Thu, 2 Jan 2025 14:47:26 +0800 Subject: [PATCH 3/5] enable skip default system init --- api/doris/v1/types.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/api/doris/v1/types.go b/api/doris/v1/types.go index 632687f2..645baf3e 100644 --- a/api/doris/v1/types.go +++ b/api/doris/v1/types.go @@ -96,6 +96,10 @@ type BeSpec struct { // Doris workloadgroup reference document: https://doris.apache.org/docs/admin-manual/resource-admin/workload-group EnableWorkloadGroup bool `json:"enableWorkloadGroup,omitempty"` + // SkipDefaultSystemInit is a switch that skips the default initialization and is used to set the default environment configuration required by the doris be node. + // Default value is 'false'. + // Default System Init means that the container must be started in privileged mode. + // 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. SkipDefaultSystemInit bool `json:"skipDefaultSystemInit,omitempty"` } From 82314c1354cdc0fe62e9070de71954ef2368d135 Mon Sep 17 00:00:00 2001 From: catpineapple Date: Thu, 2 Jan 2025 14:47:57 +0800 Subject: [PATCH 4/5] enable skip default system init --- api/doris/v1/types.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/doris/v1/types.go b/api/doris/v1/types.go index 645baf3e..3d173332 100644 --- a/api/doris/v1/types.go +++ b/api/doris/v1/types.go @@ -96,7 +96,7 @@ type BeSpec struct { // Doris workloadgroup reference document: https://doris.apache.org/docs/admin-manual/resource-admin/workload-group EnableWorkloadGroup bool `json:"enableWorkloadGroup,omitempty"` - // SkipDefaultSystemInit is a switch that skips the default initialization and is used to set the default environment configuration required by the doris be node. + // SkipDefaultSystemInit is a switch that skips the default initialization and is used to set the default environment configuration required by the doris BE node. // Default value is 'false'. // Default System Init means that the container must be started in privileged mode. // 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. From 6061691936157c3a1984d16387cfcd439d36c5de Mon Sep 17 00:00:00 2001 From: catpineapple Date: Wed, 8 Jan 2025 18:34:37 +0800 Subject: [PATCH 5/5] enable skip default system init --- pkg/common/utils/resource/pod.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pkg/common/utils/resource/pod.go b/pkg/common/utils/resource/pod.go index d96cd065..e5be42ed 100644 --- a/pkg/common/utils/resource/pod.go +++ b/pkg/common/utils/resource/pod.go @@ -86,6 +86,7 @@ func NewPodTemplateSpec(dcr *v1.DorisCluster, componentType v1.ComponentType) co var dcrAffinity *corev1.Affinity var defaultInitContainers []corev1.Container var SecurityContext *corev1.PodSecurityContext + var skipInit bool switch componentType { case v1.Component_FE: volumes = newVolumesFromBaseSpec(dcr.Spec.FeSpec.BaseSpec) @@ -97,10 +98,12 @@ func NewPodTemplateSpec(dcr *v1.DorisCluster, componentType v1.ComponentType) co si = dcr.Spec.BeSpec.BaseSpec.SystemInitialization dcrAffinity = dcr.Spec.BeSpec.BaseSpec.Affinity SecurityContext = dcr.Spec.BeSpec.BaseSpec.SecurityContext + skipInit = dcr.Spec.BeSpec.SkipDefaultSystemInit case v1.Component_CN: si = dcr.Spec.CnSpec.BaseSpec.SystemInitialization dcrAffinity = dcr.Spec.CnSpec.BaseSpec.Affinity SecurityContext = dcr.Spec.CnSpec.BaseSpec.SecurityContext + skipInit = dcr.Spec.CnSpec.SkipDefaultSystemInit case v1.Component_Broker: si = dcr.Spec.BrokerSpec.BaseSpec.SystemInitialization dcrAffinity = dcr.Spec.BrokerSpec.BaseSpec.Affinity @@ -155,7 +158,7 @@ func NewPodTemplateSpec(dcr *v1.DorisCluster, componentType v1.ComponentType) co }, } - constructInitContainers(dcr, componentType, &pts.Spec, si) + constructInitContainers(skipInit, componentType, &pts.Spec, si) pts.Spec.Affinity = constructAffinity(dcrAffinity, componentType) return pts @@ -220,7 +223,7 @@ func ApplySecurityContext(containers []corev1.Container, securityContext *corev1 return containers } -func constructInitContainers(dcr *v1.DorisCluster, componentType v1.ComponentType, podSpec *corev1.PodSpec, si *v1.SystemInitialization) { +func constructInitContainers(skipInit bool, componentType v1.ComponentType, podSpec *corev1.PodSpec, si *v1.SystemInitialization) { defaultImage := "" var defaultInitContains []corev1.Container if si != nil { @@ -230,7 +233,7 @@ func constructInitContainers(dcr *v1.DorisCluster, componentType v1.ComponentTyp } // the init containers have sequence,should confirm use initial is always in the first priority. - if (componentType == v1.Component_BE && !dcr.Spec.BeSpec.SkipDefaultSystemInit) || (componentType == v1.Component_CN && !dcr.Spec.CnSpec.SkipDefaultSystemInit) { + if !skipInit && (componentType == v1.Component_BE || componentType == v1.Component_CN) { podSpec.InitContainers = append(podSpec.InitContainers, constructBeDefaultInitContainer(defaultImage)) } podSpec.InitContainers = append(podSpec.InitContainers, defaultInitContains...)