Skip to content

Commit

Permalink
Fix dynamic config when upgrading from old version
Browse files Browse the repository at this point in the history
Signed-off-by: shaoyue.chen <[email protected]>
  • Loading branch information
haorenfsa committed May 24, 2024
1 parent cbe3673 commit 52336c5
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 11 deletions.
4 changes: 2 additions & 2 deletions pkg/controllers/configmaps.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ func (r *MilvusReconciler) updateConfigMap(ctx context.Context, mc v1beta1.Milvu
configmap.Data = make(map[string]string)
}

configmap.Data[MilvusUserConfigMountSubPath] = string(milvusYaml)
configmap.Data[UserYaml] = string(milvusYaml)

if len(mc.Spec.HookConf.Data) > 0 {
hookYaml, err := yaml.Marshal(mc.Spec.HookConf.Data)
if err != nil {
r.logger.Error(err, "yaml Unmarshal hook conf error")
return err
}
configmap.Data[MilvusHookConfigMountSubPath] = string(hookYaml)
configmap.Data[HookYaml] = string(hookYaml)
}

return nil
Expand Down
1 change: 1 addition & 0 deletions pkg/controllers/deployment_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ func updateBuiltInVolumeMounts(template *corev1.PodTemplateSpec, updater deploym
configVolumeMount,
toolVolumeMount,
}
removeVolumeMounts(&container.VolumeMounts, MilvusConfigVolumeName)
for _, volumeMount := range builtInVolumeMounts {
addVolumeMount(&container.VolumeMounts, volumeMount)
}
Expand Down
30 changes: 21 additions & 9 deletions pkg/controllers/deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@ import (
)

const (
MilvusDataVolumeName = "milvus-data" // for standalone persistence only
MilvusConfigVolumeName = "milvus-config"
MilvusOriginalConfigPath = "/milvus/configs/milvus.yaml"
MilvusConfigmapMountPath = "/milvus/configs/operator"
MilvusUserConfigMountSubPath = "user.yaml"
MilvusHookConfigMountSubPath = "hook.yaml"
AccessKey = "accesskey"
SecretKey = "secretkey"
AnnotationCheckSum = "checksum/config"
MilvusDataVolumeName = "milvus-data" // for standalone persistence only
MilvusConfigVolumeName = "milvus-config"
MilvusConfigRootPath = "/milvus/configs"
MilvusOriginalConfigPath = MilvusConfigRootPath + "/milvus.yaml"
MilvusConfigmapMountPath = MilvusConfigRootPath + "/operator"

UserYaml = "user.yaml"
HookYaml = "hook.yaml"
AccessKey = "accesskey"
SecretKey = "secretkey"
AnnotationCheckSum = "checksum/config"

ToolsVolumeName = "tools"
ToolsMountPath = "/milvus/tools"
Expand Down Expand Up @@ -235,6 +237,16 @@ func addVolume(volumes *[]corev1.Volume, volume corev1.Volume) {
}
}

func removeVolumeMounts(volumeMounts *[]corev1.VolumeMount, volumeName string) {
result := make([]corev1.VolumeMount, 0)
for i := range *volumeMounts {
if (*volumeMounts)[i].Name != volumeName {
result = append(result, (*volumeMounts)[i])
}
}
*volumeMounts = result
}

func addVolumeMount(volumeMounts *[]corev1.VolumeMount, volumeMount corev1.VolumeMount) {
volumeMountIdx := GetVolumeMountIndex(*volumeMounts, volumeMount.MountPath)
if volumeMountIdx < 0 {
Expand Down
25 changes: 25 additions & 0 deletions pkg/controllers/deployments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,28 @@ func TestReconciler_handleOldInstanceChangingMode(t *testing.T) {
assert.NoError(t, err)
})
}

func Test_removeVolumeMounts(t *testing.T) {
vms := []corev1.VolumeMount{
{
Name: "v1",
MountPath: "p1",
},
{
Name: "v1",
MountPath: "p2",
},
{
Name: "v2",
MountPath: "p3",
},
{
Name: "v3",
MountPath: "p4",
},
}
removeVolumeMounts(&vms, "v1")
assert.Len(t, vms, 2)
assert.Equal(t, "p3", vms[0].MountPath)
assert.Equal(t, "p4", vms[1].MountPath)
}

0 comments on commit 52336c5

Please sign in to comment.