Skip to content

Commit

Permalink
Fix node affinity
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Wishart committed Mar 5, 2018
1 parent 16873e9 commit 29e49d5
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 1 deletion.
Binary file removed chart/ibm-swift-sample/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion chart/ibm-swift-sample/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v1
description: A Swift sample application.
name: ibm-swift-sample
version: 1.0.0
version: 1.1.0
icon: https://raw.githubusercontent.com/IBM-Swift/kitura.io/master/assets/appIcon%402x.png
tillerVersion: ">=2.6.0"
44 changes: 44 additions & 0 deletions chart/ibm-swift-sample/templates/_affinity.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{{/* affinity - https://kubernetes.io/docs/concepts/configuration/assign-pod-node/ */}}

{{- define "nodeaffinity" }}
#https://kubernetes.io/docs/concepts/configuration/assign-pod-node/
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
{{- include "nodeAffinityRequiredDuringScheduling" . }}
preferredDuringSchedulingIgnoredDuringExecution:
{{- include "nodeAffinityPreferredDuringScheduling" . }}
{{- end }}

{{- define "nodeAffinityRequiredDuringScheduling" }}
#If you specify multiple nodeSelectorTerms associated with nodeAffinity types,
#then the pod can be scheduled onto a node if one of the nodeSelectorTerms is satisfied.
#
#If you specify multiple matchExpressions associated with nodeSelectorTerms,
#then the pod can be scheduled onto a node only if all matchExpressions can be satisfied.
#
#valid operators: In, NotIn, Exists, DoesNotExist, Gt, Lt
nodeSelectorTerms:
- matchExpressions:
- key: beta.kubernetes.io/arch
operator: In
values:
{{- range $key, $val := .Values.arch }}
{{- if gt ($val | trunc 1 | int) 0 }}
- {{ $key }}
{{- end }}
{{- end }}
{{- end }}

{{- define "nodeAffinityPreferredDuringScheduling" }}
{{- range $key, $val := .Values.arch }}
{{- if gt ($val | trunc 1 | int) 0 }}
- weight: {{ $val | trunc 1 | int }}
preference:
matchExpressions:
- key: beta.kubernetes.io/arch
operator: In
values:
- {{ $key }}
{{- end }}
{{- end }}
{{- end }}
8 changes: 8 additions & 0 deletions chart/ibm-swift-sample/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ spec:
labels:
app: "{{ .Chart.Name }}-selector"
spec:
affinity:
{{- include "nodeaffinity" . | indent 6 }}
containers:
- name: "{{ .Chart.Name }}"
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
Expand All @@ -35,6 +37,12 @@ spec:
port: {{ .Values.service.servicePort }}
initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds}}
periodSeconds: {{ .Values.livenessProbe.periodSeconds}}
readinessProbe:
httpGet:
path: /health
port: {{ .Values.service.servicePort }}
initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds}}
periodSeconds: {{ .Values.livenessProbe.periodSeconds}}
resources:
requests:
cpu: "{{ .Values.image.resources.requests.cpu }}"
Expand Down
40 changes: 40 additions & 0 deletions chart/ibm-swift-sample/values-metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ image:
type: "string"
immutable: true
required: true

service:
__metadata:
label: "Service configuration"
Expand Down Expand Up @@ -49,3 +50,42 @@ service:
type: "string"
immutable: true
required: true


arch:
__metadata:
label: "Architecture scheduling preferences"
amd64:
__metadata:
name: "amd64"
label: "amd64"
description: "Architecture preference for target worker node."
type: "string"
immutable: false
required: true
options:
- label: "0 - Do not use"
value: "0 - Do not use"
- label: "1 - Least preferred"
value: "1 - Least preferred"
- label: "2 - No Preference"
value: "2 - No Preference"
- label: "3 - Most preferred"
value: "3 - Most preferred"
s390x:
__metadata:
name: "s390x"
label: "s390x scheduling preference"
description: "Architecture preference for target worker node."
type: "string"
immutable: false
required: true
options:
- label: "0 - Do not use"
value: "0 - Do not use"
- label: "1 - Least preferred"
value: "1 - Least preferred"
- label: "2 - No Preference"
value: "2 - No Preference"
- label: "3 - Most preferred"
value: "3 - Most preferred"
3 changes: 3 additions & 0 deletions chart/ibm-swift-sample/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ hpa:
metrics:
cpu:
targetAverageUtilization: 100m
arch:
amd64: "3 - Most preferred"
s390x: "2 - No preference"

0 comments on commit 29e49d5

Please sign in to comment.