From 35b037c7eedc06a724fe80565da9e28dcaa9cf18 Mon Sep 17 00:00:00 2001 From: Xan Manning Date: Fri, 23 Oct 2020 16:31:21 +0100 Subject: [PATCH] Pre-FQCN breakage --- defaults/main.yml | 3 +++ molecule/default/converge.yml | 1 + molecule/highavailabilityetcd/converge.yml | 2 +- tasks/build/preconfigure-k3s.yml | 6 ++++-- tasks/validate/check-experimental-variables.yml | 8 ++++---- tasks/validate/check-master-count.yml | 12 ++++++------ tasks/validate/check-variables.yml | 8 ++++++++ templates/config.yaml.j2 | 5 +++++ templates/k3s.service.j2 | 4 ++++ vars/main.yml | 5 +++++ 10 files changed, 41 insertions(+), 13 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index f83c65e..75be6b3 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -41,6 +41,9 @@ k3s_use_experimental: false # Allow for unsupported configurations in k3s? k3s_use_unsupported_config: false +# Enable etcd embedded datastore (EXPERIMENTAL) +k3s_etcd_datastore: false + ## # Server Configuration diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml index aa6404d..2a437a2 100644 --- a/molecule/default/converge.yml +++ b/molecule/default/converge.yml @@ -5,5 +5,6 @@ vars: molecule_is_test: true k3s_install_hard_links: true + k3s_release_version: latest roles: - role: xanmanning.k3s diff --git a/molecule/highavailabilityetcd/converge.yml b/molecule/highavailabilityetcd/converge.yml index 0b947cc..b23c043 100644 --- a/molecule/highavailabilityetcd/converge.yml +++ b/molecule/highavailabilityetcd/converge.yml @@ -6,8 +6,8 @@ molecule_is_test: true k3s_release_version: latest k3s_use_experimental: true + k3s_etcd_datastore: true k3s_server: - cluster-init: true secrets-encryption: true pre_tasks: - name: Set each node to be a control node diff --git a/tasks/build/preconfigure-k3s.yml b/tasks/build/preconfigure-k3s.yml index 5a640d0..336c9bf 100644 --- a/tasks/build/preconfigure-k3s.yml +++ b/tasks/build/preconfigure-k3s.yml @@ -78,9 +78,11 @@ - name: Ensure k3s_runtime_config is set for control plane set_fact: k3s_runtime_config: "{{ (k3s_server | default('None')) | combine (k3s_agent | default('None')) }}" - when: k3s_control_node is defined and k3s_control_node + when: k3s_server is defined + and (k3s_control_node is defined and k3s_control_node) - name: Ensure k3s_runtime_config is set for agents set_fact: k3s_runtime_config: "{{ k3s_agent | default('None') }}" - when: k3s_control_node is not defined or not k3s_control_node + when: k3s_agent is defined + and (k3s_control_node is not defined or not k3s_control_node) diff --git a/tasks/validate/check-experimental-variables.yml b/tasks/validate/check-experimental-variables.yml index 84f7f46..6b4c1d0 100644 --- a/tasks/validate/check-experimental-variables.yml +++ b/tasks/validate/check-experimental-variables.yml @@ -6,7 +6,7 @@ - k3s_use_experimental is defined and k3s_use_experimental success_msg: "Experimental variables are defined and enabled." fail_msg: "Experimental variables have been configured. If you want to use them ensure you set k3s_use_experimental" - when: ("rootless" in k3s_runtime_config and k3s_runtime_config.rootless) - or ("etcd-datastore" in k3s_runtime_config and k3s_runtime_config.etcd-datastore) - or ("secrets-encryption" in k3s_runtime_config and k3s_runtime_config.secrets-encryption) - or ("selinux" in k3s_runtime_config and k3s_runtime_config.selinux) + when: ("rootless" in k3s_runtime_config and k3s_runtime_config['rootless']) + or (k3s_etcd_datastore is defined and k3s_etcd_datastore) + or ("secrets-encryption" in k3s_runtime_config and k3s_runtime_config['secrets-encryption']) + or ("selinux" in k3s_runtime_config and k3s_runtime_config['selinux']) diff --git a/tasks/validate/check-master-count.yml b/tasks/validate/check-master-count.yml index 2bb0775..59c5614 100644 --- a/tasks/validate/check-master-count.yml +++ b/tasks/validate/check-master-count.yml @@ -4,8 +4,8 @@ assert: that: - (k3s_controller_count | length == 1) - and ("datastore-endpoint" not in k3s_runtime_config or not k3s_runtime_config.datastore-endpoint) - and ("cluster-init" not in k3s_runtime_config or not k3s_runtime_config.cluster-init) + and ("datastore-endpoint" not in k3s_runtime_config or not k3s_runtime_config['datastore-endpoint']) + and (k3s_etcd_datastore is not defined or not k3s_etcd_datastore) success_msg: "Control plane configuration is valid." fail_msg: "Control plane configuration is invalid. Please see notes about k3s_control_node and HA in README.md." when: k3s_controller_count | length == 1 @@ -15,8 +15,8 @@ assert: that: - (k3s_controller_count | length >= 2) - and (("datastore-endpoint" in k3s_runtime_config and k3s_runtime_config.datastore-endpoint) - or ("cluster-init" in k3s_runtime_config and k3s_runtime_config.cluster-init)) + and (("datastore-endpoint" in k3s_runtime_config and k3s_runtime_config['datastore-endpoint']) + or (k3s_etcd_datastore is defined and k3s_etcd_datastore)) success_msg: "Control plane configuration is valid." fail_msg: "Control plane configuration is invalid. Please see notes about k3s_control_node and HA in README.md." when: k3s_controller_count | length >= 2 @@ -28,6 +28,6 @@ and (((k3s_controller_count | length) % 2) == 1) success_msg: "Control plane configuration is valid." fail_msg: "Etcd should have a minimum of 3 defined members and the number of members should be odd. Please see notes about HA in README.md" - when: ("cluster-init" in k3s_runtime_config) - and k3s_runtime_config.cluster-init + when: k3s_etcd_datastore is defined + and k3s_etcd_datastore and not k3s_use_unsupported_config diff --git a/tasks/validate/check-variables.yml b/tasks/validate/check-variables.yml index 0a1eaf9..5237bff 100644 --- a/tasks/validate/check-variables.yml +++ b/tasks/validate/check-variables.yml @@ -7,5 +7,13 @@ success_msg: "{{ k3s_release_version }} is supported by this role." fail_msg: "{{ k3s_release_version }} is not supported by this role, please use xanmanning.k3s v1.x." +- name: Check configuration in k3s_server and k3s_agent + assert: + that: + - (item.setting not in k3s_runtime_config) + success_msg: "{{ item.setting }} not found in server/agent config" + fail_msg: "{{ item.setting }} found in server/agent config. Please set {{ item.correction }} to use this option." + loop: "{{ k3s_config_exclude }}" + # Due to the v2 role now only supporting k3s v1.19+ - this file is intentionlly # blank until new configuration options are added. diff --git a/templates/config.yaml.j2 b/templates/config.yaml.j2 index 24dc17c..3a17499 100644 --- a/templates/config.yaml.j2 +++ b/templates/config.yaml.j2 @@ -1,3 +1,8 @@ --- +{% if k3s_etcd_datastore and (k3s_control_node is defined and k3s_control_node) and (k3s_primary_control_node is defined and k3s_primary_control_node) %} +cluster-init: true +{% endif %} +{% if k3s_runtime_config is defined and k3s_runtime_config | length > 0 %} {{ k3s_runtime_config | to_nice_yaml(indent=2) }} +{% endif %} diff --git a/templates/k3s.service.j2 b/templates/k3s.service.j2 index bc3b435..1ce9119 100644 --- a/templates/k3s.service.j2 +++ b/templates/k3s.service.j2 @@ -16,6 +16,10 @@ ExecStart={{ k3s_install_dir }}/k3s {% endif %} {% if k3s_control_node %} server + {% if (k3s_etcd_datastore is defined and k3s_etcd_datastore) and (k3s_primary_control_node is not defined or not k3s_primary_control_node) %} + --server https://{{ k3s_control_node_address }}:{{ k3s_runtime_config['https-listen-port'] | default(6443) }} + --token-file {{ k3s_token_location }}/cluster-token + {% endif %} {% if k3s_server is defined %} --config {{ k3s_config_file }} {% endif %} diff --git a/vars/main.yml b/vars/main.yml index 6392384..8428ad9 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -65,3 +65,8 @@ k3s_token_location: "/etc/rancher" # Path for additional Kubernetes Manifests # https://rancher.com/docs/k3s/latest/en/advanced/#auto-deploying-manifests k3s_server_manifests_dir: /var/lib/rancher/k3s/server/manifests + +# Items that should not appear in k3s_server or k3s_agent +k3s_config_exclude: + - setting: "cluster-init" + correction: "k3s_etcd_datastore"