Skip to content

Commit

Permalink
csi: account for nil volume/mount in API-to-structs conversion
Browse files Browse the repository at this point in the history
Fix a nil pointer in the API struct to `nomad/structs` conversion when a
`volume` or `volume_mount` block is empty.
  • Loading branch information
tgross committed Jul 6, 2021
1 parent 062f441 commit 12dca86
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .changelog/10855.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
csi: Fix a bug where the HTTP server would crash if a `volume` or `volume_mount` block was empty
```
17 changes: 10 additions & 7 deletions command/agent/job_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ func ApiTgToStructsTG(job *structs.Job, taskGroup *api.TaskGroup, tg *structs.Ta
if l := len(taskGroup.Volumes); l != 0 {
tg.Volumes = make(map[string]*structs.VolumeRequest, l)
for k, v := range taskGroup.Volumes {
if v.Type != structs.VolumeTypeHost && v.Type != structs.VolumeTypeCSI {
if v == nil || (v.Type != structs.VolumeTypeHost && v.Type != structs.VolumeTypeCSI) {
// Ignore volumes we don't understand in this iteration currently.
// - This is because we don't currently have a way to return errors here.
continue
Expand Down Expand Up @@ -1027,12 +1027,15 @@ func ApiTaskToStructsTask(job *structs.Job, group *structs.TaskGroup,

if l := len(apiTask.VolumeMounts); l != 0 {
structsTask.VolumeMounts = make([]*structs.VolumeMount, l)
for i, mount := range apiTask.VolumeMounts {
structsTask.VolumeMounts[i] = &structs.VolumeMount{
Volume: *mount.Volume,
Destination: *mount.Destination,
ReadOnly: *mount.ReadOnly,
PropagationMode: *mount.PropagationMode,
for _, mount := range apiTask.VolumeMounts {
if mount != nil {
structsTask.VolumeMounts = append(structsTask.VolumeMounts,
&structs.VolumeMount{
Volume: *mount.Volume,
Destination: *mount.Destination,
ReadOnly: *mount.ReadOnly,
PropagationMode: *mount.PropagationMode,
})
}
}
}
Expand Down

0 comments on commit 12dca86

Please sign in to comment.