2021-12-22 17:51:48 +00:00
|
|
|
package validatecluster
|
|
|
|
|
|
|
|
import (
|
2022-02-08 17:34:57 +00:00
|
|
|
"flag"
|
2021-12-22 17:51:48 +00:00
|
|
|
"fmt"
|
|
|
|
"os"
|
2023-05-12 17:36:41 +00:00
|
|
|
"regexp"
|
2021-12-22 17:51:48 +00:00
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
2022-03-15 17:29:56 +00:00
|
|
|
"github.com/k3s-io/k3s/tests/e2e"
|
2022-02-09 16:22:53 +00:00
|
|
|
. "github.com/onsi/ginkgo/v2"
|
2021-12-22 17:51:48 +00:00
|
|
|
. "github.com/onsi/gomega"
|
|
|
|
)
|
|
|
|
|
2022-08-26 16:36:13 +00:00
|
|
|
// Valid nodeOS:
|
2024-03-27 16:55:13 +00:00
|
|
|
// generic/ubuntu2310, generic/centos7, generic/rocky8,
|
2023-01-27 17:01:13 +00:00
|
|
|
// opensuse/Leap-15.3.x86_64
|
2024-03-27 16:55:13 +00:00
|
|
|
var nodeOS = flag.String("nodeOS", "generic/ubuntu2310", "VM operating system")
|
2022-02-08 17:34:57 +00:00
|
|
|
var serverCount = flag.Int("serverCount", 3, "number of server nodes")
|
|
|
|
var agentCount = flag.Int("agentCount", 2, "number of agent nodes")
|
2022-08-05 16:16:10 +00:00
|
|
|
var hardened = flag.Bool("hardened", false, "true or false")
|
2022-09-08 21:02:47 +00:00
|
|
|
var ci = flag.Bool("ci", false, "running on CI")
|
2022-09-08 21:31:50 +00:00
|
|
|
var local = flag.Bool("local", false, "deploy a locally built K3s binary")
|
2022-02-08 17:34:57 +00:00
|
|
|
|
2022-03-02 20:42:55 +00:00
|
|
|
// Environment Variables Info:
|
2022-08-26 16:36:13 +00:00
|
|
|
// E2E_EXTERNAL_DB: mysql, postgres, etcd (default: etcd)
|
|
|
|
// E2E_RELEASE_VERSION=v1.23.1+k3s2 (default: latest commit from master)
|
2022-09-20 16:58:19 +00:00
|
|
|
// E2E_REGISTRY: true/false (default: false)
|
2022-02-08 17:34:57 +00:00
|
|
|
|
2021-12-22 17:51:48 +00:00
|
|
|
func Test_E2EClusterValidation(t *testing.T) {
|
|
|
|
RegisterFailHandler(Fail)
|
2022-02-08 17:34:57 +00:00
|
|
|
flag.Parse()
|
2022-11-04 23:07:12 +00:00
|
|
|
suiteConfig, reporterConfig := GinkgoConfiguration()
|
|
|
|
RunSpecs(t, "Create Cluster Test Suite", suiteConfig, reporterConfig)
|
2021-12-22 17:51:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
kubeConfigFile string
|
2022-03-02 20:42:55 +00:00
|
|
|
serverNodeNames []string
|
|
|
|
agentNodeNames []string
|
2021-12-22 17:51:48 +00:00
|
|
|
)
|
|
|
|
|
2022-11-04 23:07:12 +00:00
|
|
|
var _ = ReportAfterEach(e2e.GenReport)
|
|
|
|
|
2022-09-06 19:56:37 +00:00
|
|
|
var _ = Describe("Verify Create", Ordered, func() {
|
2023-05-12 17:36:41 +00:00
|
|
|
Context("Cluster Starts up and deploys basic components", func() {
|
2021-12-22 17:51:48 +00:00
|
|
|
It("Starts up with no issues", func() {
|
|
|
|
var err error
|
2022-09-08 21:31:50 +00:00
|
|
|
if *local {
|
|
|
|
serverNodeNames, agentNodeNames, err = e2e.CreateLocalCluster(*nodeOS, *serverCount, *agentCount)
|
|
|
|
} else {
|
|
|
|
serverNodeNames, agentNodeNames, err = e2e.CreateCluster(*nodeOS, *serverCount, *agentCount)
|
|
|
|
}
|
2022-10-06 19:27:44 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred(), e2e.GetVagrantLog(err))
|
2021-12-22 17:51:48 +00:00
|
|
|
fmt.Println("CLUSTER CONFIG")
|
2022-02-08 17:34:57 +00:00
|
|
|
fmt.Println("OS:", *nodeOS)
|
2022-03-02 20:42:55 +00:00
|
|
|
fmt.Println("Server Nodes:", serverNodeNames)
|
|
|
|
fmt.Println("Agent Nodes:", agentNodeNames)
|
|
|
|
kubeConfigFile, err = e2e.GenKubeConfigFile(serverNodeNames[0])
|
2021-12-22 17:51:48 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
})
|
2022-02-08 17:34:57 +00:00
|
|
|
|
|
|
|
It("Checks Node and Pod Status", func() {
|
2021-12-22 17:51:48 +00:00
|
|
|
fmt.Printf("\nFetching node status\n")
|
|
|
|
Eventually(func(g Gomega) {
|
2022-02-08 17:34:57 +00:00
|
|
|
nodes, err := e2e.ParseNodes(kubeConfigFile, false)
|
2021-12-22 17:51:48 +00:00
|
|
|
g.Expect(err).NotTo(HaveOccurred())
|
|
|
|
for _, node := range nodes {
|
2022-02-08 17:34:57 +00:00
|
|
|
g.Expect(node.Status).Should(Equal("Ready"))
|
2021-12-22 17:51:48 +00:00
|
|
|
}
|
2023-01-12 00:09:45 +00:00
|
|
|
}, "620s", "5s").Should(Succeed())
|
2022-02-08 17:34:57 +00:00
|
|
|
_, _ = e2e.ParseNodes(kubeConfigFile, true)
|
2021-12-22 17:51:48 +00:00
|
|
|
|
|
|
|
fmt.Printf("\nFetching Pods status\n")
|
|
|
|
Eventually(func(g Gomega) {
|
2022-02-08 17:34:57 +00:00
|
|
|
pods, err := e2e.ParsePods(kubeConfigFile, false)
|
2021-12-22 17:51:48 +00:00
|
|
|
g.Expect(err).NotTo(HaveOccurred())
|
|
|
|
for _, pod := range pods {
|
|
|
|
if strings.Contains(pod.Name, "helm-install") {
|
2022-02-08 17:34:57 +00:00
|
|
|
g.Expect(pod.Status).Should(Equal("Completed"), pod.Name)
|
2021-12-22 17:51:48 +00:00
|
|
|
} else {
|
2022-02-08 17:34:57 +00:00
|
|
|
g.Expect(pod.Status).Should(Equal("Running"), pod.Name)
|
2021-12-22 17:51:48 +00:00
|
|
|
}
|
|
|
|
}
|
2023-01-12 00:09:45 +00:00
|
|
|
}, "620s", "5s").Should(Succeed())
|
2022-02-08 17:34:57 +00:00
|
|
|
_, _ = e2e.ParsePods(kubeConfigFile, true)
|
|
|
|
})
|
|
|
|
|
|
|
|
It("Verifies ClusterIP Service", func() {
|
2022-09-08 21:31:50 +00:00
|
|
|
res, err := e2e.DeployWorkload("clusterip.yaml", kubeConfigFile, *hardened)
|
|
|
|
Expect(err).NotTo(HaveOccurred(), "Cluster IP manifest not deployed: "+res)
|
2022-02-08 17:34:57 +00:00
|
|
|
|
|
|
|
Eventually(func(g Gomega) {
|
|
|
|
cmd := "kubectl get pods -o=name -l k8s-app=nginx-app-clusterip --field-selector=status.phase=Running --kubeconfig=" + kubeConfigFile
|
|
|
|
res, err := e2e.RunCommand(cmd)
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2022-09-08 19:27:18 +00:00
|
|
|
g.Expect(res).Should((ContainSubstring("test-clusterip")), "failed cmd: "+cmd+" result: "+res)
|
2022-02-08 17:34:57 +00:00
|
|
|
}, "240s", "5s").Should(Succeed())
|
|
|
|
|
2022-06-14 15:40:29 +00:00
|
|
|
clusterip, _ := e2e.FetchClusterIP(kubeConfigFile, "nginx-clusterip-svc", false)
|
2022-03-01 19:28:39 +00:00
|
|
|
cmd := "curl -L --insecure http://" + clusterip + "/name.html"
|
2022-03-02 20:42:55 +00:00
|
|
|
for _, nodeName := range serverNodeNames {
|
2022-02-08 17:34:57 +00:00
|
|
|
Eventually(func(g Gomega) {
|
|
|
|
res, err := e2e.RunCmdOnNode(cmd, nodeName)
|
|
|
|
g.Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(res).Should(ContainSubstring("test-clusterip"))
|
|
|
|
}, "120s", "10s").Should(Succeed())
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
It("Verifies NodePort Service", func() {
|
2022-08-05 16:16:10 +00:00
|
|
|
_, err := e2e.DeployWorkload("nodeport.yaml", kubeConfigFile, *hardened)
|
2022-02-08 17:34:57 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred(), "NodePort manifest not deployed")
|
|
|
|
|
2022-03-02 20:42:55 +00:00
|
|
|
for _, nodeName := range serverNodeNames {
|
2022-03-15 17:29:56 +00:00
|
|
|
nodeExternalIP, _ := e2e.FetchNodeExternalIP(nodeName)
|
2022-02-08 17:34:57 +00:00
|
|
|
cmd := "kubectl get service nginx-nodeport-svc --kubeconfig=" + kubeConfigFile + " --output jsonpath=\"{.spec.ports[0].nodePort}\""
|
|
|
|
nodeport, err := e2e.RunCommand(cmd)
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
Eventually(func(g Gomega) {
|
|
|
|
cmd := "kubectl get pods -o=name -l k8s-app=nginx-app-nodeport --field-selector=status.phase=Running --kubeconfig=" + kubeConfigFile
|
|
|
|
res, err := e2e.RunCommand(cmd)
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
g.Expect(res).Should(ContainSubstring("test-nodeport"), "nodeport pod was not created")
|
|
|
|
}, "240s", "5s").Should(Succeed())
|
|
|
|
|
2022-03-15 17:29:56 +00:00
|
|
|
cmd = "curl -L --insecure http://" + nodeExternalIP + ":" + nodeport + "/name.html"
|
2023-05-12 17:36:41 +00:00
|
|
|
|
2022-02-08 17:34:57 +00:00
|
|
|
Eventually(func(g Gomega) {
|
|
|
|
res, err := e2e.RunCommand(cmd)
|
2022-08-15 22:00:22 +00:00
|
|
|
g.Expect(err).NotTo(HaveOccurred(), "failed cmd: "+cmd+" result: "+res)
|
2022-02-08 17:34:57 +00:00
|
|
|
g.Expect(res).Should(ContainSubstring("test-nodeport"))
|
|
|
|
}, "240s", "5s").Should(Succeed())
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
It("Verifies LoadBalancer Service", func() {
|
2022-08-05 16:16:10 +00:00
|
|
|
_, err := e2e.DeployWorkload("loadbalancer.yaml", kubeConfigFile, *hardened)
|
2022-02-08 17:34:57 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred(), "Loadbalancer manifest not deployed")
|
|
|
|
|
2022-03-02 20:42:55 +00:00
|
|
|
for _, nodeName := range serverNodeNames {
|
2022-02-08 17:34:57 +00:00
|
|
|
ip, _ := e2e.FetchNodeExternalIP(nodeName)
|
|
|
|
|
|
|
|
cmd := "kubectl get service nginx-loadbalancer-svc --kubeconfig=" + kubeConfigFile + " --output jsonpath=\"{.spec.ports[0].port}\""
|
|
|
|
port, err := e2e.RunCommand(cmd)
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
Eventually(func(g Gomega) {
|
|
|
|
cmd := "kubectl get pods -o=name -l k8s-app=nginx-app-loadbalancer --field-selector=status.phase=Running --kubeconfig=" + kubeConfigFile
|
|
|
|
res, err := e2e.RunCommand(cmd)
|
2022-08-15 22:00:22 +00:00
|
|
|
g.Expect(err).NotTo(HaveOccurred(), "failed cmd: "+cmd+" result: "+res)
|
2022-02-08 17:34:57 +00:00
|
|
|
g.Expect(res).Should(ContainSubstring("test-loadbalancer"))
|
|
|
|
}, "240s", "5s").Should(Succeed())
|
|
|
|
|
|
|
|
Eventually(func(g Gomega) {
|
|
|
|
cmd = "curl -L --insecure http://" + ip + ":" + port + "/name.html"
|
|
|
|
res, err := e2e.RunCommand(cmd)
|
2022-08-15 22:00:22 +00:00
|
|
|
g.Expect(err).NotTo(HaveOccurred(), "failed cmd: "+cmd+" result: "+res)
|
2022-02-08 17:34:57 +00:00
|
|
|
g.Expect(res).Should(ContainSubstring("test-loadbalancer"))
|
|
|
|
}, "240s", "5s").Should(Succeed())
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
It("Verifies Ingress", func() {
|
2022-08-05 16:16:10 +00:00
|
|
|
_, err := e2e.DeployWorkload("ingress.yaml", kubeConfigFile, *hardened)
|
2022-02-08 17:34:57 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred(), "Ingress manifest not deployed")
|
|
|
|
|
2022-03-02 20:42:55 +00:00
|
|
|
for _, nodeName := range serverNodeNames {
|
2022-02-08 17:34:57 +00:00
|
|
|
ip, _ := e2e.FetchNodeExternalIP(nodeName)
|
|
|
|
cmd := "curl --header host:foo1.bar.com" + " http://" + ip + "/name.html"
|
|
|
|
fmt.Println(cmd)
|
|
|
|
|
|
|
|
Eventually(func(g Gomega) {
|
|
|
|
res, err := e2e.RunCommand(cmd)
|
2022-08-15 22:00:22 +00:00
|
|
|
g.Expect(err).NotTo(HaveOccurred(), "failed cmd: "+cmd+" result: "+res)
|
2022-02-08 17:34:57 +00:00
|
|
|
g.Expect(res).Should(ContainSubstring("test-ingress"))
|
|
|
|
}, "240s", "5s").Should(Succeed())
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
It("Verifies Daemonset", func() {
|
2022-08-05 16:16:10 +00:00
|
|
|
_, err := e2e.DeployWorkload("daemonset.yaml", kubeConfigFile, *hardened)
|
2022-02-08 17:34:57 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred(), "Daemonset manifest not deployed")
|
|
|
|
|
|
|
|
nodes, _ := e2e.ParseNodes(kubeConfigFile, false)
|
|
|
|
|
|
|
|
Eventually(func(g Gomega) {
|
2022-08-26 16:36:13 +00:00
|
|
|
pods, _ := e2e.ParsePods(kubeConfigFile, false)
|
2022-02-08 17:34:57 +00:00
|
|
|
count := e2e.CountOfStringInSlice("test-daemonset", pods)
|
|
|
|
fmt.Println("POD COUNT")
|
|
|
|
fmt.Println(count)
|
|
|
|
fmt.Println("NODE COUNT")
|
|
|
|
fmt.Println(len(nodes))
|
|
|
|
g.Expect(len(nodes)).Should((Equal(count)), "Daemonset pod count does not match node count")
|
|
|
|
}, "420s", "10s").Should(Succeed())
|
|
|
|
})
|
|
|
|
|
|
|
|
It("Verifies dns access", func() {
|
2022-08-05 16:16:10 +00:00
|
|
|
_, err := e2e.DeployWorkload("dnsutils.yaml", kubeConfigFile, *hardened)
|
2022-02-08 17:34:57 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred(), "dnsutils manifest not deployed")
|
|
|
|
|
|
|
|
Eventually(func(g Gomega) {
|
|
|
|
cmd := "kubectl get pods dnsutils --kubeconfig=" + kubeConfigFile
|
2022-08-15 22:00:22 +00:00
|
|
|
res, err := e2e.RunCommand(cmd)
|
|
|
|
g.Expect(err).NotTo(HaveOccurred(), "failed cmd: "+cmd+" result: "+res)
|
2022-02-08 17:34:57 +00:00
|
|
|
g.Expect(res).Should(ContainSubstring("dnsutils"))
|
|
|
|
}, "420s", "2s").Should(Succeed())
|
|
|
|
|
|
|
|
Eventually(func(g Gomega) {
|
|
|
|
cmd := "kubectl --kubeconfig=" + kubeConfigFile + " exec -i -t dnsutils -- nslookup kubernetes.default"
|
2023-05-12 17:36:41 +00:00
|
|
|
|
2022-08-15 22:00:22 +00:00
|
|
|
res, err := e2e.RunCommand(cmd)
|
|
|
|
g.Expect(err).NotTo(HaveOccurred(), "failed cmd: "+cmd+" result: "+res)
|
2022-02-08 17:34:57 +00:00
|
|
|
g.Expect(res).Should(ContainSubstring("kubernetes.default.svc.cluster.local"))
|
|
|
|
}, "420s", "2s").Should(Succeed())
|
|
|
|
})
|
|
|
|
|
|
|
|
It("Verifies Local Path Provisioner storage ", func() {
|
2022-09-08 21:31:50 +00:00
|
|
|
res, err := e2e.DeployWorkload("local-path-provisioner.yaml", kubeConfigFile, *hardened)
|
|
|
|
Expect(err).NotTo(HaveOccurred(), "local-path-provisioner manifest not deployed: "+res)
|
2022-02-08 17:34:57 +00:00
|
|
|
|
|
|
|
Eventually(func(g Gomega) {
|
|
|
|
cmd := "kubectl get pvc local-path-pvc --kubeconfig=" + kubeConfigFile
|
|
|
|
res, err := e2e.RunCommand(cmd)
|
2022-08-15 22:00:22 +00:00
|
|
|
g.Expect(err).NotTo(HaveOccurred(), "failed cmd: "+cmd+" result: "+res)
|
2022-02-08 17:34:57 +00:00
|
|
|
g.Expect(res).Should(ContainSubstring("local-path-pvc"))
|
|
|
|
g.Expect(res).Should(ContainSubstring("Bound"))
|
|
|
|
}, "420s", "2s").Should(Succeed())
|
|
|
|
|
|
|
|
Eventually(func(g Gomega) {
|
|
|
|
cmd := "kubectl get pod volume-test --kubeconfig=" + kubeConfigFile
|
|
|
|
res, err := e2e.RunCommand(cmd)
|
2022-08-15 22:00:22 +00:00
|
|
|
g.Expect(err).NotTo(HaveOccurred(), "failed cmd: "+cmd+" result: "+res)
|
2022-02-08 17:34:57 +00:00
|
|
|
g.Expect(res).Should(ContainSubstring("volume-test"))
|
|
|
|
g.Expect(res).Should(ContainSubstring("Running"))
|
|
|
|
}, "420s", "2s").Should(Succeed())
|
|
|
|
|
|
|
|
cmd := "kubectl --kubeconfig=" + kubeConfigFile + " exec volume-test -- sh -c 'echo local-path-test > /data/test'"
|
|
|
|
_, err = e2e.RunCommand(cmd)
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
cmd = "kubectl delete pod volume-test --kubeconfig=" + kubeConfigFile
|
2022-09-08 21:31:50 +00:00
|
|
|
res, err = e2e.RunCommand(cmd)
|
2022-08-15 22:00:22 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred(), "failed cmd: "+cmd+" result: "+res)
|
2022-02-08 17:34:57 +00:00
|
|
|
|
2022-08-05 16:16:10 +00:00
|
|
|
_, err = e2e.DeployWorkload("local-path-provisioner.yaml", kubeConfigFile, *hardened)
|
2022-02-08 17:34:57 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred(), "local-path-provisioner manifest not deployed")
|
|
|
|
|
|
|
|
Eventually(func(g Gomega) {
|
|
|
|
cmd := "kubectl get pods -o=name -l app=local-path-provisioner --field-selector=status.phase=Running -n kube-system --kubeconfig=" + kubeConfigFile
|
|
|
|
res, _ := e2e.RunCommand(cmd)
|
|
|
|
g.Expect(res).Should(ContainSubstring("local-path-provisioner"))
|
|
|
|
}, "420s", "2s").Should(Succeed())
|
|
|
|
|
|
|
|
Eventually(func(g Gomega) {
|
|
|
|
cmd := "kubectl get pod volume-test --kubeconfig=" + kubeConfigFile
|
|
|
|
res, err := e2e.RunCommand(cmd)
|
2022-08-15 22:00:22 +00:00
|
|
|
g.Expect(err).NotTo(HaveOccurred(), "failed cmd: "+cmd+" result: "+res)
|
|
|
|
|
2022-02-08 17:34:57 +00:00
|
|
|
g.Expect(res).Should(ContainSubstring("volume-test"))
|
|
|
|
g.Expect(res).Should(ContainSubstring("Running"))
|
|
|
|
}, "420s", "2s").Should(Succeed())
|
|
|
|
|
|
|
|
Eventually(func(g Gomega) {
|
2022-08-15 22:00:22 +00:00
|
|
|
cmd := "kubectl exec volume-test --kubeconfig=" + kubeConfigFile + " -- cat /data/test"
|
2022-02-08 17:34:57 +00:00
|
|
|
res, err = e2e.RunCommand(cmd)
|
2022-08-15 22:00:22 +00:00
|
|
|
g.Expect(err).NotTo(HaveOccurred(), "failed cmd: "+cmd+" result: "+res)
|
2022-02-08 17:34:57 +00:00
|
|
|
fmt.Println("Data after re-creation", res)
|
|
|
|
g.Expect(res).Should(ContainSubstring("local-path-test"))
|
|
|
|
}, "180s", "2s").Should(Succeed())
|
2021-12-22 17:51:48 +00:00
|
|
|
})
|
|
|
|
})
|
2023-05-12 17:36:41 +00:00
|
|
|
|
|
|
|
Context("Validate restart", func() {
|
|
|
|
It("Restarts normally", func() {
|
|
|
|
errRestart := e2e.RestartCluster(append(serverNodeNames, agentNodeNames...))
|
|
|
|
Expect(errRestart).NotTo(HaveOccurred(), "Restart Nodes not happened correctly")
|
|
|
|
|
|
|
|
Eventually(func(g Gomega) {
|
|
|
|
nodes, err := e2e.ParseNodes(kubeConfigFile, false)
|
|
|
|
g.Expect(err).NotTo(HaveOccurred())
|
|
|
|
for _, node := range nodes {
|
|
|
|
g.Expect(node.Status).Should(Equal("Ready"))
|
|
|
|
}
|
|
|
|
pods, _ := e2e.ParsePods(kubeConfigFile, false)
|
|
|
|
count := e2e.CountOfStringInSlice("test-daemonset", pods)
|
|
|
|
g.Expect(len(nodes)).Should((Equal(count)), "Daemonset pod count does not match node count")
|
|
|
|
podsRunningAr := 0
|
|
|
|
for _, pod := range pods {
|
|
|
|
if strings.Contains(pod.Name, "test-daemonset") && pod.Status == "Running" && pod.Ready == "1/1" {
|
|
|
|
podsRunningAr++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g.Expect(len(nodes)).Should((Equal(podsRunningAr)), "Daemonset pods are not running after the restart")
|
|
|
|
}, "620s", "5s").Should(Succeed())
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Context("Valdiate Certificate Rotation", func() {
|
|
|
|
It("Stops K3s and rotates certificates", func() {
|
|
|
|
errStop := e2e.StopCluster(serverNodeNames)
|
2023-06-12 08:24:30 +00:00
|
|
|
Expect(errStop).NotTo(HaveOccurred(), "Cluster could not be stopped successfully")
|
2023-05-12 17:36:41 +00:00
|
|
|
|
|
|
|
for _, nodeName := range serverNodeNames {
|
2023-06-07 23:03:36 +00:00
|
|
|
cmd := "k3s certificate rotate"
|
2023-11-17 20:02:42 +00:00
|
|
|
_, err := e2e.RunCmdOnNode(cmd, nodeName)
|
|
|
|
Expect(err).NotTo(HaveOccurred(), "Certificate could not be rotated successfully on "+nodeName)
|
2023-05-12 17:36:41 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
It("Start normally", func() {
|
|
|
|
// Since we stopped all the server, we have to start 2 at once to get it back up
|
|
|
|
// If we only start one at a time, the first will hang waiting for the second to be up
|
2023-06-07 23:03:36 +00:00
|
|
|
_, err := e2e.RunCmdOnNode("systemctl --no-block start k3s", serverNodeNames[0])
|
2023-05-12 17:36:41 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
err = e2e.StartCluster(serverNodeNames[1:])
|
|
|
|
Expect(err).NotTo(HaveOccurred(), "Cluster could not be started successfully")
|
|
|
|
|
|
|
|
Eventually(func(g Gomega) {
|
2023-11-17 20:02:42 +00:00
|
|
|
for _, nodeName := range serverNodeNames {
|
|
|
|
cmd := "test ! -e /var/lib/rancher/k3s/server/tls/dynamic-cert-regenerate"
|
|
|
|
_, err := e2e.RunCmdOnNode(cmd, nodeName)
|
|
|
|
Expect(err).NotTo(HaveOccurred(), "Dynamic cert regenerate file not removed on "+nodeName)
|
2023-05-12 17:36:41 +00:00
|
|
|
}
|
|
|
|
}, "620s", "5s").Should(Succeed())
|
|
|
|
|
|
|
|
Eventually(func(g Gomega) {
|
|
|
|
pods, err := e2e.ParsePods(kubeConfigFile, false)
|
|
|
|
g.Expect(err).NotTo(HaveOccurred())
|
|
|
|
for _, pod := range pods {
|
|
|
|
if strings.Contains(pod.Name, "helm-install") {
|
|
|
|
g.Expect(pod.Status).Should(Equal("Completed"), pod.Name)
|
|
|
|
} else {
|
|
|
|
g.Expect(pod.Status).Should(Equal("Running"), pod.Name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, "620s", "5s").Should(Succeed())
|
|
|
|
})
|
2023-11-17 20:02:42 +00:00
|
|
|
|
2023-05-12 17:36:41 +00:00
|
|
|
It("Validates certificates", func() {
|
2023-06-07 23:03:36 +00:00
|
|
|
const grepCert = "ls -lt /var/lib/rancher/k3s/server/ | grep tls"
|
2023-11-17 20:02:42 +00:00
|
|
|
// This is a list of files that should be IDENTICAL after certificates are rotated.
|
|
|
|
// Everything else should be changed.
|
2023-05-26 23:37:13 +00:00
|
|
|
var expectResult = []string{
|
|
|
|
"client-ca.crt", "client-ca.key", "client-ca.nochain.crt",
|
2023-11-17 20:02:42 +00:00
|
|
|
"peer-ca.crt", "peer-ca.key",
|
|
|
|
"server-ca.crt", "server-ca.key",
|
|
|
|
"request-header-ca.crt", "request-header-ca.key",
|
|
|
|
"server-ca.crt", "server-ca.key", "server-ca.nochain.crt",
|
2023-05-12 17:36:41 +00:00
|
|
|
"service.current.key", "service.key",
|
2023-05-26 23:37:13 +00:00
|
|
|
"apiserver-loopback-client__.crt", "apiserver-loopback-client__.key",
|
|
|
|
"",
|
2023-05-12 17:36:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, nodeName := range serverNodeNames {
|
|
|
|
grCert, errGrep := e2e.RunCmdOnNode(grepCert, nodeName)
|
2023-11-17 20:02:42 +00:00
|
|
|
Expect(errGrep).NotTo(HaveOccurred(), "TLS dirs could not be listed on "+nodeName)
|
2023-05-12 17:36:41 +00:00
|
|
|
re := regexp.MustCompile("tls-[0-9]+")
|
|
|
|
tls := re.FindAllString(grCert, -1)[0]
|
2023-11-17 20:02:42 +00:00
|
|
|
diff := fmt.Sprintf("diff -sr /var/lib/rancher/k3s/server/tls/ /var/lib/rancher/k3s/server/%s/"+
|
2023-05-12 17:36:41 +00:00
|
|
|
"| grep -i identical | cut -f4 -d ' ' | xargs basename -a \n", tls)
|
2023-11-17 20:02:42 +00:00
|
|
|
result, err := e2e.RunCmdOnNode(diff, nodeName)
|
|
|
|
Expect(err).NotTo(HaveOccurred(), "Certificate diff not created successfully on "+nodeName)
|
|
|
|
|
|
|
|
certArray := strings.Split(result, "\n")
|
|
|
|
Expect((certArray)).Should((Equal(expectResult)), "Certificate diff does not match the expected results on "+nodeName)
|
2023-05-12 17:36:41 +00:00
|
|
|
}
|
2023-11-17 20:02:42 +00:00
|
|
|
|
2023-05-12 17:36:41 +00:00
|
|
|
errRestartAgent := e2e.RestartCluster(agentNodeNames)
|
|
|
|
Expect(errRestartAgent).NotTo(HaveOccurred(), "Agent could not be restart successfully")
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
2021-12-22 17:51:48 +00:00
|
|
|
})
|
|
|
|
|
2022-11-04 23:07:12 +00:00
|
|
|
var failed bool
|
2021-12-22 17:51:48 +00:00
|
|
|
var _ = AfterEach(func() {
|
2022-09-08 21:31:50 +00:00
|
|
|
failed = failed || CurrentSpecReport().Failed()
|
2021-12-22 17:51:48 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
var _ = AfterSuite(func() {
|
2024-03-05 20:17:20 +00:00
|
|
|
if !failed {
|
2023-08-01 16:32:34 +00:00
|
|
|
Expect(e2e.GetCoverageReport(append(serverNodeNames, agentNodeNames...))).To(Succeed())
|
2024-03-05 20:17:20 +00:00
|
|
|
}
|
|
|
|
if !failed || *ci {
|
2021-12-22 17:51:48 +00:00
|
|
|
Expect(e2e.DestroyCluster()).To(Succeed())
|
|
|
|
Expect(os.Remove(kubeConfigFile)).To(Succeed())
|
|
|
|
}
|
|
|
|
})
|