Skip to content

Commit

Permalink
Merge pull request #1273 from tu1h/add_extra_dependencies_sprayjob
Browse files Browse the repository at this point in the history
Add playbook to set containerd registry mirrors
  • Loading branch information
ErikJiang authored Jun 14, 2024
2 parents a1d0c3b + 6ed126b commit f869698
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
4 changes: 4 additions & 0 deletions build/images/spray-job/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ FROM ghcr.io/${REPO}/kubespray:${SPRAY_TAG}
WORKDIR /kubespray

COPY playbooks/ /kubespray/

# Add extra python packages and collections needed for the playbooks
RUN python3 -m pip install toml
RUN ansible-galaxy collection install sivel.toiletwater
58 changes: 58 additions & 0 deletions playbooks/set-containerd-registry-mirror.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Copyright 2023 Authors of kubean-io
# SPDX-License-Identifier: Apache-2.0

---
- name: Set containerd registry mirrors
hosts: all
any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
vars:
containerd_config_path: /etc/containerd/config.toml
#containerd_mirror:
# override: false
# mirror: docker.io
# endpoints:
# - 192.168.1.1
tasks:
- name: containerd_mirror must not be empty
assert:
that: containerd_mirror is defined and containerd_mirror

- name: fetch containerd config toml
ansible.builtin.slurp:
src: "{{ containerd_config_path }}"
register: containerd_config_file

- name: parse containerd config toml
set_fact:
containerd_config: "{{ containerd_config_file['content'] | b64decode | sivel.toiletwater.from_toml }}"

- name: detect if mirror is already defined
set_fact:
mirror_exists: "{{ (containerd_mirror.mirror in (containerd_config.plugins['io.containerd.grpc.v1.cri'].registry.mirrors | default([]))) }}"

- name: update containerd_config
set_fact:
containerd_config: >-
{{
containerd_config | combine({
"plugins": {
"io.containerd.grpc.v1.cri": {
"registry": {
"mirrors": (containerd_config.plugins['io.containerd.grpc.v1.cri'].registry.mirrors | default({})) | combine({
containerd_mirror.mirror: {
"endpoint": containerd_mirror.endpoints + (containerd_config.plugins['io.containerd.grpc.v1.cri'].registry.mirrors[containerd_mirror.mirror].endpoint if (mirror_exists | default(false)) and not (containerd_mirror.override | default(false)) else [])
}
})
},
},
}
}, recursive=True)
}}
- name: writeback containerd config toml
copy:
dest: "{{ containerd_config_path }}"
mode: 0644
content: "{{ containerd_config | sivel.toiletwater.to_toml }}"
backup: true
become: true

0 comments on commit f869698

Please sign in to comment.