Skip to content
This repository has been archived by the owner on Nov 9, 2022. It is now read-only.
This repository is currently being migrated. It's locked while the migration is in progress.

Commit

Permalink
Pass cluster node selector to NFS pods (#236)
Browse files Browse the repository at this point in the history
* Inherit NFS server node selectors from cluster
  • Loading branch information
croomes authored Mar 18, 2020
1 parent be03b69 commit 0462d79
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ Parameter | Description | Default
`disableTCMU` | Disable TCMU to allow co-existence with other storage systems but degrades performance | `false`
`forceTCMU` | Forces TCMU to be enabled or causes StorageOS to abort startup | `false`
`disableScheduler` | Disable StorageOS scheduler for data locality | `false`
`nodeSelectorTerms` | Set node selector for storageos pod placement |
`nodeSelectorTerms` | Set node selector for storageos pod placement, including NFS pods |
`tolerations` | Set pod tolerations for storageos pod placement |
`resources` | Set resource requirements for the containers |
`k8sDistro` | The name of the Kubernetes distribution is use, e.g. `rancher` or `eks` |
Expand Down
7 changes: 6 additions & 1 deletion pkg/nfs/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,14 @@ func (d *Deployment) createStatefulSet(pvcVS *corev1.PersistentVolumeClaimVolume
}
spec.Template.Spec.Volumes = append(spec.Template.Spec.Volumes, vol)

// TODO: Add node affinity support for NFS server pods.
util.AddTolerations(&spec.Template.Spec, d.nfsServer.Spec.Tolerations)

// If the cluster was configured with node selectors to only run on certain
// nodes, use the same selectors to selct the nodes that the NFS pods can
// run on. NFSServer does not currently allow setting node selectors or
// affinity directly.
util.AddRequiredNodeAffinity(&spec.Template.Spec, d.cluster.Spec.NodeSelectorTerms)

return d.k8sResourceManager.StatefulSet(d.nfsServer.Name, d.nfsServer.Namespace, nil, spec).Create()
}

Expand Down
14 changes: 14 additions & 0 deletions pkg/util/podspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,17 @@ func AddTolerations(podSpec *corev1.PodSpec, tolerations []corev1.Toleration) er
}
return nil
}

// AddRequiredNodeAffinity adds required node affinity to the given pod spec.
func AddRequiredNodeAffinity(podSpec *corev1.PodSpec, terms []corev1.NodeSelectorTerm) {
if len(terms) == 0 {
return
}
podSpec.Affinity = &corev1.Affinity{
NodeAffinity: &corev1.NodeAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: &corev1.NodeSelector{
NodeSelectorTerms: terms,
},
},
}
}

0 comments on commit 0462d79

Please sign in to comment.