Skip to content

Commit c1adf1c

Browse files
author
smiletan
authored
Merge pull request #331 from catpineapple/watch-cm
[feature](dcr)watch configmap modify and restart nodes
2 parents 7228234 + 153d161 commit c1adf1c

File tree

15 files changed

+453
-18
lines changed

15 files changed

+453
-18
lines changed

api/doris/v1/doriscluster_util.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,3 +378,33 @@ func (dcr *DorisCluster) GetElectionNumber() int32 {
378378
}
379379
return DefaultFeElectionNumber
380380
}
381+
382+
func GetRestartAnnotationKey(componentType ComponentType) string {
383+
var restartAnnotationsKey string
384+
switch componentType {
385+
case Component_FE:
386+
restartAnnotationsKey = FERestartAt
387+
case Component_BE:
388+
restartAnnotationsKey = BERestartAt
389+
default:
390+
klog.Infof("GetRestartAnnotationKey the componentType %s is not supported.", componentType)
391+
}
392+
return restartAnnotationsKey
393+
394+
}
395+
396+
func (dcr *DorisCluster) GetComponentStatus(componentType ComponentType) *ComponentStatus {
397+
switch componentType {
398+
case Component_FE:
399+
return dcr.Status.FEStatus
400+
case Component_BE:
401+
return dcr.Status.BEStatus
402+
case Component_CN:
403+
return &dcr.Status.CnStatus.ComponentStatus
404+
case Component_Broker:
405+
return dcr.Status.BrokerStatus
406+
default:
407+
klog.Infof("GetComponentStatus the componentType %s is not supported.", componentType)
408+
}
409+
return nil
410+
}

api/doris/v1/types.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
1918
package v1
2019

2120
import (
@@ -49,6 +48,10 @@ type DorisClusterSpec struct {
4948
// the name of secret that type is `kubernetes.io/basic-auth` and contains keys username, password for management doris node in cluster as fe, be register.
5049
// the password key is `password`. the username defaults to `root` and is omitempty.
5150
AuthSecret string `json:"authSecret,omitempty"`
51+
52+
// EnableRestartWhenConfigChange configmap monitoring, default is false.
53+
// When EnableRestartWhenConfigChange is true, changing the doris core configmap will cause a rolling restart of the corresponding node
54+
EnableRestartWhenConfigChange bool `json:"enableRestartWhenConfigChange,omitempty"`
5255
}
5356

5457
// AdminUser describe administrator for manage components in specified cluster.
@@ -86,8 +89,8 @@ type BeSpec struct {
8689
// Default System Init means that the container must be started in privileged mode.
8790
// 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.
8891
SkipDefaultSystemInit bool `json:"skipDefaultSystemInit,omitempty"`
89-
90-
//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.
92+
93+
//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.
9194
//the weight of antiAffinity in same node is greater than this affinity.
9295
EnableFeAffinity bool `json:"enableFeAffinity,omitempty"`
9396
}
@@ -388,6 +391,8 @@ type ComponentStatus struct {
388391
//the name of fe service exposed for user.
389392
AccessService string `json:"accessService,omitempty"`
390393

394+
CoreConfigMapHashValue string `json:"coreConfigMapHashValue,omitempty"`
395+
391396
//FailedInstances failed pod names.
392397
FailedMembers []string `json:"failedInstances,omitempty"`
393398

config/crd/bases/crds.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6108,6 +6108,11 @@ spec:
61086108
required:
61096109
- image
61106110
type: object
6111+
enableRestartWhenConfigChange:
6112+
description: |-
6113+
EnableRestartWhenConfigChange configmap monitoring, default is false.
6114+
When EnableRestartWhenConfigChange is true, changing the doris core configmap will cause a rolling restart of the corresponding node
6115+
type: boolean
61116116
feSpec:
61126117
description: defines the fe cluster state that will be created by
61136118
operator.
@@ -7946,6 +7951,8 @@ spec:
79467951
- phase
79477952
- reason
79487953
type: object
7954+
coreConfigMapHashValue:
7955+
type: string
79497956
creatingInstances:
79507957
description: CreatingInstances in creating pod names.
79517958
items:
@@ -7997,6 +8004,8 @@ spec:
79978004
- phase
79988005
- reason
79998006
type: object
8007+
coreConfigMapHashValue:
8008+
type: string
80008009
creatingInstances:
80018010
description: CreatingInstances in creating pod names.
80028011
items:
@@ -8048,6 +8057,8 @@ spec:
80488057
- phase
80498058
- reason
80508059
type: object
8060+
coreConfigMapHashValue:
8061+
type: string
80518062
creatingInstances:
80528063
description: CreatingInstances in creating pod names.
80538064
items:
@@ -8109,6 +8120,8 @@ spec:
81098120
- phase
81108121
- reason
81118122
type: object
8123+
coreConfigMapHashValue:
8124+
type: string
81128125
creatingInstances:
81138126
description: CreatingInstances in creating pod names.
81148127
items:

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6108,6 +6108,11 @@ spec:
61086108
required:
61096109
- image
61106110
type: object
6111+
enableRestartWhenConfigChange:
6112+
description: |-
6113+
EnableRestartWhenConfigChange configmap monitoring, default is false.
6114+
When EnableRestartWhenConfigChange is true, changing the doris core configmap will cause a rolling restart of the corresponding node
6115+
type: boolean
61116116
feSpec:
61126117
description: defines the fe cluster state that will be created by
61136118
operator.
@@ -7946,6 +7951,8 @@ spec:
79467951
- phase
79477952
- reason
79487953
type: object
7954+
coreConfigMapHashValue:
7955+
type: string
79497956
creatingInstances:
79507957
description: CreatingInstances in creating pod names.
79517958
items:
@@ -7997,6 +8004,8 @@ spec:
79978004
- phase
79988005
- reason
79998006
type: object
8007+
coreConfigMapHashValue:
8008+
type: string
80008009
creatingInstances:
80018010
description: CreatingInstances in creating pod names.
80028011
items:
@@ -8048,6 +8057,8 @@ spec:
80488057
- phase
80498058
- reason
80508059
type: object
8060+
coreConfigMapHashValue:
8061+
type: string
80518062
creatingInstances:
80528063
description: CreatingInstances in creating pod names.
80538064
items:
@@ -8109,6 +8120,8 @@ spec:
81098120
- phase
81108121
- reason
81118122
type: object
8123+
coreConfigMapHashValue:
8124+
type: string
81128125
creatingInstances:
81138126
description: CreatingInstances in creating pod names.
81148127
items:

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6108,6 +6108,11 @@ spec:
61086108
required:
61096109
- image
61106110
type: object
6111+
enableRestartWhenConfigChange:
6112+
description: |-
6113+
EnableRestartWhenConfigChange configmap monitoring, default is false.
6114+
When EnableRestartWhenConfigChange is true, changing the doris core configmap will cause a rolling restart of the corresponding node
6115+
type: boolean
61116116
feSpec:
61126117
description: defines the fe cluster state that will be created by
61136118
operator.
@@ -7946,6 +7951,8 @@ spec:
79467951
- phase
79477952
- reason
79487953
type: object
7954+
coreConfigMapHashValue:
7955+
type: string
79497956
creatingInstances:
79507957
description: CreatingInstances in creating pod names.
79517958
items:
@@ -7997,6 +8004,8 @@ spec:
79978004
- phase
79988005
- reason
79998006
type: object
8007+
coreConfigMapHashValue:
8008+
type: string
80008009
creatingInstances:
80018010
description: CreatingInstances in creating pod names.
80028011
items:
@@ -8048,6 +8057,8 @@ spec:
80488057
- phase
80498058
- reason
80508059
type: object
8060+
coreConfigMapHashValue:
8061+
type: string
80518062
creatingInstances:
80528063
description: CreatingInstances in creating pod names.
80538064
items:
@@ -8109,6 +8120,8 @@ spec:
81098120
- phase
81108121
- reason
81118122
type: object
8123+
coreConfigMapHashValue:
8124+
type: string
81128125
creatingInstances:
81138126
description: CreatingInstances in creating pod names.
81148127
items:

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6108,6 +6108,11 @@ spec:
61086108
required:
61096109
- image
61106110
type: object
6111+
enableRestartWhenConfigChange:
6112+
description: |-
6113+
EnableRestartWhenConfigChange configmap monitoring, default is false.
6114+
When EnableRestartWhenConfigChange is true, changing the doris core configmap will cause a rolling restart of the corresponding node
6115+
type: boolean
61116116
feSpec:
61126117
description: defines the fe cluster state that will be created by
61136118
operator.
@@ -7946,6 +7951,8 @@ spec:
79467951
- phase
79477952
- reason
79487953
type: object
7954+
coreConfigMapHashValue:
7955+
type: string
79497956
creatingInstances:
79507957
description: CreatingInstances in creating pod names.
79517958
items:
@@ -7997,6 +8004,8 @@ spec:
79978004
- phase
79988005
- reason
79998006
type: object
8007+
coreConfigMapHashValue:
8008+
type: string
80008009
creatingInstances:
80018010
description: CreatingInstances in creating pod names.
80028011
items:
@@ -8048,6 +8057,8 @@ spec:
80488057
- phase
80498058
- reason
80508059
type: object
8060+
coreConfigMapHashValue:
8061+
type: string
80518062
creatingInstances:
80528063
description: CreatingInstances in creating pod names.
80538064
items:
@@ -8109,6 +8120,8 @@ spec:
81098120
- phase
81108121
- reason
81118122
type: object
8123+
coreConfigMapHashValue:
8124+
type: string
81128125
creatingInstances:
81138126
description: CreatingInstances in creating pod names.
81148127
items:

pkg/common/utils/resource/configmap.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,57 @@ func GetMountConfigMapInfo(c dorisv1.ConfigMapInfo) (finalConfigMaps []dorisv1.M
148148

149149
return finalConfigMaps
150150
}
151+
152+
// getDorisCoreConfigMapName return a configmap`s name include doris configurations such as fe.conf/be.conf
153+
func getDorisCoreConfigMapName(dcr *dorisv1.DorisCluster, componentType dorisv1.ComponentType) string {
154+
var cmInfo dorisv1.ConfigMapInfo
155+
switch componentType {
156+
case dorisv1.Component_FE:
157+
cmInfo = dcr.Spec.FeSpec.ConfigMapInfo
158+
case dorisv1.Component_BE:
159+
cmInfo = dcr.Spec.BeSpec.ConfigMapInfo
160+
case dorisv1.Component_CN:
161+
cmInfo = dcr.Spec.CnSpec.ConfigMapInfo
162+
case dorisv1.Component_Broker:
163+
cmInfo = dcr.Spec.BrokerSpec.ConfigMapInfo
164+
default:
165+
klog.Infof("getCoreCmName: the componentType: %s have not default ResolveKey", componentType)
166+
}
167+
168+
maps := GetMountConfigMapInfo(cmInfo)
169+
for i := range maps {
170+
if maps[i].MountPath == "" || maps[i].MountPath == ConfigEnvPath {
171+
return maps[i].ConfigMapName
172+
}
173+
}
174+
return ""
175+
}
176+
177+
func GetDorisCoreConfigMapNames(dcr *dorisv1.DorisCluster) map[dorisv1.ComponentType]string {
178+
dorisCoreConfigMaps := map[dorisv1.ComponentType]string{}
179+
if dcr.Spec.FeSpec != nil {
180+
if cm := getDorisCoreConfigMapName(dcr, dorisv1.Component_FE); cm != "" {
181+
dorisCoreConfigMaps[dorisv1.Component_FE] = cm
182+
}
183+
}
184+
185+
if dcr.Spec.BeSpec != nil {
186+
if cm := getDorisCoreConfigMapName(dcr, dorisv1.Component_BE); cm != "" {
187+
dorisCoreConfigMaps[dorisv1.Component_BE] = cm
188+
}
189+
}
190+
191+
if dcr.Spec.CnSpec != nil {
192+
if cm := getDorisCoreConfigMapName(dcr, dorisv1.Component_CN); cm != "" {
193+
dorisCoreConfigMaps[dorisv1.Component_CN] = cm
194+
}
195+
}
196+
197+
if dcr.Spec.BrokerSpec != nil {
198+
if cm := getDorisCoreConfigMapName(dcr, dorisv1.Component_Broker); cm != "" {
199+
dorisCoreConfigMaps[dorisv1.Component_Broker] = cm
200+
}
201+
}
202+
203+
return dorisCoreConfigMaps
204+
}

pkg/common/utils/resource/configmap_test.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package resource
2020
import (
2121
dorisv1 "github.com/apache/doris-operator/api/doris/v1"
2222
corev1 "k8s.io/api/core/v1"
23+
"reflect"
2324
"strconv"
2425
"testing"
2526
)
@@ -124,3 +125,65 @@ func Test_GetMountConfigMapInfo(t *testing.T) {
124125
t.Errorf("get mountConfigMapInfo failed, len not equal 1")
125126
}
126127
}
128+
129+
func Test_getCoreCmName(t *testing.T) {
130+
type args struct {
131+
dcr *dorisv1.DorisCluster
132+
componentType dorisv1.ComponentType
133+
}
134+
135+
tests := []struct {
136+
name string
137+
args args
138+
want string
139+
}{
140+
{
141+
name: "test1",
142+
args: args{
143+
dcr: &dorisv1.DorisCluster{
144+
Spec: dorisv1.DorisClusterSpec{
145+
FeSpec: &dorisv1.FeSpec{
146+
BaseSpec: dorisv1.BaseSpec{
147+
ConfigMapInfo: dorisv1.ConfigMapInfo{
148+
ConfigMapName: "fe-config",
149+
},
150+
},
151+
},
152+
},
153+
},
154+
componentType: dorisv1.Component_FE,
155+
},
156+
want: "fe-config",
157+
},
158+
{
159+
name: "test2",
160+
args: args{dcr: &dorisv1.DorisCluster{
161+
Spec: dorisv1.DorisClusterSpec{
162+
FeSpec: &dorisv1.FeSpec{
163+
BaseSpec: dorisv1.BaseSpec{
164+
ConfigMapInfo: dorisv1.ConfigMapInfo{
165+
ConfigMapName: "fe-config",
166+
ConfigMaps: []dorisv1.MountConfigMapInfo{
167+
{
168+
ConfigMapName: "fe-config-1",
169+
MountPath: "config",
170+
},
171+
},
172+
},
173+
},
174+
},
175+
},
176+
},
177+
componentType: dorisv1.Component_FE,
178+
},
179+
want: "fe-config",
180+
},
181+
}
182+
for _, tt := range tests {
183+
t.Run(tt.name, func(t *testing.T) {
184+
if got := getDorisCoreConfigMapName(tt.args.dcr, tt.args.componentType); !reflect.DeepEqual(got, tt.want) {
185+
t.Errorf("getDorisCoreConfigMapName() = %v, want %v", got, tt.want)
186+
}
187+
})
188+
}
189+
}

0 commit comments

Comments
 (0)