@@ -67,6 +67,8 @@ const (
67
67
OptionKeyPodUID = "kubernetes.io/pod.uid"
68
68
69
69
OptionKeyServiceAccountName = "kubernetes.io/serviceAccount.name"
70
+
71
+ DefaultSymlinkDirectory = "oci-bvs"
70
72
)
71
73
72
74
// Driver is the main Flexvolume interface.
@@ -111,6 +113,15 @@ func Fail(a ...interface{}) DriverStatus {
111
113
}
112
114
}
113
115
116
+ // Failf creates a StatusFailure Result with a given message.
117
+ func Failf (s string , a ... interface {}) DriverStatus {
118
+ msg := fmt .Sprintf (s , a ... )
119
+ return DriverStatus {
120
+ Status : StatusFailure ,
121
+ Message : msg ,
122
+ }
123
+ }
124
+
114
125
// Succeed creates a StatusSuccess Result with a given message.
115
126
func Succeed (a ... interface {}) DriverStatus {
116
127
return DriverStatus {
@@ -119,6 +130,14 @@ func Succeed(a ...interface{}) DriverStatus {
119
130
}
120
131
}
121
132
133
+ // NotSupportedf creates a StatusNotSupported Result with a given message.
134
+ func NotSupportedf (s string , a ... interface {}) DriverStatus {
135
+ return DriverStatus {
136
+ Status : StatusNotSupported ,
137
+ Message : fmt .Sprintf (s , a ... ),
138
+ }
139
+ }
140
+
122
141
// NotSupported creates a StatusNotSupported Result with a given message.
123
142
func NotSupported (a ... interface {}) DriverStatus {
124
143
return DriverStatus {
@@ -143,127 +162,127 @@ func processOpts(optsStr string) (Options, error) {
143
162
144
163
// ExecDriver executes the appropriate FlexvolumeDriver command based on
145
164
// recieved call-out.
146
- func ExecDriver (driver Driver , args []string ) {
165
+ func ExecDriver (driver Driver , args []string ) DriverStatus {
147
166
if len (args ) < 2 {
148
- ExitWithResult ( Fail ( "Expected at least one argument" ) )
167
+ return Failf ( "Expected at least one argument" )
149
168
}
150
169
151
170
log .Printf ("'%s %s' called with %s" , args [0 ], args [1 ], args [2 :])
152
171
153
172
switch args [1 ] {
154
173
// <driver executable> init
155
174
case "init" :
156
- ExitWithResult ( driver .Init () )
175
+ return driver .Init ()
157
176
158
177
// <driver executable> getvolumename <json options>
159
178
// Currently broken as of lates kube release (1.6.4). Work around hardcodes
160
179
// exiting with StatusNotSupported.
161
180
// TODO(apryde): Investigate current situation and version support
162
181
// requirements.
163
182
case "getvolumename" :
164
- ExitWithResult ( NotSupported ( "getvolumename is broken as of kube 1.6.4" ) )
183
+ return NotSupportedf ( "getvolumename is broken as of kube 1.6.4" )
165
184
166
185
// <driver executable> attach <json options> <node name>
167
186
case "attach" :
168
187
if len (args ) != 4 {
169
- ExitWithResult ( Fail ( "attach expected exactly 4 arguments; got " , args ) )
188
+ Failf ( "attach expected exactly 4 arguments; got " , args )
170
189
}
171
190
172
191
opts , err := processOpts (args [2 ])
173
192
if err != nil {
174
- ExitWithResult ( Fail ( err ))
193
+ return Failf ( err . Error ( ))
175
194
}
176
195
177
196
nodeName := args [3 ]
178
- ExitWithResult ( driver .Attach (opts , nodeName ) )
197
+ return driver .Attach (opts , nodeName )
179
198
180
199
// <driver executable> detach <mount device> <node name>
181
200
case "detach" :
182
201
if len (args ) != 4 {
183
- ExitWithResult ( Fail ( "detach expected exactly 4 arguments; got " , args ) )
202
+ return Failf ( "detach expected exactly 4 arguments; got " , args )
184
203
}
185
204
186
205
mountDevice := args [2 ]
187
206
nodeName := args [3 ]
188
- ExitWithResult ( driver .Detach (mountDevice , nodeName ) )
207
+ return driver .Detach (mountDevice , nodeName )
189
208
190
209
// <driver executable> waitforattach <mount device> <json options>
191
210
case "waitforattach" :
192
211
if len (args ) != 4 {
193
- ExitWithResult ( Fail ( "waitforattach expected exactly 4 arguments; got " , args ) )
212
+ return Failf ( "waitforattach expected exactly 4 arguments; got " , args )
194
213
}
195
214
196
215
mountDevice := args [2 ]
197
216
opts , err := processOpts (args [3 ])
198
217
if err != nil {
199
- ExitWithResult ( Fail ( err ))
218
+ return Failf ( err . Error ( ))
200
219
}
201
220
202
- ExitWithResult ( driver .WaitForAttach (mountDevice , opts ) )
221
+ return driver .WaitForAttach (mountDevice , opts )
203
222
204
223
// <driver executable> isattached <json options> <node name>
205
224
case "isattached" :
206
225
if len (args ) != 4 {
207
- ExitWithResult ( Fail ( "isattached expected exactly 4 arguments; got " , args ) )
226
+ return Failf ( "isattached expected exactly 4 arguments; got " , args )
208
227
}
209
228
210
229
opts , err := processOpts (args [2 ])
211
230
if err != nil {
212
- ExitWithResult ( Fail ( err ))
231
+ return Failf ( err . Error ( ))
213
232
}
214
233
nodeName := args [3 ]
215
- ExitWithResult ( driver .IsAttached (opts , nodeName ) )
234
+ return driver .IsAttached (opts , nodeName )
216
235
217
236
// <driver executable> mountdevice <mount dir> <mount device> <json options>
218
237
case "mountdevice" :
219
238
if len (args ) != 5 {
220
- ExitWithResult ( Fail ( "mountdevice expected exactly 5 arguments; got " , args ) )
239
+ return Failf ( "mountdevice expected exactly 5 arguments; got " , args )
221
240
}
222
241
223
242
mountDir := args [2 ]
224
243
mountDevice := args [3 ]
225
244
226
245
opts , err := processOpts (args [4 ])
227
246
if err != nil {
228
- ExitWithResult ( Fail ( err ))
247
+ return Failf ( err . Error ( ))
229
248
}
230
249
231
- ExitWithResult ( driver .MountDevice (mountDir , mountDevice , opts ) )
250
+ return driver .MountDevice (mountDir , mountDevice , opts )
232
251
233
252
// <driver executable> unmountdevice <mount dir>
234
253
case "unmountdevice" :
235
254
if len (args ) != 3 {
236
- ExitWithResult ( Fail ( "unmountdevice expected exactly 3 arguments; got " , args ) )
255
+ return Failf ( "unmountdevice expected exactly 3 arguments; got " , args )
237
256
}
238
257
239
258
mountDir := args [2 ]
240
- ExitWithResult ( driver .UnmountDevice (mountDir ) )
259
+ return driver .UnmountDevice (mountDir )
241
260
242
261
// <driver executable> mount <mount dir> <json options>
243
262
case "mount" :
244
263
if len (args ) != 4 {
245
- ExitWithResult ( Fail ( "mount expected exactly 4 arguments; got " , args ) )
264
+ return Failf ( "mount expected exactly 4 arguments; got " , args )
246
265
}
247
266
248
267
mountDir := args [2 ]
249
268
250
269
opts , err := processOpts (args [3 ])
251
270
if err != nil {
252
- ExitWithResult ( Fail ( err ))
271
+ return Failf ( err . Error ( ))
253
272
}
254
273
255
- ExitWithResult ( driver .Mount (mountDir , opts ) )
274
+ return driver .Mount (mountDir , opts )
256
275
257
276
// <driver executable> unmount <mount dir>
258
277
case "unmount" :
259
278
if len (args ) != 3 {
260
- ExitWithResult ( Fail ( "mount expected exactly 3 arguments; got " , args ) )
279
+ return Failf ( "mount expected exactly 3 arguments; got " , args )
261
280
}
262
281
263
282
mountDir := args [2 ]
264
- ExitWithResult ( driver .Unmount (mountDir ) )
283
+ return driver .Unmount (mountDir )
265
284
266
285
default :
267
- ExitWithResult ( Fail ( "Invalid command; got " , args ) )
286
+ return Failf ( "invalid command; got " , args )
268
287
}
269
288
}
0 commit comments