Skip to content

Commit 04f6ac4

Browse files
authored
Replace kubectl usage with embedded k0s kubectl (#127)
* Replace installed kubectl usage with k0s embedded kubectl usage Signed-off-by: Jussi Nummelin <[email protected]> * Use sudo with install when creating the upload target dir Signed-off-by: Jussi Nummelin <[email protected]> * Add note to bump up rig version Signed-off-by: Jussi Nummelin <[email protected]> * I see dead code Signed-off-by: Jussi Nummelin <[email protected]> * Move k0s upload/download phases up so we get proper support for embedded kubectl command for upgrade case Signed-off-by: Jussi Nummelin <[email protected]> * Bump rig to 0.3.17 to get fixes for file uploads Signed-off-by: Jussi Nummelin <[email protected]>
1 parent 9dc8830 commit 04f6ac4

File tree

13 files changed

+90
-109
lines changed

13 files changed

+90
-109
lines changed

cmd/apply.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ var applyCommand = &cli.Command{
5858
&phase.DetectOS{},
5959
&phase.PrepareHosts{},
6060
&phase.GatherFacts{},
61-
&phase.ValidateHosts{},
62-
&phase.GatherK0sFacts{},
63-
&phase.ValidateFacts{},
6461
&phase.DownloadBinaries{},
6562
&phase.UploadBinaries{},
6663
&phase.DownloadK0s{},
6764
&phase.UploadFiles{},
65+
&phase.ValidateHosts{},
66+
&phase.GatherK0sFacts{},
67+
&phase.ValidateFacts{},
6868
&phase.ConfigureK0s{},
6969
&phase.InitializeK0s{},
7070
&phase.InstallControllers{},

config/cluster/host.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ type configurer interface {
6060
DeleteFile(os.Host, string) error
6161
CommandExist(os.Host, string) bool
6262
Hostname(os.Host) string
63-
InstallKubectl(os.Host) error
6463
KubectlCmdf(string, ...interface{}) string
6564
KubeconfigPath() string
6665
IsContainer(os.Host) bool

configurer/linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func (l Linux) KubeconfigPath() string {
111111

112112
// KubectlCmdf returns a command line in sprintf manner for running kubectl on the host using the kubeconfig from KubeconfigPath
113113
func (l Linux) KubectlCmdf(s string, args ...interface{}) string {
114-
return fmt.Sprintf(`sudo kubectl --kubeconfig "%s" %s`, l.KubeconfigPath(), fmt.Sprintf(s, args...))
114+
return l.K0sCmdf(`kubectl --kubeconfig "%s" %s`, l.KubeconfigPath(), fmt.Sprintf(s, args...))
115115
}
116116

117117
// HTTPStatus makes a HTTP GET request to the url and returns the status code or an error

configurer/linux/alpine.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,6 @@ type BaseLinux struct {
1414
configurer.Linux
1515
}
1616

17-
var kubectlInstallScript = []string{
18-
`curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"`,
19-
`curl -LO "https://dl.k8s.io/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"`,
20-
`echo "$(<kubectl.sha256) kubectl" | sha256sum --check`,
21-
`sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl`,
22-
}
23-
24-
// InstallKubectl installs kubectl using the curl method
25-
func (l BaseLinux) InstallKubectl(h os.Host) error {
26-
for _, c := range kubectlInstallScript {
27-
if err := h.Exec(c); err != nil {
28-
return err
29-
}
30-
}
31-
return nil
32-
}
33-
3417
// Alpine provides OS support for Alpine Linux
3518
type Alpine struct {
3619
os.Linux
@@ -53,11 +36,6 @@ func (l Alpine) InstallPackage(h os.Host, pkg ...string) error {
5336
return h.Execf("sudo apk add --update %s", strings.Join(pkg, " "))
5437
}
5538

56-
// InstallKubectl installs kubectl using the alpine edge/testing repo
57-
func (l Alpine) InstallKubectl(h os.Host) error {
58-
return l.InstallPackage(h, "--repository https://dl-cdn.alpinelinux.org/alpine/edge/testing kubectl")
59-
}
60-
6139
func (l Alpine) Prepare(h os.Host) error {
6240
if !l.CommandExist(h, "sudo") {
6341
return h.Exec("apk add --update sudo")

configurer/linux/debian.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package linux
33
import (
44
"github.com/k0sproject/k0sctl/configurer"
55
"github.com/k0sproject/rig"
6-
"github.com/k0sproject/rig/os"
76
"github.com/k0sproject/rig/os/linux"
87
"github.com/k0sproject/rig/os/registry"
98
)
@@ -24,22 +23,3 @@ func init() {
2423
},
2524
)
2625
}
27-
28-
// InstallKubectl installs kubectl using the gcloud kubernetes repo
29-
func (c Debian) InstallKubectl(h os.Host) error {
30-
if err := c.InstallPackage(h, "apt-transport-https", "gnupg2"); err != nil {
31-
return err
32-
}
33-
34-
err := h.Exec(`curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -`)
35-
if err != nil {
36-
return err
37-
}
38-
39-
err = h.Exec(`sudo test -e /etc/apt/sources.list.d/kubernetes.list || (echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.list)`)
40-
if err != nil {
41-
return err
42-
}
43-
44-
return c.InstallPackage(h, "kubectl")
45-
}

configurer/linux/enterpriselinux.go

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

33
import (
44
"github.com/k0sproject/k0sctl/configurer"
5-
"github.com/k0sproject/rig/os"
65
"github.com/k0sproject/rig/os/linux"
76
)
87

@@ -11,21 +10,3 @@ type EnterpriseLinux struct {
1110
linux.EnterpriseLinux
1211
configurer.Linux
1312
}
14-
15-
// InstallKubectl installs kubectl using the gcloud kubernetes repo
16-
func (c EnterpriseLinux) InstallKubectl(h os.Host) error {
17-
err := c.WriteFile(h, "/etc/yum.repos.d/kubernetes.repo", `[kubernetes]
18-
name=Kubernetes
19-
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
20-
enabled=1
21-
gpgcheck=1
22-
repo_gpgcheck=1
23-
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
24-
`, "0644")
25-
26-
if err != nil {
27-
return err
28-
}
29-
30-
return c.InstallPackage(h, "kubectl")
31-
}

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ require (
1515
github.com/go-playground/validator/v10 v10.4.1
1616
github.com/hashicorp/go-version v1.2.1
1717
github.com/k0sproject/dig v0.1.1
18-
github.com/k0sproject/rig v0.3.15
18+
github.com/k0sproject/rig v0.3.17
1919
github.com/logrusorgru/aurora v2.0.3+incompatible
2020
github.com/mattn/go-isatty v0.0.12
2121
github.com/segmentio/analytics-go v3.1.0+incompatible
2222
github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18
23-
github.com/sirupsen/logrus v1.7.0
23+
github.com/sirupsen/logrus v1.8.1
2424
github.com/stretchr/testify v1.7.0
2525
github.com/urfave/cli/v2 v2.3.0
2626
golang.org/x/sys v0.0.0-20200622214017-ed371f2e16b4

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1
149149
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
150150
github.com/k0sproject/dig v0.1.1 h1:TmNoZtsCXF3jDzwSSEEwKjjD7fG5IyG0p8uvK+z1Wyo=
151151
github.com/k0sproject/dig v0.1.1/go.mod h1:rBcqaQlJpcKdt2x/OE/lPvhGU50u/e95CSm5g/r4s78=
152-
github.com/k0sproject/rig v0.3.15 h1:hq5GxDw3PiozvteAqlZZbiKMWTA5r8/0FSEeBirbXxg=
153-
github.com/k0sproject/rig v0.3.15/go.mod h1:2FBHQkR4t9VveNzFF4iNuMGx9T171kKPNuS2PFunASI=
152+
github.com/k0sproject/rig v0.3.17 h1:dsxhZIHcuoi+sIhFrR9xTv5tN9Bp5mu2ejBE8tUtu7o=
153+
github.com/k0sproject/rig v0.3.17/go.mod h1:2FBHQkR4t9VveNzFF4iNuMGx9T171kKPNuS2PFunASI=
154154
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
155155
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
156156
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
@@ -213,8 +213,8 @@ github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18 h1:DAYUYH5869yV94
213213
github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18/go.mod h1:nkxAfR/5quYxwPZhyDxgasBMnRtBZd0FCEpawpjMUFg=
214214
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
215215
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
216-
github.com/sirupsen/logrus v1.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM=
217-
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
216+
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
217+
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
218218
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
219219
github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
220220
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=

phase/prepare_hosts.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,6 @@ func (p *PrepareHosts) prepareHost(h *cluster.Host) error {
5858
}
5959
}
6060

61-
if h.IsController() && !h.Configurer.CommandExist(h, "kubectl") {
62-
log.Infof("%s: installing kubectl", h)
63-
if err := h.Configurer.InstallKubectl(h); err != nil {
64-
return err
65-
}
66-
}
67-
6861
if h.Configurer.IsContainer(h) {
6962
log.Infof("%s: is a container, applying a fix", h)
7063
if err := h.Configurer.FixContainer(h); err != nil {

phase/uploadfiles.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func (p *UploadFiles) uploadFiles(h *cluster.Host) error {
4949
return err
5050
}
5151

52-
if err := h.Execf("install -d %s -m %s", f.DestinationDir, f.PermMode); err != nil {
52+
if err := h.Execf("sudo install -d %s -m %s", f.DestinationDir, f.PermMode); err != nil {
5353
return err
5454
}
5555

0 commit comments

Comments
 (0)