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

Bug 1795696: templates: etcd-member: setup environment variables needed for easy etcdctl execution #1429

Merged

Conversation

retroflexer
Copy link
Contributor

@retroflexer retroflexer commented Feb 1, 2020

Closes: #1795696

One can easily update .bashrc or .bash_profile using postStart hooks. However, oc rsh apparently doesn't use bash, so these are not getting automatically invoked.

openshift/origin#7514
openshift/origin#7496

openshift/origin#7519

However, standard shell (Bourne shell) uses .profile. But in RHCOS, /bin/sh is symbolically linked to /usr/bin/bash.

If bash is invoked with the name sh, it tries to mimic the startup behavior of historical versions of sh as closely as possible, while conforming to the POSIX standard as well. [...] When invoked as an interactive shell with the name sh, bash looks for the variable ENV, expands its value if it is defined, and uses the expanded value as the name of a file to read and execute. Since a shell invoked as sh does not attempt to read and execute commands from any other startup files, the --rcfile option has no effect.

- What I did
Added the environment variables needed for straightforward execution of etcdctl into /root/.profile, so that oc rsh has the ready-made environment.
- How to verify it

  1. Install cluster
  2. oc rsh -n openshift-etcd etcd-member-pod
  3. Run etcdctl commands such as etcdctl member list

Should work right off the bat.

- Description for the changelog

Provide environment variables for straightfoward execution of etcdctl commands on pods.

@openshift-ci-robot openshift-ci-robot added the bugzilla/valid-bug Indicates that a referenced Bugzilla bug is valid for the branch this PR is targeting. label Feb 1, 2020
@openshift-ci-robot
Copy link
Contributor

@retroflexer: This pull request references Bugzilla bug 1795696, which is valid. The bug has been moved to the POST state. The bug has been updated to refer to the pull request using the external bug tracker.

In response to this:

Bug 1795696: templates: etcd-member: Write environment variables needed for etcdctl execution

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.

@openshift-ci-robot openshift-ci-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Feb 1, 2020
command:
- /bin/sh
- -c
- echo 'export ETCDCTL_API=3 ETCDCTL_CACERT=/etc/ssl/etcd/ca.crt ETCDCTL_CERT=$(find /etc/ssl/ -name *peer*crt) ETCDCTL_KEY=$(find /etc/ssl/ -name *peer*key)' >> /root/.profile
Copy link
Contributor

@hexfusion hexfusion Feb 1, 2020

Choose a reason for hiding this comment

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

we set API version in env below. we should do one or the other. does this work if we exec in as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed ETCDCTL_API. crictl exec works well too.

@hexfusion
Copy link
Contributor

overall looks good, thanks @retroflexer

@openshift-ci-robot
Copy link
Contributor

@retroflexer: This pull request references Bugzilla bug 1795696, which is valid.

In response to this:

Bug 1795696: templates: etcd-member: Write environment variables needed for etcdctl execution

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.

@retroflexer retroflexer changed the title Bug 1795696: templates: etcd-member: Write environment variables needed for etcdctl execution Bug 1795696: templates: etcd-member: setup environment variables needed for easy etcdctl execution Feb 2, 2020
@openshift-ci-robot
Copy link
Contributor

@retroflexer: This pull request references Bugzilla bug 1795696, which is valid.

In response to this:

Bug 1795696: templates: etcd-member: setup environment variables needed for easy etcdctl execution

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.


env:
- name: ETCDCTL_API
value: "3"
- name: ETCD_DATA_DIR
value: "/var/lib/etcd"
- name: ENV
value: "/root/.profile"
Copy link
Contributor Author

@retroflexer retroflexer Feb 2, 2020

Choose a reason for hiding this comment

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

In RHCOS, /bin/sh is symbolically linked to bash, but it tries to mimic the behavior of historical bourne shell.

When bash is invoked as an interactive shell with the name sh, bash looks for the variable ENV, expands its value if it is defined, and uses the expanded value as the name of a file to read and execute. Since a shell invoked as sh does not attempt to read and execute commands from any other startup files (including .profile), the --rcfile option has no effect.
(from the man pages of bash)

Copy link
Contributor

Choose a reason for hiding this comment

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

@retroflexer thanks, for the crisp explanation. I wonder if it would be a good idea to create a secret/configmap for the env variables here and then mount the configmap? I think it would be lot cleaner and admins can configure the env variable independent of static pod yaml.

/cc @hexfusion

@retroflexer
Copy link
Contributor Author

/test e2e-gcp-op

@retroflexer
Copy link
Contributor Author

/test e2e-aws-disruptive

1 similar comment
@retroflexer
Copy link
Contributor Author

/test e2e-aws-disruptive

@retroflexer
Copy link
Contributor Author

/test e2e-gcp-op

@openshift-ci-robot
Copy link
Contributor

@retroflexer: This pull request references Bugzilla bug 1795696, which is valid.

In response to this:

Bug 1795696: templates: etcd-member: setup environment variables needed for easy etcdctl execution

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.

1 similar comment
@openshift-ci-robot
Copy link
Contributor

@retroflexer: This pull request references Bugzilla bug 1795696, which is valid.

In response to this:

Bug 1795696: templates: etcd-member: setup environment variables needed for easy etcdctl execution

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.

command:
- /bin/sh
- -c
- echo 'export ETCDCTL_CACERT=/etc/ssl/etcd/ca.crt ETCDCTL_CERT=$(find /etc/ssl/ -name *peer*crt) ETCDCTL_KEY=$(find /etc/ssl/ -name *peer*key)' >> /root/.profile
Copy link
Member

Choose a reason for hiding this comment

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

I really don't think we should have starting any containers affect host content like this by default.

The etcd recovery tools are going to be containerized anyways, so let's just document this stuff over there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The etcd recovery tools are going to be containerized in 4.5+. And it assumes cluster-etcd-operator to be available, which is not available prior to 4.4. That means, our current customers of 4.2 and 4.3 (and perhaps 4.4) will not have easy execution of etcdctl.

Also .profile is current not used by anyone (that file doesn't exist at all in most pod installations). So, I do not see a reason to oppose it. If you don't like the use of .profile, I can put it in a file named .etcdctl_env.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I mistakenly thought these hooks ran on the host.

@cgwalters
Copy link
Member

/hold
I really don't like this and think we should take another approach that doesn't involve changing root's .profile.

@openshift-ci-robot openshift-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 3, 2020
@retroflexer
Copy link
Contributor Author

retroflexer commented Feb 3, 2020

/hold
I really don't like this and think we should take another approach that doesn't involve changing root's .profile.

What other solution do you recommend, Colins?

Our customers and customer supporting staff are struggling with typing a mile long commands to achieve simple member list or endpoint status.

Michal thought this should be ported to 4.2 and 4.3 as well to help mitigate the pain for our customers.

Cc: @mfojtik, @hexfusion

@mfojtik
Copy link
Contributor

mfojtik commented Feb 4, 2020

@cgwalters i'm willing to accept this for 4.4, but revisit in 4.5 where we should make the ETCD_DNS_NAME in the cert names go away and one could just set normal pod level env vars that points to ETCDCTL_CERT/etc.
We made this hard to ourself by making the file names non-deterministic, lets drop that legacy and make them deterministic (use a pod name or something).

Also this is important when debugging broken clusters and also come up recently during one escalation call.

/cc @smarterclayton

@alaypatel07
Copy link
Contributor

@retroflexer @hexfusion can we maybe do this via the discovery container? for instance, we set the DNS name here[1], can we set the ETCDCTL_CERT* env variables here as well. It will be in the /run/etcd/environment and we source that anyway. The etcd container can then always have the env variable. Sorry for the late response, it hit me now.

  1. unexportedEnv["DNS_NAME"] = setupEnv.etcdDNS

@alaypatel07
Copy link
Contributor

alaypatel07 commented Feb 5, 2020

we set the DNS name here[1], can we set the ETCDCTL_CERT* env variables here as well. It will be in the /run/etcd/environment and we source that anyway. The etcd container can then always have the env variable

Thanks @retroflexer for confirming over slack, this will only work if the user explicitly sources /run/etcd/environment after execing or rshing into the container, hence dropping the idea

@cgwalters
Copy link
Member

/hold cancel
per #1429 (comment)

@openshift-ci-robot openshift-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 5, 2020
@retroflexer
Copy link
Contributor Author

/test e2e-aws-disruptive

@retroflexer
Copy link
Contributor Author

/test e2e-aws-scaleup-rhel7

@hexfusion
Copy link
Contributor

The bottom line here is we are improving user experience. This is a simple and practical approach in my opinion. thanks @retroflexer

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Feb 6, 2020
@hexfusion
Copy link
Contributor

cc @cgwalters @runcom

@hexfusion
Copy link
Contributor

/skip

@cgwalters
Copy link
Member

/approve

@openshift-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cgwalters, hexfusion, retroflexer

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

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 10, 2020
@retroflexer
Copy link
Contributor Author

/cherrypick release-4.3

@openshift-cherrypick-robot

@retroflexer: once the present PR merges, I will cherry-pick it on top of release-4.3 in a new PR and assign it to you.

In response to this:

/cherrypick release-4.3

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.

@openshift-ci-robot
Copy link
Contributor

openshift-ci-robot commented Feb 10, 2020

@retroflexer: The following tests failed, say /retest to rerun all failed tests:

Test name Commit Details Rerun command
ci/prow/e2e-aws-disruptive 144c710 link /test e2e-aws-disruptive
ci/prow/e2e-aws-scaleup-rhel7 144c710 link /test e2e-aws-scaleup-rhel7

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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. I understand the commands that are listed here.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

1 similar comment
@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-merge-robot openshift-merge-robot merged commit d9dec38 into openshift:master Feb 10, 2020
@openshift-ci-robot
Copy link
Contributor

@retroflexer: All pull requests linked via external trackers have merged. Bugzilla bug 1795696 has been moved to the MODIFIED state.

In response to this:

Bug 1795696: templates: etcd-member: setup environment variables needed for easy etcdctl execution

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.

@openshift-cherrypick-robot

@retroflexer: new pull request created: #1452

In response to this:

/cherrypick release-4.3

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. bugzilla/valid-bug Indicates that a referenced Bugzilla bug is valid for the branch this PR is targeting. lgtm Indicates that a PR is ready to be merged. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants