-
Notifications
You must be signed in to change notification settings - Fork 584
/
addonjob.go
62 lines (61 loc) · 2.08 KB
/
addonjob.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package templates
const AddonJobTemplate = `
{{- $addonName := .AddonName }}
{{- $nodeName := .NodeName }}
{{- $image := .Image }}
{{- $OSLabel := .OSLabel }}
apiVersion: batch/v1
kind: Job
metadata:
{{- if eq .DeleteJob "true" }}
name: {{$addonName}}-delete-job
{{- else }}
name: {{$addonName}}-deploy-job
{{- end }}
namespace: kube-system
spec:
backoffLimit: 10
template:
metadata:
name: rke-deploy
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: {{$OSLabel}}
operator: NotIn
values:
- windows
tolerations:
- operator: Exists
hostNetwork: true
serviceAccountName: rke-job-deployer
nodeName: {{$nodeName}}
containers:
{{- if eq .DeleteJob "true" }}
- name: {{$addonName}}-delete-pod
{{- else }}
- name: {{$addonName}}-pod
{{- end }}
image: {{$image}}
{{- if eq .DeleteJob "true" }}
command: ["/bin/sh"]
args: ["-c" ,"kubectl get --ignore-not-found=true -f /etc/config/{{$addonName}}.yaml -o custom-columns=NAME:.metadata.name,NAMESPACE:.metadata.namespace,KIND:.kind --no-headers | while read name namespace kind; do if [ \"x${namespace}\" = \"x<none>\" ]; then kubectl delete $kind $name; else kubectl -n $namespace delete $kind $name; fi; done"]
{{- else }}
command: [ "kubectl", "apply", "-f" , "/etc/config/{{$addonName}}.yaml"]
{{- end }}
volumeMounts:
- name: config-volume
mountPath: /etc/config
volumes:
- name: config-volume
configMap:
# Provide the name of the ConfigMap containing the files you want
# to add to the container
name: {{$addonName}}
items:
- key: {{$addonName}}
path: {{$addonName}}.yaml
restartPolicy: Never`