From 369b0e54b9a60d203d39b5ebf77af8957cc23853 Mon Sep 17 00:00:00 2001 From: Lang Martin Date: Tue, 3 Mar 2020 10:59:58 -0500 Subject: [PATCH] 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 --- api/csi.go | 31 ++++++++++++++++--------------- nomad/state/state_store.go | 6 +++--- nomad/state/state_store_test.go | 4 ++-- nomad/structs/csi.go | 28 ++++++++++++++++++---------- nomad/structs/csi_test.go | 2 +- 5 files changed, 40 insertions(+), 31 deletions(-) diff --git a/api/csi.go b/api/csi.go index ca6474970..556867d4e 100644 --- a/api/csi.go +++ b/api/csi.go @@ -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 diff --git a/nomad/state/state_store.go b/nomad/state/state_store.go index c85c3cc90..2b1567d7a 100644 --- a/nomad/state/state_store.go +++ b/nomad/state/state_store.go @@ -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 diff --git a/nomad/state/state_store_test.go b/nomad/state/state_store_test.go index 5b8cccf66..5af1ad81b 100644 --- a/nomad/state/state_store_test.go +++ b/nomad/state/state_store_test.go @@ -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 diff --git a/nomad/structs/csi.go b/nomad/structs/csi.go index 5526c04d8..77709b362 100644 --- a/nomad/structs/csi.go +++ b/nomad/structs/csi.go @@ -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, diff --git a/nomad/structs/csi_test.go b/nomad/structs/csi_test.go index 7685b41b4..83f2ba2c9 100644 --- a/nomad/structs/csi_test.go +++ b/nomad/structs/csi_test.go @@ -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"}