github.com/uchennaokeke444/nomad@v0.11.8/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 MountOptions *CSIMountOptions 94 } 95 96 func (v *VolumeRequest) Copy() *VolumeRequest { 97 if v == nil { 98 return nil 99 } 100 nv := new(VolumeRequest) 101 *nv = *v 102 103 if v.MountOptions == nil { 104 return nv 105 } 106 107 nv.MountOptions = &(*v.MountOptions) 108 109 return nv 110 } 111 112 func CopyMapVolumeRequest(s map[string]*VolumeRequest) map[string]*VolumeRequest { 113 if s == nil { 114 return nil 115 } 116 117 l := len(s) 118 c := make(map[string]*VolumeRequest, l) 119 for k, v := range s { 120 c[k] = v.Copy() 121 } 122 return c 123 } 124 125 // VolumeMount represents the relationship between a destination path in a task 126 // and the task group volume that should be mounted there. 127 type VolumeMount struct { 128 Volume string 129 Destination string 130 ReadOnly bool 131 PropagationMode string 132 } 133 134 func (v *VolumeMount) Copy() *VolumeMount { 135 if v == nil { 136 return nil 137 } 138 139 nv := new(VolumeMount) 140 *nv = *v 141 return nv 142 } 143 144 func CopySliceVolumeMount(s []*VolumeMount) []*VolumeMount { 145 l := len(s) 146 if l == 0 { 147 return nil 148 } 149 150 c := make([]*VolumeMount, l) 151 for i, v := range s { 152 c[i] = v.Copy() 153 } 154 return c 155 }