io.fabric8.kubernetes.api.model.PersistentVolumeClaimVolumeSource Java Examples

The following examples show how to use io.fabric8.kubernetes.api.model.PersistentVolumeClaimVolumeSource. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KubernetesEnvironmentPodsValidator.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
private void validatePodVolumes(KubernetesEnvironment env) throws ValidationException {
  Set<String> pvcsNames = env.getPersistentVolumeClaims().keySet();
  for (PodData pod : env.getPodsData().values()) {
    Set<String> volumesNames = new HashSet<>();
    for (Volume volume : pod.getSpec().getVolumes()) {
      volumesNames.add(volume.getName());

      PersistentVolumeClaimVolumeSource pvcSource = volume.getPersistentVolumeClaim();
      if (pvcSource != null && !pvcsNames.contains(pvcSource.getClaimName())) {
        throw new ValidationException(
            String.format(
                "Pod '%s' contains volume '%s' with PVC sources that references missing PVC '%s'",
                pod.getMetadata().getName(), volume.getName(), pvcSource.getClaimName()));
      }
    }

    for (Container container : pod.getSpec().getContainers()) {
      for (VolumeMount volumeMount : container.getVolumeMounts()) {
        if (!volumesNames.contains(volumeMount.getName())) {
          throw new ValidationException(
              String.format(
                  "Container '%s' in pod '%s' contains volume mount that references missing volume '%s'",
                  container.getName(), pod.getMetadata().getName(), volumeMount.getName()));
        }
      }
    }
  }
}
 
Example #2
Source File: KubernetesObjectUtil.java    From che with Eclipse Public License 2.0 4 votes vote down vote up
/** Returns new instance of {@link Volume} with specified name and name of claim related to. */
public static Volume newVolume(String name, String pvcName) {
  final PersistentVolumeClaimVolumeSource pvcs =
      new PersistentVolumeClaimVolumeSourceBuilder().withClaimName(pvcName).build();
  return new VolumeBuilder().withPersistentVolumeClaim(pvcs).withName(name).build();
}