Skip to content

Commit 7f5aa6d

Browse files
author
Jeff McCormick
committed
add affinity to templates
1 parent c75c9bc commit 7f5aa6d

File tree

6 files changed

+53
-2
lines changed

6 files changed

+53
-2
lines changed

client/cmd/cluster.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func listPods(name string) {
135135
return
136136
}
137137
for _, pod := range pods.Items {
138-
fmt.Println(TREE_BRANCH + "pod : " + pod.ObjectMeta.Name + " (" + string(pod.Status.Phase) + ") (" + getReadyStatus(&pod) + ")")
138+
fmt.Println(TREE_BRANCH + "pod : " + pod.ObjectMeta.Name + " (" + string(pod.Status.Phase) + " on " + pod.Spec.NodeName + ") (" + getReadyStatus(&pod) + ")")
139139
//fmt.Println(TREE_TRUNK + " phase : " + pod.Status.Phase)
140140
}
141141

conf/postgres-operator/cluster/1/cluster-deployment-1.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,24 @@
103103
}
104104
}
105105

106-
107106
],
108107

108+
"affinity": {
109+
"nodeAffinity": {
110+
"requiredDuringSchedulingIgnoredDuringExecution": {
111+
"nodeSelectorTerms": [{
112+
"matchExpressions": [{
113+
"key": "kubernetes.io/hostname",
114+
"operator": "In",
115+
"values": [
116+
"{{.NODE_SELECTOR}}"
117+
]
118+
}]
119+
}]
120+
}
121+
}
122+
},
123+
109124
"restartPolicy": "Always",
110125
"dnsPolicy": "ClusterFirst"
111126
}

conf/postgres-operator/cluster/1/cluster-replica-deployment-1-shared.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,22 @@
8383
}
8484
],
8585

86+
"affinity": {
87+
"nodeAffinity": {
88+
"preferredDuringSchedulingIgnoredDuringExecution": [{
89+
"weight": 1,
90+
"preference": {
91+
"matchExpressions": [{
92+
"key": "kubernetes.io/hostname",
93+
"operator": "NotIn",
94+
"values": [
95+
"{{.NODE_SELECTOR}}"
96+
]
97+
}]
98+
}
99+
}]
100+
}
101+
},
86102
"restartPolicy": "Always",
87103
"dnsPolicy": "ClusterFirst"
88104
}

conf/postgres-operator/cluster/1/cluster-replica-deployment-1.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,23 @@
8181
}
8282
],
8383

84+
"affinity": {
85+
"nodeAffinity": {
86+
"preferredDuringSchedulingIgnoredDuringExecution": [{
87+
"weight": 1,
88+
"preference": {
89+
"matchExpressions": [{
90+
"key": "kubernetes.io/hostname",
91+
"operator": "NotIn",
92+
"values": [
93+
"{{.NODE_SELECTOR}}"
94+
]
95+
}]
96+
}
97+
}]
98+
}
99+
},
100+
84101
"restartPolicy": "Always",
85102
"dnsPolicy": "ClusterFirst"
86103
}

operator/cluster/cluster.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ type DeploymentTemplateFields struct {
6868
PGUSER_SECRET_NAME string
6969
PGMASTER_SECRET_NAME string
7070
SECURITY_CONTEXT string
71+
NODE_SELECTOR string
7172
//next 2 are for the replica deployment only
7273
REPLICAS string
7374
PG_MASTER_HOST string

operator/cluster/cluster_strategy_1.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ func (r ClusterStrategy1) AddCluster(clientset *kubernetes.Clientset, client *re
9393
PGROOT_SECRET_NAME: cl.Spec.PGROOT_SECRET_NAME,
9494
PGMASTER_SECRET_NAME: cl.Spec.PGMASTER_SECRET_NAME,
9595
PGUSER_SECRET_NAME: cl.Spec.PGUSER_SECRET_NAME,
96+
NODE_SELECTOR: "operator",
9697
}
9798

9899
err = DeploymentTemplate1.Execute(&masterDoc, deploymentFields)
@@ -426,6 +427,7 @@ func (r ClusterStrategy1) CreateReplica(serviceName string, clientset *kubernete
426427
PGROOT_SECRET_NAME: cl.Spec.PGROOT_SECRET_NAME,
427428
PGMASTER_SECRET_NAME: cl.Spec.PGMASTER_SECRET_NAME,
428429
PGUSER_SECRET_NAME: cl.Spec.PGUSER_SECRET_NAME,
430+
NODE_SELECTOR: "operator",
429431
}
430432

431433
switch cl.Spec.ReplicaStorage.StorageType {

0 commit comments

Comments
 (0)