csi: volumes use `Schedulable` rather than `Healthy` (#7250)

* structs: add ControllerRequired, volume.Name, no plug.Type

* structs: Healthy -> Schedulable

* state_store: Healthy -> Schedulable

* api: add ControllerRequired to api data types

* api: copy csi structs changes

* nomad/structs/csi: include name and external id

* api/csi: include Name and ExternalID

* nomad/structs/csi: comments for the 3 ids
This commit is contained in:
Lang Martin 2020-03-03 10:59:58 -05:00 committed by Tim Gross
parent a4784ef258
commit 369b0e54b9
5 changed files with 40 additions and 31 deletions

View File

@ -81,6 +81,8 @@ const (
type CSIVolume struct {
ID string
Namespace string
Name string
ExternalID string
Topologies []*CSITopology
AccessMode CSIVolumeAccessMode
AttachmentMode CSIVolumeAttachmentMode
@ -88,11 +90,9 @@ type CSIVolume struct {
// Combine structs.{Read,Write,Past}Allocs
Allocations []*AllocationListStub
// Healthy is true iff all the denormalized plugin health fields are true, and the
// volume has not been marked for garbage collection
Healthy bool
VolumeGC time.Time
Schedulable bool
PluginID string
ControllerRequired bool
ControllersHealthy int
ControllersExpected int
NodesHealthy int
@ -119,17 +119,16 @@ func (v CSIVolumeIndexSort) Swap(i, j int) {
// CSIVolumeListStub omits allocations. See also nomad/structs/csi.go
type CSIVolumeListStub struct {
ID string
Namespace string
Topologies []*CSITopology
AccessMode CSIVolumeAccessMode
AttachmentMode CSIVolumeAttachmentMode
// Healthy is true iff all the denormalized plugin health fields are true, and the
// volume has not been marked for garbage collection
Healthy bool
VolumeGC time.Time
ID string
Namespace string
Name string
ExternalID string
Topologies []*CSITopology
AccessMode CSIVolumeAccessMode
AttachmentMode CSIVolumeAttachmentMode
Schedulable bool
PluginID string
ControllerRequired bool
ControllersHealthy int
ControllersExpected int
NodesHealthy int
@ -156,7 +155,8 @@ type CSIPlugins struct {
}
type CSIPlugin struct {
ID string
ID string
ControllerRequired bool
// Map Node.ID to CSIInfo fingerprint results
Controllers map[string]*CSIInfo
Nodes map[string]*CSIInfo
@ -168,6 +168,7 @@ type CSIPlugin struct {
type CSIPluginListStub struct {
ID string
ControllerRequired bool
ControllersHealthy int
ControllersExpected int
NodesHealthy int

View File

@ -1783,7 +1783,7 @@ func (s *StateStore) CSIVolumeDenormalizePlugins(ws memdb.WatchSet, vol *structs
if plug == nil {
vol.ControllersHealthy = 0
vol.NodesHealthy = 0
vol.Healthy = false
vol.Schedulable = false
return vol, nil
}
@ -1795,9 +1795,9 @@ func (s *StateStore) CSIVolumeDenormalizePlugins(ws memdb.WatchSet, vol *structs
vol.ControllersExpected = len(plug.Controllers)
vol.NodesExpected = len(plug.Nodes)
vol.Healthy = vol.NodesHealthy > 0
vol.Schedulable = vol.NodesHealthy > 0
if vol.ControllerRequired {
vol.Healthy = vol.ControllersHealthy > 0 && vol.Healthy
vol.Schedulable = vol.ControllersHealthy > 0 && vol.Schedulable
}
return vol, nil

View File

@ -2837,7 +2837,7 @@ func TestStateStore_CSIVolume(t *testing.T) {
v0.ID = id0
v0.Namespace = "default"
v0.PluginID = "minnie"
v0.Healthy = true
v0.Schedulable = true
v0.AccessMode = structs.CSIVolumeAccessModeMultiNodeSingleWriter
v0.AttachmentMode = structs.CSIVolumeAttachmentModeFilesystem
@ -2846,7 +2846,7 @@ func TestStateStore_CSIVolume(t *testing.T) {
v1.ID = id1
v1.Namespace = "default"
v1.PluginID = "adam"
v1.Healthy = true
v1.Schedulable = true
v1.AccessMode = structs.CSIVolumeAccessModeMultiNodeSingleWriter
v1.AttachmentMode = structs.CSIVolumeAttachmentModeFilesystem

View File

@ -137,7 +137,12 @@ func ValidCSIVolumeWriteAccessMode(accessMode CSIVolumeAccessMode) bool {
// CSIVolume is the full representation of a CSI Volume
type CSIVolume struct {
ID string
// ID is a namespace unique URL safe identifier for the volume
ID string
// Name is a display name for the volume, not required to be unique
Name string
// ExternalID identifies the volume for the CSI interface, may be URL unsafe
ExternalID string
Namespace string
Topologies []*CSITopology
AccessMode CSIVolumeAccessMode
@ -147,10 +152,9 @@ type CSIVolume struct {
ReadAllocs map[string]*Allocation
WriteAllocs map[string]*Allocation
// Healthy is true if all the denormalized plugin health fields are true, and the
// Schedulable is true if all the denormalized plugin health fields are true, and the
// volume has not been marked for garbage collection
Healthy bool
VolumeGC time.Time
Schedulable bool
PluginID string
ControllerRequired bool
ControllersHealthy int
@ -167,13 +171,14 @@ type CSIVolume struct {
type CSIVolListStub struct {
ID string
Namespace string
Name string
ExternalID string
Topologies []*CSITopology
AccessMode CSIVolumeAccessMode
AttachmentMode CSIVolumeAttachmentMode
CurrentReaders int
CurrentWriters int
Healthy bool
VolumeGC time.Time
Schedulable bool
PluginID string
ControllersHealthy int
ControllersExpected int
@ -208,13 +213,14 @@ func (v *CSIVolume) Stub() *CSIVolListStub {
stub := CSIVolListStub{
ID: v.ID,
Namespace: v.Namespace,
Name: v.Name,
ExternalID: v.ExternalID,
Topologies: v.Topologies,
AccessMode: v.AccessMode,
AttachmentMode: v.AttachmentMode,
CurrentReaders: len(v.ReadAllocs),
CurrentWriters: len(v.WriteAllocs),
Healthy: v.Healthy,
VolumeGC: v.VolumeGC,
Schedulable: v.Schedulable,
PluginID: v.PluginID,
ControllersHealthy: v.ControllersHealthy,
NodesHealthy: v.NodesHealthy,
@ -227,7 +233,7 @@ func (v *CSIVolume) Stub() *CSIVolListStub {
}
func (v *CSIVolume) CanReadOnly() bool {
if !v.Healthy {
if !v.Schedulable {
return false
}
@ -235,7 +241,7 @@ func (v *CSIVolume) CanReadOnly() bool {
}
func (v *CSIVolume) CanWrite() bool {
if !v.Healthy {
if !v.Schedulable {
return false
}
@ -555,6 +561,7 @@ func (p *CSIPlugin) DeleteNode(nodeID string) {
type CSIPluginListStub struct {
ID string
ControllerRequired bool
ControllersHealthy int
ControllersExpected int
NodesHealthy int
@ -566,6 +573,7 @@ type CSIPluginListStub struct {
func (p *CSIPlugin) Stub() *CSIPluginListStub {
return &CSIPluginListStub{
ID: p.ID,
ControllerRequired: p.ControllerRequired,
ControllersHealthy: p.ControllersHealthy,
ControllersExpected: len(p.Controllers),
NodesHealthy: p.NodesHealthy,

View File

@ -9,7 +9,7 @@ import (
func TestCSIVolumeClaim(t *testing.T) {
vol := NewCSIVolume("", 0)
vol.AccessMode = CSIVolumeAccessModeMultiNodeSingleWriter
vol.Healthy = true
vol.Schedulable = true
alloc := &Allocation{ID: "al"}