|
|
|
@ -12,13 +12,21 @@ import (
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var server *testutil.K3sServer
|
|
|
|
|
var serverArgs = []string{"--cluster-init"}
|
|
|
|
|
var _ = BeforeSuite(func() {
|
|
|
|
|
var err error
|
|
|
|
|
server, err = testutil.K3sStartServer("--cluster-init")
|
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
if !testutil.IsExistingServer() {
|
|
|
|
|
var err error
|
|
|
|
|
server, err = testutil.K3sStartServer(serverArgs...)
|
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
var _ = Describe("etcd snapshots", func() {
|
|
|
|
|
BeforeEach(func() {
|
|
|
|
|
if testutil.IsExistingServer() && !testutil.ServerArgsPresent(serverArgs) {
|
|
|
|
|
Skip("Test needs k3s server with: " + strings.Join(serverArgs, " "))
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
When("a new etcd is created", func() {
|
|
|
|
|
It("starts up with no problems", func() {
|
|
|
|
|
Eventually(func() (string, error) {
|
|
|
|
@ -44,9 +52,6 @@ var _ = Describe("etcd snapshots", func() {
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
When("saving a custom name", func() {
|
|
|
|
|
It("starts with no snapshots", func() {
|
|
|
|
|
Expect(testutil.K3sCmd("etcd-snapshot", "ls")).To(BeEmpty())
|
|
|
|
|
})
|
|
|
|
|
It("saves an etcd snapshot with a custom name", func() {
|
|
|
|
|
Expect(testutil.K3sCmd("etcd-snapshot", "save", "--name", "ALIVEBEEF")).
|
|
|
|
|
To(ContainSubstring("Saving etcd snapshot to /var/lib/rancher/k3s/server/db/snapshots/ALIVEBEEF"))
|
|
|
|
@ -62,9 +67,6 @@ var _ = Describe("etcd snapshots", func() {
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
When("using etcd snapshot prune", func() {
|
|
|
|
|
It("starts with no snapshots", func() {
|
|
|
|
|
Expect(testutil.K3sCmd("etcd-snapshot", "ls")).To(BeEmpty())
|
|
|
|
|
})
|
|
|
|
|
It("saves 3 different snapshots", func() {
|
|
|
|
|
Expect(testutil.K3sCmd("etcd-snapshot", "save", "-name", "PRUNE_TEST")).
|
|
|
|
|
To(ContainSubstring("Saving current etcd snapshot set to k3s-etcd-snapshots"))
|
|
|
|
@ -79,10 +81,9 @@ var _ = Describe("etcd snapshots", func() {
|
|
|
|
|
It("lists all 3 snapshots", func() {
|
|
|
|
|
lsResult, err := testutil.K3sCmd("etcd-snapshot", "ls")
|
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
sepLines := strings.FieldsFunc(lsResult, func(c rune) bool {
|
|
|
|
|
return c == '\n'
|
|
|
|
|
})
|
|
|
|
|
Expect(lsResult).To(MatchRegexp(`:///var/lib/rancher/k3s/server/db/snapshots/PRUNE_TEST`))
|
|
|
|
|
reg, err := regexp.Compile(`:///var/lib/rancher/k3s/server/db/snapshots/PRUNE_TEST`)
|
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
sepLines := reg.FindAllString(lsResult, -1)
|
|
|
|
|
Expect(sepLines).To(HaveLen(3))
|
|
|
|
|
})
|
|
|
|
|
It("prunes snapshots down to 2", func() {
|
|
|
|
@ -90,10 +91,9 @@ var _ = Describe("etcd snapshots", func() {
|
|
|
|
|
To(BeEmpty())
|
|
|
|
|
lsResult, err := testutil.K3sCmd("etcd-snapshot", "ls")
|
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
sepLines := strings.FieldsFunc(lsResult, func(c rune) bool {
|
|
|
|
|
return c == '\n'
|
|
|
|
|
})
|
|
|
|
|
Expect(lsResult).To(MatchRegexp(`:///var/lib/rancher/k3s/server/db/snapshots/PRUNE_TEST`))
|
|
|
|
|
reg, err := regexp.Compile(`:///var/lib/rancher/k3s/server/db/snapshots/PRUNE_TEST`)
|
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
sepLines := reg.FindAllString(lsResult, -1)
|
|
|
|
|
Expect(sepLines).To(HaveLen(2))
|
|
|
|
|
})
|
|
|
|
|
It("cleans up remaining snapshots", func() {
|
|
|
|
@ -110,7 +110,9 @@ var _ = Describe("etcd snapshots", func() {
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
var _ = AfterSuite(func() {
|
|
|
|
|
Expect(testutil.K3sKillServer(server)).To(Succeed())
|
|
|
|
|
if !testutil.IsExistingServer() {
|
|
|
|
|
Expect(testutil.K3sKillServer(server)).To(Succeed())
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
func Test_IntegrationEtcd(t *testing.T) {
|
|
|
|
|