zuul-jobs/roles/ensure-kubernetes/tasks/microk8s.yaml
Clark Boylan b16fae463e Bump the default ensure-kubernetes microk8s version to 1.31/stable
Previously we pinned to 1.28/stable due to a bug that prevented
1.29/stable from working. Now we've hit a new issue with 1.28/stable on
bookworm. The fix for that appears to simply be to upgrade to
1.31/stable so we do so here. More details can be found in this GitHub
issue:

  https://github.com/canonical/microk8s/issues/4361

The new version appears to return from the snap installation before the
k8s installation is fully ready to deal with add-on installation. This
occasionally produces errors like:

  subprocess.CalledProcessError:
  Command '('/snap/microk8s/7178/microk8s-kubectl.wrapper', 'get',
            'all,ingress', '--all-namespaces')'
  returned non-zero exit status 1.

Work around that with `microk8s status --wait-ready` to ensure that k8s
is up before adding addons.

While we are at it we also update the collect-kubernetes-logs role to
collect microk8s inspect output as that would've enabled us to debug the
above issue without holding nodes. We also update test jobs to trigger
when the collect-kubernetes-logs and collect-container-logs roles are
updated to ensure we get coverage from those jobs when updating these
roles.

Change-Id: I60022ec6468c2cadd723a71bbc583f20096b27dc
2024-09-17 15:04:05 -07:00

63 lines
1.4 KiB
YAML

- name: Check distro
assert:
that: ansible_distribution_release in ['jammy', 'bookworm', 'noble']
msg: 'This role is only supported on Jammy or Bookworm or Noble'
- name: Install snapd
become: yes
package:
name: snapd
state: present
- name: Install microk8s snap
become: yes
command: 'snap install microk8s --classic --channel={{ ensure_kubernetes_microk8s_channel }}'
- name: Wait for kubernetes to be ready before adding add-ons
become: yes
command: '/snap/bin/microk8s status --wait-ready'
- name: Install add-ons
become: yes
command: '/snap/bin/microk8s enable {{ ensure_kubernetes_microk8s_addons | join(" ") }}'
- name: Install kubectl wrapper
become: yes
copy:
content: |
#!/bin/bash
/snap/bin/microk8s.kubectl "$@"
dest: /usr/local/bin/kubectl
owner: root
group: root
mode: 0755
- name: Allow zuul user kubectl access
become: yes
user:
name: 'zuul'
groups: 'microk8s'
append: yes
- name: Create .kube directory
file:
path: "{{ ansible_user_dir }}/.kube"
state: directory
mode: 0755
- name: Populate kube config
become: yes
shell: /snap/bin/microk8s config > {{ ansible_user_dir }}/.kube/config
- name: Ensure we can read config
become: yes
file:
path: "{{ ansible_user_dir }}/.kube/config"
owner: zuul
group: zuul
state: touch
mode: 0644
- name: Reset connection to pickup group
meta: reset_connection