Skip to content

Commit e05848d

Browse files
author
smiletan
authored
Merge pull request #375 from catpineapple/share_pvc
[feature](dcr) enable configure the shared pvc that needs to be mounted on the pod
2 parents e86c415 + eef11bb commit e05848d

File tree

15 files changed

+400
-57
lines changed

15 files changed

+400
-57
lines changed

api/doris/v1/types.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,23 @@ type DorisClusterSpec struct {
5555

5656
// KerberosInfo contains a series of access key files, Provides access to kerberos.
5757
KerberosInfo *KerberosInfo `json:"kerberosInfo,omitempty"`
58+
59+
// SharedPersistentVolumeClaims used to configure the shared pvc that needs to be mounted on the pod
60+
SharedPersistentVolumeClaims []SharedPersistentVolumeClaim `json:"sharedPersistentVolumeClaims,omitempty"`
61+
}
62+
63+
type SharedPersistentVolumeClaim struct {
64+
// MountPath must be an absolute path. support use environment : ${DORIS_HOME}, ${DORIS_HOME} is /opt/apache-doris/fe/ in fe container, /opt/apache-doris/be in be container.
65+
// if the MountPath conflict to the MountPath in BaseSpec.PersistentVolumes config, this MountPath will have high priority, and the MountPath will attach the shard pvc.
66+
MountPath string `json:"mountPath,omitempty"`
67+
68+
// the shared PersistentVolumeClaim's name
69+
// PersistentVolumeClaim AccessModes must include ReadWriteMany, Please create the ReadWriteMany pvc before deploying doris cluster.
70+
// Doris Operator will check the pvc exists or not, the AccessMode is ReadWriteMany or not.
71+
PersistentVolumeClaimName string `json:"persistentVolumeClaimName,omitempty"`
72+
73+
//the components of need config the pvc, if empty, all deployment component will config the pvc.
74+
SupportComponents []ComponentType `json:"supportComponents,omitempty"`
5875
}
5976

6077
type KerberosInfo struct {

api/doris/v1/zz_generated.deepcopy.go

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

config/crd/bases/crds.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8869,6 +8869,30 @@ spec:
88698869
description: Krb5ConfigMap is the name of configmap within 'krb5.conf'
88708870
type: string
88718871
type: object
8872+
sharedPersistentVolumeClaims:
8873+
description: SharedPersistentVolumeClaims used to configure the shared
8874+
pvc that needs to be mounted on the pod
8875+
items:
8876+
properties:
8877+
mountPath:
8878+
description: |-
8879+
MountPath must be an absolute path. support use environment : ${DORIS_HOME}, ${DORIS_HOME} is /opt/apache-doris/fe/ in fe container, /opt/apache-doris/be in be container.
8880+
if the MountPath conflict to the MountPath in BaseSpec.PersistentVolumes config, this MountPath will have high priority, and the MountPath will attach the shard pvc.
8881+
type: string
8882+
persistentVolumeClaimName:
8883+
description: |-
8884+
the shared PersistentVolumeClaim's name
8885+
PersistentVolumeClaim AccessModes must include ReadWriteMany, Please create the ReadWriteMany pvc before deploying doris cluster.
8886+
Doris Operator will check the pvc exists or not, the AccessMode is ReadWriteMany or not.
8887+
type: string
8888+
supportComponents:
8889+
description: the components of need config the pvc, if empty,
8890+
all deployment component will config the pvc.
8891+
items:
8892+
type: string
8893+
type: array
8894+
type: object
8895+
type: array
88728896
type: object
88738897
status:
88748898
description: DorisClusterStatus defines the observed state of DorisCluster

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8869,6 +8869,30 @@ spec:
88698869
description: Krb5ConfigMap is the name of configmap within 'krb5.conf'
88708870
type: string
88718871
type: object
8872+
sharedPersistentVolumeClaims:
8873+
description: SharedPersistentVolumeClaims used to configure the shared
8874+
pvc that needs to be mounted on the pod
8875+
items:
8876+
properties:
8877+
mountPath:
8878+
description: |-
8879+
MountPath must be an absolute path. support use environment : ${DORIS_HOME}, ${DORIS_HOME} is /opt/apache-doris/fe/ in fe container, /opt/apache-doris/be in be container.
8880+
if the MountPath conflict to the MountPath in BaseSpec.PersistentVolumes config, this MountPath will have high priority, and the MountPath will attach the shard pvc.
8881+
type: string
8882+
persistentVolumeClaimName:
8883+
description: |-
8884+
the shared PersistentVolumeClaim's name
8885+
PersistentVolumeClaim AccessModes must include ReadWriteMany, Please create the ReadWriteMany pvc before deploying doris cluster.
8886+
Doris Operator will check the pvc exists or not, the AccessMode is ReadWriteMany or not.
8887+
type: string
8888+
supportComponents:
8889+
description: the components of need config the pvc, if empty,
8890+
all deployment component will config the pvc.
8891+
items:
8892+
type: string
8893+
type: array
8894+
type: object
8895+
type: array
88728896
type: object
88738897
status:
88748898
description: DorisClusterStatus defines the observed state of DorisCluster

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8869,6 +8869,30 @@ spec:
88698869
description: Krb5ConfigMap is the name of configmap within 'krb5.conf'
88708870
type: string
88718871
type: object
8872+
sharedPersistentVolumeClaims:
8873+
description: SharedPersistentVolumeClaims used to configure the shared
8874+
pvc that needs to be mounted on the pod
8875+
items:
8876+
properties:
8877+
mountPath:
8878+
description: |-
8879+
MountPath must be an absolute path. support use environment : ${DORIS_HOME}, ${DORIS_HOME} is /opt/apache-doris/fe/ in fe container, /opt/apache-doris/be in be container.
8880+
if the MountPath conflict to the MountPath in BaseSpec.PersistentVolumes config, this MountPath will have high priority, and the MountPath will attach the shard pvc.
8881+
type: string
8882+
persistentVolumeClaimName:
8883+
description: |-
8884+
the shared PersistentVolumeClaim's name
8885+
PersistentVolumeClaim AccessModes must include ReadWriteMany, Please create the ReadWriteMany pvc before deploying doris cluster.
8886+
Doris Operator will check the pvc exists or not, the AccessMode is ReadWriteMany or not.
8887+
type: string
8888+
supportComponents:
8889+
description: the components of need config the pvc, if empty,
8890+
all deployment component will config the pvc.
8891+
items:
8892+
type: string
8893+
type: array
8894+
type: object
8895+
type: array
88728896
type: object
88738897
status:
88748898
description: DorisClusterStatus defines the observed state of DorisCluster

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8869,6 +8869,30 @@ spec:
88698869
description: Krb5ConfigMap is the name of configmap within 'krb5.conf'
88708870
type: string
88718871
type: object
8872+
sharedPersistentVolumeClaims:
8873+
description: SharedPersistentVolumeClaims used to configure the shared
8874+
pvc that needs to be mounted on the pod
8875+
items:
8876+
properties:
8877+
mountPath:
8878+
description: |-
8879+
MountPath must be an absolute path. support use environment : ${DORIS_HOME}, ${DORIS_HOME} is /opt/apache-doris/fe/ in fe container, /opt/apache-doris/be in be container.
8880+
if the MountPath conflict to the MountPath in BaseSpec.PersistentVolumes config, this MountPath will have high priority, and the MountPath will attach the shard pvc.
8881+
type: string
8882+
persistentVolumeClaimName:
8883+
description: |-
8884+
the shared PersistentVolumeClaim's name
8885+
PersistentVolumeClaim AccessModes must include ReadWriteMany, Please create the ReadWriteMany pvc before deploying doris cluster.
8886+
Doris Operator will check the pvc exists or not, the AccessMode is ReadWriteMany or not.
8887+
type: string
8888+
supportComponents:
8889+
description: the components of need config the pvc, if empty,
8890+
all deployment component will config the pvc.
8891+
items:
8892+
type: string
8893+
type: array
8894+
type: object
8895+
type: array
88728896
type: object
88738897
status:
88748898
description: DorisClusterStatus defines the observed state of DorisCluster

pkg/common/utils/k8s/client.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,3 +376,11 @@ func DeletePVC(ctx context.Context, k8sclient client.Client, namespace, pvcName
376376
}
377377
return nil
378378
}
379+
380+
func GetPVC(ctx context.Context, k8sclient client.Client, name, namespace string) (*corev1.PersistentVolumeClaim, error) {
381+
var pvc corev1.PersistentVolumeClaim
382+
if err := k8sclient.Get(ctx, types.NamespacedName{Name: name, Namespace: namespace}, &pvc); err != nil {
383+
return nil, err
384+
}
385+
return &pvc, nil
386+
}

pkg/common/utils/resource/persistent_volume_claim.go

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ import (
2121
dorisv1 "github.com/apache/doris-operator/api/doris/v1"
2222
"github.com/apache/doris-operator/pkg/common/utils/doris"
2323
"github.com/apache/doris-operator/pkg/common/utils/hash"
24+
"github.com/apache/doris-operator/pkg/common/utils/set"
2425
corev1 "k8s.io/api/core/v1"
2526
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2627
"k8s.io/klog/v2"
28+
"strings"
2729
)
2830

2931
var (
@@ -83,7 +85,7 @@ func getDefaultDorisHome(componentType dorisv1.ComponentType) string {
8385
return ""
8486
}
8587

86-
// GenerateEveryoneMountPathPersistentVolume is used to process the pvc template configuration in CRD.
88+
// GenerateEveryoneMountPathDorisPersistentVolume is used to process the pvc template configuration in CRD.
8789
// The template is defined as follows:
8890
// - PersistentVolume.MountPath is "", it`s template configuration.
8991
// - PersistentVolume.MountPath is not "", it`s actual pvc configuration.
@@ -92,24 +94,31 @@ func getDefaultDorisHome(componentType dorisv1.ComponentType) string {
9294
// 2. If there is a pvc template, return the actual list of pvcs after processing.
9395
// 3. The template needs to parse the configuration of the doris config file to create the pvc.
9496
// 4. If there are multiple templates, the last valid template will be used.
95-
func GenerateEveryoneMountPathPersistentVolume(spec *dorisv1.BaseSpec, config map[string]interface{}, componentType dorisv1.ComponentType) ([]dorisv1.PersistentVolume, error) {
96-
97+
func GenerateEveryoneMountPathDorisPersistentVolume(spec *dorisv1.BaseSpec, excludePaths []string, config map[string]interface{}, componentType dorisv1.ComponentType) ([]dorisv1.PersistentVolume, error) {
9798
// Only the last data pvc template configuration takes effect
9899
var template *dorisv1.PersistentVolume
99-
// pvs is the pvc that needs to be actually created, specified by the user
100-
var pvs []dorisv1.PersistentVolume
101-
100+
// dorisPersistentVolumes is the pvc that needs to be actually created, specified by the user
101+
var dorisPersistentVolumes []dorisv1.PersistentVolume
102102
for i := range spec.PersistentVolumes {
103103
if spec.PersistentVolumes[i].MountPath != "" {
104-
pvs = append(pvs, spec.PersistentVolumes[i])
105-
104+
path := spec.PersistentVolumes[i].MountPath
105+
if strings.HasSuffix(path, "/") {
106+
path = path[:len(path)-1]
107+
}
108+
if !set.ArrayContains(excludePaths, path) {
109+
dorisPersistentVolumes = append(dorisPersistentVolumes, spec.PersistentVolumes[i])
110+
} else {
111+
klog.Errorf("GenerateEveryoneMountPathDorisPersistentVolume SharedPersistentVolumeClaim.MountPath (%s) conflicts with the MountPath configured in BaseSpec.PersistentVolumes, "+
112+
"and the SharedPersistentVolumeClaims configuration takes precedence, skipping the processing of the BaseSpec.PersistentVolumes for the PVC. "+
113+
"If it does not meet expectations, please handle the conflict and rebuild the cluster.", path)
114+
}
106115
} else {
107116
template = (&spec.PersistentVolumes[i]).DeepCopy()
108117
}
109118
}
110119

111120
if template == nil {
112-
return pvs, nil
121+
return dorisPersistentVolumes, nil
113122
}
114123

115124
// Processing pvc template
@@ -124,13 +133,13 @@ func GenerateEveryoneMountPathPersistentVolume(spec *dorisv1.BaseSpec, config ma
124133
dataPathKey = "storage_root_path"
125134
dataDefaultPath = dorisHome + "/storage"
126135
default:
127-
klog.Infof("GenerateEveryoneMountPathPersistentVolume the componentType: %s is not supported, PersistentVolume template will not work ", componentType)
128-
return pvs, nil
136+
klog.Infof("GenerateEveryoneMountPathDorisPersistentVolume the componentType: %s is not supported, PersistentVolume template will not work ", componentType)
137+
return dorisPersistentVolumes, nil
129138
}
130139

131140
dataPathValue, dataExist := config[dataPathKey]
132141
if !dataExist {
133-
klog.Infof("GenerateEveryoneMountPathPersistentVolume: dataPathKey '%s' not found in config, default value will effect", dataPathKey)
142+
klog.Infof("GenerateEveryoneMountPathDorisPersistentVolume: dataPathKey '%s' not found in config, default value will effect", dataPathKey)
134143
dataPaths = append(dataPaths, dataDefaultPath)
135144
} else {
136145
dataPaths = doris.ResolveStorageRootPath(dataPathValue.(string))
@@ -139,16 +148,28 @@ func GenerateEveryoneMountPathPersistentVolume(spec *dorisv1.BaseSpec, config ma
139148
if len(dataPaths) == 1 {
140149
tmp := *template.DeepCopy()
141150
tmp.MountPath = dataPaths[0]
142-
pvs = append(pvs, tmp)
151+
if !set.ArrayContains(excludePaths, dataPaths[0]) {
152+
dorisPersistentVolumes = append(dorisPersistentVolumes, tmp)
153+
} else {
154+
klog.Errorf("GenerateEveryoneMountPathDorisPersistentVolume SharedPersistentVolumeClaims.MountPath (%s) conflicts with the MountPath configured in BaseSpec.PersistentVolumes, "+
155+
"and the SharedPersistentVolumeClaims configuration takes precedence, skipping the processing of the BaseSpec.PersistentVolumes for the PVC. "+
156+
"If it does not meet expectations, please handle the conflict and rebuild the cluster.", dataPaths[0])
157+
}
143158
} else {
144159
pathNames := doris.GetNameOfEachPath(dataPaths)
145160
for i := range dataPaths {
146161
tmp := *template.DeepCopy()
147162
tmp.Name = tmp.Name + "-" + pathNames[i]
148163
tmp.MountPath = dataPaths[i]
149-
pvs = append(pvs, tmp)
164+
if !set.ArrayContains(excludePaths, dataPaths[i]) {
165+
dorisPersistentVolumes = append(dorisPersistentVolumes, tmp)
166+
} else {
167+
klog.Errorf("GenerateEveryoneMountPathDorisPersistentVolume SharedPersistentVolumeClaims.MountPath (%s) conflicts with the MountPath configured in BaseSpec.PersistentVolumes, "+
168+
"and the SharedPersistentVolumeClaims configuration takes precedence, skipping the processing of the BaseSpec.PersistentVolumes for the PVC. "+
169+
"If it does not meet expectations, please handle the conflict and rebuild the cluster.", dataPaths[i])
170+
}
150171
}
151172
}
152173

153-
return pvs, nil
174+
return dorisPersistentVolumes, nil
154175
}

0 commit comments

Comments
 (0)