Skip to content

Commit

Permalink
[Enhancement] If hostPath is set, the storage class will be considere…
Browse files Browse the repository at this point in the history
…d as hostPath (#552)

* [Enhancement] If hostPath is set, the storage class will be considered as hostPath

Signed-off-by: yandongxiao <[email protected]>

* [BugFix] If the the sv.HostPath is provided and the sv.StorageClassName is provided as well, name will have a high priority

Signed-off-by: yandongxiao <[email protected]>

---------

Signed-off-by: yandongxiao <[email protected]>
  • Loading branch information
yandongxiao authored Jun 25, 2024
1 parent 2938429 commit c7f0549
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 26 deletions.
20 changes: 13 additions & 7 deletions helm-charts/charts/kube-starrocks/charts/starrocks/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,9 @@ starrocksFESpec:
# For persistent storage, specify a volume name prefix.
# For example, using `fe` as the name prefix would be appropriate.
name: ""
# the storageClassName represent the used storageclass name. if not set will use k8s cluster default storageclass.
# you must set name when you set storageClassName
# The storageClassName represent the used storageclass name. if not set will use k8s cluster default storageclass.
# You must set name when you set storageClassName.
# Note: Because hostPath field is not supported here, hostPath is not allowed to be set in storageClassName.
storageClassName: ""
# the persistent volume size, default 10Gi.
# fe container stop running if the disk free space which the fe meta directory residents, is less than 5Gi.
Expand Down Expand Up @@ -549,8 +550,9 @@ starrocksCnSpec:
# For persistent storage, specify a volume name prefix.
# For example, using `cn` as the name prefix would be appropriate.
name: ""
# the storageClassName represent the used storageclass name. if not set will use k8s cluster default storageclass.
# you must set name when you set storageClassName
# The storageClassName represent the used storageclass name. if not set will use k8s cluster default storageclass.
# You must set name when you set storageClassName
# Note: Because hostPath field is not supported here, hostPath is not allowed to be set in storageClassName.
storageClassName: ""
# the storage size of persistent volume for data.
storageSize: 1Ti
Expand All @@ -570,7 +572,10 @@ starrocksCnSpec:
# - name: tmp-data
# mountPath: /tmp
# mount hostPath volumes if necessary.
# Note: please use storageSpec field for persistent storage data and log.
# Note:
# 1. please use storageSpec field for persistent storage data and log.
# 2. please use podAntiAffinity to avoid the pods are scheduled on the same node.
# 3. If you use hostPath to mount the volume of cache data, cache will be lost when the pod is restarted.
hostPaths: []
# e.g. mount a hostPath volume to /tmp
# - name: tmp-data
Expand Down Expand Up @@ -798,8 +803,9 @@ starrocksBeSpec:
# For persistent storage, specify a volume name prefix.
# For example, using `be` as the name prefix would be appropriate.
name: ""
# the storageClassName represent the used storageclass name. if not set will use k8s cluster default storageclass.
# you must set name when you set storageClassName
# The storageClassName represent the used storageclass name. if not set will use k8s cluster default storageclass.
# You must set name when you set storageClassName
# Note: Because hostPath field is not supported here, hostPath is not allowed to be set in storageClassName.
storageClassName: ""
# the storage size of persistent volume for data.
storageSize: 1Ti
Expand Down
20 changes: 13 additions & 7 deletions helm-charts/charts/kube-starrocks/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,9 @@ starrocks:
# For persistent storage, specify a volume name prefix.
# For example, using `fe` as the name prefix would be appropriate.
name: ""
# the storageClassName represent the used storageclass name. if not set will use k8s cluster default storageclass.
# you must set name when you set storageClassName
# The storageClassName represent the used storageclass name. if not set will use k8s cluster default storageclass.
# You must set name when you set storageClassName.
# Note: Because hostPath field is not supported here, hostPath is not allowed to be set in storageClassName.
storageClassName: ""
# the persistent volume size, default 10Gi.
# fe container stop running if the disk free space which the fe meta directory residents, is less than 5Gi.
Expand Down Expand Up @@ -657,8 +658,9 @@ starrocks:
# For persistent storage, specify a volume name prefix.
# For example, using `cn` as the name prefix would be appropriate.
name: ""
# the storageClassName represent the used storageclass name. if not set will use k8s cluster default storageclass.
# you must set name when you set storageClassName
# The storageClassName represent the used storageclass name. if not set will use k8s cluster default storageclass.
# You must set name when you set storageClassName
# Note: Because hostPath field is not supported here, hostPath is not allowed to be set in storageClassName.
storageClassName: ""
# the storage size of persistent volume for data.
storageSize: 1Ti
Expand All @@ -678,7 +680,10 @@ starrocks:
# - name: tmp-data
# mountPath: /tmp
# mount hostPath volumes if necessary.
# Note: please use storageSpec field for persistent storage data and log.
# Note:
# 1. please use storageSpec field for persistent storage data and log.
# 2. please use podAntiAffinity to avoid the pods are scheduled on the same node.
# 3. If you use hostPath to mount the volume of cache data, cache will be lost when the pod is restarted.
hostPaths: []
# e.g. mount a hostPath volume to /tmp
# - name: tmp-data
Expand Down Expand Up @@ -906,8 +911,9 @@ starrocks:
# For persistent storage, specify a volume name prefix.
# For example, using `be` as the name prefix would be appropriate.
name: ""
# the storageClassName represent the used storageclass name. if not set will use k8s cluster default storageclass.
# you must set name when you set storageClassName
# The storageClassName represent the used storageclass name. if not set will use k8s cluster default storageclass.
# You must set name when you set storageClassName
# Note: Because hostPath field is not supported here, hostPath is not allowed to be set in storageClassName.
storageClassName: ""
# the storage size of persistent volume for data.
storageSize: 1Ti
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/starrocks/v1/starrockscluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,10 @@ func (storageVolume *StorageVolume) Validate() error {
return ErrHostPathRequired
}
}
} else if storageVolume.HostPath != nil {
if storageVolume.HostPath.Path == "" {
return ErrHostPathRequired
}
}
return nil
}
Expand Down
35 changes: 24 additions & 11 deletions pkg/k8sutils/templates/pod/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,24 @@ import (
"github.com/StarRocks/starrocks-kubernetes-operator/pkg/common/hash"
)

func IsSpecialStorageClass(storageClassName *string) bool {
return storageClassName != nil && (common.EqualsIgnoreCase(*storageClassName, v1.EmptyDir) ||
common.EqualsIgnoreCase(*storageClassName, v1.HostPath))
// SpecialStorageClassName returns the special storage class name of the storage volume, else return "".
// Now we support HostPath and EmptyDir as special storage class.
func SpecialStorageClassName(sv v1.StorageVolume) string {
storageClassName := sv.StorageClassName
if storageClassName != nil {
if common.EqualsIgnoreCase(*storageClassName, v1.EmptyDir) {
return v1.EmptyDir
} else if common.EqualsIgnoreCase(*storageClassName, v1.HostPath) {
return v1.HostPath
}
return ""
}

if sv.HostPath != nil {
return v1.HostPath
}

return ""
}

// MountStorageVolumes parse StorageVolumes from spec and mount them to pod.
Expand All @@ -24,14 +39,12 @@ func MountStorageVolumes(spec v1.SpecInterface) ([]corev1.Volume, []corev1.Volum
if strings.HasPrefix(sv.StorageSize, "0") {
continue
}
if IsSpecialStorageClass(sv.StorageClassName) {
switch *sv.StorageClassName {
case v1.EmptyDir:
volumes, volumeMounts = MountEmptyDirVolume(volumes, volumeMounts, sv.Name, sv.MountPath, sv.SubPath)
case v1.HostPath:
volumes, volumeMounts = MountHostPathVolume(volumes, volumeMounts, sv.Name, sv.MountPath, sv.SubPath, sv.HostPath)
}
} else {
switch name := SpecialStorageClassName(sv); name {
case v1.EmptyDir:
volumes, volumeMounts = MountEmptyDirVolume(volumes, volumeMounts, sv.Name, sv.MountPath, sv.SubPath)
case v1.HostPath:
volumes, volumeMounts = MountHostPathVolume(volumes, volumeMounts, sv.Name, sv.MountPath, sv.SubPath, sv.HostPath)
default:
volumes, volumeMounts = MountPersistentVolumeClaim(volumes, volumeMounts, sv.Name, sv.MountPath, sv.SubPath)
}
}
Expand Down
71 changes: 71 additions & 0 deletions pkg/k8sutils/templates/pod/mount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,74 @@ func TestMountPersistentVolumeClaim(t *testing.T) {
})
}
}

func TestSpecialStorageClassName(t *testing.T) {
type args struct {
sv v1.StorageVolume
}
tests := []struct {
name string
args args
want string
}{
{
name: "test storage volume with empty dir",
args: args{
sv: v1.StorageVolume{
StorageClassName: func() *string { s := v1.EmptyDir; return &s }(),
},
},
want: v1.EmptyDir,
},
{
name: "test storage volume with host path",
args: args{
sv: v1.StorageVolume{
StorageClassName: func() *string { s := v1.HostPath; return &s }(),
},
},
want: v1.HostPath,
},
{
name: "test storage volume with persistent volume claim",
args: args{
sv: v1.StorageVolume{
StorageClassName: func() *string { s := "pvc"; return &s }(),
},
},
want: "",
},
{
name: "test storage volume with host path",
args: args{
sv: v1.StorageVolume{
HostPath: &corev1.HostPathVolumeSource{
Path: "",
Type: nil,
},
},
},
want: v1.HostPath,
},
{
name: "test storage volume with host path and pvc name",
args: args{
sv: v1.StorageVolume{
HostPath: &corev1.HostPathVolumeSource{
Path: "",
Type: nil,
},
StorageClassName: func() *string { s := "pvc"; return &s }(),
},
},
want: "",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := SpecialStorageClassName(tt.args.sv); got != tt.want {
t.Errorf("SpecialStorageClassName() = %v, want %v", got, tt.want)
}
})
}
}
2 changes: 1 addition & 1 deletion pkg/k8sutils/templates/statefulset/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const STARROCKS_WAREHOUSE_FINALIZER = "starrocks.com.starrockswarehouse/protecti
func PVCList(volumes []v1.StorageVolume) []corev1.PersistentVolumeClaim {
var pvcs []corev1.PersistentVolumeClaim
for _, vm := range volumes {
if pod.IsSpecialStorageClass(vm.StorageClassName) {
if name := pod.SpecialStorageClassName(vm); name != "" {
continue
}
if strings.HasPrefix(vm.StorageSize, "0") {
Expand Down

0 comments on commit c7f0549

Please sign in to comment.