Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,21 +542,38 @@ func (p *LocalPathProvisioner) getPathAndNodeForPV(pv *v1.PersistentVolume, cfg

// Dealing with local filesystem

// First, capture node from annotation if present
var annoNode string
if pv.Annotations != nil {
if v, ok := pv.Annotations[nodeNameAnnotationKey]; ok {
annoNode = v
}
}

nodeAffinity := pv.Spec.NodeAffinity
if nodeAffinity == nil {
return "", "", fmt.Errorf("no NodeAffinity set")
if annoNode != "" {
return path, annoNode, nil
}
return "", "", fmt.Errorf("no NodeAffinity set and missing %s annotation", nodeNameAnnotationKey)
}
required := nodeAffinity.Required
if required == nil {
return "", "", fmt.Errorf("no NodeAffinity.Required set")
if annoNode != "" {
return path, annoNode, nil
}
return "", "", fmt.Errorf("no NodeAffinity.Required set and missing %s annotation", nodeNameAnnotationKey)
}

node = ""
for _, selectorTerm := range required.NodeSelectorTerms {
for _, expression := range selectorTerm.MatchExpressions {
if expression.Key == KeyNode && expression.Operator == v1.NodeSelectorOpIn {
if len(expression.Values) != 1 {
return "", "", fmt.Errorf("multiple values for the node affinity")
if annoNode != "" {
return path, annoNode, nil
}
return "", "", fmt.Errorf("multiple values for the node affinity and missing %s annotation", nodeNameAnnotationKey)
}
node = expression.Values[0]
break
Expand All @@ -567,7 +584,13 @@ func (p *LocalPathProvisioner) getPathAndNodeForPV(pv *v1.PersistentVolume, cfg
}
}
if node == "" {
return "", "", fmt.Errorf("cannot find affinited node")
if annoNode != "" {
return path, annoNode, nil
}
return "", "", fmt.Errorf("cannot find affinited node and missing %s annotation", nodeNameAnnotationKey)
}
if annoNode != "" && annoNode != node {
logrus.Debugf("PV %s node from NodeAffinity %s differs from annotation %s; using NodeAffinity", pv.Name, node, annoNode)
}
return path, node, nil
}
Expand Down
Loading