Skip to content

Commit

Permalink
[BugFix] Operator do not create the default data storage volume when …
Browse files Browse the repository at this point in the history
…deploying BE with multiple volumes

Signed-off-by: yandongxiao <[email protected]>
  • Loading branch information
yandongxiao committed Jan 9, 2025
1 parent 5404d68 commit 1d48466
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 68 deletions.
6 changes: 3 additions & 3 deletions doc/cn/logging_and_related_configurations_howto.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ spec:
starRocksFeSpec:
storageVolumes:
- mountPath: /opt/starrocks/fe/log
name: fe-storage-log
name: fe-log
storageSize: 10Gi
# storageClassName: "" # 如果 storageClassName 为空,Kubernetes 将使用默认的存储卷类型。
```
Expand All @@ -52,7 +52,7 @@ spec:
starrocks:
starrocksFESpec:
storageSpec:
name: "fe-storage"
name: "fe"
storageSize: 10Gi
logStorageSize: 10Gi
# storageClassName: "" # 如果 storageClassName 为空,Kubernetes 将使用默认的存储卷类型。
Expand All @@ -63,7 +63,7 @@ starrocks:
```yaml
starrocksFESpec:
storageSpec:
name: "fe-storage"
name: "fe"
storageSize: 10Gi
logStorageSize: 10Gi
# storageClassName: "" # 如果 storageClassName 为空,Kubernetes 将使用默认的存储卷类型。
Expand Down
6 changes: 3 additions & 3 deletions doc/logging_and_related_configurations_howto.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ spec:
starRocksFeSpec:
storageVolumes:
- mountPath: /opt/starrocks/fe/log
name: fe-storage-log
name: fe-log
storageSize: 10Gi
# storageClassName: "" # If storageClassName is not set, Kubernetes will use the default storage class.
```
Expand All @@ -61,7 +61,7 @@ For the kube-starrocks Helm Chart, you can configure as:
starrocks:
starrocksFESpec:
storageSpec:
name: "fe-storage"
name: "fe"
storageSize: 10Gi
logStorageSize: 10Gi
# storageClassName: "" # If storageClassName is not set, Kubernetes will use the default storage class.
Expand All @@ -72,7 +72,7 @@ For the starrocks Helm Chart, configure as:
```yaml
starrocksFESpec:
storageSpec:
name: "fe-storage"
name: "fe"
storageSize: 10Gi
logStorageSize: 10Gi
# storageClassName: "" # If storageClassName is not set, Kubernetes will use the default storage class.
Expand Down
10 changes: 5 additions & 5 deletions doc/mount_persistent_volume_howto.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,24 @@ spec:
image: "starrocks/fe-ubuntu:3.3-latest"
replicas: 1
storageVolumes:
- name: fe-storage-meta
- name: fe-meta
storageClassName: standard-rwo # standard-rwo is the default storageClassName in GKE.
# fe container stop running if the disk free space which the fe meta directory residents, is less than 5Gi.
storageSize: 10Gi
mountPath: /opt/starrocks/fe/meta
- name: fe-storage-log
- name: fe-log
storageClassName: standard-rwo
storageSize: 5Gi
mountPath: /opt/starrocks/fe/log
starRocksBeSpec:
image: "starrocks/be-ubuntu:3.3-latest"
replicas: 3
storageVolumes:
- name: be-storage-data
- name: be-data
storageClassName: standard-rwo
storageSize: 1Ti
mountPath: /opt/starrocks/be/storage
- name: be-storage-log
- name: be-log
storageClassName: standard-rwo
storageSize: 1Gi
mountPath: /opt/starrocks/be/log
Expand Down Expand Up @@ -109,7 +109,7 @@ starrocks:
repository: starrocks/fe-ubuntu
tag: 3.3-latest
storageSpec:
name: fe-storage
name: fe-data
storageClassName: standard-rwo # standard-rwo is the default storageClassName in GKE.
logStorageSize: 10Gi
storageSize: 100Gi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ spec:
resolveKey: fe.conf
# fe storage volumes for persistent metadata and log
storageVolumes:
- name: fe-storage-meta
- name: fe-meta
# the storageClassName represent the used storageclass name. if not set will use k8s cluster default storageclass.
# storageClassName: ""
# the persistent volume size. FE container stop running if the disk free space which the
# fe meta directory residents, is less than 5Gi.
storageSize: 10Gi
# the mount path for FE meta.
mountPath: /opt/starrocks/fe/meta
- name: fe-storage-log
- name: fe-log
# storageClassName: ""
# the size of storage volume for log
storageSize: 1Gi
Expand Down Expand Up @@ -148,14 +148,14 @@ spec:
resolveKey: be.conf
# be storage volumes for persistent storage.
storageVolumes:
- name: be-storage-data
- name: be-data
# the storageClassName represent the used storageclass name. if not set will use k8s cluster default storageclass.
# storageClassName: ""
# the size of storage volume for data
storageSize: 10Gi
# the mount path for BE data.
mountPath: /opt/starrocks/be/storage
- name: be-storage-log
- name: be-log
# storageClassName: ""
# the size of storage volume for log
storageSize: 1Gi
Expand Down Expand Up @@ -271,14 +271,14 @@ spec:
configMapName: starrockscluster-sample-cn-cm
resolveKey: cn.conf
storageVolumes:
- name: cn-storage-data
- name: cn-data
# the storageClassName represent the used storageclass name. if not set will use k8s cluster default storageclass.
# storageClassName: ""
# the size of storage volume for data
storageSize: 10Gi
# the mount path of CN data
mountPath: /opt/starrocks/cn/storage
- name: cn-storage-log
- name: cn-log
# storageClassName: ""
# the size of storage volume for log
storageSize: 1Gi
Expand Down
8 changes: 4 additions & 4 deletions examples/starrocks/deploy_a_starrocks_cluster_with_cn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ spec:
# storageVolumes is optional. If you don't specify it, emptyDir will be used to store FE meta and log, and the files
# and directories written to the volume will be completely lost upon container restarting.
storageVolumes:
- name: fe-storage-meta
- name: fe-meta
# storageClassName: "" # If storageClassName is not set, Kubernetes will use the default storage class.
# FE container stop running if the disk free space which the fe meta directory residents, is less than 5Gi.
storageSize: 10Gi
mountPath: /opt/starrocks/fe/meta
- name: fe-storage-log
- name: fe-log
# storageClassName: "" # If storageClassName is not set, Kubernetes will use the default storage class.
storageSize: 5Gi
mountPath: /opt/starrocks/fe/log
Expand All @@ -45,11 +45,11 @@ spec:
# storageVolumes is optional. If you don't specify it, emptyDir will be used to store BE data and log, and be aware
# that the files and directories written to the volume will be completely lost upon container restarting.
storageVolumes:
- name: be-storage-data
- name: be-data
# storageClassName: "" # If storageClassName is not set, Kubernetes will use the default storage class.
storageSize: 1Ti
mountPath: /opt/starrocks/be/storage
- name: be-storage-log
- name: be-log
# storageClassName: "" # If storageClassName is not set, Kubernetes will use the default storage class.
storageSize: 1Gi
mountPath: /opt/starrocks/be/log
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ spec:
cpu: 8
memory: 16Gi
storageVolumes:
- name: fe-storage-meta
- name: fe-meta
# storageClassName: "" # if storageClassName is not set, the default storage class will be used
storageSize: 10Gi # the size of storage volume for metadata
mountPath: /opt/starrocks/fe/meta # the path of metadata
- name: fe-storage-log
- name: fe-log
# storageClassName: "" # if storageClassName is not set, the default storage class will be used
storageSize: 1Gi # the size of storage volume for log
mountPath: /opt/starrocks/fe/log # the path of log
Expand All @@ -44,11 +44,11 @@ spec:
cpu: 16
memory: 64Gi
storageVolumes:
- name: be-storage-data
- name: be-data
# storageClassName: "" # if storageClassName is not set, the default storage class will be used
storageSize: 10Gi # the size of storage volume for data
mountPath: /opt/starrocks/be/storage # the path of data
- name: be-storage-log
- name: be-log
# storageClassName: "" # if storageClassName is not set, the default storage class will be used
storageSize: 1Gi # the size of storage volume for log
mountPath: /opt/starrocks/be/log # the path of log
Expand All @@ -62,11 +62,11 @@ spec:
cpu: 16
memory: 64Gi
storageVolumes:
- name: cn-storage-data
- name: cn-data
# storageClassName: "" # if storageClassName is not set, the default storage class will be used
storageSize: 10Gi # the size of storage volume for data
mountPath: /opt/starrocks/cn/storage # the path of data
- name: cn-storage-log
- name: cn-log
# storageClassName: "" # if storageClassName is not set, the default storage class will be used
storageSize: 1Gi # the size of storage volume for log
mountPath: /opt/starrocks/cn/log # the path of log
8 changes: 4 additions & 4 deletions examples/starrocks/starrocks-fe-and-be.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ spec:
# storageVolumes is optional. If you don't specify it, emptyDir will be used to store FE meta and log, and be aware
# that the files and directories written to the volume will be completely lost upon container restarting.
storageVolumes:
- name: fe-storage-meta
- name: fe-meta
# storageClassName: "" # If storageClassName is not set, Kubernetes will use the default storage class.
# fe container stop running if the disk free space which the fe meta directory residents, is less than 5Gi.
storageSize: 10Gi
mountPath: /opt/starrocks/fe/meta
- name: fe-storage-log
- name: fe-log
# storageClassName: "" # If storageClassName is not set, Kubernetes will use the default storage class.
storageSize: 5Gi
mountPath: /opt/starrocks/fe/log
Expand All @@ -43,11 +43,11 @@ spec:
# storageVolumes is optional. If you don't specify it, emptyDir will be used to store BE data and log, and be aware
# that the files and directories written to the volume will be completely lost upon container restarting.
storageVolumes:
- name: be-storage-data
- name: be-data
# storageClassName: "" # If storageClassName is not set, Kubernetes will use the default storage class.
storageSize: 1Ti
mountPath: /opt/starrocks/be/storage
- name: be-storage-log
- name: be-log
# storageClassName: "" # If storageClassName is not set, Kubernetes will use the default storage class.
storageSize: 1Gi
mountPath: /opt/starrocks/be/log
2 changes: 1 addition & 1 deletion pkg/controllers/starrockscluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func TestReconcileConstructFeResource(t *testing.T) {
},
StorageVolumes: []srapi.StorageVolume{
{
Name: "fe-storage",
Name: "fe-meta",
StorageClassName: rutils.GetStringPointer("shard-data"),
MountPath: "/data/fe/meta",
StorageSize: "10Gi",
Expand Down
26 changes: 22 additions & 4 deletions pkg/k8sutils/k8sutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,18 +430,36 @@ func GetValueFromSecret(ctx context.Context, k8sClient client.Client, namespace
return string(value), nil
}

func HasVolume(volumes []corev1.Volume, newVolumeName string) bool {
// HasVolume is used to decide whether operator should create a default volume for a component.
func HasVolume(volumes []corev1.Volume, defaultVolumeName string) bool {
for _, v := range volumes {
if v.Name == newVolumeName {
if v.Name == defaultVolumeName {
return true
}

// The defaultVolumeName is like be-data, be-log, fe-meta, fe-log, cn-log.
// If a user deploy StarRocks by helm chart with multiple volumes, their volume names may be like: be0-data, be1-data...,
// and their mount paths may be like: /opt/starrocks/be/storage0, /opt/starrocks/be/storage1...
// Considering this situation, we will only check if they have the same suffix, e.g. -data, -log
subStrings1 := strings.Split(defaultVolumeName, "-")
suffixFromDefaultVolumeName := subStrings1[len(subStrings1)-1]
subStrings2 := strings.Split(v.Name, "-")
suffixFromVolumeName := subStrings2[len(subStrings2)-1]
if len(subStrings1) > 1 && len(subStrings2) > 1 && suffixFromDefaultVolumeName == suffixFromVolumeName {
return true
}
}
return false
}

func HasMountPath(mounts []corev1.VolumeMount, newMountPath string) bool {
// HasMountPath is used to decide whether operator should create a default volume for a component.
func HasMountPath(mounts []corev1.VolumeMount, defaultMountPath string) bool {
for _, v := range mounts {
if v.MountPath == newMountPath {
// The defaultVolumeName is like be-data, be-log, fe-meta, fe-log, cn-log.
// If a user deploy StarRocks by helm chart with multiple volumes, their volume names may be like: be0-data, be1-data...,
// and their mount paths may be like: /opt/starrocks/be/storage0, /opt/starrocks/be/storage1...
// Considering this situation, we need to check if the defaultMountPath is a prefix of the mount path.
if strings.Contains(v.MountPath, defaultMountPath) {
return true
}
}
Expand Down
Loading

0 comments on commit 1d48466

Please sign in to comment.