Skip to content

Commit

Permalink
add support for pvcs to apiserver
Browse files Browse the repository at this point in the history
Signed-off-by: Paul S. Schweigert <[email protected]>
  • Loading branch information
psschwei committed May 26, 2023
1 parent f6a172f commit 05b3711
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
13 changes: 12 additions & 1 deletion apiserver/pkg/util/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,18 @@ func buildVols(apiVolumes []*api.Volume) []v1.Volume {
}
vols = append(vols, vol)
}
// TODO(Jeffwan@): handle PVC in the future
if rayVol.VolumeType == api.Volume_PERSISTENT_VOLUME_CLAIM {
vol := v1.Volume{
Name: rayVol.Name,
VolumeSource: v1.VolumeSource{
PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{
ClaimName: rayVol.Name,
ReadOnly: rayVol.ReadOnly,
},
},
}
vols = append(vols, vol)
}
}

return vols
Expand Down
32 changes: 32 additions & 0 deletions apiserver/pkg/util/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ var testFileVolume = &api.Volume{
ReadOnly: true,
}

var testPVCVolume = &api.Volume{
Name: "test-pvc",
VolumeType: api.Volume_PERSISTENT_VOLUME_CLAIM,
MountPath: "/pvc/dir",
ReadOnly: true,
}

func TestBuildVolumes(t *testing.T) {
targetVolume := v1.Volume{
Name: testVolume.Name,
Expand All @@ -47,6 +54,16 @@ func TestBuildVolumes(t *testing.T) {
},
},
}

targetPVCVolume := v1.Volume{
Name: testPVCVolume.Name,
VolumeSource: v1.VolumeSource{
PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{
ClaimName: testPVCVolume.Name,
ReadOnly: testPVCVolume.ReadOnly,
},
},
}
tests := []struct {
name string
apiVolume []*api.Volume
Expand All @@ -59,6 +76,11 @@ func TestBuildVolumes(t *testing.T) {
},
[]v1.Volume{targetVolume, targetFileVolume},
},
{
"pvc test",
[]*api.Volume{testPVCVolume},
[]v1.Volume{targetPVCVolume},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -83,6 +105,11 @@ func TestBuildVolumeMounts(t *testing.T) {
MountPath: testFileVolume.MountPath,
MountPropagation: &hostToContainer,
}
targetPVCVolumeMount := v1.VolumeMount{
Name: testPVCVolume.Name,
ReadOnly: testPVCVolume.ReadOnly,
MountPath: testPVCVolume.MountPath,
}
tests := []struct {
name string
apiVolume []*api.Volume
Expand All @@ -99,6 +126,11 @@ func TestBuildVolumeMounts(t *testing.T) {
targetFileVolumeMount,
},
},
{
"pvc test",
[]*api.Volume{testPVCVolume},
[]v1.VolumeMount{targetPVCVolumeMount},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 05b3711

Please sign in to comment.