Skip to content

Commit 75294e2

Browse files
committed
first pass at helm chart for fastcs instances
1 parent 225dca8 commit 75294e2

10 files changed

Lines changed: 490 additions & 1 deletion

File tree

.pre-commit-config.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.5.0
3+
rev: v5.0.0
44
hooks:
55
- id: check-added-large-files
66
- id: check-yaml
7+
exclude: ^helm/templates/
78
- id: check-merge-conflict
89
- id: end-of-file-fixer
910

helm/.helmignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*.orig
18+
*~
19+
# Various IDEs
20+
.project
21+
.idea/
22+
*.tmproj
23+
.vscode/

helm/Chart.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: v2
2+
name: fastcs-instance
3+
description: A Helm chart for Kubernetes
4+
5+
# A chart can be either an 'application' or a 'library' chart.
6+
#
7+
# Application charts are a collection of templates that can be packaged into versioned archives
8+
# to be deployed.
9+
#
10+
# Library charts provide useful utilities or functions for the chart developer. They're included as
11+
# a dependency of application charts to inject those utilities and functions into the rendering
12+
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
13+
type: application
14+
15+
# This is the chart version. This version number should be incremented each time you make changes
16+
# to the chart and its templates, including the app version.
17+
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18+
version: 0.1.0
19+
20+
# This is the version number of the application being deployed. This version number should be
21+
# incremented each time you make changes to the application. Versions are not expected to
22+
# follow Semantic Versioning. They should reflect the version the application is using.
23+
# It is recommended to use it with quotes.
24+
appVersion: "1.16.0"

helm/templates/_helpers.tpl

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "fastcs.name" -}}
5+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
6+
{{- end }}
7+
8+
{{/*
9+
Create a default fully qualified app name.
10+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
11+
If release name contains chart name it will be used as a full name.
12+
*/}}
13+
{{- define "fastcs.fullname" -}}
14+
{{- if .Values.fullnameOverride }}
15+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
16+
{{- else }}
17+
{{- $name := default .Chart.Name .Values.nameOverride }}
18+
{{- if contains $name .Release.Name }}
19+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
20+
{{- else }}
21+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
22+
{{- end }}
23+
{{- end }}
24+
{{- end }}
25+
26+
{{/*
27+
Create chart name and version as used by the chart label.
28+
*/}}
29+
{{- define "fastcs.chart" -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "fastcs.labels" -}}
37+
helm.sh/chart: {{ include "fastcs.chart" . }}
38+
{{ include "fastcs.selectorLabels" . }}
39+
{{- if .Chart.AppVersion }}
40+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
41+
{{- end }}
42+
app.kubernetes.io/managed-by: {{ .Release.Service }}
43+
{{- end }}
44+
45+
{{/*
46+
Selector labels
47+
*/}}
48+
{{- define "fastcs.selectorLabels" -}}
49+
app.kubernetes.io/name: {{ include "fastcs.name" . }}
50+
app.kubernetes.io/instance: {{ .Release.Name }}
51+
{{- end }}
52+
53+
{{/*
54+
Create the name of the service account to use
55+
*/}}
56+
{{- define "fastcs.serviceAccountName" -}}
57+
{{- if .Values.serviceAccount.create }}
58+
{{- default (include "fastcs.fullname" .) .Values.serviceAccount.name }}
59+
{{- else }}
60+
{{- default "default" .Values.serviceAccount.name }}
61+
{{- end }}
62+
{{- end }}

helm/templates/clusterIP.tpl

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
2+
{{- define "allocateIpFromName" -}}
3+
{{- $name := printf "%s.%s" .name .namespace -}}
4+
{{- $baseIpWithCIDR := .baseIp -}}
5+
6+
{{- $startIp := .startIp | int -}}
7+
{{- $conversion := atoi (adler32sum $name) -}}
8+
9+
{{- $baseIpParts := split "/" $baseIpWithCIDR -}}
10+
{{- $baseIp := index $baseIpParts "_0" -}}
11+
{{- $cidrRange := index $baseIpParts "_1" | int -}}
12+
13+
{{- $octets := split "." $baseIp -}}
14+
{{- $firstOctet := index $octets "_0" | int -}}
15+
{{- $secondOctet := index $octets "_1" | int -}}
16+
{{- $thirdOctet := index $octets "_2" | int -}}
17+
{{- $fourthOctet := index $octets "_3" | int -}}
18+
19+
20+
{{- $totalIps := 1 }}
21+
{{- $loopcnt:= sub 32 $cidrRange -}}
22+
{{- range $i,$k := until ($loopcnt | int) }}
23+
{{- $totalIps = mul $totalIps 2 }}
24+
{{- end }}
25+
26+
{{- $ipSuffix := add $startIp (mod $conversion $totalIps) -}}
27+
28+
{{- $secondOctet := add $secondOctet (div $ipSuffix 65536) -}}
29+
{{- $ipSuffix = mod $ipSuffix 65536 -}}
30+
{{- $thirdOctet := add $thirdOctet (div $ipSuffix 256) -}}
31+
{{- $fourthOctet := mod $ipSuffix 256 -}}
32+
33+
{{- if gt $fourthOctet 255 }}
34+
{{- $fourthOctet = mod $fourthOctet 256 -}}
35+
{{- end }}
36+
{{- if gt $thirdOctet 255 }}
37+
{{- $thirdOctet = mod $thirdOctet 256 -}}
38+
{{- $secondOctet = add $secondOctet 1 -}}
39+
{{- end }}
40+
{{- if gt $secondOctet 255 }}
41+
{{- $secondOctet = mod $secondOctet 256 -}}
42+
{{- end }}
43+
44+
{{- printf "%d.%d.%d.%d" $firstOctet $secondOctet $thirdOctet $fourthOctet -}}
45+
{{- end -}}
46+
47+
48+
{{- define "allocateIpFromNames" -}}
49+
{{- $name := printf "%s.%s" .name .namespace -}}
50+
{{- $baseIpWithCIDR := .baseIp -}}
51+
52+
{{- $startIp := .startIp | int -}}
53+
{{- $conversion := atoi (adler32sum $name) -}}
54+
55+
{{- $baseIpParts := split "/" $baseIpWithCIDR -}}
56+
{{- $baseIp := index $baseIpParts "_0" -}}
57+
{{- $cidrRange := index $baseIpParts "_1" | int -}}
58+
59+
{{- $octets := split "." $baseIp -}}
60+
{{- $firstOctet := index $octets "_0" | int -}}
61+
{{- $secondOctet := index $octets "_1" | int -}}
62+
{{- $thirdOctet := index $octets "_2" | int -}}
63+
{{- $fourthOctet := index $octets "_3" | int -}}
64+
65+
{{- $totalIps := 1 }}
66+
{{- $loopcnt:= sub 32 $cidrRange -}}
67+
{{- range $i,$k := until ($loopcnt | int) }}
68+
{{- $totalIps = mul $totalIps 2 }}
69+
{{- end }}
70+
{{- printf "CIDR %d IPs %d" $cidrRange $totalIps -}}
71+
72+
73+
{{- end -}}

helm/templates/deployment.yaml

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
{{- /*
2+
Default the derivable substitution values.
3+
4+
This keeps the length of the values.txt file for each individual IOC
5+
to a minimum
6+
*/ -}}
7+
{{- $location := default .Values.global.location .Values.location | required "ERROR - You must supply location or global.location" -}}
8+
{{- $ioc_group := default .Values.global.ioc_group .Values.ioc_group | required "ERROR - You must supply ioc_group or global.ioc_group" -}}
9+
{{- $opisClaim := default (print $ioc_group "-opi-claim") .Values.opisClaim -}}
10+
{{- $runtimeClaim := default (print $ioc_group "-runtime-claim") .Values.runtimeClaim -}}
11+
{{- $autosaveClaim := default (print $ioc_group "-autosave-claim") .Values.autosaveClaim -}}
12+
{{- $image := .Values.image | required "ERROR - You must supply image." -}}
13+
14+
{{- $enabled := eq .Values.global.enabled false | ternary false true -}}
15+
16+
apiVersion: apps/v1
17+
kind: StatefulSet
18+
metadata:
19+
name: {{ include "fastcs.fullname" . }}
20+
labels:
21+
location: {{ $location }}
22+
ioc_group: {{ $ioc_group }}
23+
enabled: {{ $enabled | quote }}
24+
is_ioc: "true"
25+
{{- include "fastcs.labels" . | nindent 4 }}
26+
spec:
27+
replicas: {{ $enabled | ternary 1 0 }}
28+
selector:
29+
matchLabels:
30+
{{- include "fastcs.selectorLabels" . | nindent 6 }}
31+
template:
32+
metadata:
33+
{{- with .Values.podAnnotations }}
34+
annotations:
35+
{{- toYaml . | nindent 8 }}
36+
{{- end }}
37+
labels:
38+
{{- include "fastcs.labels" . | nindent 8 }}
39+
{{- with .Values.podLabels }}
40+
{{- toYaml . | nindent 8 }}
41+
{{- end }}
42+
# re-deploy in case the configMap has changed - use a random value
43+
# unless the Commit Hash is supplied (by ArgoCD or helm command line)
44+
rollme: {{ .Values.global.commitHash | default (randAlphaNum 5) | quote }}
45+
spec:
46+
serviceAccountName: {{ include "fastcs.serviceAccountName" . }}
47+
{{- with .Values.podSecurityContext }}
48+
securityContext:
49+
{{- toYaml . | nindent 8 }}
50+
{{- end }}
51+
containers:
52+
{{- range .Values.extra_containers }}
53+
- name: {{ .name }}
54+
{{- with $.Values.securityContext }}
55+
securityContext:
56+
{{- toYaml . | nindent 12 }}
57+
{{- end }}
58+
image: {{ .image }}
59+
{{- with .startCommand }}
60+
command:
61+
{{- if (kindIs "string" .) }}
62+
- {{ . }}
63+
{{- else if (kindIs "slice" .) }}
64+
{{- . | toYaml | nindent 10 }}
65+
{{- end }}
66+
{{- end }}
67+
volumeMounts:
68+
{{- with $.Values.volumeMounts }}
69+
{{- toYaml . | nindent 12 }}
70+
{{- end }}
71+
- name: opis-volume
72+
mountPath: /epics/opi
73+
subPath: "{{ $.Release.Name }}"
74+
- name: config-volume
75+
mountPath: {{ $.Values.iocConfig }}
76+
{{- end }}
77+
- name: {{ .Chart.Name }}
78+
{{- with .Values.securityContext }}
79+
securityContext:
80+
{{- toYaml . | nindent 12 }}
81+
{{- end }}
82+
image: "{{ .Values.image }}"
83+
imagePullPolicy: IfNotPresent
84+
{{- with .Values.startCommand }}
85+
command:
86+
{{- if (kindIs "string" .) }}
87+
- {{ . }}
88+
{{- else if (kindIs "slice" .) }}
89+
{{- . | toYaml | nindent 10 }}
90+
{{- end }}
91+
{{- end }}
92+
{{- with .Values.startArgs }}
93+
args:
94+
{{- if (kindIs "string" .) }}
95+
- {{ . }}
96+
{{- else if (kindIs "slice" .) }}
97+
{{- . | toYaml | nindent 10 }}
98+
{{- end }}
99+
{{- end }}
100+
101+
ports:
102+
- name: channel-access
103+
containerPort: 5064
104+
protocol: TCP
105+
- name: pv-access
106+
containerPort: 5075
107+
protocol: TCP
108+
{{- with .Values.livenessProbe }}
109+
livenessProbe:
110+
{{- toYaml . | nindent 12 }}
111+
{{- end }}
112+
{{- with .Values.readinessProbe }}
113+
readinessProbe:
114+
{{- toYaml . | nindent 12 }}
115+
{{- end }}
116+
{{- with .Values.resources }}
117+
resources:
118+
{{- toYaml . | nindent 12 }}
119+
{{- end }}
120+
volumeMounts:
121+
{{- with .Values.volumeMounts }}
122+
{{- toYaml . | nindent 12 }}
123+
{{- end }}
124+
- name: opis-volume
125+
mountPath: /epics/opi
126+
subPath: "{{ .Release.Name }}"
127+
- name: config-volume
128+
mountPath: {{ .Values.iocConfig }}
129+
volumes:
130+
{{- with .Values.volumes }}
131+
{{- toYaml . | nindent 8 }}
132+
{{- end }}
133+
- name: opis-volume
134+
persistentVolumeClaim:
135+
claimName: {{ $opisClaim }}
136+
- name: config-volume
137+
configMap:
138+
name: {{ .Release.Name }}-config
139+
{{- with .Values.nodeSelector }}
140+
nodeSelector:
141+
{{- toYaml . | nindent 8 }}
142+
{{- end }}
143+
{{- with .Values.affinity }}
144+
affinity:
145+
{{- toYaml . | nindent 8 }}
146+
{{- end }}
147+
{{- with .Values.tolerations }}
148+
tolerations:
149+
{{- toYaml . | nindent 8 }}
150+
{{- end }}

helm/templates/service.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: {{ include "fastcs.fullname" . }}
5+
labels:
6+
"{{- include "fastcs.labels" . | nindent 4 }}"
7+
spec:
8+
type: {{ .Values.service.type }}
9+
# allocate a fixed clusterIP for this service based on the service name
10+
{{- $alloc_args := dict "name" .Release.Name "namespace" .Release.Namespace "baseIp" .Values.baseIp "startIp" .Values.startIp }}
11+
clusterIP: {{ .Values.clusterIP | default (include "allocateIpFromName" $alloc_args) }}
12+
ports:
13+
- port: {{ .Values.service.ca_port }}
14+
targetPort: 5064
15+
protocol: TCP
16+
name: channel-access
17+
- port: {{ .Values.service.pva_port }}
18+
targetPort: 5075
19+
protocol: TCP
20+
name: pv-access
21+
selector:
22+
{{- include "fastcs.selectorLabels" . | nindent 4 }}

helm/templates/serviceaccount.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{{- if .Values.serviceAccount.create -}}
2+
apiVersion: v1
3+
kind: ServiceAccount
4+
metadata:
5+
name: {{ include "fastcs.serviceAccountName" . }}
6+
labels:
7+
{{- include "fastcs.labels" . | nindent 4 }}
8+
{{- with .Values.serviceAccount.annotations }}
9+
annotations:
10+
{{- toYaml . | nindent 4 }}
11+
{{- end }}
12+
automountServiceAccountToken: {{ .Values.serviceAccount.automount }}
13+
{{- end }}

0 commit comments

Comments
 (0)