Skip to content

Commit

Permalink
Fix volumeMounts merge (#36)
Browse files Browse the repository at this point in the history
Signed-off-by: shaoyue.chen <[email protected]>
  • Loading branch information
haorenfsa authored Nov 7, 2023
1 parent 10694ce commit 21ed968
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pkg/controllers/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,17 @@ func MergeComponentSpec(src, dst ComponentSpec) ComponentSpec {
}

if src.VolumeMounts != nil {
dst.VolumeMounts = src.VolumeMounts
if dst.VolumeMounts == nil {
dst.VolumeMounts = []corev1.VolumeMount{}
}
for _, srcVolumeMount := range src.VolumeMounts {
idx := GetVolumeMountIndex(dst.VolumeMounts, srcVolumeMount.SubPath)
if idx < 0 {
dst.VolumeMounts = append(dst.VolumeMounts, srcVolumeMount)
} else {
dst.VolumeMounts[idx] = srcVolumeMount
}
}
}

if src.Volumes != nil {
Expand Down
22 changes: 22 additions & 0 deletions pkg/controllers/components_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,28 @@ func TestMergeComponentSpec(t *testing.T) {
merged = MergeComponentSpec(src, dst).PriorityClassName
assert.Equal(t, "b", merged)
})

t.Run("merge volumeMounts", func(t *testing.T) {
dst.VolumeMounts = []corev1.VolumeMount{
{SubPath: "a.yaml"},
}
merged := MergeComponentSpec(src, dst).VolumeMounts
assert.Equal(t, 1, len(merged))
assert.Equal(t, "a.yaml", merged[0].SubPath)

src.VolumeMounts = []corev1.VolumeMount{
{SubPath: "b.yaml"},
}
merged = MergeComponentSpec(src, dst).VolumeMounts
assert.Equal(t, 2, len(merged))

src.VolumeMounts = []corev1.VolumeMount{
{SubPath: "a.yaml", Name: "c"},
}
merged = MergeComponentSpec(src, dst).VolumeMounts
assert.Equal(t, 2, len(merged))
assert.Equal(t, "c", merged[1].Name)
})
}

func TestMilvusComponent_GetReplicas(t *testing.T) {
Expand Down

0 comments on commit 21ed968

Please sign in to comment.