Decouple kubespray-defaults from download (#10626)

* Decouple role kubespray-defaults from download

Avoids doing re-importing the download role on every invocation of
kubespray-defaults (and skipping everything).

This has a measurable effect on playbook performance.

* Update docs refering to moved download defaults
pull/10575/head
Max Gautier 2023-12-11 16:56:17 +01:00 committed by GitHub
parent 17b51240c9
commit 51069223f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 16 additions and 22 deletions

View File

@ -5,4 +5,4 @@ roles/kubernetes/control-plane/defaults/main/main.yml jinja[spacing]
roles/kubernetes/kubeadm/defaults/main.yml jinja[spacing] roles/kubernetes/kubeadm/defaults/main.yml jinja[spacing]
roles/kubernetes/node/defaults/main.yml jinja[spacing] roles/kubernetes/node/defaults/main.yml jinja[spacing]
roles/kubernetes/preinstall/defaults/main.yml jinja[spacing] roles/kubernetes/preinstall/defaults/main.yml jinja[spacing]
roles/kubespray-defaults/defaults/main.yaml jinja[spacing] roles/kubespray-defaults/defaults/main/main.yml jinja[spacing]

View File

@ -37,7 +37,7 @@ RUN apt update -q \
MarkupSafe==2.1.3 \ MarkupSafe==2.1.3 \
ruamel.yaml==0.17.21 \ ruamel.yaml==0.17.21 \
passlib==1.7.4 \ passlib==1.7.4 \
&& KUBE_VERSION=$(sed -n 's/^kube_version: //p' roles/kubespray-defaults/defaults/main.yaml) \ && KUBE_VERSION=$(sed -n 's/^kube_version: //p' roles/kubespray-defaults/defaults/main/main.yml) \
&& curl -L https://dl.k8s.io/release/$KUBE_VERSION/bin/linux/$(dpkg --print-architecture)/kubectl -o /usr/local/bin/kubectl \ && curl -L https://dl.k8s.io/release/$KUBE_VERSION/bin/linux/$(dpkg --print-architecture)/kubectl -o /usr/local/bin/kubectl \
&& echo $(curl -L https://dl.k8s.io/release/$KUBE_VERSION/bin/linux/$(dpkg --print-architecture)/kubectl.sha256) /usr/local/bin/kubectl | sha256sum --check \ && echo $(curl -L https://dl.k8s.io/release/$KUBE_VERSION/bin/linux/$(dpkg --print-architecture)/kubectl.sha256) /usr/local/bin/kubectl | sha256sum --check \
&& chmod a+x /usr/local/bin/kubectl \ && chmod a+x /usr/local/bin/kubectl \

View File

@ -27,7 +27,7 @@ manage-offline-container-images.sh register
## generate_list.sh ## generate_list.sh
This script generates the list of downloaded files and the list of container images by `roles/download/defaults/main/main.yml` file. This script generates the list of downloaded files and the list of container images by `roles/kubespray-defaults/main/download.yml` file.
Run this script will execute `generate_list.yml` playbook in kubespray root directory and generate four files, Run this script will execute `generate_list.yml` playbook in kubespray root directory and generate four files,
all downloaded files url in files.list, all container images in images.list, jinja2 templates in *.template. all downloaded files url in files.list, all container images in images.list, jinja2 templates in *.template.

View File

@ -5,7 +5,7 @@ CURRENT_DIR=$(cd $(dirname $0); pwd)
TEMP_DIR="${CURRENT_DIR}/temp" TEMP_DIR="${CURRENT_DIR}/temp"
REPO_ROOT_DIR="${CURRENT_DIR%/contrib/offline}" REPO_ROOT_DIR="${CURRENT_DIR%/contrib/offline}"
: ${DOWNLOAD_YML:="roles/download/defaults/main/main.yml"} : ${DOWNLOAD_YML:="roles/kubespray-defaults/main/download.yml"}
mkdir -p ${TEMP_DIR} mkdir -p ${TEMP_DIR}
@ -19,7 +19,7 @@ sed -n '/^downloads:/,/download_defaults:/p' ${REPO_ROOT_DIR}/${DOWNLOAD_YML} \
| sed 'N;s#\n# #g' | tr ' ' ':' | sed 's/\"//g' > ${TEMP_DIR}/images.list.template | sed 'N;s#\n# #g' | tr ' ' ':' | sed 's/\"//g' > ${TEMP_DIR}/images.list.template
# add kube-* images to images list template # add kube-* images to images list template
# Those container images are downloaded by kubeadm, then roles/download/defaults/main/main.yml # Those container images are downloaded by kubeadm, then roles/kubespray-defaults/main/download.yml
# doesn't contain those images. That is reason why here needs to put those images into the # doesn't contain those images. That is reason why here needs to put those images into the
# list separately. # list separately.
KUBE_IMAGES="kube-apiserver kube-controller-manager kube-scheduler kube-proxy" KUBE_IMAGES="kube-apiserver kube-controller-manager kube-scheduler kube-proxy"

View File

@ -95,7 +95,7 @@ If you use the settings like the one above, you'll need to define in your invent
* `registry_host`: Container image registry. If you _don't_ use the same repository path for the container images that * `registry_host`: Container image registry. If you _don't_ use the same repository path for the container images that
the ones defined the ones defined
in [Download's role defaults](https://github.com/kubernetes-sigs/kubespray/blob/master/roles/download/defaults/main/main.yml) in [kubesprays-defaults's role defaults](https://github.com/kubernetes-sigs/kubespray/blob/master/roles/kubespray-defaults/main/download.yml)
, you need to override the `*_image_repo` for these container images. If you want to make your life easier, use the , you need to override the `*_image_repo` for these container images. If you want to make your life easier, use the
same repository path, you won't have to override anything else. same repository path, you won't have to override anything else.
* `registry_addr`: Container image registry, but only have [domain or ip]:[port]. * `registry_addr`: Container image registry, but only have [domain or ip]:[port].

View File

@ -12,7 +12,7 @@
hosts: kube_control_plane[0] hosts: kube_control_plane[0]
tasks: tasks:
- name: Include kubespray-default variables - name: Include kubespray-default variables
include_vars: ../roles/kubespray-defaults/defaults/main.yaml include_vars: ../roles/kubespray-defaults/defaults/main/main.yml
- name: Copy get_cinder_pvs.sh to master - name: Copy get_cinder_pvs.sh to master
copy: copy:
src: get_cinder_pvs.sh src: get_cinder_pvs.sh

View File

@ -57,7 +57,7 @@ loadbalancer_apiserver_healthcheck_port: 8081
# https_proxy: "" # https_proxy: ""
# https_proxy_cert_file: "" # https_proxy_cert_file: ""
## Refer to roles/kubespray-defaults/defaults/main.yml before modifying no_proxy ## Refer to roles/kubespray-defaults/defaults/main/main.yml before modifying no_proxy
# no_proxy: "" # no_proxy: ""
## Some problems may occur when downloading files over https proxy due to ansible bug ## Some problems may occur when downloading files over https proxy due to ansible bug

View File

@ -40,11 +40,11 @@ WORKDIR /kubespray
RUN --mount=type=bind,target=./requirements.txt,src=./requirements.txt \ RUN --mount=type=bind,target=./requirements.txt,src=./requirements.txt \
--mount=type=bind,target=./tests/requirements.txt,src=./tests/requirements.txt \ --mount=type=bind,target=./tests/requirements.txt,src=./tests/requirements.txt \
--mount=type=bind,target=./roles/kubespray-defaults/defaults/main.yaml,src=./roles/kubespray-defaults/defaults/main.yaml \ --mount=type=bind,target=./roles/kubespray-defaults/defaults/main/main.yml,src=./roles/kubespray-defaults/defaults/main/main.yml \
update-alternatives --install /usr/bin/python python /usr/bin/python3 1 \ update-alternatives --install /usr/bin/python python /usr/bin/python3 1 \
&& pip install --no-compile --no-cache-dir pip -U \ && pip install --no-compile --no-cache-dir pip -U \
&& pip install --no-compile --no-cache-dir -r tests/requirements.txt \ && pip install --no-compile --no-cache-dir -r tests/requirements.txt \
&& KUBE_VERSION=$(sed -n 's/^kube_version: //p' roles/kubespray-defaults/defaults/main.yaml) \ && KUBE_VERSION=$(sed -n 's/^kube_version: //p' roles/kubespray-defaults/defaults/main/main.yml) \
&& curl -L https://dl.k8s.io/release/$KUBE_VERSION/bin/linux/$(dpkg --print-architecture)/kubectl -o /usr/local/bin/kubectl \ && curl -L https://dl.k8s.io/release/$KUBE_VERSION/bin/linux/$(dpkg --print-architecture)/kubectl -o /usr/local/bin/kubectl \
&& echo $(curl -L https://dl.k8s.io/release/$KUBE_VERSION/bin/linux/$(dpkg --print-architecture)/kubectl.sha256) /usr/local/bin/kubectl | sha256sum --check \ && echo $(curl -L https://dl.k8s.io/release/$KUBE_VERSION/bin/linux/$(dpkg --print-architecture)/kubectl.sha256) /usr/local/bin/kubectl | sha256sum --check \
&& chmod a+x /usr/local/bin/kubectl \ && chmod a+x /usr/local/bin/kubectl \

View File

@ -1,6 +0,0 @@
---
dependencies:
- role: download
skip_downloads: true
tags:
- facts

View File

@ -1,7 +1,7 @@
--- ---
- name: Configure defaults - name: Configure defaults
debug: debug:
msg: "Check roles/kubespray-defaults/defaults/main.yml" msg: "Check roles/kubespray-defaults/defaults/main/main.yml"
tags: tags:
- always - always

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# After a new version of Kubernetes has been released, # After a new version of Kubernetes has been released,
# run this script to update roles/download/defaults/main/main.yml # run this script to update roles/kubespray-defaults/main/download.yml
# with new hashes. # with new hashes.
import hashlib import hashlib
@ -10,7 +10,7 @@ import sys
import requests import requests
from ruamel.yaml import YAML from ruamel.yaml import YAML
MAIN_YML = "../roles/download/defaults/main/main.yml" MAIN_YML = "../roles/kubespray-defaults/main/download.yml"
def open_main_yaml(): def open_main_yaml():
yaml = YAML() yaml = YAML()

View File

@ -6,7 +6,7 @@ if [[ ${DEBUG:-false} == "true" ]]; then
set -o xtrace set -o xtrace
fi fi
checksums_file="$(git rev-parse --show-toplevel)/roles/download/defaults/main/checksums.yml" checksums_file="$(git rev-parse --show-toplevel)/roles/kubespray-defaults/defaults/main/checksums.yml"
downloads_folder=/tmp/kubespray_binaries downloads_folder=/tmp/kubespray_binaries
function get_versions { function get_versions {

View File

@ -7,7 +7,7 @@ TARGET_COMPONENTS="containerd calico cilium flannel kube-ovn kube-router weave c
cd $(dirname $0)/../../ cd $(dirname $0)/../../
echo checking kubernetes.. echo checking kubernetes..
version_from_default=$(grep "^kube_version:" ./roles/kubespray-defaults/defaults/main.yaml | awk '{print $2}' | sed s/\"//g) version_from_default=$(grep "^kube_version:" ./roles/kubespray-defaults/defaults/main/main.yml | awk '{print $2}' | sed s/\"//g)
version_from_readme=$(grep " \[kubernetes\]" ./README.md | awk '{print $3}') version_from_readme=$(grep " \[kubernetes\]" ./README.md | awk '{print $3}')
if [ "${version_from_default}" != "${version_from_readme}" ]; then if [ "${version_from_default}" != "${version_from_readme}" ]; then
echo "The version of kubernetes is different between main.yml(${version_from_default}) and README.md(${version_from_readme})." echo "The version of kubernetes is different between main.yml(${version_from_default}) and README.md(${version_from_readme})."
@ -17,7 +17,7 @@ fi
for component in $(echo ${TARGET_COMPONENTS}); do for component in $(echo ${TARGET_COMPONENTS}); do
echo checking ${component}.. echo checking ${component}..
version_from_default=$(grep "^$(echo ${component} | sed s/"-"/"_"/g)_version:" ./roles/download/defaults/main/main.yml | awk '{print $2}' | sed s/\"//g | sed s/^v//) version_from_default=$(grep "^$(echo ${component} | sed s/"-"/"_"/g)_version:" ./roles/kubespray-defaults/defaults/main/download.yml | awk '{print $2}' | sed s/\"//g | sed s/^v//)
if [ "${version_from_default}" = "" ]; then if [ "${version_from_default}" = "" ]; then
version_from_default=$(grep "^$(echo ${component} | sed s/"-"/"_"/g)_version:" ./roles/kubernetes/node/defaults/main.yml | awk '{print $2}' | sed s/\"//g | sed s/^v//) version_from_default=$(grep "^$(echo ${component} | sed s/"-"/"_"/g)_version:" ./roles/kubernetes/node/defaults/main.yml | awk '{print $2}' | sed s/\"//g | sed s/^v//)
fi fi