Return code for install command should be checked for all pipe commands
- Vorherrschende Sprache
- Go
- Sterne
- 7.4k
- Forks
- 430
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
Currently the code just executes a command like
`curl -sfL https://get.k3s.io | K3S_URL='https://:6443' K3S_TOKEN=’ INSTALL_K3S_VERSION='v1.19.1+k3s1' INSTALL_K3S_EXEC='server --server https://:6443' sh -s -`
in https://github.com/alexellis/k3sup/blob/master/cmd/join.go#L319. The return code is checked afterwards. The problem is that the return code of this command is always the return code of the last command in the pipe. So if `curl` fails here this will not be visible in the return code. This behaviour in bash can be changed by setting `pipefail`, see https://stackoverflow.com/questions/5934108/how-to-use-the-return-code-of-the-first-program-in-a-pipe-command-line. So the getscript in https://github.com/alexellis/k3sup/blob/master/cmd/install.go#L41 should be prefixed the command with `set -o pipefail; ` so the return code is != 0 if one of the commands in the pipe is !=0
## Expected Behaviour
If curl fails e.g. due to a network error or a DNS resolution issue an error should be returned.
## Current Behaviour
If curl fails no feedback is given. The tool just stops without any feedback.
## Are you a GitHub Sponsor (Yes/No?)
- [ ] Yes
- [X] No
## Possible Solution
I attached a patch as [patch.txt](https://github.com/alexellis/k3sup/files/7192593/patch.txt)
## Steps to Reproduce
1. Blacklist one of the systems on which k3s should be installed in the router, so the internet access is blocked or tamper the /etc/resolv.conf file of a system so name resolution doesn't work properly.
2. Run the installation on this modified machine via k3sup
## Context
I tried to install on a machine that had a broken internet access and no proper error was returned as the curl failed which was not detected.
## Your Environment
* What Kubernetes distribution are you using?
```
Client Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.4", GitCommit:"3cce4a82b44f032d0cd1a1790e6d2f5a55d20aae", GitTreeState:"clean", BuildDate:"2021-08-11T18:16:05Z", GoVersion:"go1.16.7", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.1+k3s1", GitCommit:"b66760fccdddfc98fa107ec38c86c5e2814e559d", GitTreeState:"clean", BuildDate:"2020-09-17T17:17:18Z", GoVersion:"go1.15.2", Compiler:"gc", Platform:"linux/arm"}
```
* What OS or type or VM are you using for your cluster? Where is it hosted? (for `k3sup install/join`):
Rasbian on RaspberryPi
* Operating System and version (e.g. Linux, Windows, MacOS):
```
uname -a
Linux name 4.19.66-v7+ #1253 SMP Thu Aug 15 11:49:46 BST 2019 armv7l GNU/Linux
cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
NAME="Raspbian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
VERSION_CODENAME=stretch
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
```
## "Be part of the solution"
Subject to approval, are you willing to work on a Pull Request for this issue or feature request?
- [X] Yes
- [ ] No
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Bewertung
Dieses Issue wurde noch nicht bewertet.