Install etcdutl file by default (#10385)

pull/10387/head
Samuel Liu 2023-08-23 22:04:22 +08:00 committed by GitHub
parent 5ed85094c2
commit e1881fae02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 68 additions and 99 deletions

View File

@ -1,9 +1,4 @@
---
- name: Install etcdctl from docker
import_tasks: install_etcdctl_docker.yml
when: etcd_cluster_setup
- name: Get currently-deployed etcd version
shell: "{{ docker_bin_dir }}/docker ps --filter='name={{ etcd_member_name }}' --format='{{ '{{ .Image }}' }}'"
register: etcd_current_docker_image

View File

@ -1,11 +0,0 @@
---
- name: Install | Copy etcdctl binary from docker container
command: sh -c "{{ docker_bin_dir }}/docker rm -f etcdctl-binarycopy;
{{ docker_bin_dir }}/docker create --name etcdctl-binarycopy {{ etcd_image_repo }}:{{ etcd_image_tag }} &&
{{ docker_bin_dir }}/docker cp etcdctl-binarycopy:/usr/local/bin/etcdctl {{ bin_dir }}/etcdctl &&
{{ docker_bin_dir }}/docker rm -f etcdctl-binarycopy"
register: etcdctl_install_result
until: etcdctl_install_result.rc == 0
retries: "{{ etcd_retries }}"
delay: "{{ retry_stagger | random + 3 }}"
changed_when: false

View File

@ -20,16 +20,7 @@
- etcd_events_cluster_setup
- etcd_version.lstrip('v') not in etcd_current_host_version.stdout | default('')
- name: Install | Download etcd and etcdctl
include_tasks: "../../download/tasks/download_file.yml"
vars:
download: "{{ download_defaults | combine(downloads.etcd) }}"
when: etcd_cluster_setup
tags:
- never
- etcd
- name: Install | Copy etcd and etcdctl binary from download dir
- name: Install | Copy etcd binary from download dir
copy:
src: "{{ local_release_dir }}/etcd-{{ etcd_version }}-linux-{{ host_architecture }}/{{ item }}"
dest: "{{ bin_dir }}/{{ item }}"
@ -37,5 +28,4 @@
remote_src: yes
with_items:
- etcd
- etcdctl
when: etcd_cluster_setup

View File

@ -53,6 +53,17 @@
- master
- network
- name: Install etcdctl and etcdutl binary
import_role:
name: etcdctl_etcdutl
tags:
- etcdctl
- etcdutl
- upgrade
when:
- inventory_hostname in groups['etcd']
- etcd_cluster_setup
- name: Install etcd
include_tasks: "install_{{ etcd_deployment_type }}.yml"
when: is_etcd_master

View File

@ -1,70 +0,0 @@
---
# To get the binary from container to host, use the etcd data directory mounted
# rw from host into the container.
- name: Check unintentional include of this role
assert:
that: etcd_deployment_type == "kubeadm"
- name: Check if etcdctl exist
stat:
path: "{{ bin_dir }}/etcdctl"
get_attributes: no
get_checksum: no
get_mime: no
register: stat_etcdctl
- name: Remove old etcd binary
when: stat_etcdctl.stat.exists
block:
- name: Check version
command: "{{ bin_dir }}/etcdctl version"
register: etcdctl_version
check_mode: no
changed_when: false
- name: Remove old binary if version is not OK
file:
path: "{{ bin_dir }}/etcdctl"
state: absent
when: etcd_version.lstrip('v') not in etcdctl_version.stdout
- name: Check if etcdctl still exist after version check
stat:
path: "{{ bin_dir }}/etcdctl"
get_attributes: no
get_checksum: no
get_mime: no
register: stat_etcdctl
- name: Copy etcdctl script to host
when: not stat_etcdctl.stat.exists
block:
- name: Copy etcdctl script to host
shell: "{{ docker_bin_dir }}/docker cp \"$({{ docker_bin_dir }}/docker ps -qf ancestor={{ etcd_image_repo }}:{{ etcd_image_tag }})\":/usr/local/bin/etcdctl {{ etcd_data_dir }}/etcdctl"
when: container_manager == "docker"
- name: Copy etcdctl script to host
shell: >-
etcd_ctr_id="$({{ bin_dir }}/crictl ps -q --image {{ etcd_image_repo }}:{{ etcd_image_tag }})" &&
etcd_ctr_pid="$({{ bin_dir }}/crictl inspect --output go-template --template '{{ '{{' }} .info.pid {{ '}}' }}' ${etcd_ctr_id})" &&
cp /proc/${etcd_ctr_pid}/root/usr/local/bin/etcdctl {{ etcd_data_dir }}/etcdctl
when: container_manager in ['crio', 'containerd']
- name: Copy etcdctl to {{ bin_dir }}
copy:
src: "{{ etcd_data_dir }}/etcdctl"
dest: "{{ bin_dir }}"
remote_src: true
mode: 0755
- name: Remove binary in etcd data dir
file:
path: "{{ etcd_data_dir }}/etcdctl"
state: absent
- name: Create etcdctl wrapper script
template:
src: etcdctl.sh.j2
dest: "{{ bin_dir }}/etcdctl.sh"
mode: 0755

View File

@ -0,0 +1,45 @@
---
- name: Copy etcdctl and etcdutl binary from docker container
command: sh -c "{{ docker_bin_dir }}/docker rm -f etcdxtl-binarycopy;
{{ docker_bin_dir }}/docker create --name etcdxtl-binarycopy {{ etcd_image_repo }}:{{ etcd_image_tag }} &&
{{ docker_bin_dir }}/docker cp etcdxtl-binarycopy:/usr/local/bin/{{ item }} {{ bin_dir }}/{{ item }} &&
{{ docker_bin_dir }}/docker rm -f etcdxtl-binarycopy"
with_items:
- etcdctl
- etcdutl
register: etcdxtl_install_result
until: etcdxtl_install_result.rc == 0
retries: "{{ etcd_retries }}"
delay: "{{ retry_stagger | random + 3 }}"
changed_when: false
when: container_manager == "docker"
- name: Download etcd binary
include_tasks: "../../download/tasks/download_file.yml"
vars:
download: "{{ download_defaults | combine(downloads.etcd) }}"
when: container_manager in ['crio', 'containerd']
- name: Copy etcd binary
unarchive:
src: "{{ downloads.etcd.dest }}"
dest: "{{ local_release_dir }}/"
remote_src: yes
when: container_manager in ['crio', 'containerd']
- name: Copy etcdctl and etcdutl binary from download dir
copy:
src: "{{ local_release_dir }}/etcd-{{ etcd_version }}-linux-{{ host_architecture }}/{{ item }}"
dest: "{{ bin_dir }}/{{ item }}"
mode: 0755
remote_src: yes
with_items:
- etcdctl
- etcdutl
when: container_manager in ['crio', 'containerd']
- name: Create etcdctl wrapper script
template:
src: etcdctl.sh.j2
dest: "{{ bin_dir }}/etcdctl.sh"
mode: 0755

View File

@ -3,6 +3,12 @@
# example invocation: etcdctl.sh get --keys-only --from-key ""
etcdctl \
{% if etcd_deployment_type == "kubeadm" %}
--cacert {{ kube_cert_dir }}/etcd/ca.crt \
--cert {{ kube_cert_dir }}/etcd/server.crt \
--key {{ kube_cert_dir }}/etcd/server.key "$@"
{% else %}
--cacert {{ etcd_cert_dir }}/etcd/ca.crt \
--cert {{ etcd_cert_dir }}/etcd/server.crt \
--key {{ etcd_cert_dir }}/etcd/server.key "$@"
{% endif %}

View File

@ -12,10 +12,13 @@
tags:
- network
- name: Ensure etcdctl script is installed
- name: Ensure etcdctl and etcdutl script is installed
import_role:
name: etcdctl
name: etcdctl_etcdutl
when: etcd_deployment_type == "kubeadm"
tags:
- etcdctl
- etcdutl
- name: Set ownership for etcd data directory
file: