Validates the DiskInfos specified in the given resources (if exist). Returns error if any DiskInfo is found invalid or unsupported.
| 869 | // exist). Returns error if any DiskInfo is found invalid or |
| 870 | // unsupported. |
| 871 | Option<Error> validateDiskInfo(const RepeatedPtrField<Resource>& resources) |
| 872 | { |
| 873 | foreach (const Resource& resource, resources) { |
| 874 | if (!resource.has_disk()) { |
| 875 | continue; |
| 876 | } |
| 877 | |
| 878 | if (resource.disk().has_persistence()) { |
| 879 | if (Resources::isRevocable(resource)) { |
| 880 | return Error( |
| 881 | "Persistent volumes cannot be created from revocable resources"); |
| 882 | } |
| 883 | if (Resources::isUnreserved(resource)) { |
| 884 | return Error( |
| 885 | "Persistent volumes cannot be created from unreserved resources"); |
| 886 | } |
| 887 | if (!resource.disk().has_volume()) { |
| 888 | return Error("Expecting 'volume' to be set for persistent volume"); |
| 889 | } |
| 890 | if (resource.disk().volume().has_host_path()) { |
| 891 | return Error("Expecting 'host_path' to be unset for persistent volume"); |
| 892 | } |
| 893 | |
| 894 | // Ensure persistence ID meets common ID requirements. |
| 895 | Option<Error> error = |
| 896 | common::validation::validateID(resource.disk().persistence().id()); |
| 897 | if (error.isSome()) { |
| 898 | return Error("Invalid persistence ID for persistent volume: " + |
| 899 | error->message); |
| 900 | } |
| 901 | } else if (resource.disk().has_volume()) { |
| 902 | return Error("Non-persistent volume not supported"); |
| 903 | } else if (!resource.disk().has_source()) { |
| 904 | return Error("DiskInfo is set but empty"); |
| 905 | } |
| 906 | } |
| 907 | |
| 908 | return None(); |
| 909 | } |
| 910 | |
| 911 | |
| 912 | // Validates the uniqueness of the persistence IDs used in the given |