From 63622118601d610e75d90398f4b952f2cc1ec7d1 Mon Sep 17 00:00:00 2001 From: Rong Zhang Date: Wed, 19 Dec 2018 21:17:58 +0800 Subject: [PATCH] Add images downloader to download roles (#3914) * Add images downloader to download roles * Use single jinja2 templates * add kube_version to templates --- roles/download/tasks/kubeadm_images.yml | 7 +++++++ roles/download/tasks/main.yml | 5 +++++ roles/download/templates/kubeadm-images.yaml.j2 | 16 ++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 roles/download/tasks/kubeadm_images.yml create mode 100644 roles/download/templates/kubeadm-images.yaml.j2 diff --git a/roles/download/tasks/kubeadm_images.yml b/roles/download/tasks/kubeadm_images.yml new file mode 100644 index 000000000..4ed068b91 --- /dev/null +++ b/roles/download/tasks/kubeadm_images.yml @@ -0,0 +1,7 @@ +- name: kubeadm | Create kubeadm config + template: + src: "kubeadm-images.yaml.j2" + dest: "{{ kube_config_dir }}/kubeadm-images.yaml" + +- name: container_download | download images for kubeadm config images + command: "{{ local_release_dir }}/kubeadm config images pull --config={{ kube_config_dir }}/kubeadm-images.yaml" diff --git a/roles/download/tasks/main.yml b/roles/download/tasks/main.yml index efef4e483..2100519fb 100644 --- a/roles/download/tasks/main.yml +++ b/roles/download/tasks/main.yml @@ -24,3 +24,8 @@ - item.value.container | default(false) - download_run_once - group_names | intersect(download.groups) | length + +- include_tasks: kubeadm_images.yml + when: + - not skip_downloads|default(false) + - inventory_hostname in groups['kube-master'] diff --git a/roles/download/templates/kubeadm-images.yaml.j2 b/roles/download/templates/kubeadm-images.yaml.j2 new file mode 100644 index 000000000..f15fe0fef --- /dev/null +++ b/roles/download/templates/kubeadm-images.yaml.j2 @@ -0,0 +1,16 @@ +{% if kube_version is version('v1.11.0', '<') %} +apiVersion: kubeadm.k8s.io/v1alpha1 +{% elif kube_version is version('v1.11.0', '>=') and kube_version is version('v1.12.0', '<') %} +apiVersion: kubeadm.k8s.io/v1alpha2 +{% elif kube_version is version('v1.12.0', '>=') and kube_version is version('v1.13.0', '<') %} +apiVersion: kubeadm.k8s.io/v1alpha3 +{% else %} +apiVersion: kubeadm.k8s.io/v1beta1 +{% endif %} +{% if kube_version is version('v1.12.0', '<') %} +kind: MasterConfiguration +{% else %} +kind: ClusterConfiguration +{% endif %} +imageRepository: {{ kube_image_repo }} +kubernetesVersion: {{ kube_version }}