github.com/manicqin/nomad@v0.9.5/nomad/structs/volumes.go (about) 1 package structs 2 3 const ( 4 VolumeTypeHost = "host" 5 ) 6 7 const ( 8 VolumeMountPropagationPrivate = "private" 9 VolumeMountPropagationHostToTask = "host-to-task" 10 VolumeMountPropagationBidirectional = "bidirectional" 11 ) 12 13 func MountPropagationModeIsValid(propagationMode string) bool { 14 switch propagationMode { 15 case "", VolumeMountPropagationPrivate, VolumeMountPropagationHostToTask, VolumeMountPropagationBidirectional: 16 return true 17 default: 18 return false 19 } 20 } 21 22 // ClientHostVolumeConfig is used to configure access to host paths on a Nomad Client 23 type ClientHostVolumeConfig struct { 24 Name string `hcl:",key"` 25 Path string `hcl:"path"` 26 ReadOnly bool `hcl:"read_only"` 27 } 28 29 func (p *ClientHostVolumeConfig) Copy() *ClientHostVolumeConfig { 30 if p == nil { 31 return nil 32 } 33 34 c := new(ClientHostVolumeConfig) 35 *c = *p 36 return c 37 } 38 39 func CopyMapStringClientHostVolumeConfig(m map[string]*ClientHostVolumeConfig) map[string]*ClientHostVolumeConfig { 40 if m == nil { 41 return nil 42 } 43 44 nm := make(map[string]*ClientHostVolumeConfig, len(m)) 45 for k, v := range m { 46 nm[k] = v.Copy() 47 } 48 49 return nm 50 } 51 52 func CopySliceClientHostVolumeConfig(s []*ClientHostVolumeConfig) []*ClientHostVolumeConfig { 53 l := len(s) 54 if l == 0 { 55 return nil 56 } 57 58 ns := make([]*ClientHostVolumeConfig, l) 59 for idx, cfg := range s { 60 ns[idx] = cfg.Copy() 61 } 62 63 return ns 64 } 65 66 func HostVolumeSliceMerge(a, b []*ClientHostVolumeConfig) []*ClientHostVolumeConfig { 67 n := make([]*ClientHostVolumeConfig, len(a)) 68 seenKeys := make(map[string]int, len(a)) 69 70 for i, config := range a { 71 n[i] = config.Copy() 72 seenKeys[config.Name] = i 73 } 74 75 for _, config := range b { 76 if fIndex, ok := seenKeys[config.Name]; ok { 77 n[fIndex] = config.Copy() 78 continue 79 } 80 81 n = append(n, config.Copy()) 82 } 83 84 return n 85 } 86 87 // VolumeRequest is a representation of a storage volume that a TaskGroup wishes to use. 88 type VolumeRequest struct { 89 Name string 90 Type string 91 Source string 92 ReadOnly bool 93 } 94 95 func (v *VolumeRequest) Copy() *VolumeRequest { 96 if v == nil { 97 return nil 98 } 99 nv := new(VolumeRequest) 100 *nv = *v 101 102 return nv 103 } 104 105 func CopyMapVolumeRequest(s map[string]*VolumeRequest) map[string]*VolumeRequest { 106 if s == nil { 107 return nil 108 } 109 110 l := len(s) 111 c := make(map[string]*VolumeRequest, l) 112 for k, v := range s { 113 c[k] = v.Copy() 114 } 115 return c 116 } 117 118 // VolumeMount represents the relationship between a destination path in a task 119 // and the task group volume that should be mounted there. 120 type VolumeMount struct { 121 Volume string 122 Destination string 123 ReadOnly bool 124 PropagationMode string 125 } 126 127 func (v *VolumeMount) Copy() *VolumeMount { 128 if v == nil { 129 return nil 130 } 131 132 nv := new(VolumeMount) 133 *nv = *v 134 return nv 135 } 136 137 func CopySliceVolumeMount(s []*VolumeMount) []*VolumeMount { 138 l := len(s) 139 if l == 0 { 140 return nil 141 } 142 143 c := make([]*VolumeMount, l) 144 for i, v := range s { 145 c[i] = v.Copy() 146 } 147 return c 148 }