Merge pull request #973 from galexrt/feature/add_pod_affinities

Add podAffinity and podAntiAffinity to placement spec
This commit is contained in:
Travis Nielsen
2017-09-12 10:51:19 -07:00
committed by GitHub
3 changed files with 33 additions and 6 deletions
+3 -1
View File
@@ -71,6 +71,8 @@ Placement configuration for the cluster services. It includes the following keys
A Placement configuration is specified (according to the kubernetes [PodSpec](https://kubernetes.io/docs/api-reference/v1.6/#podspec-v1-core)) as:
- `nodeAffinity`: kubernetes [NodeAffinity](https://kubernetes.io/docs/api-reference/v1.6/#nodeaffinity-v1-core)
- `podAffinity`: kubernetes [PodAffinity](https://kubernetes.io/docs/api-reference/v1.6/#podaffinity-v1-core)
- `podAntiAffinity`: kubernetes [PodAntiAffinity](https://kubernetes.io/docs/api-reference/v1.6/#podantiaffinity-v1-core)
- `tolerations`: list of kubernetes [Toleration](https://kubernetes.io/docs/api-reference/v1.6/#toleration-v1-core)
## Samples
@@ -106,7 +108,7 @@ spec:
### Storage Configuration: Specific devices
Individual nodes and their config can be specified so that only the named nodes below will be used as storage resources.
Individual nodes and their config can be specified so that only the named nodes below will be used as storage resources.
Each node's 'name' field should match their 'kubernetes.io/hostname' label.
```
@@ -24,20 +24,30 @@ spec:
# operator: In
# values:
# - storage-node
# podAffinity:
# podAntiAffinity:
# tolerations:
# - key: storage-node
# operator: Exists
# api:
# nodeAffinity:
# podAffinity:
# podAntiAffinity:
# tolerations:
# mgr:
# nodeAffinity:
# podAffinity:
# podAntiAffinity:
# tolerations:
# mon:
# nodeAffinity:
# podAffinity:
# podAntiAffinity:
# tolerations:
# osd:
# nodeAffinity:
# podAffinity:
# podAntiAffinity:
# tolerations:
storage: # cluster level storage configuration and selection
useAllNodes: true
+20 -5
View File
@@ -24,18 +24,27 @@ import (
// Placement encapsulates the various kubernetes options that control where
// pods are scheduled and executed.
type Placement struct {
NodeAffinity *v1.NodeAffinity `json:"nodeAffinity,omitempty"`
Tolerations []v1.Toleration `json:"tolerations,omitemtpy"`
NodeAffinity *v1.NodeAffinity `json:"nodeAffinity,omitempty"`
PodAffinity *v1.PodAffinity `json:"podAffinity,omitempty"`
PodAntiAffinity *v1.PodAntiAffinity `json:"podAntiAffinity,omitempty"`
Tolerations []v1.Toleration `json:"tolerations,omitemtpy"`
}
// ApplyToPodSpec adds placement to a pod spec
func (p Placement) ApplyToPodSpec(t *v1.PodSpec) {
if t.Affinity == nil {
t.Affinity = &v1.Affinity{}
}
if p.NodeAffinity != nil {
if t.Affinity == nil {
t.Affinity = &v1.Affinity{}
}
t.Affinity.NodeAffinity = p.NodeAffinity
}
if p.PodAffinity != nil {
t.Affinity.PodAffinity = p.PodAffinity
}
if p.PodAntiAffinity != nil {
t.Affinity.PodAntiAffinity = p.PodAntiAffinity
}
if p.Tolerations != nil {
t.Tolerations = p.Tolerations
}
@@ -49,6 +58,12 @@ func (p Placement) Merge(with Placement) Placement {
if with.NodeAffinity != nil {
ret.NodeAffinity = with.NodeAffinity
}
if with.PodAffinity != nil {
ret.PodAffinity = with.PodAffinity
}
if with.PodAntiAffinity != nil {
ret.PodAntiAffinity = with.PodAntiAffinity
}
if with.Tolerations != nil {
ret.Tolerations = with.Tolerations
}