Cleanup: merge checkVolumeNodeAffinity with CheckVolumeNodeAffinity

Signed-off-by: Konstantin Misyutin <konstantin.misyutin@huawei.com>
This commit is contained in:
Konstantin Misyutin 2021-11-10 21:50:19 +08:00
parent 4ba98a8610
commit 0b5b04842c

View File

@ -52,15 +52,12 @@ func GetPersistentVolumeClass(volume *v1.PersistentVolume) string {
// CheckNodeAffinity looks at the PV node affinity, and checks if the node has the same corresponding labels
// This ensures that we don't mount a volume that doesn't belong to this node
func CheckNodeAffinity(pv *v1.PersistentVolume, nodeLabels map[string]string) error {
return checkVolumeNodeAffinity(pv, &v1.Node{ObjectMeta: metav1.ObjectMeta{Labels: nodeLabels}})
}
func checkVolumeNodeAffinity(pv *v1.PersistentVolume, node *v1.Node) error {
if pv.Spec.NodeAffinity == nil {
return nil
}
if pv.Spec.NodeAffinity.Required != nil {
node := &v1.Node{ObjectMeta: metav1.ObjectMeta{Labels: nodeLabels}}
terms := pv.Spec.NodeAffinity.Required
if matches, err := corev1.MatchNodeSelectorTerms(node, terms); err != nil {
return err