Restructure for validation checks

This commit is contained in:
Xan Manning 2020-10-17 18:26:30 +01:00
parent c63d984301
commit 45a41f895b
15 changed files with 78 additions and 37 deletions

View file

@ -13,6 +13,7 @@ env:
- MOLECULE_SCENARIO: default
matrix:
- MOLECULE_DISTRO: geerlingguy/docker-debian10-ansible:latest
- MOLECULE_DISTRO: geerlingguy/docker-ubuntu2004-ansible:latest
# Test installing docker
- MOLECULE_DISTRO: geerlingguy/docker-centos7-ansible:latest

View file

@ -47,7 +47,7 @@ consistency.
| Variable | Description | Default Value |
|------------------------------------------|-------------------------------------------------------------------------------------|--------------------------------------------|
| `k3s_cluster_state` | State of cluster: installed, started, stopped, restarted, downloaded, uninstalled. | installed |
| `k3s_state` | State of k3s: installed, started, stopped, restarted, downloaded, uninstalled, validated. | installed |
| `k3s_release_version` | Use a specific version of k3s, eg. `v0.2.0`. Specify `false` for stable. | `false` |
| `k3s_build_cluster` | When multiple `play_hosts` are available, attempt to cluster. Read notes below. | `true` |
| `k3s_github_url` | Set the GitHub URL to install k3s from. | https://github.com/rancher/k3s |

View file

@ -1,8 +1,8 @@
---
# k3s cluster state, options: installed, started, stopped, restarted
# k3s state, options: installed, started, stopped, restarted, validated
# (default: installed)
k3s_cluster_state: installed
k3s_state: installed
# Use a specific k3s version, if set to "false" we will get the latest
# k3s_release_version: v0.1.0

View file

@ -6,6 +6,6 @@
molecule_is_test: true
k3s_build_cluster: false
k3s_server_manifests_templates:
- "molecule/highavailability/templates/00-ns-monitoring.yml.j2"
- "molecule/autodeploy/templates/00-ns-monitoring.yml.j2"
roles:
- role: xanmanning.k3s

View file

@ -6,7 +6,6 @@
molecule_is_test: true
k3s_use_docker: true
k3s_https_port: 26443
k3s_flannel_backend: wireguard
k3s_cluster_domain: examplecluster.local
roles:
- role: xanmanning.k3s

View file

@ -10,7 +10,7 @@ lint: |
ansible-lint
platforms:
- name: node1
image: "${MOLECULE_DISTRO:-geerlingguy/docker-centos8-ansible:latest}"
image: "${MOLECULE_DISTRO:-geerlingguy/docker-ubuntu2004-ansible:latest}"
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
@ -19,7 +19,7 @@ platforms:
networks:
- name: k3snet
- name: node2
image: "${MOLECULE_DISTRO:-geerlingguy/docker-centos8-ansible:latest}"
image: "${MOLECULE_DISTRO:-geerlingguy/docker-ubuntu2004-ansible:latest}"
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
@ -28,7 +28,7 @@ platforms:
networks:
- name: k3snet
- name: node3
image: "${MOLECULE_DISTRO:-geerlingguy/docker-centos8-ansible:latest}"
image: "${MOLECULE_DISTRO:-geerlingguy/docker-ubuntu2004-ansible:latest}"
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro

View file

@ -1,4 +0,0 @@
apiVersion: v1
kind: Namespace
metadata:
name: monitoring

View file

@ -59,25 +59,10 @@
when: k3s_control_node and not k3s_primary_control_node
become: "{{ k3s_become_for_systemd | ternary(true, false, k3s_become_for_all) }}"
- name: Wait for control plane to be ready to accept connections
wait_for:
port: "{{ k3s_https_port }}"
host: "{{ k3s_bind_address | default('127.0.0.1') }}"
delay: 5
sleep: 5
timeout: 300
when: k3s_control_node
- import_tasks: ../validate/check-control-plane.yml
when: not k3s_skip_validation
- meta: flush_handlers
- name: Wait for all nodes to be ready
command: "{{ k3s_install_dir }}/kubectl get nodes"
changed_when: false
failed_when: false
register: kubectl_get_nodes_result
until: kubectl_get_nodes_result.rc == 0
and kubectl_get_nodes_result.stdout.find("NotReady") == -1
retries: 30
delay: 20
when: k3s_control_node and not k3s_no_flannel and not ansible_check_mode
become: "{{ k3s_become_for_kubectl | ternary(true, false, k3s_become_for_all) }}"
- import_tasks: ../validate/check-cluster-nodes-ready.yml
when: not k3s_skip_validation

View file

@ -1,11 +1,11 @@
---
- name: Check to see if k3s_cluster_state is a supported value
- name: Check to see if k3s_state is a supported value
assert:
that:
- k3s_cluster_state in ['installed', 'started', 'stopped', 'restarted', 'downloaded', 'uninstalled']
fail_msg: "k3s_cluster_state not valid. Check README.md for details."
success_msg: "k3s_cluster_state is valid."
when: k3s_cluster_state is defined
- k3s_state in k3s_valid_states
fail_msg: "k3s_state not valid. Check README.md for details."
success_msg: "k3s_state is valid."
when: k3s_state is defined
- include_tasks: state-{{ (k3s_cluster_state | lower) | default('installed') }}.yml
- include_tasks: state-{{ (k3s_state | lower) | default('installed') }}.yml

View file

@ -0,0 +1,7 @@
---
- import_tasks: validate/check-environment.yml
- import_tasks: validate/main.yml
- import_tasks: validate/post-install.yml

View file

@ -0,0 +1,14 @@
---
- name: Check that all nodes to be ready
command: "{{ k3s_install_dir }}/kubectl get nodes"
changed_when: false
failed_when: kubectl_get_nodes_result.stdout.find("was refused") != -1 or
kubectl_get_nodes_result.stdout.find("ServiceUnavailable") != -1
register: kubectl_get_nodes_result
until: kubectl_get_nodes_result.rc == 0
and kubectl_get_nodes_result.stdout.find("NotReady") == -1
retries: 30
delay: 20
when: k3s_control_node and not k3s_no_flannel and not ansible_check_mode
become: "{{ k3s_become_for_kubectl | ternary(true, false, k3s_become_for_all) }}"

View file

@ -0,0 +1,10 @@
---
- name: Check that the control plane to is available to accept connections
wait_for:
port: "{{ k3s_https_port }}"
host: "{{ k3s_bind_address | default('127.0.0.1') }}"
delay: 5
sleep: 5
timeout: 300
when: k3s_control_node

View file

@ -0,0 +1,4 @@
---
- import_tasks: check-control-plane.yml
- import_tasks: check-clustr-nodes-ready.yml

View file

@ -1,5 +1,16 @@
---
# Valid states for this role
k3s_valid_states:
- installed
- started
- stopped
- restarted
- downloaded
- uninstalled
- validated
# Map ansible fact gathering architecture to a release name and suffix in github.
k3s_arch_lookup:
amd64:
arch: amd64
@ -26,13 +37,27 @@ k3s_arch_lookup:
arch: arm
suffix: "-armhf"
# Always default to stable channel, this will change with k3s_release_version
k3s_release_channel: stable
# Create the API address for the k3s_github_url that has been specified
k3s_github_api: "{{ k3s_github_url | replace('github.com', 'api.github.com') }}"
# Create the latest release API link for github. Possibly deprecated with k3s.io updates API
k3s_github_api_releases: "{{ k3s_github_api | replace('.com', '.com/repos') }}/releases/latest"
# K3s updates API
k3s_api_releases: https://update.k3s.io/v1-release/channels
# Download location for releases
k3s_github_download_url: "{{ k3s_github_url }}/releases/download"
# Empty array for counting the number of control plane nodes
k3s_controller_count: []
# Default to the "system" systemd context, this will be "user" when running rootless
k3s_systemd_context: system
# Directory for systemd unit files to be installed. As this role doesn't use package
# management, this should live in /etc/systemd, not /lib/systemd
k3s_systemd_unit_directory: "/etc/systemd/{{ k3s_systemd_context }}"
# Directory for gathering the k3s token for clustering. I don't see this changing.
k3s_token_location: "/etc/rancher"