diff --git a/Documentation/cluster-crd.md b/Documentation/cluster-crd.md index 14e7298c6..6162e9d9b 100644 --- a/Documentation/cluster-crd.md +++ b/Documentation/cluster-crd.md @@ -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. ``` diff --git a/cluster/examples/kubernetes/rook-cluster.yaml b/cluster/examples/kubernetes/rook-cluster.yaml index 1fa4eff4c..59e701d9f 100644 --- a/cluster/examples/kubernetes/rook-cluster.yaml +++ b/cluster/examples/kubernetes/rook-cluster.yaml @@ -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 diff --git a/pkg/operator/k8sutil/placement.go b/pkg/operator/k8sutil/placement.go index d43c12e76..050e025ec 100644 --- a/pkg/operator/k8sutil/placement.go +++ b/pkg/operator/k8sutil/placement.go @@ -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 }