Is there a way to identify Kubernetes volume type using the Java API?

2/20/2020

When looking at the volumes associated with a deployment (or a Pod) I was hoping to find a way to identify the volume type without having the make the call to obtain the volume type and then check for null. I was unable to find a specific call that returned the volume type. So, instead I resorted to some ugly code. This is using the Kubernetes Java API.

                V1Pod item;

                List<V1Volume> podVolumes = item.getSpec().getVolumes();
                ListIterator<V1Volume> podVolIter = podVolumes.listIterator();
                while (podVolIter.hasNext()) {
                    V1Volume volume = podVolIter.next();

                    V1EmptyDirVolumeSource emptyDir = volume.getEmptyDir();
                    V1HostPathVolumeSource hostPath = volume.getHostPath();

                    if (emptyDir != null) {
                       // Do something with the emptyDir volume
                    } else if (hostPath != null) {
                       // Do something with the hostPath volume
                    } else {
                    }

Is there an API call to obtain the volume type that I missed?

-- Noel Otterness
java
kubernetes

0 Answers