Skip to content

Commit

Permalink
[BugFix] Fix mountPath (#491)
Browse files Browse the repository at this point in the history
Signed-off-by: yandongxiao <[email protected]>
  • Loading branch information
yandongxiao authored Mar 25, 2024
1 parent a90a5c5 commit a3c9c45
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 11 deletions.
16 changes: 8 additions & 8 deletions config/crd/bases/starrocks.com_starrocksclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1544,8 +1544,8 @@ spec:
type: string
storageClassName:
description: 'storageClassName is the name of the StorageClass
required by the claim. If storageClassName is empty, the
default StorageClass of kubernetes will be used. there
required by the claim. If storageClassName is not set,
the default StorageClass of kubernetes will be used. there
are some special storageClassName: emptyDir, hostPath.
In this case, It will use emptyDir or hostPath, not PVC.
More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#class-1'
Expand Down Expand Up @@ -3790,8 +3790,8 @@ spec:
type: string
storageClassName:
description: 'storageClassName is the name of the StorageClass
required by the claim. If storageClassName is empty, the
default StorageClass of kubernetes will be used. there
required by the claim. If storageClassName is not set,
the default StorageClass of kubernetes will be used. there
are some special storageClassName: emptyDir, hostPath.
In this case, It will use emptyDir or hostPath, not PVC.
More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#class-1'
Expand Down Expand Up @@ -5165,8 +5165,8 @@ spec:
type: string
storageClassName:
description: 'storageClassName is the name of the StorageClass
required by the claim. If storageClassName is empty, the
default StorageClass of kubernetes will be used. there
required by the claim. If storageClassName is not set,
the default StorageClass of kubernetes will be used. there
are some special storageClassName: emptyDir, hostPath.
In this case, It will use emptyDir or hostPath, not PVC.
More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#class-1'
Expand Down Expand Up @@ -6718,8 +6718,8 @@ spec:
type: string
storageClassName:
description: 'storageClassName is the name of the StorageClass
required by the claim. If storageClassName is empty, the
default StorageClass of kubernetes will be used. there
required by the claim. If storageClassName is not set,
the default StorageClass of kubernetes will be used. there
are some special storageClassName: emptyDir, hostPath.
In this case, It will use emptyDir or hostPath, not PVC.
More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#class-1'
Expand Down
4 changes: 2 additions & 2 deletions config/crd/bases/starrocks.com_starrockswarehouses.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2215,8 +2215,8 @@ spec:
type: string
storageClassName:
description: 'storageClassName is the name of the StorageClass
required by the claim. If storageClassName is empty, the
default StorageClass of kubernetes will be used. there
required by the claim. If storageClassName is not set,
the default StorageClass of kubernetes will be used. there
are some special storageClassName: emptyDir, hostPath.
In this case, It will use emptyDir or hostPath, not PVC.
More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#class-1'
Expand Down
2 changes: 1 addition & 1 deletion pkg/k8sutils/k8sutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ func HasVolume(volumes []corev1.Volume, newVolumeName string) bool {

func HasMountPath(mounts []corev1.VolumeMount, newMountPath string) bool {
for _, v := range mounts {
if v.Name == newMountPath {
if v.MountPath == newMountPath {
return true
}
}
Expand Down
100 changes: 100 additions & 0 deletions pkg/k8sutils/k8sutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -779,3 +779,103 @@ func TestDeleteAutoscaler(t *testing.T) {
})
}
}

func TestHasMountPath(t *testing.T) {
type args struct {
mounts []corev1.VolumeMount
newMountPath string
}
tests := []struct {
name string
args args
want bool
}{
{
name: "test has mount path",
args: args{
mounts: []corev1.VolumeMount{
{
Name: "fe-meta-storage",
MountPath: "/opt/starrocks/fe/fe-meta",
},
},
newMountPath: "/opt/starrocks/fe/fe-meta",
},
want: true,
},
{
name: "test has mount path 2",
args: args{
mounts: []corev1.VolumeMount{
{
Name: "fe-meta-storage",
MountPath: "/opt/starrocks/fe/fe-meta",
},
},
newMountPath: "/opt/starrocks/fe/fe-meta2",
},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := k8sutils.HasMountPath(tt.args.mounts, tt.args.newMountPath); got != tt.want {
t.Errorf("HasMountPath() = %v, want %v", got, tt.want)
}
})
}
}

func TestHasVolume(t *testing.T) {
type args struct {
volumes []corev1.Volume
newVolumeName string
}
tests := []struct {
name string
args args
want bool
}{
{
name: "test has volume",
args: args{
volumes: []corev1.Volume{
{
Name: "fe-meta",
VolumeSource: corev1.VolumeSource{
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "fe-meta",
},
},
},
},
newVolumeName: "fe-meta",
},
want: true,
},
{
name: "test has volume",
args: args{
volumes: []corev1.Volume{
{
Name: "fe-meta",
VolumeSource: corev1.VolumeSource{
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "fe-meta",
},
},
},
},
newVolumeName: "fe-meta2",
},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := k8sutils.HasVolume(tt.args.volumes, tt.args.newVolumeName); got != tt.want {
t.Errorf("HasVolume() = %v, want %v", got, tt.want)
}
})
}
}
53 changes: 53 additions & 0 deletions pkg/k8sutils/templates/pod/mount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,56 @@ func Test_getVolumeName(t *testing.T) {
})
}
}

func TestMountPersistentVolumeClaim(t *testing.T) {
type args struct {
volumes []corev1.Volume
volumeMounts []corev1.VolumeMount
volumeName string
mountPath string
subPath string
}
tests := []struct {
name string
args args
want []corev1.Volume
want1 []corev1.VolumeMount
}{
{
name: "test mount persistent volume claim",
args: args{
volumes: []corev1.Volume{},
volumeMounts: []corev1.VolumeMount{},
volumeName: "fe-meta",
mountPath: "/opt/starrocks/fe/fe-meta",
},
want: []corev1.Volume{
{
Name: "fe-meta",
VolumeSource: corev1.VolumeSource{
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "fe-meta",
},
},
},
},
want1: []corev1.VolumeMount{
{
Name: "fe-meta",
MountPath: "/opt/starrocks/fe/fe-meta",
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, got1 := MountPersistentVolumeClaim(tt.args.volumes, tt.args.volumeMounts, tt.args.volumeName, tt.args.mountPath, tt.args.subPath)
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("MountPersistentVolumeClaim() got = %v, want %v", got, tt.want)
}
if !reflect.DeepEqual(got1, tt.want1) {
t.Errorf("MountPersistentVolumeClaim() got1 = %v, want %v", got1, tt.want1)
}
})
}
}

0 comments on commit a3c9c45

Please sign in to comment.