Skip to content

Commit 372a589

Browse files
authored
Fix host_test (#631)
Signed-off-by: Kimmo Lehto <[email protected]>
1 parent 1889c20 commit 372a589

File tree

5 files changed

+13
-19
lines changed

5 files changed

+13
-19
lines changed

phase/initialize_k0s.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (p *InitializeK0s) Run() error {
7979
}
8080

8181
err = p.Wet(p.leader, fmt.Sprintf("install first k0s controller using `%s`", strings.ReplaceAll(cmd, p.leader.Configurer.K0sBinaryPath(), "k0s")), func() error {
82-
return h.Exec(cmd)
82+
return h.Exec(cmd, exec.Sudo(h))
8383
}, func() error {
8484
p.leader.Metadata.DryRunFakeLeader = true
8585
return nil

phase/install_controllers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func (p *InstallControllers) Run() error {
154154
}
155155
log.Infof("%s: installing k0s controller", h)
156156
err = p.Wet(h, fmt.Sprintf("install k0s controller using `%s", strings.ReplaceAll(cmd, h.Configurer.K0sBinaryPath(), "k0s")), func() error {
157-
return h.Exec(cmd)
157+
return h.Exec(cmd, exec.Sudo(h))
158158
})
159159
if err != nil {
160160
return err

phase/install_workers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func (p *InstallWorkers) Run() error {
187187
return err
188188
}
189189
err = p.Wet(h, fmt.Sprintf("install k0s worker with `%s`", strings.ReplaceAll(cmd, h.Configurer.K0sBinaryPath(), "k0s")), func() error {
190-
return h.Exec(cmd)
190+
return h.Exec(cmd, exec.Sudo(h))
191191
})
192192
if err != nil {
193193
return err

pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster/host.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -337,13 +337,7 @@ func (h *Host) K0sInstallCommand() (string, error) {
337337
flags.Delete("--force")
338338
}
339339

340-
cmd := h.Configurer.K0sCmdf("install %s %s", role, flags.Join())
341-
sudocmd, err := h.Sudo(cmd)
342-
if err != nil {
343-
log.Warnf("%s: %s", h, err.Error())
344-
return cmd, nil
345-
}
346-
return sudocmd, nil
340+
return h.Configurer.K0sCmdf("install %s %s", role, flags.Join()), nil
347341
}
348342

349343
// K0sBackupCommand returns a full command to be used as run k0s backup

pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster/host_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package cluster
22

33
import (
44
"fmt"
5-
"strings"
65
"testing"
76

87
cfg "github.com/k0sproject/k0sctl/configurer"
@@ -79,44 +78,45 @@ func TestK0sInstallCommand(t *testing.T) {
7978

8079
cmd, err := h.K0sInstallCommand()
8180
require.NoError(t, err)
82-
require.True(t, strings.HasSuffix(cmd, `k0s install worker --data-dir=/tmp/k0s --token-file "from-configurer"`))
81+
require.Equal(t, `k0s install worker --data-dir=/tmp/k0s --token-file "from-configurer"`, cmd)
8382

8483
h.Role = "controller"
8584
h.Metadata.IsK0sLeader = true
8685
cmd, err = h.K0sInstallCommand()
8786
require.NoError(t, err)
88-
require.True(t, strings.HasSuffix(cmd, `k0s install controller --data-dir=/tmp/k0s --config "from-configurer"`))
87+
require.Equal(t, `k0s install controller --data-dir=/tmp/k0s --config "from-configurer"`, cmd)
8988

9089
h.Metadata.IsK0sLeader = false
9190
cmd, err = h.K0sInstallCommand()
9291
require.NoError(t, err)
93-
require.True(t, strings.HasSuffix(cmd, `k0s install controller --data-dir=/tmp/k0s --token-file "from-configurer" --config "from-configurer"`))
92+
require.Equal(t, `k0s install controller --data-dir=/tmp/k0s --token-file "from-configurer" --config "from-configurer"`, cmd)
9493

9594
h.Role = "controller+worker"
9695
h.Metadata.IsK0sLeader = true
9796
cmd, err = h.K0sInstallCommand()
9897
require.NoError(t, err)
99-
require.True(t, strings.HasSuffix(cmd, `k0s install controller --data-dir=/tmp/k0s --enable-worker --config "from-configurer"`))
98+
require.Equal(t, `k0s install controller --data-dir=/tmp/k0s --enable-worker --config "from-configurer"`, cmd)
99+
100100
h.Metadata.IsK0sLeader = false
101101
cmd, err = h.K0sInstallCommand()
102102
require.NoError(t, err)
103-
require.True(t, strings.HasSuffix(cmd, `k0s install controller --data-dir=/tmp/k0s --enable-worker --token-file "from-configurer" --config "from-configurer"`))
103+
require.Equal(t, `k0s install controller --data-dir=/tmp/k0s --enable-worker --token-file "from-configurer" --config "from-configurer"`, cmd)
104104

105105
h.Role = "worker"
106106
h.PrivateAddress = "10.0.0.9"
107107
cmd, err = h.K0sInstallCommand()
108108
require.NoError(t, err)
109-
require.True(t, strings.HasSuffix(cmd, `k0s install worker --data-dir=/tmp/k0s --token-file "from-configurer" --kubelet-extra-args="--node-ip=10.0.0.9"`))
109+
require.Equal(t, `k0s install worker --data-dir=/tmp/k0s --token-file "from-configurer" --kubelet-extra-args="--node-ip=10.0.0.9"`, cmd)
110110

111111
h.InstallFlags = []string{`--kubelet-extra-args="--foo bar"`}
112112
cmd, err = h.K0sInstallCommand()
113113
require.NoError(t, err)
114-
require.True(t, strings.HasSuffix(cmd, `k0s install worker --kubelet-extra-args="--foo bar --node-ip=10.0.0.9" --data-dir=/tmp/k0s --token-file "from-configurer"`))
114+
require.Equal(t, `k0s install worker --kubelet-extra-args="--foo bar --node-ip=10.0.0.9" --data-dir=/tmp/k0s --token-file "from-configurer"`, cmd)
115115

116116
h.InstallFlags = []string{`--enable-cloud-provider`}
117117
cmd, err = h.K0sInstallCommand()
118118
require.NoError(t, err)
119-
require.True(t, strings.HasSuffix(cmd, `k0s install worker --enable-cloud-provider --data-dir=/tmp/k0s --token-file "from-configurer"`))
119+
require.Equal(t, `k0s install worker --enable-cloud-provider --data-dir=/tmp/k0s --token-file "from-configurer"`, cmd)
120120
}
121121

122122
func TestValidation(t *testing.T) {

0 commit comments

Comments
 (0)