Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installation framework for python packages #11158

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions roles/kubernetes/preinstall/tasks/0040-verify-settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,14 @@
- name: Verify that the packages list structure is valid
ansible.utils.validate:
criteria: "{{ lookup('file', 'pkgs-schema.json') }}"
data: "{{ pkgs }}"
data: "{{ os_pkgs }}"

- name: Verify that the packages list is sorted
- name: Verify that package lists are sorted
vars:
pkgs_lists: "{{ pkgs.keys() | list }}"
pkgs_lists: "{{ lookup('vars', item + '_pkgs').keys() | list }}"
assert:
that: "pkgs_lists | sort == pkgs_lists"
fail_msg: "pkgs is not sorted: {{ pkgs_lists | ansible.utils.fact_diff(pkgs_lists | sort) }}"
loop:
- os
- python
41 changes: 30 additions & 11 deletions roles/kubernetes/preinstall/tasks/0070-system-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,13 @@
tags:
- bootstrap-os

- name: Install packages requirements
- name: Install requirements
tags:
- bootstrap-os
vars:
# The json_query for selecting packages name is split for readability
# see files/pkgs-schema.json for the structure of `pkgs`
# and the matching semantics
full_query: "[? value | (enabled == null || enabled) && ( {{ filters_os }} ) && ( {{ filters_groups }} ) ].key"
filters_groups: "groups | @ == null || [? contains(`{{ group_names }}`, @)]"
filters_os: "os == null || (os | ( {{ filters_family }} ) || ( {{ filters_distro }} ))"
dquote: !unsafe '"'
Expand All @@ -75,12 +76,30 @@
contains(not_null(versions, `[]`), '{{ ansible_distribution_version }}') ||
contains(not_null(releases, `[]`), '{{ ansible_distribution_release }}')"
filters_family: "families && contains(families, '{{ ansible_os_family }}')"
package:
name: "{{ pkgs | dict2items | to_json|from_json | community.general.json_query(full_query) }}"
state: present
register: pkgs_task_result
until: pkgs_task_result is succeeded
retries: "{{ pkg_install_retries }}"
delay: "{{ retry_stagger | random + 3 }}"
tags:
- bootstrap-os
to_install: "{{ pkgs | dict2items | to_json|from_json | community.general.json_query(full_query) }}"
block:
- name: Install system packages
vars:
full_query: "[? value | (enabled == null || enabled) && ( {{ filters_os }} ) && ( {{ filters_groups }} ) ].key"
pkgs: "{{ os_pkgs }}"
package:
name: "{{ to_install }}"
state: present
register: pkgs_task_result
until: pkgs_task_result is succeeded
retries: "{{ pkg_install_retries }}"
delay: "{{ retry_stagger | random + 3 }}"
- name: Install virtualenv with needed packages
vars:
full_query: "[? value | ( {{ filters_groups }} ) ].key"
pkgs: "{{ python_pkgs }}"
ansible.builtin.pip:
name: "{{ to_install }}"
extra_args: "--only-binary :all:"
# FIXME: add --no-deps and --requires-hashes, use a fully resolved stack with hashes
# (see https://pip.pypa.io/en/stable/topics/secure-installs/)
virtualenv_site_packages: true
virtualenv: "{{ kubespray_virtualenv }}"
virtualenv_command: "{{ ansible_facts.python.executable }} -m venv"
when:
- to_install | length != 0
4 changes: 3 additions & 1 deletion roles/kubernetes/preinstall/vars/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
pkgs:
os_pkgs:
apparmor: &debian_family_base
os:
families:
Expand Down Expand Up @@ -104,3 +104,5 @@ pkgs:
tar: {}
unzip: {}
xfsprogs: {}

python_pkgs: {}
2 changes: 2 additions & 0 deletions roles/kubespray-defaults/defaults/main/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ ansible_ssh_common_args: "{% if 'bastion' in groups['all'] %} -o ProxyCommand='s
# selinux state
preinstall_selinux_state: permissive

kubespray_virtualenv: "/opt/virtualenvs/kubespray"

# Setting this value to false will fail
# For details, read this comment https://github.com/kubernetes-sigs/kubespray/pull/11016#issuecomment-2004985001
kube_api_anonymous_auth: true
Expand Down