csi/api: populate ReadAllocs/WriteAllocs fields (#9377)

The API is missing values for `ReadAllocs` and `WriteAllocs` fields, resulting
in allocation claims not being populated in the web UI. These fields mirror
the fields in `nomad/structs.CSIVolume`. Returning a separate list of stubs
for read and write would be ideal, but this can't be done without either
bloating the API response with repeated full `Allocation` data, or causing a
panic in previous versions of the CLI.

The `nomad/structs` fields are persisted with nil values and are populated
during RPC, so we'll do the same in the HTTP API and populate the `ReadAllocs`
and `WriteAllocs` fields with a map of allocation IDs, but with null
values. The web UI will then create its `ReadAllocations` and
`WriteAllocations` fields by mapping from those IDs to the values in
`Allocations`, instead of flattening the map into a list.
This commit is contained in:
Tim Gross
2020-11-25 16:44:06 -05:00
committed by GitHub
parent bda5049aa2
commit 8351c3f9d6
10 changed files with 79 additions and 61 deletions

View File

@@ -41,9 +41,6 @@ func (v *CSIVolumes) Info(id string, q *QueryOptions) (*CSIVolume, *QueryMeta, e
return nil, nil, err
}
// Cleanup allocation representation for the ui
resp.allocs()
return &resp, qm, nil
}
@@ -110,11 +107,17 @@ type CSIVolume struct {
Parameters map[string]string `hcl:"parameters"`
Context map[string]string `hcl:"context"`
// Allocations, tracking claim status
ReadAllocs map[string]*Allocation
// ReadAllocs is a map of allocation IDs for tracking reader claim status.
// The Allocation value will always be nil; clients can populate this data
// by iterating over the Allocations field.
ReadAllocs map[string]*Allocation
// WriteAllocs is a map of allocation IDs for tracking writer claim
// status. The Allocation value will always be nil; clients can populate
// this data by iterating over the Allocations field.
WriteAllocs map[string]*Allocation
// Combine structs.{Read,Write}Allocs
// Allocations is a combined list of readers and writers
Allocations []*AllocationListStub
// Schedulable is true if all the denormalized plugin health fields are true
@@ -136,21 +139,6 @@ type CSIVolume struct {
ExtraKeysHCL []string `hcl1:",unusedKeys" json:"-"`
}
// allocs is called after we query the volume (creating this CSIVolume struct) to collapse
// allocations for the UI
func (v *CSIVolume) allocs() {
for _, a := range v.WriteAllocs {
if a != nil {
v.Allocations = append(v.Allocations, a.Stub())
}
}
for _, a := range v.ReadAllocs {
if a != nil {
v.Allocations = append(v.Allocations, a.Stub())
}
}
}
type CSIVolumeIndexSort []*CSIVolumeListStub
func (v CSIVolumeIndexSort) Len() int {