Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PWX-30455] feat: volume-mount override via custom mount #1168

Closed
wants to merge 8 commits into from
30 changes: 30 additions & 0 deletions drivers/storage/portworx/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -1295,9 +1295,39 @@ func (t *template) getVolumeMounts() []v1.VolumeMount {
for _, fn := range extensions {
volumeInfoList = append(volumeInfoList, fn()...)
}
volumeInfoList = t.overrideVolumeMount(volumeInfoList)
return t.mountsFromVolInfo(volumeInfoList)
}

func (t *template) overrideVolumeMount(volInfos []volumeInfo) []volumeInfo {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this called overrideVolumeMount?

  • we are not overriding the internal mounts-list
  • instead, we are filtering (and extending) the list that was provided as input

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are not just filtering but also modifying the host path property inside the function

volPaths := map[string]int{}

for i := range volInfos {
volPaths[volInfos[i].mountPath] = i
}

for i := range t.cluster.Spec.Volumes {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we'll take the volInfos first, then we'll append all the previous cluster.Spec.Volumes

This seems to be clashing with how the px-runc is working on the "lower level":

  • "default" mounts "go in" first
  • "custom mounts" will go after the "default mounts" -- and have the opportunity to override the defaults

Is this code behaving the same?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the ticket requires allowing to existing mount paths with a custom hostpath
this function is triggered at last as this will allow us to add more mount paths as well as modify any existing mount paths that is utilized by our application

v := t.cluster.Spec.Volumes[i]
existingVolIdx, ok := volPaths[v.MountPath]
if !ok {
volInfos = append(volInfos, volumeInfo{
name: v.Name,
readOnly: v.ReadOnly,
hostPath: v.HostPath.String(),
mountPath: v.MountPath,
mountPropagation: v.MountPropagation,
hostPathType: v.HostPath.Type,
configMapType: v.ConfigMap,
})
} else {
volInfos[existingVolIdx].hostPath = v.HostPath.String()
volInfos[existingVolIdx].mountPropagation = v.MountPropagation
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we overriding only the host-path and the mount-propagation?

Shouldn't we at least copy the mount-options (i.e. read-only)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for existing mounts, if a stc yaml overrides the mount options then it could affect the functionality of porx
imagine someone makes the oci log file to be read only then we do not get to write the logs

}
}

return volInfos
}

func (t *template) mountsFromVolInfo(vols []volumeInfo) []v1.VolumeMount {
volumeMounts := make([]v1.VolumeMount, 0, len(vols))
mountPathSet := make(map[string]bool)
Expand Down
102 changes: 102 additions & 0 deletions drivers/storage/portworx/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4436,3 +4436,105 @@ func assertContainerEqual(t *testing.T, expected, actual v1.Container) {
assert.ElementsMatch(t, expected.Env, actual.Env)
assert.ElementsMatch(t, expected.VolumeMounts, actual.VolumeMounts)
}

func Test_template_overrideVolumeMount(t *testing.T) {
testVols := getCommonVolumeList(pxutil.MinimumPxVersionAutoTLS)
hp0 := &v1.HostPathVolumeSource{
Path: "/test0",
}
overRideVols := append(testVols, []volumeInfo{}...)
for i := range overRideVols {
if overRideVols[i].name == "diagsdump" {
overRideVols[i].hostPath = hp0.String()
overRideVols[i].mountPropagation = mountPropagationModePtr(v1.MountPropagationBidirectional)
break
}
}

hp1 := &v1.HostPathVolumeSource{
Path: "/test1",
}
hp2 := &v1.HostPathVolumeSource{
Path: "/test2",
}
additionalMounts := append(testVols, volumeInfo{
name: "test",
hostPath: hp2.String(),
mountPath: "/test2",
mountPropagation: mountPropagationModePtr(v1.MountPropagationBidirectional),
})
for i := range additionalMounts {
if additionalMounts[i].name == "diagsdump" {
additionalMounts[i].hostPath = hp1.String()
additionalMounts[i].mountPropagation = mountPropagationModePtr(v1.MountPropagationBidirectional)
break
}
}

tests := []struct {
name string
vols []corev1.VolumeSpec
volInfos []volumeInfo
want []volumeInfo
}{
{
"no override",
[]corev1.VolumeSpec{},
testVols,
testVols,
},
{
"override existing volume mounts",
[]corev1.VolumeSpec{
{
Name: "diagsdump",
MountPath: "/var/cores",
VolumeSource: v1.VolumeSource{
HostPath: hp0,
},
MountPropagation: mountPropagationModePtr(v1.MountPropagationBidirectional),
},
},
testVols,
overRideVols,
},
{
"override existing volume mounts and append new mounts",
[]corev1.VolumeSpec{
{
Name: "diagsdump",
MountPath: "/var/cores",
VolumeSource: v1.VolumeSource{
HostPath: hp1,
},
MountPropagation: mountPropagationModePtr(v1.MountPropagationBidirectional),
},
{
Name: "test",
MountPath: "/test2",
VolumeSource: v1.VolumeSource{
HostPath: hp2,
},
MountPropagation: mountPropagationModePtr(v1.MountPropagationBidirectional),
},
},
testVols,
additionalMounts,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tr := &template{
cluster: &corev1.StorageCluster{
Spec: corev1.StorageClusterSpec{
Volumes: tt.vols,
},
},
}
// if got := tr.overrideVolumeMount(tt.volInfos); !reflect.DeepEqual(got, tt.want) {
if got := tr.overrideVolumeMount(tt.volInfos); !assert.Equal(t, got, tt.want) {
t.Errorf("template.overrideVolumeMount() = %v, want %v", got, tt.want)
}
})
}
}
Loading