2022-09-16 15:42:45 +00:00
|
|
|
// nolint
|
2022-08-12 13:55:47 +00:00
|
|
|
package mos_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"io/ioutil"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
|
2022-09-16 15:42:45 +00:00
|
|
|
"github.com/kairos-io/kairos/tests/machine"
|
2022-08-12 13:55:47 +00:00
|
|
|
. "github.com/onsi/ginkgo/v2"
|
|
|
|
. "github.com/onsi/gomega"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ = Describe("k3s upgrade test", Label("upgrade-k8s"), func() {
|
|
|
|
BeforeEach(func() {
|
|
|
|
machine.EventuallyConnects()
|
|
|
|
})
|
|
|
|
|
|
|
|
AfterEach(func() {
|
|
|
|
if CurrentGinkgoTestDescription().Failed {
|
|
|
|
gatherLogs()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
Context("live cd", func() {
|
|
|
|
It("has default service active", func() {
|
|
|
|
if os.Getenv("FLAVOR") == "alpine" {
|
|
|
|
out, _ := machine.Sudo("rc-status")
|
2022-09-16 15:42:45 +00:00
|
|
|
Expect(out).Should(ContainSubstring("kairos"))
|
|
|
|
Expect(out).Should(ContainSubstring("kairos-agent"))
|
2022-08-12 13:55:47 +00:00
|
|
|
Expect(out).Should(ContainSubstring("crond"))
|
|
|
|
} else {
|
|
|
|
// Eventually(func() string {
|
2022-09-16 15:42:45 +00:00
|
|
|
// out, _ := machine.SSHCommand("sudo systemctl status kairos-agent")
|
2022-08-12 13:55:47 +00:00
|
|
|
// return out
|
|
|
|
// }, 30*time.Second, 10*time.Second).Should(ContainSubstring("no network token"))
|
|
|
|
|
2022-09-16 15:42:45 +00:00
|
|
|
out, _ := machine.Sudo("systemctl status kairos")
|
|
|
|
Expect(out).Should(ContainSubstring("loaded (/etc/systemd/system/kairos.service; enabled; vendor preset: disabled)"))
|
2022-08-12 13:55:47 +00:00
|
|
|
|
|
|
|
out, _ = machine.Sudo("systemctl status logrotate.timer")
|
|
|
|
Expect(out).Should(ContainSubstring("active (waiting)"))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Context("install", func() {
|
|
|
|
It("to disk with custom config", func() {
|
|
|
|
err := machine.SendFile("assets/single.yaml", "/tmp/config.yaml", "0770")
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
out, _ := machine.Sudo("elemental install --cloud-init /tmp/config.yaml /dev/sda")
|
|
|
|
Expect(out).Should(ContainSubstring("Running after-install hook"))
|
|
|
|
fmt.Println(out)
|
|
|
|
machine.Sudo("sync")
|
|
|
|
machine.DetachCD()
|
|
|
|
machine.Restart()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Context("first-boot", func() {
|
|
|
|
|
|
|
|
It("has default services on", func() {
|
|
|
|
if os.Getenv("FLAVOR") == "alpine" {
|
|
|
|
out, _ := machine.Sudo("rc-status")
|
2022-09-16 15:42:45 +00:00
|
|
|
Expect(out).Should(ContainSubstring("kairos"))
|
|
|
|
Expect(out).Should(ContainSubstring("kairos-agent"))
|
2022-08-12 13:55:47 +00:00
|
|
|
} else {
|
2022-09-16 15:42:45 +00:00
|
|
|
out, _ := machine.Sudo("systemctl status kairos-agent")
|
|
|
|
Expect(out).Should(ContainSubstring("loaded (/etc/systemd/system/kairos-agent.service; enabled; vendor preset: disabled)"))
|
2022-08-12 13:55:47 +00:00
|
|
|
|
|
|
|
out, _ = machine.Sudo("systemctl status systemd-timesyncd")
|
|
|
|
Expect(out).Should(ContainSubstring("loaded (/usr/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: disabled)"))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
It("has kubeconfig", func() {
|
|
|
|
Eventually(func() string {
|
|
|
|
var out string
|
|
|
|
if os.Getenv("FLAVOR") == "alpine" {
|
2022-09-16 15:42:45 +00:00
|
|
|
out, _ = machine.Sudo("cat /var/log/kairos/agent.log;cat /var/log/kairos-agent.log")
|
2022-08-12 13:55:47 +00:00
|
|
|
} else {
|
2022-09-16 15:42:45 +00:00
|
|
|
out, _ = machine.Sudo("systemctl status kairos-agent")
|
2022-08-12 13:55:47 +00:00
|
|
|
}
|
|
|
|
return out
|
|
|
|
}, 900*time.Second, 10*time.Second).Should(ContainSubstring("One time bootstrap starting"))
|
|
|
|
|
|
|
|
Eventually(func() string {
|
2022-09-16 15:42:45 +00:00
|
|
|
out, _ := machine.Sudo("cat /var/log/kairos/agent-provider.log")
|
2022-08-12 13:55:47 +00:00
|
|
|
return out
|
|
|
|
}, 900*time.Second, 10*time.Second).Should(Or(ContainSubstring("One time bootstrap starting"), ContainSubstring("Sentinel exists")))
|
|
|
|
|
|
|
|
Eventually(func() string {
|
|
|
|
out, _ := machine.Sudo("cat /etc/rancher/k3s/k3s.yaml")
|
|
|
|
return out
|
|
|
|
}, 900*time.Second, 10*time.Second).Should(ContainSubstring("https:"))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("rotates logs", func() {
|
2022-09-16 15:42:45 +00:00
|
|
|
out, err := machine.Sudo("logrotate -vf /etc/logrotate.d/kairos")
|
2022-08-12 13:55:47 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(out).To(ContainSubstring("log needs rotating"))
|
2022-09-16 15:42:45 +00:00
|
|
|
_, err = machine.Sudo("ls /var/log/kairos/agent-provider.log.1.gz")
|
2022-08-12 13:55:47 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
})
|
|
|
|
|
|
|
|
It("upgrades", func() {
|
|
|
|
By("installing system-upgrade-controller", func() {
|
|
|
|
kubectl := func(s string) (string, error) {
|
|
|
|
return machine.Sudo("k3s kubectl " + s)
|
|
|
|
}
|
|
|
|
temp, err := ioutil.TempFile("", "temp")
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
defer os.RemoveAll(temp.Name())
|
|
|
|
|
|
|
|
Eventually(func() string {
|
|
|
|
// Re-attempt to download in case it fails
|
|
|
|
resp, err := http.Get("https://github.com/rancher/system-upgrade-controller/releases/download/v0.9.1/system-upgrade-controller.yaml")
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
defer resp.Body.Close()
|
|
|
|
data := bytes.NewBuffer([]byte{})
|
|
|
|
|
|
|
|
_, err = io.Copy(data, resp.Body)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
err = ioutil.WriteFile(temp.Name(), data.Bytes(), os.ModePerm)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
err = machine.SendFile(temp.Name(), "/tmp/kubectl.yaml", "0770")
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
kubectl("apply -f /tmp/kubectl.yaml")
|
|
|
|
out, _ := kubectl("apply -f /tmp/kubectl.yaml")
|
|
|
|
return out
|
|
|
|
}, 900*time.Second, 10*time.Second).Should(ContainSubstring("unchanged"))
|
|
|
|
|
|
|
|
err = machine.SendFile("assets/suc.yaml", "./suc.yaml", "0770")
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
Eventually(func() string {
|
|
|
|
out, _ := kubectl("apply -f suc.yaml")
|
|
|
|
return out
|
|
|
|
}, 900*time.Second, 10*time.Second).Should(ContainSubstring("unchanged"))
|
|
|
|
|
|
|
|
Eventually(func() string {
|
|
|
|
out, _ := kubectl("get pods -A")
|
|
|
|
fmt.Println(out)
|
|
|
|
return out
|
|
|
|
}, 900*time.Second, 10*time.Second).Should(ContainSubstring("apply-os-upgrade-on-"))
|
|
|
|
|
|
|
|
Eventually(func() string {
|
|
|
|
out, _ := kubectl("get pods -A")
|
|
|
|
fmt.Println(out)
|
|
|
|
version, _ := machine.SSHCommand("source /etc/os-release; echo $VERSION")
|
|
|
|
return version
|
2022-09-19 09:59:28 +00:00
|
|
|
}, 20*time.Minute, 10*time.Second).Should(ContainSubstring("v"))
|
2022-08-12 13:55:47 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|