Skip to content

Commit 29e49d5

Browse files
author
Alex Wishart
committed
Fix node affinity
1 parent 16873e9 commit 29e49d5

File tree

6 files changed

+96
-1
lines changed

6 files changed

+96
-1
lines changed

chart/ibm-swift-sample/.DS_Store

-6 KB
Binary file not shown.

chart/ibm-swift-sample/Chart.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
apiVersion: v1
22
description: A Swift sample application.
33
name: ibm-swift-sample
4-
version: 1.0.0
4+
version: 1.1.0
55
icon: https://raw.githubusercontent.com/IBM-Swift/kitura.io/master/assets/appIcon%402x.png
66
tillerVersion: ">=2.6.0"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{{/* affinity - https://kubernetes.io/docs/concepts/configuration/assign-pod-node/ */}}
2+
3+
{{- define "nodeaffinity" }}
4+
#https://kubernetes.io/docs/concepts/configuration/assign-pod-node/
5+
nodeAffinity:
6+
requiredDuringSchedulingIgnoredDuringExecution:
7+
{{- include "nodeAffinityRequiredDuringScheduling" . }}
8+
preferredDuringSchedulingIgnoredDuringExecution:
9+
{{- include "nodeAffinityPreferredDuringScheduling" . }}
10+
{{- end }}
11+
12+
{{- define "nodeAffinityRequiredDuringScheduling" }}
13+
#If you specify multiple nodeSelectorTerms associated with nodeAffinity types,
14+
#then the pod can be scheduled onto a node if one of the nodeSelectorTerms is satisfied.
15+
#
16+
#If you specify multiple matchExpressions associated with nodeSelectorTerms,
17+
#then the pod can be scheduled onto a node only if all matchExpressions can be satisfied.
18+
#
19+
#valid operators: In, NotIn, Exists, DoesNotExist, Gt, Lt
20+
nodeSelectorTerms:
21+
- matchExpressions:
22+
- key: beta.kubernetes.io/arch
23+
operator: In
24+
values:
25+
{{- range $key, $val := .Values.arch }}
26+
{{- if gt ($val | trunc 1 | int) 0 }}
27+
- {{ $key }}
28+
{{- end }}
29+
{{- end }}
30+
{{- end }}
31+
32+
{{- define "nodeAffinityPreferredDuringScheduling" }}
33+
{{- range $key, $val := .Values.arch }}
34+
{{- if gt ($val | trunc 1 | int) 0 }}
35+
- weight: {{ $val | trunc 1 | int }}
36+
preference:
37+
matchExpressions:
38+
- key: beta.kubernetes.io/arch
39+
operator: In
40+
values:
41+
- {{ $key }}
42+
{{- end }}
43+
{{- end }}
44+
{{- end }}

chart/ibm-swift-sample/templates/deployment.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ spec:
2525
labels:
2626
app: "{{ .Chart.Name }}-selector"
2727
spec:
28+
affinity:
29+
{{- include "nodeaffinity" . | indent 6 }}
2830
containers:
2931
- name: "{{ .Chart.Name }}"
3032
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
@@ -35,6 +37,12 @@ spec:
3537
port: {{ .Values.service.servicePort }}
3638
initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds}}
3739
periodSeconds: {{ .Values.livenessProbe.periodSeconds}}
40+
readinessProbe:
41+
httpGet:
42+
path: /health
43+
port: {{ .Values.service.servicePort }}
44+
initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds}}
45+
periodSeconds: {{ .Values.livenessProbe.periodSeconds}}
3846
resources:
3947
requests:
4048
cpu: "{{ .Values.image.resources.requests.cpu }}"

chart/ibm-swift-sample/values-metadata.yaml

+40
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ image:
1616
type: "string"
1717
immutable: true
1818
required: true
19+
1920
service:
2021
__metadata:
2122
label: "Service configuration"
@@ -49,3 +50,42 @@ service:
4950
type: "string"
5051
immutable: true
5152
required: true
53+
54+
55+
arch:
56+
__metadata:
57+
label: "Architecture scheduling preferences"
58+
amd64:
59+
__metadata:
60+
name: "amd64"
61+
label: "amd64"
62+
description: "Architecture preference for target worker node."
63+
type: "string"
64+
immutable: false
65+
required: true
66+
options:
67+
- label: "0 - Do not use"
68+
value: "0 - Do not use"
69+
- label: "1 - Least preferred"
70+
value: "1 - Least preferred"
71+
- label: "2 - No Preference"
72+
value: "2 - No Preference"
73+
- label: "3 - Most preferred"
74+
value: "3 - Most preferred"
75+
s390x:
76+
__metadata:
77+
name: "s390x"
78+
label: "s390x scheduling preference"
79+
description: "Architecture preference for target worker node."
80+
type: "string"
81+
immutable: false
82+
required: true
83+
options:
84+
- label: "0 - Do not use"
85+
value: "0 - Do not use"
86+
- label: "1 - Least preferred"
87+
value: "1 - Least preferred"
88+
- label: "2 - No Preference"
89+
value: "2 - No Preference"
90+
- label: "3 - Most preferred"
91+
value: "3 - Most preferred"

chart/ibm-swift-sample/values.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@ hpa:
2424
metrics:
2525
cpu:
2626
targetAverageUtilization: 100m
27+
arch:
28+
amd64: "3 - Most preferred"
29+
s390x: "2 - No preference"

0 commit comments

Comments
 (0)