func checkVolumeModeMatch(volume *corev1.PersistentVolume, claim *corev1.PersistentVolumeClaim) bool {
	requestedVolumeMode := corev1.PersistentVolumeFilesystem
	if claim.Spec.VolumeMode != nil {
		requestedVolumeMode = *claim.Spec.VolumeMode
	}
	pvVolumeMode := corev1.PersistentVolumeFilesystem
	if volume.Spec.VolumeMode != nil {
		pvVolumeMode = *volume.Spec.VolumeMode
	}
	return requestedVolumeMode == pvVolumeMode
}
checkVolumeModeMatch returns true if PV satisfies the PVC's requested VolumeMode.
package resource
import (
	corev1 "k8s.io/api/core/v1"
)
func CheckVolumeSatisfyClaim(volume *corev1.PersistentVolume, claim *corev1.PersistentVolumeClaim) bool {
	if !checkCapacitySatisfyRequest(volume, claim) {
		return false
	}
	if !checkStorageClassMatch(volume, claim) {
		return false
	}
	if !checkVolumeModeMatch(volume, claim) {
		return false
	}
	if !checkAccessModesMatch(volume, claim) {
		return false
	}
	return true
}
func checkCapacitySatisfyRequest(volume *corev1.PersistentVolume, claim *corev1.PersistentVolumeClaim) bool {
	volumeQty := volume.Spec.Capacity[corev1.ResourceStorage]
	volumeSize := volumeQty.Value()
	requestedQty := claim.Spec.Resources.Requests[corev1.ResourceName(corev1.ResourceStorage)]
	requestedSize := requestedQty.Value()
	return volumeSize >= requestedSize
}
func checkStorageClassMatch(volume *corev1.PersistentVolume, claim *corev1.PersistentVolumeClaim) bool {
	var (
		requestedClass string
		pvVolumeClass  string
		ok             bool
	)
	requestedClass, ok = claim.Annotations[corev1.BetaStorageClassAnnotation]
	if !ok && claim.Spec.StorageClassName != nil {
		requestedClass = *claim.Spec.StorageClassName
	}
	pvVolumeClass, ok = volume.Annotations[corev1.BetaStorageClassAnnotation]
	if !ok {
		pvVolumeClass = volume.Spec.StorageClassName
	}
	return requestedClass == pvVolumeClass
}