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

Make etcdctl copy command work on cri-o/containerd #6151

Closed

Conversation

mattymo
Copy link
Contributor

@mattymo mattymo commented May 17, 2020

This is a follow-on to #5777 where etcd_kubeadm_enabled mode used to force using etcdctl from binary sources. Now it uses a Docker image, but the fix only included Docker container engine support. This adds support for cri-o and containerd.

Change-Id: Idc3c93785139898f36bc13b6a9b135a8a6d7ffd4
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 17, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mattymo

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 17, 2020
@k8s-ci-robot k8s-ci-robot requested review from bozzo and floryut May 17, 2020 13:13
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label May 17, 2020
ctr run --rm --mount type=bind,src={{ bin_dir }},dst=/systembindir,options=rbind:rw {{ etcd_image_repo }}:{{ etcd_image_tag }} etcdctl-compare sh -c 'cmp /usr/local/bin/etcdctl /systembindir/etcdctl'
{%- endif %}
etcdctl_copy_command: >-
{%- if container_manager in ['docker', 'crio'] %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure about this ? if container_manager is crio you are using docker run ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh, you're right. I copied this from helm role. We should use crictl here. ctr is containerd-specific.

@EppO
Copy link
Contributor

EppO commented May 19, 2020

Just a shell alias wrapping up a ctr command on the master nodes would do the job too, right? Why do we need the binary installed on the hosts to achieve this use case? Running etcdctl inside the etcd container seems good enough to me although it needs the etcd container to be running if we just attach to it, but if it's not running for whatever reasons (etcd container failing), you wouldn't be able to run the etcdctl on the host anyway.

@mattymo
Copy link
Contributor Author

mattymo commented May 24, 2020

@EppO Then you have to mount all the certs if you go with the shell wrapper. It's just more effort than it is worth.

@EppO
Copy link
Contributor

EppO commented May 28, 2020

@EppO Then you have to mount all the certs if you go with the shell wrapper. It's just more effort than it is worth.

You don't have to mount anything if you "exec" in the container. I was thinking about something like this (using docker, need to port it to crictl)

alias etcdctl='docker exec -it $(docker ps -f "name=k8s_etcd" --format "{{.ID}}") etcdctl --cert-file=/etc/kubernetes/ssl/etcd/peer.crt --key-file=/etc/kubernetes/ssl/etcd/peer.key --ca-file /etc/kubernetes/ssl/etcd/ca.crt --endpoints=https://127.0.0.1:2379'

with that alias installed on every master nodes, you can run any commands without specifying the certs or endpoints on any masters:

$ etcdctl cluster-health
member 5c04bf204def0eda is healthy: got healthy result from https://10.1.2.1:2379
member e949065838d88228 is healthy: got healthy result from https://10.1.2.2:2379
member fdc65c5087f1d04f is healthy: got healthy result from https://10.1.2.3:2379
cluster is healthy
$ etcdctl member list
5c04bf204def0eda: name=master01 peerURLs=https://10.1.2.1:2380 clientURLs=https://10.1.2.1:2379 isLeader=true
e949065838d88228: name=master02 peerURLs=https://10.1.2.2:2380 clientURLs=https://10.1.2.2:2379 isLeader=false
fdc65c5087f1d04f: name=master03 peerURLs=https://10.1.2.3:2380 clientURLs=https://10.1.2.3:2379 isLeader=false

@EppO
Copy link
Contributor

EppO commented May 28, 2020

On the other hand, if you want to "run" instead of "exec", because the etcd is failing for example, you would need to do something like this:

alias etcdctl='docker run -it --rm  --net=host --volume=/etc/kubernetes/ssl/etcd:/etc/kubernetes/ssl/etcd etcd:v3.3.12 etcdctl --cert-file=/etc/kubernetes/ssl/etcd/peer.crt --key-file=/etc/kubernetes/ssl/etcd/peer.key --ca-file /etc/kubernetes/ssl/etcd/ca.crt --endpoints=https://10.1.2.1:2379'
$ etcdctl member list
5c04bf204def0eda: name=master01 peerURLs=https://10.1.2.1:2380 clientURLs=https://10.1.2.1:2379 isLeader=true
e949065838d88228: name=master02 peerURLs=https://10.1.2.2:2380 clientURLs=https://10.1.2.2:2379 isLeader=false
fdc65c5087f1d04f: name=master03 peerURLs=https://10.1.2.3:2380 clientURLs=https://10.1.2.3:2379 isLeader=false

Copy link

@didacog didacog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case of a proxy scenario ctr command does not use the ENV setup in systemd/containerd unit, so this will fail. Also, the compare command fails with a file not found error if etcdctl binary does not exist , that is what is expected, as the previous version just copies the binary from the docker image.

I made it work with proxy ajdusting few things, maybe you'll find a better way, but at least the following worked for me, while this commit is failing now.
Also replaced command by shell to make ctr command work
I've modified the roles/etcd/tasks/install_etcdctl_docker.yml like this:

---
- name: Set commands for etcdctl container tasks
  set_fact:
    etcdctl_compare_command: >-
      {%- if container_manager in ['docker', 'crio'] %}
      {{ docker_bin_dir }}/docker run --rm -v {{ bin_dir }}:/systembindir --entrypoint /usr/bin/cmp {{ etcd_image_repo }}:{{ etcd_image_tag }} /usr/local/bin/etcdctl /systembindir/helm
      {%- elif container_manager == "containerd" %}
      [[ -f {{ bin_dir }}/etcdctl ]] && ctr run --rm --mount type=bind,src={{ bin_dir }},dst=/systembindir,options=rbind:rw {{ etcd_image_repo }}:{{ etcd_image_tag }} etcdctl-compare sh -c 'cmp /usr/local/bin/etcdctl /systembindir/etcdctl'
      {%- endif %}
    etcdctl_copy_command: >-
      {%- if container_manager in ['docker', 'crio'] %}
      {{ docker_bin_dir }}/docker run --rm -v {{ bin_dir }}:/systembindir --entrypoint /bin/cp {{ etcd_image_repo }}:{{ etcd_image_tag }} -f /usr/local/bin/etcdctl /systembindir/etcdctl
      {%- elif container_manager == "containerd" %}
      ctr run --rm --mount type=bind,src={{ bin_dir }},dst=/systembindir,options=rbind:rw {{ etcd_image_repo }}:{{ etcd_image_tag }} etcdctl-copy sh -c '/bin/cp -f /usr/local/bin/etcdctl /systembindir/etcdctl'
      {%- endif %}

- name: Ensure image is pulled for containerd
  shell: "HTTPS_PROXY={{ https_proxy }} ctr i pull {{ etcd_image_repo }}:{{ etcd_image_tag }}"
  when: container_manager == "containerd"

- name: Compare host etcdctl with etcdctl image
  shell: "{{ etcdctl_compare_command }}"
  register: etcdctl_task_compare_result
  until: etcdctl_task_compare_result.rc in [0,1,2]
  retries: 4
  delay: "{{ retry_stagger | random + 3 }}"
  changed_when: false
  failed_when: "etcdctl_task_compare_result.rc not in [0,1,2]"

- name: Copy etcdctl from etcdctl container
  shell: "{{ etcdctl_copy_command }}"
  when: etcdctl_task_compare_result.rc != 0
  register: etcdctl_task_result
  until: etcdctl_task_result.rc == 0
  retries: 4
  delay: "{{ retry_stagger | random + 3 }}"

@hafe
Copy link
Contributor

hafe commented Jun 30, 2020

[root@master-1 ~]# alias etcdctl="crictl exec -it $(crictl ps --name etcd -q) etcdctl --cacert /etc/kubernetes/ssl/etcd/ca.crt --cert /etc/kubernetes/ssl/etcd/healthcheck-client.crt --key /etc/kubernetes/ssl/etcd/healthcheck-client.key"
[root@master-1 ~]# etcdctl member list
302028076f67b4ea, started, master-1, https://10.0.2.23:2380, https://10.0.2.23:2379, false

works fine!

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 30, 2020
@k8s-ci-robot
Copy link
Contributor

@mattymo: PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@hafe
Copy link
Contributor

hafe commented Jun 30, 2020

I've got a patch with a shell wrapper for etcdctl. Are you interested?

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Sep 28, 2020
@fejta-bot
Copy link

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Oct 28, 2020
@mattymo
Copy link
Contributor Author

mattymo commented Nov 4, 2020

I haven't had time to clean up my PR. I merged #6857 in favor of this.
/close

@k8s-ci-robot
Copy link
Contributor

@mattymo: Closed this PR.

In response to this:

I haven't had time to clean up my PR. I merged #6857 in favor of this.
/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants