MCPcopy Create free account
hub / github.com/apache/mesos / validateVolume

Function validateVolume

src/common/validation.cpp:213–276  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

211
212
213Option<Error> validateVolume(const Volume& volume)
214{
215 // TODO(jieyu): Add a validation for path.
216
217 // Only one of the following fields can be set:
218 // 1. host_path
219 // 2. image
220 // 3. source
221 int count = 0;
222 if (volume.has_host_path()) { count++; }
223 if (volume.has_image()) { count++; }
224 if (volume.has_source()) { count++; }
225
226 if (count != 1) {
227 return Error(
228 "Only one of them should be set: "
229 "'host_path', 'image' and 'source'");
230 }
231
232 if (volume.has_source()) {
233 switch (volume.source().type()) {
234 case Volume::Source::DOCKER_VOLUME:
235 if (!volume.source().has_docker_volume()) {
236 return Error(
237 "'source.docker_volume' is not set for DOCKER_VOLUME volume");
238 }
239 break;
240 case Volume::Source::HOST_PATH:
241 if (!volume.source().has_host_path()) {
242 return Error(
243 "'source.host_path' is not set for HOST_PATH volume");
244 }
245 break;
246 case Volume::Source::SANDBOX_PATH:
247 if (!volume.source().has_sandbox_path()) {
248 return Error(
249 "'source.sandbox_path' is not set for SANDBOX_PATH volume");
250 }
251 break;
252 case Volume::Source::SECRET:
253 if (!volume.source().has_secret()) {
254 return Error(
255 "'source.secret' is not set for SECRET volume");
256 }
257 break;
258 case Volume::Source::CSI_VOLUME:
259 if (!volume.source().has_csi_volume()) {
260 return Error(
261 "'source.csi_volume' is not set for CSI volume");
262 }
263
264 if (!volume.source().csi_volume().has_static_provisioning()) {
265 return Error(
266 "'source.csi_volume.static_provisioning' "
267 "is not set for CSI volume");
268 }
269 break;
270 default:

Callers 4

TESTFunction · 0.85
foreachFunction · 0.85
foreachFunction · 0.85
foreachFunction · 0.85

Calls 3

NoneClass · 0.85
typeMethod · 0.80
ErrorFunction · 0.50

Tested by 1

TESTFunction · 0.68