| 211 | |
| 212 | |
| 213 | Option<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: |