summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-12-16 17:24:46 +0000
committerGerrit Code Review <review@openstack.org>2018-12-16 17:24:46 +0000
commited56213244efd35fa715f29f99a6a3c71e48167f (patch)
tree6693a1660a14b85f291750c91cd01760fd49456d
parentcc4eb17aa51e010f2a676e818b1ecbf38e0702f5 (diff)
parentc13fc33d85b451d0edb173691994642b03e596fc (diff)
Merge "Support systemd unit management during node join"
-rw-r--r--examples/basic/HostSystem.yaml34
-rw-r--r--examples/basic/Kubelet.yaml1
-rw-r--r--promenade/config.py45
-rw-r--r--promenade/schemas/HostSystem.yaml17
-rw-r--r--promenade/templates/include/up.sh7
5 files changed, 103 insertions, 1 deletions
diff --git a/examples/basic/HostSystem.yaml b/examples/basic/HostSystem.yaml
index 728a3ce..2f4cbb0 100644
--- a/examples/basic/HostSystem.yaml
+++ b/examples/basic/HostSystem.yaml
@@ -8,11 +8,45 @@ metadata:
8 layer: site 8 layer: site
9 storagePolicy: cleartext 9 storagePolicy: cleartext
10data: 10data:
11 systemd_units:
12 kube-cgroup:
13 enable: true
11 files: 14 files:
12 - path: /opt/kubernetes/bin/kubelet 15 - path: /opt/kubernetes/bin/kubelet
13 tar_url: https://dl.k8s.io/v1.10.2/kubernetes-node-linux-amd64.tar.gz 16 tar_url: https://dl.k8s.io/v1.10.2/kubernetes-node-linux-amd64.tar.gz
14 tar_path: kubernetes/node/bin/kubelet 17 tar_path: kubernetes/node/bin/kubelet
15 mode: 0555 18 mode: 0555
19 - path: /etc/systemd/system/kube-cgroup.service
20 content: |
21 [Unit]
22 Description=Create and tune cgroup for Kubernetes Pods
23 Requires=network-online.target
24 Before=kubelet.service
25
26 [Service]
27 Delegate=yes
28 ExecStart=/usr/local/sbin/kube-cgroup.sh
29
30 [Install]
31 RequiredBy=kubelet.service
32 mode: 0444
33 - path: /usr/local/sbin/kube-cgroup.sh
34 mode: 0744
35 content: |-
36 #!/bin/bash
37
38 set -x
39
40 KUBE_CGROUP=${KUBE_CGROUP:-"kube_whitelist"}
41 SYSTEMD_ABSPATH="/sys/fs/cgroup/systemd/$KUBE_CGROUP"
42 CPUSET_ABSPATH="/sys/fs/cgroup/cpuset/$KUBE_CGROUP"
43 CPU_ABSPATH="/sys/fs/cgroup/cpu/$KUBE_CGROUP"
44 MEM_ABSPATH="/sys/fs/cgroup/memory/$KUBE_CGROUP"
45
46 for cg in $SYSTEMD_ABSPATH $CPUSET_ABSPATH $CPU_ABSPATH $MEM_ABSPATH
47 do
48 mkdir -p "$cg"
49 done
16 - path: /etc/logrotate.d/json-logrotate 50 - path: /etc/logrotate.d/json-logrotate
17 mode: 0444 51 mode: 0444
18 content: |- 52 content: |-
diff --git a/examples/basic/Kubelet.yaml b/examples/basic/Kubelet.yaml
index 60074cd..69c5fa7 100644
--- a/examples/basic/Kubelet.yaml
+++ b/examples/basic/Kubelet.yaml
@@ -18,6 +18,7 @@ data:
18 - --anonymous-auth=false 18 - --anonymous-auth=false
19 - --feature-gates=PodShareProcessNamespace=true 19 - --feature-gates=PodShareProcessNamespace=true
20 - --v=3 20 - --v=3
21 - --cgroup-root=/kube_whitelist
21 images: 22 images:
22 pause: gcr.io/google_containers/pause-amd64:3.0 23 pause: gcr.io/google_containers/pause-amd64:3.0
23... 24...
diff --git a/promenade/config.py b/promenade/config.py
index 296fec7..79febba 100644
--- a/promenade/config.py
+++ b/promenade/config.py
@@ -170,6 +170,51 @@ class Configuration:
170 return value 170 return value
171 171
172 @property 172 @property
173 def enable_units(self):
174 """ Get systemd unit names where enable is ``true``."""
175 return self.get_units_by_action('enable')
176
177 @property
178 def start_units(self):
179 """ Get systemd unit names where start is ``true``."""
180 return self.get_units_by_action('start')
181
182 @property
183 def stop_units(self):
184 """ Get systemd unit names where stop is ``true``."""
185 return self.get_units_by_action('stop')
186
187 @property
188 def disable_units(self):
189 """ Get systemd unit names where disable is ``true``."""
190 return self.get_units_by_action('disable')
191
192 def get_units_by_action(self, action):
193 """ Select systemd unit names by ``action``
194
195 Get all units that are ``true`` for ``action``.
196 """
197 return [
198 k for k, v in self.systemd_units.items() if v.get(action, False)
199 ]
200
201 @property
202 def systemd_units(self):
203 """ Return a dictionary of systemd units to be managed during join.
204
205 The dictionary key is the systemd unit name, each will have a four
206 boolean keys: ``enable``, ``disable``, ``start``, ``stop`` on the
207 actions to be taken at the end of genesis/node join. The steps
208 are ordered: enable, start, stop, disable.
209 """
210 all_units = {}
211
212 for document in self.iterate(kind='HostSystem'):
213 all_units.update(document['data'].get('systemd_units', {}))
214
215 return all_units
216
217 @property
173 def join_ips(self): 218 def join_ips(self):
174 maybe_ips = self.get_path('KubernetesNode:join_ips') 219 maybe_ips = self.get_path('KubernetesNode:join_ips')
175 if maybe_ips is not None: 220 if maybe_ips is not None:
diff --git a/promenade/schemas/HostSystem.yaml b/promenade/schemas/HostSystem.yaml
index fe2a943..45edb0e 100644
--- a/promenade/schemas/HostSystem.yaml
+++ b/promenade/schemas/HostSystem.yaml
@@ -11,6 +11,18 @@ data:
11 abs_path: 11 abs_path:
12 type: string 12 type: string
13 pattern: '^/.+$' 13 pattern: '^/.+$'
14 systemd_unit:
15 type: object
16 properties:
17 enable:
18 type: boolean
19 disable:
20 type: boolean
21 start:
22 type: boolean
23 stop:
24 type: boolean
25 additionalProperties: false
14 apt_source_line: 26 apt_source_line:
15 type: string 27 type: string
16 # XXX add regex 28 # XXX add regex
@@ -27,7 +39,6 @@ data:
27 $ref: '#/definitions/url' 39 $ref: '#/definitions/url'
28 tar_path: 40 tar_path:
29 $ref: '#/definitions/rel_path' 41 $ref: '#/definitions/rel_path'
30
31 requried: 42 requried:
32 - mode 43 - mode
33 - path 44 - path
@@ -68,6 +79,10 @@ data:
68 type: object 79 type: object
69 items: 80 items:
70 $ref: '#/definitions/file' 81 $ref: '#/definitions/file'
82 systemd_units:
83 type: object
84 additionalProperties:
85 $ref: '#/definitions/systemd_unit'
71 images: 86 images:
72 type: object 87 type: object
73 properties: 88 properties:
diff --git a/promenade/templates/include/up.sh b/promenade/templates/include/up.sh
index b0eb229..613291d 100644
--- a/promenade/templates/include/up.sh
+++ b/promenade/templates/include/up.sh
@@ -105,6 +105,13 @@ log
105log === Starting Docker and Kubelet === 105log === Starting Docker and Kubelet ===
106set -x 106set -x
107systemctl daemon-reload 107systemctl daemon-reload
108
109{% for a in ['enable','start','stop','disable'] %}
110{% for u in config.get_units_by_action(a) %}
111systemctl {{ a }} {{ u }}
112{% endfor %}
113{% endfor %}
114
108systemctl restart docker || true 115systemctl restart docker || true
109systemctl enable kubelet 116systemctl enable kubelet
110systemctl restart kubelet 117systemctl restart kubelet