Skip to content

Commit e02437c

Browse files
committed
enable shared pvc
1 parent e86c415 commit e02437c

File tree

15 files changed

+348
-23
lines changed

15 files changed

+348
-23
lines changed

api/doris/v1/types.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,26 @@ 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+
// Shared PVC mount path in pod.
65+
// doris operator does not provide the ability to create, but it will check the existence of the pvc and whether the MountPath conflicts.
66+
// If it conflicts with the MountPath in BaseSpec.PersistentVolumes or the actual mount path, the configuration here takes precedence
67+
// support use environment : ${DORIS_HOME}
68+
// FE: ${DORIS_HOME} = /opt/apache-doris/fe
69+
// BE: ${DORIS_HOME} = /opt/apache-doris/be
70+
MountPath string `json:"mountPath,omitempty"`
71+
72+
// the shared PersistentVolumeClaim's name
73+
// PersistentVolumeClaim AccessModes must include ReadWriteMany
74+
ClaimName string `json:"claimName,omitempty"`
75+
76+
//the components of need config the pvc, if emptyy, all deployment component will config the pvc.
77+
SupportComponents []ComponentType `json:"supportComponents,omitempty"`
5878
}
5979

6080
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: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8869,6 +8869,33 @@ 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+
claimName:
8878+
description: |-
8879+
the shared PersistentVolumeClaim's name
8880+
PersistentVolumeClaim AccessModes must include ReadWriteMany
8881+
type: string
8882+
mountPath:
8883+
description: "Shared PVC mount path in pod.\ndoris operator
8884+
does not provide the ability to create, but it will check
8885+
the existence of the pvc and whether the MountPath conflicts.\nIf
8886+
it conflicts with the MountPath in BaseSpec.PersistentVolumes
8887+
or the actual mount path, the configuration here takes precedence\nsupport
8888+
use environment : ${DORIS_HOME}\n\t FE: ${DORIS_HOME} = /opt/apache-doris/fe\n\t
8889+
BE: ${DORIS_HOME} = /opt/apache-doris/be"
8890+
type: string
8891+
supportComponents:
8892+
description: the components of need config the pvc, if emptyy,
8893+
all deployment component will config the pvc.
8894+
items:
8895+
type: string
8896+
type: array
8897+
type: object
8898+
type: array
88728899
type: object
88738900
status:
88748901
description: DorisClusterStatus defines the observed state of DorisCluster

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8869,6 +8869,33 @@ 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+
claimName:
8878+
description: |-
8879+
the shared PersistentVolumeClaim's name
8880+
PersistentVolumeClaim AccessModes must include ReadWriteMany
8881+
type: string
8882+
mountPath:
8883+
description: "Shared PVC mount path in pod.\ndoris operator
8884+
does not provide the ability to create, but it will check
8885+
the existence of the pvc and whether the MountPath conflicts.\nIf
8886+
it conflicts with the MountPath in BaseSpec.PersistentVolumes
8887+
or the actual mount path, the configuration here takes precedence\nsupport
8888+
use environment : ${DORIS_HOME}\n\t FE: ${DORIS_HOME} = /opt/apache-doris/fe\n\t
8889+
BE: ${DORIS_HOME} = /opt/apache-doris/be"
8890+
type: string
8891+
supportComponents:
8892+
description: the components of need config the pvc, if emptyy,
8893+
all deployment component will config the pvc.
8894+
items:
8895+
type: string
8896+
type: array
8897+
type: object
8898+
type: array
88728899
type: object
88738900
status:
88748901
description: DorisClusterStatus defines the observed state of DorisCluster

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8869,6 +8869,33 @@ 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+
claimName:
8878+
description: |-
8879+
the shared PersistentVolumeClaim's name
8880+
PersistentVolumeClaim AccessModes must include ReadWriteMany
8881+
type: string
8882+
mountPath:
8883+
description: "Shared PVC mount path in pod.\ndoris operator
8884+
does not provide the ability to create, but it will check
8885+
the existence of the pvc and whether the MountPath conflicts.\nIf
8886+
it conflicts with the MountPath in BaseSpec.PersistentVolumes
8887+
or the actual mount path, the configuration here takes precedence\nsupport
8888+
use environment : ${DORIS_HOME}\n\t FE: ${DORIS_HOME} = /opt/apache-doris/fe\n\t
8889+
BE: ${DORIS_HOME} = /opt/apache-doris/be"
8890+
type: string
8891+
supportComponents:
8892+
description: the components of need config the pvc, if emptyy,
8893+
all deployment component will config the pvc.
8894+
items:
8895+
type: string
8896+
type: array
8897+
type: object
8898+
type: array
88728899
type: object
88738900
status:
88748901
description: DorisClusterStatus defines the observed state of DorisCluster

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8869,6 +8869,33 @@ 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+
claimName:
8878+
description: |-
8879+
the shared PersistentVolumeClaim's name
8880+
PersistentVolumeClaim AccessModes must include ReadWriteMany
8881+
type: string
8882+
mountPath:
8883+
description: "Shared PVC mount path in pod.\ndoris operator
8884+
does not provide the ability to create, but it will check
8885+
the existence of the pvc and whether the MountPath conflicts.\nIf
8886+
it conflicts with the MountPath in BaseSpec.PersistentVolumes
8887+
or the actual mount path, the configuration here takes precedence\nsupport
8888+
use environment : ${DORIS_HOME}\n\t FE: ${DORIS_HOME} = /opt/apache-doris/fe\n\t
8889+
BE: ${DORIS_HOME} = /opt/apache-doris/be"
8890+
type: string
8891+
supportComponents:
8892+
description: the components of need config the pvc, if emptyy,
8893+
all deployment component will config the pvc.
8894+
items:
8895+
type: string
8896+
type: array
8897+
type: object
8898+
type: array
88728899
type: object
88738900
status:
88748901
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: 28 additions & 7 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 (
@@ -92,17 +94,24 @@ 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 GenerateEveryoneMountPathPersistentVolume(spec *dorisv1.BaseSpec, sharedPaths []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
99100
// pvs is the pvc that needs to be actually created, specified by the user
100101
var pvs []dorisv1.PersistentVolume
101-
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(sharedPaths, path) {
109+
pvs = append(pvs, spec.PersistentVolumes[i])
110+
} else {
111+
klog.Errorf("GenerateEveryoneMountPathPersistentVolume 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
}
@@ -139,14 +148,26 @@ 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(sharedPaths, dataPaths[0]) {
152+
pvs = append(pvs, tmp)
153+
} else {
154+
klog.Errorf("GenerateEveryoneMountPathPersistentVolume 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(sharedPaths, dataPaths[i]) {
165+
pvs = append(pvs, tmp)
166+
} else {
167+
klog.Errorf("GenerateEveryoneMountPathPersistentVolume 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

0 commit comments

Comments
 (0)