github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/nomad/mock/csi.go (about) 1 package mock 2 3 import ( 4 "fmt" 5 6 "github.com/hashicorp/nomad/helper/uuid" 7 "github.com/hashicorp/nomad/nomad/structs" 8 ) 9 10 func CSIPlugin() *structs.CSIPlugin { 11 return &structs.CSIPlugin{ 12 ID: uuid.Generate(), 13 Provider: "com.hashicorp:mock", 14 Version: "0.1", 15 ControllerRequired: true, 16 Controllers: map[string]*structs.CSIInfo{}, 17 Nodes: map[string]*structs.CSIInfo{}, 18 Allocations: []*structs.AllocListStub{}, 19 ControllersHealthy: 0, 20 NodesHealthy: 0, 21 } 22 } 23 24 func CSIVolume(plugin *structs.CSIPlugin) *structs.CSIVolume { 25 return &structs.CSIVolume{ 26 ID: uuid.Generate(), 27 Name: "test-vol", 28 ExternalID: "vol-01", 29 Namespace: "default", 30 Topologies: []*structs.CSITopology{}, 31 AccessMode: structs.CSIVolumeAccessModeUnknown, 32 AttachmentMode: structs.CSIVolumeAttachmentModeUnknown, 33 MountOptions: &structs.CSIMountOptions{}, 34 Secrets: structs.CSISecrets{}, 35 Parameters: map[string]string{}, 36 Context: map[string]string{}, 37 ReadAllocs: map[string]*structs.Allocation{}, 38 WriteAllocs: map[string]*structs.Allocation{}, 39 ReadClaims: map[string]*structs.CSIVolumeClaim{}, 40 WriteClaims: map[string]*structs.CSIVolumeClaim{}, 41 PastClaims: map[string]*structs.CSIVolumeClaim{}, 42 PluginID: plugin.ID, 43 Provider: plugin.Provider, 44 ProviderVersion: plugin.Version, 45 ControllerRequired: plugin.ControllerRequired, 46 ControllersHealthy: plugin.ControllersHealthy, 47 ControllersExpected: len(plugin.Controllers), 48 NodesHealthy: plugin.NodesHealthy, 49 NodesExpected: len(plugin.Nodes), 50 } 51 } 52 53 func CSIPluginJob(pluginType structs.CSIPluginType, pluginID string) *structs.Job { 54 55 job := new(structs.Job) 56 57 switch pluginType { 58 case structs.CSIPluginTypeController: 59 job = Job() 60 job.ID = fmt.Sprintf("mock-controller-%s", pluginID) 61 job.Name = "job-plugin-controller" 62 job.TaskGroups[0].Count = 2 63 case structs.CSIPluginTypeNode: 64 job = SystemJob() 65 job.ID = fmt.Sprintf("mock-node-%s", pluginID) 66 job.Name = "job-plugin-node" 67 case structs.CSIPluginTypeMonolith: 68 job = SystemJob() 69 job.ID = fmt.Sprintf("mock-monolith-%s", pluginID) 70 job.Name = "job-plugin-monolith" 71 } 72 73 job.TaskGroups[0].Name = "plugin" 74 job.TaskGroups[0].Tasks[0].Name = "plugin" 75 job.TaskGroups[0].Tasks[0].Driver = "docker" 76 job.TaskGroups[0].Tasks[0].Services = nil 77 job.TaskGroups[0].Tasks[0].CSIPluginConfig = &structs.TaskCSIPluginConfig{ 78 ID: pluginID, 79 Type: pluginType, 80 MountDir: "/csi", 81 } 82 job.Canonicalize() 83 return job 84 }