Browse Source

Merge "Support systemd unit management during node join"

changes/25/625725/1
Zuul 6 months ago
parent
commit
ed56213244

+ 34
- 0
examples/basic/HostSystem.yaml View File

@@ -8,11 +8,45 @@ metadata:
8 8
     layer: site
9 9
   storagePolicy: cleartext
10 10
 data:
11
+  systemd_units:
12
+    kube-cgroup:
13
+      enable: true
11 14
   files:
12 15
     - path: /opt/kubernetes/bin/kubelet
13 16
       tar_url: https://dl.k8s.io/v1.10.2/kubernetes-node-linux-amd64.tar.gz
14 17
       tar_path: kubernetes/node/bin/kubelet
15 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 50
     - path: /etc/logrotate.d/json-logrotate
17 51
       mode: 0444
18 52
       content: |-

+ 1
- 0
examples/basic/Kubelet.yaml View File

@@ -18,6 +18,7 @@ data:
18 18
     - --anonymous-auth=false
19 19
     - --feature-gates=PodShareProcessNamespace=true
20 20
     - --v=3
21
+    - --cgroup-root=/kube_whitelist
21 22
   images:
22 23
     pause: gcr.io/google_containers/pause-amd64:3.0
23 24
 ...

+ 45
- 0
promenade/config.py View File

@@ -169,6 +169,51 @@ class Configuration:
169 169
             if value:
170 170
                 return value
171 171
 
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
+
172 217
     @property
173 218
     def join_ips(self):
174 219
         maybe_ips = self.get_path('KubernetesNode:join_ips')

+ 16
- 1
promenade/schemas/HostSystem.yaml View File

@@ -11,6 +11,18 @@ data:
11 11
     abs_path:
12 12
       type: string
13 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 26
     apt_source_line:
15 27
       type: string
16 28
       # XXX add regex
@@ -27,7 +39,6 @@ data:
27 39
           $ref: '#/definitions/url'
28 40
         tar_path:
29 41
           $ref: '#/definitions/rel_path'
30
-
31 42
       requried:
32 43
         - mode
33 44
         - path
@@ -68,6 +79,10 @@ data:
68 79
         type: object
69 80
         items:
70 81
           $ref: '#/definitions/file'
82
+    systemd_units:
83
+      type: object
84
+      additionalProperties:
85
+        $ref: '#/definitions/systemd_unit'
71 86
     images:
72 87
       type: object
73 88
       properties:

+ 7
- 0
promenade/templates/include/up.sh View File

@@ -105,6 +105,13 @@ log
105 105
 log === Starting Docker and Kubelet ===
106 106
 set -x
107 107
 systemctl daemon-reload
108
+
109
+{% for a in ['enable','start','stop','disable'] %}
110
+{% for u in config.get_units_by_action(a) %}
111
+systemctl {{ a }} {{ u }}
112
+{% endfor %}
113
+{% endfor %}
114
+
108 115
 systemctl restart docker || true
109 116
 systemctl enable kubelet
110 117
 systemctl restart kubelet

Loading…
Cancel
Save