6
6
"github.com/hashicorp/nomad/client/allocrunner/interfaces"
7
7
"github.com/hashicorp/nomad/client/pluginmanager/csimanager"
8
8
cstructs "github.com/hashicorp/nomad/client/structs"
9
+ "github.com/hashicorp/nomad/client/taskenv"
9
10
"github.com/hashicorp/nomad/helper/testlog"
11
+ "github.com/hashicorp/nomad/nomad/mock"
10
12
"github.com/hashicorp/nomad/nomad/structs"
11
13
"github.com/hashicorp/nomad/plugins/drivers"
12
14
"github.com/stretchr/testify/require"
@@ -86,7 +88,7 @@ func TestVolumeHook_prepareCSIVolumes(t *testing.T) {
86
88
tr := & TaskRunner {
87
89
allocHookResources : & cstructs.AllocHookResources {
88
90
CSIMounts : map [string ]* csimanager.MountInfo {
89
- "foo" : & csimanager. MountInfo {
91
+ "foo" : {
90
92
Source : "/mnt/my-test-volume" ,
91
93
},
92
94
},
@@ -109,3 +111,72 @@ func TestVolumeHook_prepareCSIVolumes(t *testing.T) {
109
111
require .NoError (t , err )
110
112
require .Equal (t , expected , mounts )
111
113
}
114
+
115
+ func TestVolumeHook_Interpolation (t * testing.T ) {
116
+
117
+ alloc := mock .Alloc ()
118
+ task := alloc .Job .TaskGroups [0 ].Tasks [0 ]
119
+ taskEnv := taskenv .NewBuilder (mock .Node (), alloc , task , "global" ).SetHookEnv ("volume" ,
120
+ map [string ]string {
121
+ "PROPAGATION_MODE" : "private" ,
122
+ "VOLUME_ID" : "my-other-volume" ,
123
+ },
124
+ ).Build ()
125
+
126
+ mounts := []* structs.VolumeMount {
127
+ {
128
+ Volume : "foo" ,
129
+ Destination : "/tmp" ,
130
+ ReadOnly : false ,
131
+ PropagationMode : "bidirectional" ,
132
+ },
133
+ {
134
+ Volume : "foo" ,
135
+ Destination : "/bar-${NOMAD_JOB_NAME}" ,
136
+ ReadOnly : false ,
137
+ PropagationMode : "bidirectional" ,
138
+ },
139
+ {
140
+ Volume : "${VOLUME_ID}" ,
141
+ Destination : "/baz" ,
142
+ ReadOnly : false ,
143
+ PropagationMode : "bidirectional" ,
144
+ },
145
+ {
146
+ Volume : "foo" ,
147
+ Destination : "/quux" ,
148
+ ReadOnly : false ,
149
+ PropagationMode : "${PROPAGATION_MODE}" ,
150
+ },
151
+ }
152
+
153
+ expected := []* structs.VolumeMount {
154
+ {
155
+ Volume : "foo" ,
156
+ Destination : "/tmp" ,
157
+ ReadOnly : false ,
158
+ PropagationMode : "bidirectional" ,
159
+ },
160
+ {
161
+ Volume : "foo" ,
162
+ Destination : "/bar-my-job" ,
163
+ ReadOnly : false ,
164
+ PropagationMode : "bidirectional" ,
165
+ },
166
+ {
167
+ Volume : "my-other-volume" ,
168
+ Destination : "/baz" ,
169
+ ReadOnly : false ,
170
+ PropagationMode : "bidirectional" ,
171
+ },
172
+ {
173
+ Volume : "foo" ,
174
+ Destination : "/quux" ,
175
+ ReadOnly : false ,
176
+ PropagationMode : "private" ,
177
+ },
178
+ }
179
+
180
+ interpolateVolumeMounts (mounts , taskEnv )
181
+ require .Equal (t , expected , mounts )
182
+ }
0 commit comments