diff options
Diffstat (limited to 'roles/kubernetes/standalone')
-rw-r--r-- | roles/kubernetes/standalone/base/defaults/main.yml (renamed from roles/kubernetes/standalone/defaults/main.yml) | 0 | ||||
-rw-r--r-- | roles/kubernetes/standalone/base/handlers/main.yml (renamed from roles/kubernetes/standalone/handlers/main.yml) | 0 | ||||
-rw-r--r-- | roles/kubernetes/standalone/base/tasks/main.yml (renamed from roles/kubernetes/standalone/tasks/main.yml) | 0 | ||||
-rw-r--r-- | roles/kubernetes/standalone/base/templates/cni-no-portmap.conflist.j2 (renamed from roles/kubernetes/standalone/templates/cni-no-portmap.conflist.j2) | 0 | ||||
-rw-r--r-- | roles/kubernetes/standalone/base/templates/cni-with-localonly-portmap.conflist.j2 (renamed from roles/kubernetes/standalone/templates/cni-with-localonly-portmap.conflist.j2) | 0 | ||||
-rw-r--r-- | roles/kubernetes/standalone/base/templates/cni-with-portmap.conflist.j2 (renamed from roles/kubernetes/standalone/templates/cni-with-portmap.conflist.j2) | 0 | ||||
-rw-r--r-- | roles/kubernetes/standalone/base/templates/kubelet-config.yml.j2 (renamed from roles/kubernetes/standalone/templates/kubelet-config.yml.j2) | 0 | ||||
-rw-r--r-- | roles/kubernetes/standalone/base/templates/kubelet.service.override.j2 (renamed from roles/kubernetes/standalone/templates/kubelet.service.override.j2) | 0 | ||||
-rw-r--r-- | roles/kubernetes/standalone/pod/defaults/main.yml | 23 | ||||
-rw-r--r-- | roles/kubernetes/standalone/pod/tasks/main.yml | 74 |
10 files changed, 97 insertions, 0 deletions
diff --git a/roles/kubernetes/standalone/defaults/main.yml b/roles/kubernetes/standalone/base/defaults/main.yml index b0c14b11..b0c14b11 100644 --- a/roles/kubernetes/standalone/defaults/main.yml +++ b/roles/kubernetes/standalone/base/defaults/main.yml diff --git a/roles/kubernetes/standalone/handlers/main.yml b/roles/kubernetes/standalone/base/handlers/main.yml index 26438551..26438551 100644 --- a/roles/kubernetes/standalone/handlers/main.yml +++ b/roles/kubernetes/standalone/base/handlers/main.yml diff --git a/roles/kubernetes/standalone/tasks/main.yml b/roles/kubernetes/standalone/base/tasks/main.yml index 241c3136..241c3136 100644 --- a/roles/kubernetes/standalone/tasks/main.yml +++ b/roles/kubernetes/standalone/base/tasks/main.yml diff --git a/roles/kubernetes/standalone/templates/cni-no-portmap.conflist.j2 b/roles/kubernetes/standalone/base/templates/cni-no-portmap.conflist.j2 index be47f216..be47f216 100644 --- a/roles/kubernetes/standalone/templates/cni-no-portmap.conflist.j2 +++ b/roles/kubernetes/standalone/base/templates/cni-no-portmap.conflist.j2 diff --git a/roles/kubernetes/standalone/templates/cni-with-localonly-portmap.conflist.j2 b/roles/kubernetes/standalone/base/templates/cni-with-localonly-portmap.conflist.j2 index acaf7eba..acaf7eba 100644 --- a/roles/kubernetes/standalone/templates/cni-with-localonly-portmap.conflist.j2 +++ b/roles/kubernetes/standalone/base/templates/cni-with-localonly-portmap.conflist.j2 diff --git a/roles/kubernetes/standalone/templates/cni-with-portmap.conflist.j2 b/roles/kubernetes/standalone/base/templates/cni-with-portmap.conflist.j2 index 9f9b2b9a..9f9b2b9a 100644 --- a/roles/kubernetes/standalone/templates/cni-with-portmap.conflist.j2 +++ b/roles/kubernetes/standalone/base/templates/cni-with-portmap.conflist.j2 diff --git a/roles/kubernetes/standalone/templates/kubelet-config.yml.j2 b/roles/kubernetes/standalone/base/templates/kubelet-config.yml.j2 index d6af0f24..d6af0f24 100644 --- a/roles/kubernetes/standalone/templates/kubelet-config.yml.j2 +++ b/roles/kubernetes/standalone/base/templates/kubelet-config.yml.j2 diff --git a/roles/kubernetes/standalone/templates/kubelet.service.override.j2 b/roles/kubernetes/standalone/base/templates/kubelet.service.override.j2 index fe8bfb4c..fe8bfb4c 100644 --- a/roles/kubernetes/standalone/templates/kubelet.service.override.j2 +++ b/roles/kubernetes/standalone/base/templates/kubelet.service.override.j2 diff --git a/roles/kubernetes/standalone/pod/defaults/main.yml b/roles/kubernetes/standalone/pod/defaults/main.yml new file mode 100644 index 00000000..2eae33a3 --- /dev/null +++ b/roles/kubernetes/standalone/pod/defaults/main.yml @@ -0,0 +1,23 @@ +--- +# kubernetes_standalone_pod: +# name: example +# labels: +# foo: bar +# annotations: +# hello: world +# spec: | +# containers: +# - name: test +# image: "debian:stable" +# command: +# - /bin/bash +# - -c +# - "sleep inf" +# mode: "0600" +# config_hash_items: +# - path: /path/to/configfile +# properties: +# - checksum +# - mode +# - uid +# - gid diff --git a/roles/kubernetes/standalone/pod/tasks/main.yml b/roles/kubernetes/standalone/pod/tasks/main.yml new file mode 100644 index 00000000..7f87cf3f --- /dev/null +++ b/roles/kubernetes/standalone/pod/tasks/main.yml @@ -0,0 +1,74 @@ +--- +- name: generate config-hash + when: "'config_hash_items' in kubernetes_standalone_pod" + block: + - name: create directory for config-hash files + file: + path: /etc/kubernetes/config-hashes + state: directory + + - name: gather stats for config-hash items + loop: "{{ kubernetes_standalone_pod.config_hash_items }}" + loop_control: + loop_var: config_hash_item + label: "{{ config_hash_item.path }} ({{ config_hash_item.properties | sort | join(', ') }})" + stat: + path: "{{ config_hash_item.path }}" + get_checksum: yes + checksum_algorithm: sha256 + register: config_hash_items_stat + + - assert: + msg: "at least one config-hash item does not exist" + that: false not in (config_hash_items_stat.results | map(attribute='stat.exists')) + + - name: generate config-hash file + copy: + content: | + {% for result in config_hash_items_stat.results %} + {{ result.config_hash_item.path }}: + {% for property in (result.config_hash_item.properties | sort) %} + {{ property }}: {{ result.stat[property] }} + {% endfor %} + {% endfor %} + dest: "/etc/kubernetes/config-hashes/{{ kubernetes_standalone_pod.name }}.yml" + + - name: compute config-hash value from file + stat: + path: "/etc/kubernetes/config-hashes/{{ kubernetes_standalone_pod.name }}.yml" + get_checksum: yes + checksum_algorithm: sha256 + register: config_hash_file_stat + + - name: set config-hash value + set_fact: + config_hash_value: "{{ config_hash_file_stat.stat.checksum }}" + +- name: remove config-hash file + when: "'config_hash_items' not in kubernetes_standalone_pod" + file: + path: "/etc/kubernetes/config-hashes/{{ kubernetes_standalone_pod.name }}.yml" + state: absent + +- name: generate pod manifest + copy: + content: | + apiVersion: v1 + kind: Pod + metadata: + name: "{{ kubernetes_standalone_pod.name }}" + {% if 'labels' in kubernetes_standalone_pod %} + labels: + {{ kubernetes_standalone_pod.labels | to_nice_yaml(indent=2) | indent(4) }}{% endif %} + {% if config_hash_value is defined or'annotations' in kubernetes_standalone_pod %} + annotations: + {% if config_hash_value is defined %} + config-hash: "{{ config_hash_value }}" + {% endif %} + {% if 'annotations' in kubernetes_standalone_pod %} + {{ kubernetes_standalone_pod.annotations | default({}) | to_nice_yaml(indent=2) | indent(4) }}{% endif %} + {% endif %} + spec: + {{ kubernetes_standalone_pod.spec | indent(2) }} + dest: "/etc/kubernetes/manifests/{{ kubernetes_standalone_pod.name }}.yml" + mode: "{{ kubernetes_standalone_pod.mode | default(omit) }}" |