Skip to content

Commit 7e8c272

Browse files
authored
Alternatively use system ssh client to connect (k0sproject/rig v0.15.1) (#568)
* Bump github.com/k0sproject/rig to v0.15.1 Signed-off-by: Kimmo Lehto <[email protected]> * Add openssh test to workflow Signed-off-by: Kimmo Lehto <[email protected]> * Add openssh test to Makefile Signed-off-by: Kimmo Lehto <[email protected]> --------- Signed-off-by: Kimmo Lehto <[email protected]>
1 parent f6efd26 commit 7e8c272

File tree

8 files changed

+184
-14
lines changed

8 files changed

+184
-14
lines changed

.github/workflows/go.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,36 @@ jobs:
108108
env:
109109
LINUX_IMAGE: ${{ matrix.image }}
110110
run: make smoke-basic
111+
112+
smoke-basic-openssh:
113+
strategy:
114+
matrix:
115+
image:
116+
- quay.io/k0sproject/bootloose-alpine3.18
117+
name: Basic 1+1 smoke using openssh client
118+
needs: build
119+
runs-on: ubuntu-20.04
120+
121+
steps:
122+
- uses: actions/checkout@v4
123+
- name: Set up Go
124+
uses: actions/setup-go@v4
125+
with:
126+
go-version-file: go.mod
127+
check-latest: true
128+
129+
- {"name":"Go modules cache","uses":"actions/cache@v3","with":{"path":"~/go/pkg/mod\n~/.cache/go-build\n~/Library/Caches/go-build\n%LocalAppData%\\go-build\n","key":"${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}","restore-keys":"${{ runner.os }}-go-\n"}}
130+
- {"name":"Compiled binary cache","uses":"actions/download-artifact@v3","with":{"name":"k0sctl","path":"."}}
131+
- {"name":"Make executable","run":"chmod +x k0sctl"}
132+
- {"name":"K0sctl cache","uses":"actions/cache@v3","with":{"path":"/var/cache/k0sctl\n~/.cache/k0sctl\n!*.log\n","key":"k0sctl-cache"}}
133+
- {"name":"Kubectl cache","uses":"actions/cache@v3","with":{"path":"smoke-test/kubectl\n","key":"kubectl-1.21.3"}}
134+
- {"name":"Go modules cache","uses":"actions/cache@v3","with":{"path":"~/go/pkg/mod\n~/.cache/go-build\n~/Library/Caches/go-build\n%LocalAppData%\\go-build\n","key":"${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}","restore-keys":"${{ runner.os }}-go-\n"}}
135+
- {"name":"Docker Layer Caching For Bootloose","uses":"satackey/[email protected]","continue-on-error":true}
136+
137+
- name: Run smoke tests
138+
env:
139+
LINUX_IMAGE: ${{ matrix.image }}
140+
run: make smoke-basic-openssh
111141

112142
smoke-files:
113143
strategy:

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ build-all: $(addprefix bin/,$(bins)) bin/checksums.md
5151
clean:
5252
rm -rf bin/ k0sctl
5353

54-
smoketests := smoke-basic smoke-files smoke-upgrade smoke-reset smoke-os-override smoke-init smoke-backup-restore smoke-dynamic
54+
smoketests := smoke-basic smoke-files smoke-upgrade smoke-reset smoke-os-override smoke-init smoke-backup-restore smoke-dynamic smoke-basic-openssh
5555
.PHONY: $(smoketests)
5656
$(smoketests): k0sctl
5757
$(MAKE) -C smoke-test $@

README.md

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ IP address of the host
468468

469469
Username to log in as.
470470

471-
###### `spec.hosts[*].ssh.port` &lt;string&gt; (required)
471+
###### `spec.hosts[*].ssh.port` &lt;number&gt; (required)
472472

473473
TCP port of the SSH service on the host.
474474

@@ -484,6 +484,83 @@ Localhost connection options. Can be used to use the local host running k0sctl a
484484

485485
This must be set `true` to enable the localhost connection.
486486

487+
##### `spec.hosts[*].openSSH` &lt;mapping&gt; (optional)
488+
489+
An alternative SSH client protocol that uses the system's openssh client for connections.
490+
491+
Example:
492+
493+
```yaml
494+
spec:
495+
hosts:
496+
- role: controller
497+
openSSH:
498+
address: 10.0.0.2
499+
```
500+
501+
The only required field is the `address` and it can also be a hostname that is found in the ssh config. All other options such as user, port and keypath will use the same defaults as if running `ssh` from the command-line or will use values found from the ssh config.
502+
503+
An example SSH config:
504+
505+
```
506+
Host controller1
507+
Hostname 10.0.0.1
508+
Port 2222
509+
IdentityFile ~/.ssh/id_cluster_esa
510+
```
511+
512+
If this is in your `~/.ssh/config`, you can simply use the host alias as the address in your k0sctl config:
513+
514+
```yaml
515+
spec:
516+
hosts:
517+
- role: controller
518+
openSSH:
519+
address: controller1
520+
# if the ssh configuration is in a different file, you can use:
521+
# configPath: /path/to/config
522+
```
523+
524+
###### `spec.hosts[*].openSSH.address` &lt;string&gt; (required)
525+
526+
IP address, hostname or ssh config host alias of the host
527+
528+
###### `spec.hosts[*].openSSH.user` &lt;string&gt; (optional)
529+
530+
Username to connect as.
531+
532+
###### `spec.hosts[*].openSSH.port` &lt;number&gt; (optional)
533+
534+
Remote port.
535+
536+
###### `spec.hosts[*].openSSH.keyPath` &lt;string&gt; (optional)
537+
538+
Path to private key.
539+
540+
###### `spec.hosts[*].openSSH.configPath` &lt;string&gt; (optional)
541+
542+
Path to ssh config, defaults to ~/.ssh/config with fallback to /etc/ssh/ssh_config.
543+
544+
###### `spec.hosts[*].openSSH.disableMultiplexing` &lt;boolean&gt; (optional)
545+
546+
The default mode of operation is to use connection multiplexing where a ControlMaster connection is opened and the subsequent connections to the same host use the master connection over a socket to communicate to the host.
547+
548+
If this is disabled by setting `disableMultiplexing: true`, running every remote command will require reconnecting and reauthenticating to the host.
549+
550+
###### `spec.hosts[*].openSSH.options` &lt;mapping&gt; (optional)
551+
552+
Additional options as key/value pairs to use when running the ssh client.
553+
554+
Example:
555+
556+
```yaml
557+
openSSH:
558+
address: host
559+
options:
560+
ForwardAgent: true # -o ForwardAgent=yes
561+
StrictHostkeyChecking: false # -o StrictHostkeyChecking: no
562+
```
563+
487564
###### `spec.hosts[*].reset` &lt;boolean&gt; (optional) (default: `false`)
488565

489566
If set to `true` k0sctl will remove the node from kubernetes and reset k0s on the host.

go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ require (
1616
github.com/gofrs/uuid v4.4.0+incompatible // indirect
1717
github.com/hashicorp/go-version v1.6.0 // indirect
1818
github.com/k0sproject/dig v0.2.0
19-
github.com/k0sproject/rig v0.14.0
19+
github.com/k0sproject/rig v0.15.1
2020
github.com/logrusorgru/aurora v2.0.3+incompatible
2121
github.com/masterzen/simplexml v0.0.0-20190410153822-31eea3082786 // indirect
2222
github.com/masterzen/winrm v0.0.0-20220917170901-b07f6cb0598d // indirect
@@ -28,10 +28,10 @@ require (
2828
github.com/stretchr/testify v1.8.4
2929
github.com/urfave/cli/v2 v2.25.7
3030
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c // indirect
31-
golang.org/x/crypto v0.13.0 // indirect
31+
golang.org/x/crypto v0.14.0 // indirect
3232
golang.org/x/net v0.13.0 // indirect
33-
golang.org/x/sys v0.12.0 // indirect
34-
golang.org/x/term v0.12.0 // indirect
33+
golang.org/x/sys v0.13.0 // indirect
34+
golang.org/x/term v0.13.0 // indirect
3535
golang.org/x/text v0.13.0
3636
gopkg.in/yaml.v2 v2.4.0
3737
k8s.io/client-go v0.28.2

go.sum

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnr
121121
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
122122
github.com/k0sproject/dig v0.2.0 h1:cNxEIl96g9kqSMfPSZLhpnZ0P8bWXKv08nxvsMHop5w=
123123
github.com/k0sproject/dig v0.2.0/go.mod h1:rBcqaQlJpcKdt2x/OE/lPvhGU50u/e95CSm5g/r4s78=
124-
github.com/k0sproject/rig v0.14.0 h1:DqmSZTuv9Ae6WQEQwLscxcvn6EnCrwWz5/azgP7Km1c=
125-
github.com/k0sproject/rig v0.14.0/go.mod h1:1niIomLJnggPcnduA1HfmdWYvxe+N5xABQ+1DjX+nsA=
124+
github.com/k0sproject/rig v0.15.1 h1:QjEBSgDDMk24NB6vLozIilUGPn0nOGEz/AFkPOZkYWw=
125+
github.com/k0sproject/rig v0.15.1/go.mod h1:EQQjrgGbRY6MpbuZRpzMaymJJ86RJVxIuGsPGsVNfZg=
126126
github.com/k0sproject/version v0.4.2 h1:zrbT5xRv1ai4N102ZaHTTq9Zqf6pAGFm9WCxHaC9QHY=
127127
github.com/k0sproject/version v0.4.2/go.mod h1:oEjuz2ItQQtAnGyRgwEV9m5R6/9rjoFC6EiEEzbkFdI=
128128
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
@@ -214,8 +214,8 @@ golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5
214214
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
215215
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
216216
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
217-
golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck=
218-
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
217+
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
218+
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
219219
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
220220
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
221221
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
@@ -257,13 +257,13 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc
257257
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
258258
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
259259
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
260-
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
261-
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
260+
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
261+
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
262262
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
263263
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
264264
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
265-
golang.org/x/term v0.12.0 h1:/ZfYdc3zq+q02Rv9vGqTeSItdzZTSNDmfTi0mBAuidU=
266-
golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=
265+
golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek=
266+
golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
267267
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
268268
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
269269
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=

smoke-test/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ id_rsa_k0s:
2222
smoke-basic: $(bootloose) id_rsa_k0s k0sctl
2323
./smoke-basic.sh
2424

25+
smoke-basic-openssh: $(bootloose) id_rsa_k0s k0sctl
26+
./smoke-basic-openssh.sh
27+
2528
smoke-dynamic: $(bootloose) id_rsa_k0s k0sctl
2629
./smoke-dynamic.sh
2730

@@ -42,3 +45,4 @@ smoke-os-override: $(bootloose) id_rsa_k0s k0sctl
4245

4346
smoke-backup-restore: $(bootloose) id_rsa_k0s k0sctl
4447
./smoke-backup-restore.sh
48+

smoke-test/k0sctl-openssh.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: k0sctl.k0sproject.io/v1beta1
2+
kind: cluster
3+
spec:
4+
hosts:
5+
- role: controller
6+
uploadBinary: true
7+
openSSH:
8+
address: controller
9+
configPath: ssh/config
10+
- role: worker
11+
uploadBinary: true
12+
openSSH:
13+
address: worker
14+
configPath: ssh/config
15+
k0s:
16+
version: "${K0S_VERSION}"
17+
config:
18+
spec:
19+
telemetry:
20+
enabled: false

smoke-test/smoke-basic-openssh.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env sh
2+
3+
K0SCTL_CONFIG=${K0SCTL_CONFIG:-"k0sctl-openssh.yaml"}
4+
5+
set -e
6+
7+
. ./smoke.common.sh
8+
trap cleanup_openssh EXIT
9+
10+
cleanup_openssh() {
11+
cleanup
12+
[ -f "ssh/id_rsa_k0s" ] && rm -rf .ssh
13+
}
14+
15+
deleteCluster
16+
createCluster
17+
18+
echo "* Create SSH config"
19+
mkdir -p ~/.ssh
20+
mkdir -p ssh
21+
cp id_rsa_k0s ssh/
22+
cat <<EOF > ssh/config
23+
Host *
24+
StrictHostKeyChecking no
25+
UserKnownHostsFile /dev/null
26+
IdentityFile id_rsa_k0s
27+
User root
28+
Host controller
29+
Hostname 127.0.0.1
30+
Port 9022
31+
Host worker
32+
Hostname 127.0.0.1
33+
Port 9023
34+
EOF
35+
36+
echo "* Starting apply"
37+
../k0sctl apply --config "${K0SCTL_CONFIG}" --debug
38+
echo "* Apply OK"
39+

0 commit comments

Comments
 (0)