diff --git a/.ansible-lint-ignore b/.ansible-lint-ignore deleted file mode 100644 index d025a99..0000000 --- a/.ansible-lint-ignore +++ /dev/null @@ -1 +0,0 @@ -galaxy.yml galaxy[version-incorrect] \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5fa197d --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +artifacts/ +build/ +*.tar.gz \ No newline at end of file diff --git a/README.md b/README.md index ecf2c94..0c741fa 100644 --- a/README.md +++ b/README.md @@ -14,26 +14,26 @@
-![Gitlab forks count](https://img.shields.io/badge/dynamic/json?label=Forks&query=%24.forks_count&url=https%3A%2F%2Fgitlab.com%2Fapi%2Fv4%2Fprojects%2F51640029%2F&color=ff782e&logo=gitlab&style=plastic) ![Gitlab stars](https://img.shields.io/badge/dynamic/json?label=Stars&query=%24.star_count&url=https%3A%2F%2Fgitlab.com%2Fapi%2Fv4%2Fprojects%2F51640029%2F&color=ff782e&logo=gitlab&style=plastic) [![Open Issues](https://img.shields.io/badge/dynamic/json?color=ff782e&logo=gitlab&style=plastic&label=Open%20Issues&query=%24.statistics.counts.opened&url=https%3A%2F%2Fgitlab.com%2Fapi%2Fv4%2Fprojects%2F51640029%2Fissues_statistics)](https://gitlab.com/nofusscomputing/projects/ansible/kubernetes/-/issues) +![Gitlab forks count](https://img.shields.io/badge/dynamic/json?label=Forks&query=%24.forks_count&url=https%3A%2F%2Fgitlab.com%2Fapi%2Fv4%2Fprojects%2F51640029%2F&color=ff782e&logo=gitlab&style=plastic) ![Gitlab stars](https://img.shields.io/badge/dynamic/json?label=Stars&query=%24.star_count&url=https%3A%2F%2Fgitlab.com%2Fapi%2Fv4%2Fprojects%2F51640029%2F&color=ff782e&logo=gitlab&style=plastic) [![Open Issues](https://img.shields.io/badge/dynamic/json?color=ff782e&logo=gitlab&style=plastic&label=Open%20Issues&query=%24.statistics.counts.opened&url=https%3A%2F%2Fgitlab.com%2Fapi%2Fv4%2Fprojects%2F51640029%2Fissues_statistics)](https://gitlab.com/nofusscomputing/projects/ansible/collections/kubernetes/-/issues) ![GitHub forks](https://img.shields.io/github/forks/NofussComputing/ansible_collection_kubernetes?logo=github&style=plastic&color=000000&labell=Forks) ![GitHub stars](https://img.shields.io/github/stars/NofussComputing/ansible_collection_kubernetes?color=000000&logo=github&style=plastic) ![Github Watchers](https://img.shields.io/github/watchers/NofussComputing/ansible_collection_kubernetes?color=000000&label=Watchers&logo=github&style=plastic)
-This project is hosted on [gitlab](https://gitlab.com/nofusscomputing/projects/ansible/kubernetes) and has a read-only copy hosted on [Github](https://github.com/NofussComputing/ansible_collection_kubernetes). +This project is hosted on [gitlab](https://gitlab.com/nofusscomputing/projects/ansible/collections/kubernetes) and has a read-only copy hosted on [Github](https://github.com/NofussComputing/ansible_collection_kubernetes). ---- **Stable Branch** -![Gitlab build status - stable](https://img.shields.io/badge/dynamic/json?color=ff782e&label=Build&query=0.status&url=https%3A%2F%2Fgitlab.com%2Fapi%2Fv4%2Fprojects%2F51640029%2Fpipelines%3Fref%3Dmaster&logo=gitlab&style=plastic) ![branch release version](https://img.shields.io/badge/dynamic/yaml?color=ff782e&logo=gitlab&style=plastic&label=Release&query=%24.commitizen.version&url=https%3A//gitlab.com/nofusscomputing/projects/ansible/kubernetes%2F-%2Fraw%2Fmaster%2F.cz.yaml) +![Gitlab build status - stable](https://img.shields.io/badge/dynamic/json?color=ff782e&label=Build&query=0.status&url=https%3A%2F%2Fgitlab.com%2Fapi%2Fv4%2Fprojects%2F51640029%2Fpipelines%3Fref%3Dmaster&logo=gitlab&style=plastic) ![branch release version](https://img.shields.io/badge/dynamic/yaml?color=ff782e&logo=gitlab&style=plastic&label=Release&query=%24.commitizen.version&url=https%3A//gitlab.com/nofusscomputing/projects/ansible/collections/kubernetes%2F-%2Fraw%2Fmaster%2F.cz.yaml) ---- **Development Branch** -![Gitlab build status - development](https://img.shields.io/badge/dynamic/json?color=ff782e&label=Build&query=0.status&url=https%3A%2F%2Fgitlab.com%2Fapi%2Fv4%2Fprojects%2F51640029%2Fpipelines%3Fref%3Ddevelopment&logo=gitlab&style=plastic) ![branch release version](https://img.shields.io/badge/dynamic/yaml?color=ff782e&logo=gitlab&style=plastic&label=Release&query=%24.commitizen.version&url=https%3A//gitlab.com/nofusscomputing/projects/ansible/kubernetes%2F-%2Fraw%2Fdevelopment%2F.cz.yaml) +![Gitlab build status - development](https://img.shields.io/badge/dynamic/json?color=ff782e&label=Build&query=0.status&url=https%3A%2F%2Fgitlab.com%2Fapi%2Fv4%2Fprojects%2F51640029%2Fpipelines%3Fref%3Ddevelopment&logo=gitlab&style=plastic) ![branch release version](https://img.shields.io/badge/dynamic/yaml?color=ff782e&logo=gitlab&style=plastic&label=Release&query=%24.commitizen.version&url=https%3A//gitlab.com/nofusscomputing/projects/ansible/collections/kubernetes%2F-%2Fraw%2Fdevelopment%2F.cz.yaml) ----
@@ -42,14 +42,14 @@ This project is hosted on [gitlab](https://gitlab.com/nofusscomputing/projects/a links: -- [Issues](https://gitlab.com/nofusscomputing/projects/ansible/kubernetes/-/issues) +- [Issues](https://gitlab.com/nofusscomputing/projects/ansible/collections/kubernetes/-/issues) -- [Merge Requests (Pull Requests)](https://gitlab.com/nofusscomputing/projects/ansible/kubernetes/-/merge_requests) +- [Merge Requests (Pull Requests)](https://gitlab.com/nofusscomputing/projects/ansible/collections/kubernetes/-/merge_requests) ## Contributing -All contributions for this project must conducted from [Gitlab](https://gitlab.com/nofusscomputing/projects/ansible/kubernetes). +All contributions for this project must conducted from [Gitlab](https://gitlab.com/nofusscomputing/projects/ansible/collections/kubernetes). For further details on contributing please refer to the [contribution guide](CONTRIBUTING.md). diff --git a/galaxy.yml b/galaxy.yml index b0d7a96..b3ef4d4 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -44,6 +44,7 @@ tags: # L(specifiers,https://python-semanticversion.readthedocs.io/en/latest/#requirement-specification). Multiple version # range specifiers can be set and are separated by ',' dependencies: + ansible.posix: '1.5.4' kubernetes.core: '3.0.0' @@ -64,17 +65,17 @@ issues: https://gitlab.com/nofusscomputing/projects/ansible/collections/kubernet # uses 'fnmatch' to match the files or directories. Some directories and files like 'galaxy.yml', '*.pyc', '*.retry', # and '.git' are always filtered. Mutually exclusive with 'manifest' build_ignore: - - .vscode/ - - artifacts/ - - docs/ - - .gitlab* - - includes/ - - website-template/ + - .vscode + - artifacts + - docs + - .git* + - gitlab-ci + - website-template - .ansible-lint-ignore - .cz.yaml - .nfc_automation.yaml - dockerfile - - mkdocs.yaml + - mkdocs.yml # A dict controlling use of manifest directives used in building the collection artifact. The key 'directives' is a # list of MANIFEST.in style diff --git a/roles/nfc_kubernetes/handlers/main.yml b/roles/nfc_kubernetes/handlers/main.yml index 2d01807..f55e1f5 100644 --- a/roles/nfc_kubernetes/handlers/main.yml +++ b/roles/nfc_kubernetes/handlers/main.yml @@ -1,31 +1,13 @@ --- -- name: "restart ContainerD" - service: - name: containerd - state: restarted - when: > - containerd_config.changed | default(false) | bool - and - containerd_installed.rc | default(1) | int == 0 - and - kubernetes_type == 'k8s' - tags: - - configure - - install - - name: Restart Kubernetes ansible.builtin.service: name: |- - {%- if kubernetes_type == 'k3s' -%} - {%- if Kubernetes_Master | default(false) | bool -%} - k3s - {%- else -%} - k3s-agent - {%- endif -%} + {%- if nfc_role_kubernetes_master | default(false) | bool -%} + k3s {%- else -%} - kubelet - {%- endif %} + k3s-agent + {%- endif -%} state: restarted listen: kubernetes_restart when: |- @@ -33,19 +15,19 @@ nfc_kubernetes_no_restart or ( - inventory_hostname in groups['kubernetes_master'] + nfc_role_kubernetes_master and nfc_kubernetes_no_restart_master ) or ( - inventory_hostname == kubernetes_config.cluster.prime.name + inventory_hostname == kubernetes_config.cluster.prime.name | default(inventory_hostname) and nfc_kubernetes_no_restart_prime ) or ( - inventory_hostname in groups['kubernetes_worker'] + nfc_role_kubernetes_worker and nfc_kubernetes_no_restart_slave ) diff --git a/roles/nfc_kubernetes/tasks/k3s/configure.yaml b/roles/nfc_kubernetes/tasks/k3s/configure.yaml index 2f36758..57219f4 100644 --- a/roles/nfc_kubernetes/tasks/k3s/configure.yaml +++ b/roles/nfc_kubernetes/tasks/k3s/configure.yaml @@ -39,7 +39,16 @@ - src: iptables-kubernetes.rules.j2 dest: "/etc/iptables.rules.d/iptables-kubernetes.rules" notify: firewall_reloader - when: "{{ firewall_rules_dir_metadata.stat.exists }}" + when: |- + {%- if nfc_kubernetes.enable_firewall -%} + + {{ firewall_rules_dir_metadata.stat.exists }} + + {%- else -%} + + false + + {%- endif %} - name: Add Kubernetes Node Labels diff --git a/roles/nfc_kubernetes/tasks/k3s/install.yaml b/roles/nfc_kubernetes/tasks/k3s/install.yaml index 0112ec9..88a74ae 100644 --- a/roles/nfc_kubernetes/tasks/k3s/install.yaml +++ b/roles/nfc_kubernetes/tasks/k3s/install.yaml @@ -21,10 +21,10 @@ loop_var: package vars: packages: - - name: curl - - name: iptables - - name: jq - - name: wireguard + - curl + - iptables + - jq + - wireguard - name: Remove swapfile from /etc/fstab diff --git a/roles/nfc_kubernetes/templates/iptables-kubernetes.rules.j2 b/roles/nfc_kubernetes/templates/iptables-kubernetes.rules.j2 index be4103b..780d232 100644 --- a/roles/nfc_kubernetes/templates/iptables-kubernetes.rules.j2 +++ b/roles/nfc_kubernetes/templates/iptables-kubernetes.rules.j2 @@ -61,7 +61,7 @@ {%- if kubernetes_host != '' -%} - {%- for master_host in groups['kubernetes_master'] -%} + {%- for master_host in groups['kubernetes_master'] | default([]) -%} {%- if master_host in groups[kubernetes_config.cluster.group_name | default('me_is_optional')] | default([]) -%} diff --git a/roles/nfc_kubernetes/templates/k3s-config.yaml.j2 b/roles/nfc_kubernetes/templates/k3s-config.yaml.j2 index 4089176..59e8b1c 100644 --- a/roles/nfc_kubernetes/templates/k3s-config.yaml.j2 +++ b/roles/nfc_kubernetes/templates/k3s-config.yaml.j2 @@ -7,7 +7,7 @@ # {%- if - inventory_hostname in groups['kubernetes_master'] + nfc_role_kubernetes_master or kubernetes_config.cluster.prime.name | default(inventory_hostname) == inventory_hostname -%} @@ -128,6 +128,16 @@ {# SoF All Nodes #} +{%- if inventory_hostname == 'localhost' -%} + + {%- set node_name = hostname_to_check.stdout -%} + +{%- else -%} + + {%- set node_name = inventory_hostnamet -%} + +{%- endif -%} + {% set all_nodes_config = { @@ -135,7 +145,7 @@ "system-reserved=cpu=" + kubelet_arg_system_reserved_cpu + ",memory=" + kubelet_arg_system_reserved_memory + ",ephemeral-storage=" + kubelet_arg_system_reserved_storage ], - "node-name": inventory_hostname, + "node-name": node_name, } -%} @@ -149,7 +159,7 @@ {%- for cluster_node in groups[kubernetes_config.cluster.group_name] -%} - {%- if cluster_node in groups['kubernetes_master'] -%} + {%- if cluster_node in groups['kubernetes_master'] | default([]) -%} {%- if hostvars[cluster_node].host_external_ip is defined -%} @@ -228,7 +238,7 @@ {%- if - inventory_hostname in groups['kubernetes_master'] + nfc_role_kubernetes_master or kubernetes_config.cluster.prime.name | default(inventory_hostname) == inventory_hostname -%}