Skip to content

Commit 23c0ca5

Browse files
committed
feat(controller): add affinity
1 parent 6e1a04f commit 23c0ca5

7 files changed

Lines changed: 44 additions & 4 deletions

File tree

.drone/drone.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ steps:
118118
commands:
119119
- IMAGE_TAG=$([ ! -z $DRONE_TAG ] && echo \"${DRONE_TAG:1}\" || echo \"canary\")
120120
- sed -i "s/imageTag:\ \"canary\"/imageTag:\ $IMAGE_TAG/g" charts/controller/values.yaml
121-
- helm package charts/controller --version ${DRONE_TAG:-v1.0.0}
121+
- helm package -u charts/controller --version ${DRONE_TAG:-v1.0.0}
122122
- curl -u $CHARTMUSEUM_USERNAME:$CHARTMUSEUM_PASSWORD -F chart=@controller-${DRONE_TAG:-v1.0.0}.tgz "$CHARTMUSEUM_API/api/$([ -z $DRONE_TAG ] && echo testing || echo stable)/charts"
123123
environment:
124124
CHARTMUSEUM_USERNAME:

charts/controller/Chart.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
name: controller
22
home: https://github.com/drycc/controller
3-
version: v1.0.0
3+
apiVersion: v2
4+
dependencies:
5+
- name: common
6+
repository: https://charts.drycc.cc/stable
7+
version: 1.x.x
48
description: Drycc Workflow Controller (API).
59
maintainers:
610
- name: Drycc Team
711
email: engineering@drycc.com
12+
version: v1.0.0

charts/controller/templates/_helpers.tpl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ env:
180180
{{- end }}
181181
{{- end }}
182182

183-
184183
{{/* Generate controller deployment limits */}}
185184
{{- define "controller.limits" -}}
186185
{{- if or (.Values.limitsCpu) (.Values.limitsMemory) }}

charts/controller/templates/controller-celery.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ spec:
2121
labels:
2222
app: drycc-controller-celery
2323
spec:
24+
{{- include "common.affinities.nodes.soft" (dict "key" "app" "values" (list "drycc-controller-celery")) | indent 6 }}
2425
serviceAccount: drycc-controller
2526
initContainers:
2627
- name: drycc-controller-init

charts/controller/templates/controller-deployment.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ spec:
2121
labels:
2222
app: drycc-controller
2323
spec:
24+
{{- include "common.affinities.nodes.soft" (dict "key" "app" "values" (list "drycc-controller")) | indent 6 }}
2425
serviceAccount: drycc-controller
2526
initContainers:
2627
- name: drycc-controller-init

charts/controller/templates/controller-webhook-deloyment.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ spec:
1212
labels:
1313
component: drycc-controller-webhook
1414
spec:
15+
{{- include "common.affinities.nodes.soft" (dict "key" "app" "values" (list "drycc-controller-webhook")) | indent 6 }}
1516
initContainers:
1617
- name: drycc-controller-init
1718
image: docker.io/drycc/python-dev:latest

rootfs/scheduler/resources/pod.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,37 @@ def state(self, pod):
9696

9797
return states.get(pod_state, pod_state)
9898

99+
@classmethod
100+
def affinity(cls, name):
101+
return {
102+
"podAntiAffinity": {
103+
"preferredDuringSchedulingIgnoredDuringExecution": [
104+
{
105+
"weight": 100,
106+
"podAffinityTerm": {
107+
"labelSelector": {
108+
"matchExpressions": [
109+
{"key": "app", "operator": "In", "values": [name, ]}
110+
]
111+
},
112+
"topologyKey": "topology.kubernetes.io/zone",
113+
}
114+
},
115+
{
116+
"weight": 90,
117+
"podAffinityTerm": {
118+
"labelSelector": {
119+
"matchExpressions": [
120+
{"key": "app", "operator": "In", "values": [name, ]}
121+
]
122+
},
123+
"topologyKey": "kubernetes.io/hostname",
124+
}
125+
}
126+
]
127+
}
128+
}
129+
99130
def manifest(self, namespace, name, image, **kwargs):
100131
app_type = kwargs.get('app_type')
101132
volumes = kwargs.get('volumes')
@@ -118,7 +149,9 @@ def manifest(self, namespace, name, image, **kwargs):
118149
'labels': labels,
119150
'annotations': kwargs.get('annotations', {}),
120151
},
121-
'spec': {}
152+
'spec': {
153+
"affinity": self.affinity(name)
154+
}
122155
}
123156
# pod manifest spec
124157
spec = manifest['spec']

0 commit comments

Comments
 (0)