Przeglądaj źródła

Add additional parse_igintion options and support

Michael Gugino 6 lat temu
rodzic
commit
39a350fbdc

+ 29 - 0
playbooks/bootkube_node.yml

@@ -0,0 +1,29 @@
+---
+# l_scale_up_hosts may be passed in via various scaleup plays.
+
+- import_playbook: init/main.yml
+  vars:
+    l_install_base_packages: True
+    l_repo_hosts: "all:!all"
+
+# This is required for container runtime for crio, only needs to run once.
+- name: Configure os_firewall
+  hosts: "{{ l_scale_up_hosts | default(l_default_firewall_hosts) }}"
+  vars:
+    l_default_firewall_hosts: "oo_masters_to_config:oo_etcd_to_config:oo_lb_to_config:oo_nfs_to_config:oo_nodes_to_config"
+  roles:
+  - role: os_firewall
+
+- import_playbook: container-runtime/private/setup_storage.yml
+
+- import_playbook: container-runtime/private/config.yml
+
+- name: install nodes
+  hosts: bootkube_nodes
+  tasks:
+  - import_role:
+      name: openshift_node40
+      tasks_from: install.yml
+  - import_role:
+      name: openshift_node40
+      tasks_from: bootkube_config.yml

+ 1 - 0
roles/container_runtime/tasks/package_crio.yml

@@ -37,6 +37,7 @@
       - cri-tools
       - atomic
       - skopeo
+      - podman
 
 - name: Remove CRI-O default configuration files
   file:

+ 10 - 3
roles/lib_utils/action_plugins/parse_ignition.py

@@ -1,5 +1,6 @@
 """Ansible action plugin to decode ignition payloads"""
 
+import base64
 import os
 
 from ansible.plugins.action import ActionBase
@@ -13,8 +14,14 @@ def get_files(files_dict, systemd_dict, dir_list, data):
         path = item["path"]
         dir_list.add(os.path.dirname(path))
         # remove prefix "data:,"
-        contents = urllib.parse.unquote(item['contents']['source'][6:])
-        mode = str(item["mode"])
+        encoding, contents = item['contents']['source'].split(',', 1)
+        if 'base64' in encoding:
+            contents = base64.b64decode(contents).decode('utf-8')
+        else:
+            contents = urllib.parse.unquote(contents)
+        # convert from int to octal, padding at least to 4 places.
+        # eg, 420 becomes '0644'
+        mode = str(format(int(item["mode"]), '04o'))
         inode = {"contents": contents, "mode": mode}
         files_dict[path] = inode
     # get the systemd units files we're here
@@ -26,7 +33,7 @@ def get_files(files_dict, systemd_dict, dir_list, data):
         path = '/etc/systemd/system/' + name
         dir_list.add(os.path.dirname(path))
         files_dict[path] = inode
-        enabled = item['enabled']
+        enabled = item.get('enabled') or True
         systemd_dict[name] = enabled
 
 

Plik diff jest za duży
+ 1072 - 0
roles/lib_utils/test/test_data/bootstrap.ign.json


Plik diff jest za duży
+ 1 - 0
roles/lib_utils/test/test_data/bs.ign.json


Plik diff jest za duży
+ 700 - 0
roles/lib_utils/test/test_data/bs2.ign.json


+ 32 - 0
roles/lib_utils/test/test_parse_ignition.py

@@ -18,6 +18,12 @@ def read_ign(path):
     return data
 
 
+def write_out_files(files_dict):
+    for path in files_dict:
+        with open('/tmp/bsoutput/' + path.replace('/', '__'), 'w') as fpath:
+            fpath.write(files_dict[path]['contents'])
+
+
 def test_parse_json():
     ign_data = read_ign('test_data/example.ign.json')
     files_dict = {}
@@ -29,5 +35,31 @@ def test_parse_json():
     parse_ignition.get_files(files_dict, systemd_dict, dir_list, ign_data)
 
 
+def test_parse_json_encoded_files():
+    ign_data = read_ign('test_data/bootstrap.ign.json')
+    files_dict = {}
+    systemd_dict = {}
+    dir_list = set()
+    result = {}
+    result['files_dict'] = files_dict
+    result['systemd_dict'] = systemd_dict
+    parse_ignition.get_files(files_dict, systemd_dict, dir_list, ign_data)
+    #print(files_dict['/opt/tectonic/manifests/cluster-config.yaml']['contents'])
+
+
+def parse_json2():
+    ign_data = read_ign('test_data/bs.ign.json')
+    files_dict = {}
+    systemd_dict = {}
+    dir_list = set()
+    result = {}
+    result['files_dict'] = files_dict
+    result['systemd_dict'] = systemd_dict
+    parse_ignition.get_files(files_dict, systemd_dict, dir_list, ign_data)
+    write_out_files(files_dict)
+
+
 if __name__ == '__main__':
     test_parse_json()
+    test_parse_json_encoded_files()
+    parse_json2()

+ 32 - 0
roles/openshift_node40/tasks/bootkube_config.yml

@@ -0,0 +1,32 @@
+---
+- name: parse ignition file
+  parse_ignition:
+    ign_file_contents: "{{ openshift_bootkube_ign_contents }}"
+  register: l_parse_ignition_boot_kube_res
+
+- import_tasks: create_files_from_ignition.yml
+  vars:
+    l_parse_ignition_dict: "{{ l_parse_ignition_boot_kube_res }}"
+
+#### Disable SWAP #####
+# https://docs.openshift.com/container-platform/3.4/admin_guide/overcommit.html#disabling-swap-memory
+# swapoff is a custom module in lib_utils that comments out swap entries in
+# /etc/fstab and runs swapoff -a, if necessary.
+- name: Disable swap
+  swapoff: {}
+  when: openshift_disable_swap | default(true) | bool
+
+# The atomic-openshift-node service will set this parameter on
+# startup, but if the network service is restarted this setting is
+# lost. Reference: https://bugzilla.redhat.com/show_bug.cgi?id=1372388
+- sysctl:
+    name: net.ipv4.ip_forward
+    value: 1
+    sysctl_file: "/etc/sysctl.d/99-openshift.conf"
+    reload: yes
+
+- name: Setting sebool container_manage_cgroup
+  seboolean:
+    name: container_manage_cgroup
+    state: yes
+    persistent: yes

+ 2 - 12
roles/openshift_node40/tasks/config.yml

@@ -13,19 +13,9 @@
     ign_file_contents: "{{ l_worker_bootstrap.stdout }}"
   register: l_parse_ignition_res
 
-- name: Create all the directories we will need
-  command: "mkdir -p {{ item }}"
-  with_items: "{{ l_parse_ignition_res.dir_list }}"
-
-- name: create files from ignition contents
-  copy:
-    content: "{{ item.value.contents }}"
-    dest: "{{ item.key }}"
-    mode: "{{ l_file_mode }}"
-  with_dict: "{{ l_parse_ignition_res.files_dict }}"
+- import_tasks: create_files_from_ignition.yml
   vars:
-    l_mode_prepend: "{{ '0' if (item.value.mode | length < 4) else '' }}"
-    l_file_mode: "{{ l_mode_prepend ~ item.value.mode }}"
+    l_parse_ignition_dict: "{{ l_parse_ignition_res }}"
 
 #### Disable SWAP #####
 # https://docs.openshift.com/container-platform/3.4/admin_guide/overcommit.html#disabling-swap-memory

+ 14 - 0
roles/openshift_node40/tasks/create_files_from_ignition.yml

@@ -0,0 +1,14 @@
+---
+- name: Create all the directories we will need
+  command: "mkdir -p {{ item }}"
+  with_items: "{{ l_parse_ignition_dict.dir_list }}"
+
+- name: create files from ignition contents
+  copy:
+    content: "{{ item.value.contents }}"
+    dest: "{{ item.key }}"
+    mode: "{{ l_file_mode }}"
+  with_dict: "{{ l_parse_ignition_dict.files_dict }}"
+  vars:
+    l_mode_prepend: "{{ '0' if (item.value.mode | length < 4) else '' }}"
+    l_file_mode: "{{ l_mode_prepend ~ item.value.mode }}"