mirror of https://github.com/k3s-io/k3s
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
526 lines
21 KiB
526 lines
21 KiB
2 years ago
|
package upgradecluster
|
||
2 years ago
|
|
||
|
import (
|
||
|
"flag"
|
||
|
"fmt"
|
||
|
"strings"
|
||
|
"testing"
|
||
|
|
||
2 years ago
|
tf "github.com/k3s-io/k3s/tests/terraform"
|
||
|
cc "github.com/k3s-io/k3s/tests/terraform/createcluster"
|
||
2 years ago
|
. "github.com/onsi/ginkgo/v2"
|
||
|
. "github.com/onsi/gomega"
|
||
|
)
|
||
|
|
||
|
var upgradeVersion = flag.String("upgrade_version", "", "a string")
|
||
2 years ago
|
var awsAmi = flag.String("aws_ami", "", "a valid ami string like ami-abcxyz123")
|
||
|
var nodeOs = flag.String("node_os", "ubuntu", "a string")
|
||
|
var externalDb = flag.String("external_db", "mysql", "a string")
|
||
|
var arch = flag.String("arch", "amd64", "a string")
|
||
|
var clusterType = flag.String("cluster_type", "etcd", "a string")
|
||
|
var resourceName = flag.String("resource_name", "etcd", "a string")
|
||
|
var sshuser = flag.String("sshuser", "ubuntu", "a string")
|
||
|
var sshkey = flag.String("sshkey", "", "a string")
|
||
|
var accessKey = flag.String("access_key", "", "local path to the private sshkey")
|
||
|
var serverNodes = flag.Int("no_of_server_nodes", 2, "count of server nodes")
|
||
|
var workerNodes = flag.Int("no_of_worker_nodes", 1, "count of worker nodes")
|
||
|
|
||
|
var tfVars = flag.String("tfvars", "/tests/terraform/modules/k3scluster/config/local.tfvars", "custom .tfvars file from base project path")
|
||
|
var destroy = flag.Bool("destroy", false, "a bool")
|
||
|
|
||
|
var failed = false
|
||
|
var terraformOptions map[string]interface{}
|
||
2 years ago
|
|
||
2 years ago
|
func Test_TFClusterUpgradeValidation(t *testing.T) {
|
||
2 years ago
|
RegisterFailHandler(Fail)
|
||
|
flag.Parse()
|
||
|
RunSpecs(t, "Upgrade Cluster Test Suite")
|
||
|
}
|
||
|
|
||
2 years ago
|
var _ = BeforeSuite(func() {
|
||
|
terraformOptions = cc.ClusterOptions(cc.NodeOs(*nodeOs), cc.AwsAmi(*awsAmi), cc.ClusterType(*clusterType), cc.ExternalDb(*externalDb), cc.ResourceName(*resourceName), cc.AccessKey(*accessKey), cc.Sshuser(*sshuser), cc.ServerNodes(*serverNodes), cc.WorkerNodes(*workerNodes), cc.Sshkey(*sshkey))
|
||
|
})
|
||
|
|
||
2 years ago
|
var _ = Describe("Test:", func() {
|
||
|
Context("Build Cluster:", func() {
|
||
|
It("Starts up with no issues", func() {
|
||
2 years ago
|
status, err := cc.BuildCluster(&testing.T{}, *tfVars, false, terraformOptions)
|
||
2 years ago
|
Expect(err).NotTo(HaveOccurred())
|
||
2 years ago
|
Expect(status).To(Equal("cluster created"))
|
||
2 years ago
|
defer GinkgoRecover()
|
||
2 years ago
|
if strings.Contains(*clusterType, "etcd") {
|
||
|
fmt.Println("\nCLUSTER CONFIG:\nOS", *nodeOs, "\nBACKEND", *clusterType)
|
||
|
} else {
|
||
|
fmt.Println("\nCLUSTER CONFIG:\nOS", *nodeOs, "\nBACKEND", *externalDb)
|
||
|
}
|
||
2 years ago
|
fmt.Printf("\nIPs:\n")
|
||
2 years ago
|
fmt.Println("Server Node IPS:", cc.MasterIPs)
|
||
|
fmt.Println("Agent Node IPS:", cc.WorkerIPs)
|
||
|
fmt.Println(cc.KubeConfigFile)
|
||
|
Expect(cc.KubeConfigFile).Should(ContainSubstring(*resourceName))
|
||
2 years ago
|
})
|
||
|
|
||
|
It("Checks Node and Pod Status", func() {
|
||
2 years ago
|
defer func() {
|
||
|
_, err := tf.ParseNodes(cc.KubeConfigFile, true)
|
||
|
if err != nil {
|
||
|
fmt.Println("Error retrieving nodes: ", err)
|
||
|
}
|
||
|
_, err = tf.ParsePods(cc.KubeConfigFile, true)
|
||
|
if err != nil {
|
||
|
fmt.Println("Error retrieving pods: ", err)
|
||
|
}
|
||
|
}()
|
||
|
|
||
2 years ago
|
fmt.Printf("\nFetching node status\n")
|
||
2 years ago
|
expectedNodeCount := *serverNodes + *workerNodes + 1
|
||
2 years ago
|
Eventually(func(g Gomega) {
|
||
2 years ago
|
nodes, err := tf.ParseNodes(cc.KubeConfigFile, false)
|
||
2 years ago
|
g.Expect(err).NotTo(HaveOccurred())
|
||
2 years ago
|
g.Expect(len(nodes)).To(Equal(expectedNodeCount), "Number of nodes should match the spec")
|
||
2 years ago
|
for _, node := range nodes {
|
||
2 years ago
|
g.Expect(node.Status).Should(Equal("Ready"), "Nodes should all be in Ready state")
|
||
2 years ago
|
}
|
||
|
}, "420s", "5s").Should(Succeed())
|
||
|
|
||
2 years ago
|
fmt.Printf("\nFetching pod status\n")
|
||
2 years ago
|
Eventually(func(g Gomega) {
|
||
2 years ago
|
pods, err := tf.ParsePods(cc.KubeConfigFile, false)
|
||
2 years ago
|
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)
|
||
2 years ago
|
g.Expect(pod.Restarts).Should(Equal("0"), pod.Name)
|
||
2 years ago
|
}
|
||
|
}
|
||
2 years ago
|
}, "600s", "5s").Should(Succeed())
|
||
2 years ago
|
})
|
||
|
|
||
|
It("Verifies ClusterIP Service", func() {
|
||
2 years ago
|
_, err := tf.DeployWorkload("clusterip.yaml", cc.KubeConfigFile, *arch)
|
||
2 years ago
|
Expect(err).NotTo(HaveOccurred(), "Cluster IP manifest not deployed")
|
||
|
|
||
|
Eventually(func(g Gomega) {
|
||
2 years ago
|
cmd := "kubectl get pods -o=name -l k8s-app=nginx-app-clusterip --field-selector=status.phase=Running --kubeconfig=" + cc.KubeConfigFile
|
||
|
res, err := tf.RunCommand(cmd)
|
||
2 years ago
|
g.Expect(err).NotTo(HaveOccurred())
|
||
|
g.Expect(res).Should((ContainSubstring("test-clusterip")))
|
||
|
}, "420s", "5s").Should(Succeed())
|
||
|
|
||
2 years ago
|
clusterip, _ := tf.FetchClusterIP(cc.KubeConfigFile, "nginx-clusterip-svc")
|
||
|
cmd := "curl -sL --insecure http://" + clusterip + "/name.html"
|
||
|
nodeExternalIP := tf.FetchNodeExternalIP(cc.KubeConfigFile)
|
||
2 years ago
|
for _, ip := range nodeExternalIP {
|
||
|
Eventually(func(g Gomega) {
|
||
2 years ago
|
res, err := tf.RunCmdOnNode(cmd, ip, *sshuser, *accessKey)
|
||
2 years ago
|
g.Expect(err).NotTo(HaveOccurred())
|
||
|
g.Expect(res).Should(ContainSubstring("test-clusterip"))
|
||
|
}, "420s", "10s").Should(Succeed())
|
||
|
}
|
||
|
})
|
||
|
|
||
|
It("Verifies NodePort Service", func() {
|
||
2 years ago
|
_, err := tf.DeployWorkload("nodeport.yaml", cc.KubeConfigFile, *arch)
|
||
2 years ago
|
Expect(err).NotTo(HaveOccurred(), "NodePort manifest not deployed")
|
||
2 years ago
|
nodeExternalIP := tf.FetchNodeExternalIP(cc.KubeConfigFile)
|
||
|
cmd := "kubectl get service nginx-nodeport-svc --kubeconfig=" + cc.KubeConfigFile + " --output jsonpath=\"{.spec.ports[0].nodePort}\""
|
||
|
nodeport, err := tf.RunCommand(cmd)
|
||
2 years ago
|
Expect(err).NotTo(HaveOccurred())
|
||
|
|
||
|
for _, ip := range nodeExternalIP {
|
||
|
Eventually(func(g Gomega) {
|
||
2 years ago
|
cmd := "kubectl get pods -o=name -l k8s-app=nginx-app-nodeport --field-selector=status.phase=Running --kubeconfig=" + cc.KubeConfigFile
|
||
|
res, err := tf.RunCommand(cmd)
|
||
2 years ago
|
g.Expect(err).NotTo(HaveOccurred())
|
||
|
g.Expect(res).Should(ContainSubstring("test-nodeport"))
|
||
|
}, "240s", "5s").Should(Succeed())
|
||
|
|
||
2 years ago
|
cmd = "curl -sL --insecure http://" + ip + ":" + nodeport + "/name.html"
|
||
2 years ago
|
Eventually(func(g Gomega) {
|
||
2 years ago
|
res, err := tf.RunCommand(cmd)
|
||
2 years ago
|
g.Expect(err).NotTo(HaveOccurred())
|
||
|
g.Expect(res).Should(ContainSubstring("test-nodeport"))
|
||
|
}, "240s", "5s").Should(Succeed())
|
||
|
}
|
||
|
})
|
||
|
|
||
|
It("Verifies LoadBalancer Service", func() {
|
||
2 years ago
|
_, err := tf.DeployWorkload("loadbalancer.yaml", cc.KubeConfigFile, *arch)
|
||
2 years ago
|
Expect(err).NotTo(HaveOccurred(), "Loadbalancer manifest not deployed")
|
||
2 years ago
|
nodeExternalIP := tf.FetchNodeExternalIP(cc.KubeConfigFile)
|
||
|
cmd := "kubectl get service nginx-loadbalancer-svc --kubeconfig=" + cc.KubeConfigFile + " --output jsonpath=\"{.spec.ports[0].port}\""
|
||
|
port, err := tf.RunCommand(cmd)
|
||
2 years ago
|
Expect(err).NotTo(HaveOccurred())
|
||
|
for _, ip := range nodeExternalIP {
|
||
|
|
||
|
Eventually(func(g Gomega) {
|
||
2 years ago
|
cmd := "kubectl get pods -o=name -l k8s-app=nginx-app-loadbalancer --field-selector=status.phase=Running --kubeconfig=" + cc.KubeConfigFile
|
||
|
res, err := tf.RunCommand(cmd)
|
||
2 years ago
|
g.Expect(err).NotTo(HaveOccurred())
|
||
|
g.Expect(res).Should(ContainSubstring("test-loadbalancer"))
|
||
|
}, "240s", "5s").Should(Succeed())
|
||
|
|
||
|
Eventually(func(g Gomega) {
|
||
2 years ago
|
cmd = "curl -sL --insecure http://" + ip + ":" + port + "/name.html"
|
||
|
res, err := tf.RunCommand(cmd)
|
||
2 years ago
|
g.Expect(err).NotTo(HaveOccurred())
|
||
|
g.Expect(res).Should(ContainSubstring("test-loadbalancer"))
|
||
|
}, "240s", "5s").Should(Succeed())
|
||
|
}
|
||
|
})
|
||
|
|
||
|
It("Verifies Ingress", func() {
|
||
2 years ago
|
_, err := tf.DeployWorkload("ingress.yaml", cc.KubeConfigFile, *arch)
|
||
2 years ago
|
Expect(err).NotTo(HaveOccurred(), "Ingress manifest not deployed")
|
||
|
|
||
|
Eventually(func(g Gomega) {
|
||
2 years ago
|
cmd := "kubectl get pods -o=name -l k8s-app=nginx-app-ingress --field-selector=status.phase=Running --kubeconfig=" + cc.KubeConfigFile
|
||
|
res, err := tf.RunCommand(cmd)
|
||
2 years ago
|
g.Expect(err).NotTo(HaveOccurred())
|
||
|
g.Expect(res).Should(ContainSubstring("test-ingress"))
|
||
|
}, "240s", "5s").Should(Succeed())
|
||
|
|
||
2 years ago
|
ingressIps, err := tf.FetchIngressIP(cc.KubeConfigFile)
|
||
2 years ago
|
Expect(err).NotTo(HaveOccurred(), "Ingress ip is not returned")
|
||
|
|
||
|
for _, ip := range ingressIps {
|
||
2 years ago
|
cmd := "curl -s --header host:foo1.bar.com" + " http://" + ip + "/name.html"
|
||
2 years ago
|
Eventually(func(g Gomega) {
|
||
2 years ago
|
res, err := tf.RunCommand(cmd)
|
||
2 years ago
|
g.Expect(err).NotTo(HaveOccurred())
|
||
|
g.Expect(res).Should(ContainSubstring("test-ingress"))
|
||
|
}, "240s", "5s").Should(Succeed())
|
||
|
}
|
||
|
})
|
||
|
|
||
|
It("Verifies Daemonset", func() {
|
||
2 years ago
|
_, err := tf.DeployWorkload("daemonset.yaml", cc.KubeConfigFile, *arch)
|
||
2 years ago
|
Expect(err).NotTo(HaveOccurred(), "Daemonset manifest not deployed")
|
||
|
|
||
2 years ago
|
nodes, _ := tf.ParseNodes(cc.KubeConfigFile, false)
|
||
|
pods, _ := tf.ParsePods(cc.KubeConfigFile, false)
|
||
2 years ago
|
|
||
|
Eventually(func(g Gomega) {
|
||
2 years ago
|
count := tf.CountOfStringInSlice("test-daemonset", pods)
|
||
2 years ago
|
g.Expect(len(nodes)).Should((Equal(count)), "Daemonset pod count does not match node count")
|
||
|
}, "420s", "10s").Should(Succeed())
|
||
|
})
|
||
|
|
||
|
It("Verifies Local Path Provisioner storage ", func() {
|
||
2 years ago
|
_, err := tf.DeployWorkload("local-path-provisioner.yaml", cc.KubeConfigFile, *arch)
|
||
2 years ago
|
Expect(err).NotTo(HaveOccurred(), "local-path-provisioner manifest not deployed")
|
||
|
|
||
|
Eventually(func(g Gomega) {
|
||
2 years ago
|
cmd := "kubectl get pvc local-path-pvc --kubeconfig=" + cc.KubeConfigFile
|
||
|
res, err := tf.RunCommand(cmd)
|
||
2 years ago
|
g.Expect(err).NotTo(HaveOccurred())
|
||
|
g.Expect(res).Should(ContainSubstring("local-path-pvc"))
|
||
|
g.Expect(res).Should(ContainSubstring("Bound"))
|
||
|
}, "420s", "2s").Should(Succeed())
|
||
2 years ago
|
|
||
2 years ago
|
Eventually(func(g Gomega) {
|
||
2 years ago
|
cmd := "kubectl get pod volume-test --kubeconfig=" + cc.KubeConfigFile
|
||
|
res, err := tf.RunCommand(cmd)
|
||
2 years ago
|
Expect(err).NotTo(HaveOccurred())
|
||
|
g.Expect(res).Should(ContainSubstring("volume-test"))
|
||
|
g.Expect(res).Should(ContainSubstring("Running"))
|
||
|
}, "420s", "2s").Should(Succeed())
|
||
|
|
||
2 years ago
|
cmd := "kubectl --kubeconfig=" + cc.KubeConfigFile + " exec volume-test -- sh -c 'echo local-path-test > /data/test'"
|
||
|
_, err = tf.RunCommand(cmd)
|
||
2 years ago
|
Expect(err).NotTo(HaveOccurred())
|
||
|
|
||
2 years ago
|
cmd = "kubectl delete pod volume-test --kubeconfig=" + cc.KubeConfigFile
|
||
|
_, err = tf.RunCommand(cmd)
|
||
2 years ago
|
Expect(err).NotTo(HaveOccurred())
|
||
2 years ago
|
|
||
|
_, err = tf.DeployWorkload("local-path-provisioner.yaml", cc.KubeConfigFile, *arch)
|
||
2 years ago
|
Expect(err).NotTo(HaveOccurred(), "local-path-provisioner manifest not deployed")
|
||
|
|
||
|
Eventually(func(g Gomega) {
|
||
2 years ago
|
cmd := "kubectl get pods -o=name -l app=local-path-provisioner --field-selector=status.phase=Running -n kube-system --kubeconfig=" + cc.KubeConfigFile
|
||
|
res, err := tf.RunCommand(cmd)
|
||
|
Expect(err).NotTo(HaveOccurred())
|
||
2 years ago
|
g.Expect(res).Should(ContainSubstring("pod/local-path-provisioner"))
|
||
|
}, "420s", "2s").Should(Succeed())
|
||
|
|
||
|
Eventually(func(g Gomega) {
|
||
2 years ago
|
cmd := "kubectl get pod volume-test --kubeconfig=" + cc.KubeConfigFile
|
||
|
res, err := tf.RunCommand(cmd)
|
||
2 years ago
|
g.Expect(err).NotTo(HaveOccurred())
|
||
|
g.Expect(res).Should(ContainSubstring("volume-test"))
|
||
|
g.Expect(res).Should(ContainSubstring("Running"))
|
||
|
}, "420s", "2s").Should(Succeed())
|
||
|
|
||
|
Eventually(func(g Gomega) {
|
||
2 years ago
|
cmd = "kubectl exec volume-test --kubeconfig=" + cc.KubeConfigFile + " -- cat /data/test"
|
||
|
res, err := tf.RunCommand(cmd)
|
||
2 years ago
|
g.Expect(err).NotTo(HaveOccurred())
|
||
|
g.Expect(res).Should(ContainSubstring("local-path-test"))
|
||
|
}, "180s", "2s").Should(Succeed())
|
||
|
})
|
||
|
|
||
|
It("Verifies dns access", func() {
|
||
2 years ago
|
_, err := tf.DeployWorkload("dnsutils.yaml", cc.KubeConfigFile, *arch)
|
||
2 years ago
|
Expect(err).NotTo(HaveOccurred(), "dnsutils manifest not deployed")
|
||
|
|
||
|
Eventually(func(g Gomega) {
|
||
2 years ago
|
cmd := "kubectl get pods dnsutils --kubeconfig=" + cc.KubeConfigFile
|
||
|
res, _ := tf.RunCommand(cmd)
|
||
2 years ago
|
g.Expect(res).Should(ContainSubstring("dnsutils"))
|
||
|
g.Expect(res).Should(ContainSubstring("Running"))
|
||
|
}, "420s", "2s").Should(Succeed())
|
||
|
|
||
|
Eventually(func(g Gomega) {
|
||
2 years ago
|
cmd := "kubectl --kubeconfig=" + cc.KubeConfigFile + " exec -t dnsutils -- nslookup kubernetes.default"
|
||
|
res, _ := tf.RunCommand(cmd)
|
||
2 years ago
|
g.Expect(res).Should(ContainSubstring("kubernetes.default.svc.cluster.local"))
|
||
|
}, "420s", "2s").Should(Succeed())
|
||
|
})
|
||
|
|
||
2 years ago
|
It("Verify Cluster is upgraded", func() {
|
||
|
MIPs := strings.Split(cc.MasterIPs, ",")
|
||
2 years ago
|
for _, ip := range MIPs {
|
||
|
cmd := "sudo sed -i \"s/|/| INSTALL_K3S_VERSION=" + *upgradeVersion + "/g\" /tmp/master_cmd"
|
||
|
Eventually(func(g Gomega) {
|
||
2 years ago
|
_, err := tf.RunCmdOnNode(cmd, ip, *sshuser, *accessKey)
|
||
2 years ago
|
g.Expect(err).NotTo(HaveOccurred())
|
||
|
}, "420s", "2s").Should(Succeed())
|
||
|
|
||
|
cmd = "sudo chmod u+x /tmp/master_cmd && sudo /tmp/master_cmd"
|
||
|
fmt.Println(cmd)
|
||
|
Eventually(func(g Gomega) {
|
||
2 years ago
|
_, err := tf.RunCmdOnNode(cmd, ip, *sshuser, *accessKey)
|
||
2 years ago
|
g.Expect(err).NotTo(HaveOccurred())
|
||
|
}, "420s", "2s").Should(Succeed())
|
||
|
}
|
||
|
|
||
2 years ago
|
WIPs := strings.Split(cc.WorkerIPs, ",")
|
||
|
for _, ip := range WIPs {
|
||
|
// for i := 0; i < len(WIPs) && len(WIPs[0]) > 1; i++ {
|
||
|
// ip := WIPs[i]
|
||
|
// strings.TrimSpace(WIPs[i])
|
||
2 years ago
|
cmd := "sudo sed -i \"s/|/| INSTALL_K3S_VERSION=" + *upgradeVersion + "/g\" /tmp/agent_cmd"
|
||
|
Eventually(func(g Gomega) {
|
||
2 years ago
|
_, err := tf.RunCmdOnNode(cmd, ip, *sshuser, *accessKey)
|
||
2 years ago
|
g.Expect(err).NotTo(HaveOccurred())
|
||
|
}, "420s", "2s").Should(Succeed())
|
||
|
cmd = "sudo chmod u+x /tmp/agent_cmd && sudo /tmp/agent_cmd"
|
||
|
Eventually(func(g Gomega) {
|
||
2 years ago
|
_, err := tf.RunCmdOnNode(cmd, ip, *sshuser, *accessKey)
|
||
2 years ago
|
g.Expect(err).NotTo(HaveOccurred())
|
||
|
}, "420s", "2s").Should(Succeed())
|
||
|
}
|
||
|
})
|
||
|
|
||
|
It("Checks Node and Pod Status after upgrade", func() {
|
||
2 years ago
|
defer func() {
|
||
|
_, err := tf.ParseNodes(cc.KubeConfigFile, true)
|
||
|
if err != nil {
|
||
|
fmt.Println("Error retrieving nodes: ", err)
|
||
|
}
|
||
|
_, err = tf.ParsePods(cc.KubeConfigFile, true)
|
||
|
if err != nil {
|
||
|
fmt.Println("Error retrieving pods: ", err)
|
||
|
}
|
||
|
}()
|
||
|
|
||
|
fmt.Printf("\nFetching node status\n")
|
||
|
expectedNodeCount := *serverNodes + *workerNodes + 1
|
||
2 years ago
|
Eventually(func(g Gomega) {
|
||
2 years ago
|
nodes, err := tf.ParseNodes(cc.KubeConfigFile, false)
|
||
2 years ago
|
g.Expect(err).NotTo(HaveOccurred())
|
||
2 years ago
|
g.Expect(len(nodes)).To(Equal(expectedNodeCount), "Number of nodes should match the spec")
|
||
2 years ago
|
for _, node := range nodes {
|
||
2 years ago
|
g.Expect(node.Status).Should(Equal("Ready"), "Nodes should all be in Ready state")
|
||
2 years ago
|
g.Expect(node.Version).Should(ContainSubstring(*upgradeVersion))
|
||
|
}
|
||
|
}, "420s", "5s").Should(Succeed())
|
||
|
|
||
2 years ago
|
fmt.Printf("\nFetching pod status\n")
|
||
2 years ago
|
Eventually(func(g Gomega) {
|
||
2 years ago
|
pods, err := tf.ParsePods(cc.KubeConfigFile, false)
|
||
2 years ago
|
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)
|
||
|
}
|
||
|
}
|
||
2 years ago
|
}, "600s", "5s").Should(Succeed())
|
||
2 years ago
|
})
|
||
|
|
||
2 years ago
|
It("Verifies ClusterIP Service after upgrade", func() {
|
||
2 years ago
|
Eventually(func(g Gomega) {
|
||
2 years ago
|
cmd := "kubectl get pods -o=name -l k8s-app=nginx-app-clusterip --field-selector=status.phase=Running --kubeconfig=" + cc.KubeConfigFile
|
||
|
res, err := tf.RunCommand(cmd)
|
||
2 years ago
|
g.Expect(err).NotTo(HaveOccurred())
|
||
|
g.Expect(res).Should((ContainSubstring("test-clusterip")))
|
||
|
}, "420s", "5s").Should(Succeed())
|
||
|
|
||
2 years ago
|
clusterip, _ := tf.FetchClusterIP(cc.KubeConfigFile, "nginx-clusterip-svc")
|
||
|
cmd := "curl -sL --insecure http://" + clusterip + "/name.html"
|
||
|
nodeExternalIP := tf.FetchNodeExternalIP(cc.KubeConfigFile)
|
||
2 years ago
|
for _, ip := range nodeExternalIP {
|
||
|
Eventually(func(g Gomega) {
|
||
2 years ago
|
res, err := tf.RunCmdOnNode(cmd, ip, *sshuser, *accessKey)
|
||
2 years ago
|
g.Expect(err).NotTo(HaveOccurred())
|
||
|
g.Expect(res).Should(ContainSubstring("test-clusterip"))
|
||
|
|
||
|
}, "420s", "10s").Should(Succeed())
|
||
|
}
|
||
|
})
|
||
2 years ago
|
|
||
|
It("Verifies NodePort Service after upgrade", func() {
|
||
|
nodeExternalIP := tf.FetchNodeExternalIP(cc.KubeConfigFile)
|
||
|
cmd := "kubectl get service nginx-nodeport-svc --kubeconfig=" + cc.KubeConfigFile + " --output jsonpath=\"{.spec.ports[0].nodePort}\""
|
||
|
nodeport, err := tf.RunCommand(cmd)
|
||
2 years ago
|
Expect(err).NotTo(HaveOccurred())
|
||
|
|
||
|
for _, ip := range nodeExternalIP {
|
||
|
Eventually(func(g Gomega) {
|
||
2 years ago
|
cmd := "kubectl get pods -o=name -l k8s-app=nginx-app-nodeport --field-selector=status.phase=Running --kubeconfig=" + cc.KubeConfigFile
|
||
|
res, err := tf.RunCommand(cmd)
|
||
2 years ago
|
g.Expect(err).NotTo(HaveOccurred())
|
||
|
g.Expect(res).Should(ContainSubstring("test-nodeport"))
|
||
|
}, "240s", "5s").Should(Succeed())
|
||
|
|
||
|
cmd = "curl -L --insecure http://" + ip + ":" + nodeport + "/name.html"
|
||
|
Eventually(func(g Gomega) {
|
||
2 years ago
|
res, err := tf.RunCommand(cmd)
|
||
2 years ago
|
g.Expect(err).NotTo(HaveOccurred())
|
||
|
g.Expect(res).Should(ContainSubstring("test-nodeport"))
|
||
|
}, "240s", "5s").Should(Succeed())
|
||
|
}
|
||
|
})
|
||
2 years ago
|
|
||
|
It("Verifies LoadBalancer Service after upgrade", func() {
|
||
|
nodeExternalIP := tf.FetchNodeExternalIP(cc.KubeConfigFile)
|
||
|
cmd := "kubectl get service nginx-loadbalancer-svc --kubeconfig=" + cc.KubeConfigFile + " --output jsonpath=\"{.spec.ports[0].port}\""
|
||
|
port, err := tf.RunCommand(cmd)
|
||
2 years ago
|
Expect(err).NotTo(HaveOccurred())
|
||
|
for _, ip := range nodeExternalIP {
|
||
|
|
||
|
Eventually(func(g Gomega) {
|
||
2 years ago
|
cmd := "kubectl get pods -o=name -l k8s-app=nginx-app-loadbalancer --field-selector=status.phase=Running --kubeconfig=" + cc.KubeConfigFile
|
||
|
res, err := tf.RunCommand(cmd)
|
||
2 years ago
|
g.Expect(err).NotTo(HaveOccurred())
|
||
|
g.Expect(res).Should(ContainSubstring("test-loadbalancer"))
|
||
|
}, "240s", "5s").Should(Succeed())
|
||
|
|
||
|
Eventually(func(g Gomega) {
|
||
2 years ago
|
cmd = "curl -sL --insecure http://" + ip + ":" + port + "/name.html"
|
||
|
res, err := tf.RunCommand(cmd)
|
||
2 years ago
|
g.Expect(err).NotTo(HaveOccurred())
|
||
|
g.Expect(res).Should(ContainSubstring("test-loadbalancer"))
|
||
|
}, "240s", "5s").Should(Succeed())
|
||
|
}
|
||
|
})
|
||
|
|
||
2 years ago
|
It("Verifies Ingress after upgrade", func() {
|
||
2 years ago
|
Eventually(func(g Gomega) {
|
||
2 years ago
|
cmd := "kubectl get pods -o=name -l k8s-app=nginx-app-ingress --field-selector=status.phase=Running --kubeconfig=" + cc.KubeConfigFile
|
||
|
res, err := tf.RunCommand(cmd)
|
||
2 years ago
|
g.Expect(err).NotTo(HaveOccurred())
|
||
|
g.Expect(res).Should(ContainSubstring("test-ingress"))
|
||
|
}, "240s", "5s").Should(Succeed())
|
||
|
|
||
2 years ago
|
ingressIps, err := tf.FetchIngressIP(cc.KubeConfigFile)
|
||
2 years ago
|
Expect(err).NotTo(HaveOccurred(), "Ingress ip is not returned")
|
||
|
|
||
|
for _, ip := range ingressIps {
|
||
2 years ago
|
cmd := "curl -s --header host:foo1.bar.com" + " http://" + ip + "/name.html"
|
||
2 years ago
|
Eventually(func(g Gomega) {
|
||
2 years ago
|
res, err := tf.RunCommand(cmd)
|
||
2 years ago
|
g.Expect(err).NotTo(HaveOccurred())
|
||
|
g.Expect(res).Should(ContainSubstring("test-ingress"))
|
||
|
}, "240s", "5s").Should(Succeed())
|
||
|
}
|
||
|
})
|
||
|
|
||
2 years ago
|
It("Verifies Daemonset after upgrade", func() {
|
||
|
nodes, _ := tf.ParseNodes(cc.KubeConfigFile, false)
|
||
|
pods, _ := tf.ParsePods(cc.KubeConfigFile, false)
|
||
2 years ago
|
|
||
|
Eventually(func(g Gomega) {
|
||
2 years ago
|
count := tf.CountOfStringInSlice("test-daemonset", pods)
|
||
2 years ago
|
g.Expect(len(nodes)).Should((Equal(count)), "Daemonset pod count does not match node count")
|
||
|
}, "420s", "10s").Should(Succeed())
|
||
2 years ago
|
|
||
|
Eventually(func(g Gomega) {
|
||
|
for _, pod := range pods {
|
||
|
if strings.Contains(pod.Name, "test-daemonset") {
|
||
|
g.Expect(pod.Status).Should(Equal("Running"), pod.Name)
|
||
|
}
|
||
|
}
|
||
|
}, "240s", "5s").Should(Succeed())
|
||
2 years ago
|
})
|
||
|
|
||
|
It("Validating Local Path Provisioner storage after upgrade", func() {
|
||
|
Eventually(func(g Gomega) {
|
||
2 years ago
|
cmd := "kubectl get pods -o=name -l app=local-path-provisioner --field-selector=status.phase=Running -n kube-system --kubeconfig=" + cc.KubeConfigFile
|
||
|
res, err := tf.RunCommand(cmd)
|
||
|
Expect(err).NotTo(HaveOccurred())
|
||
2 years ago
|
g.Expect(res).Should(ContainSubstring("pod/local-path-provisioner"))
|
||
|
}, "420s", "2s").Should(Succeed())
|
||
|
|
||
|
Eventually(func(g Gomega) {
|
||
2 years ago
|
cmd := "kubectl get pod volume-test --kubeconfig=" + cc.KubeConfigFile
|
||
|
res, err := tf.RunCommand(cmd)
|
||
2 years ago
|
g.Expect(err).NotTo(HaveOccurred())
|
||
|
g.Expect(res).Should(ContainSubstring("volume-test"))
|
||
|
g.Expect(res).Should(ContainSubstring("Running"))
|
||
|
}, "420s", "2s").Should(Succeed())
|
||
|
|
||
|
Eventually(func(g Gomega) {
|
||
2 years ago
|
cmd := "kubectl exec volume-test --kubeconfig=" + cc.KubeConfigFile + " -- cat /data/test"
|
||
|
res, err := tf.RunCommand(cmd)
|
||
2 years ago
|
g.Expect(err).NotTo(HaveOccurred())
|
||
|
g.Expect(res).Should(ContainSubstring("local-path-test"))
|
||
|
}, "180s", "2s").Should(Succeed())
|
||
|
})
|
||
|
|
||
2 years ago
|
It("Verifies dns access after upgrade", func() {
|
||
2 years ago
|
Eventually(func(g Gomega) {
|
||
2 years ago
|
cmd := "kubectl get pods dnsutils --kubeconfig=" + cc.KubeConfigFile
|
||
|
res, _ := tf.RunCommand(cmd)
|
||
2 years ago
|
g.Expect(res).Should(ContainSubstring("dnsutils"))
|
||
|
g.Expect(res).Should(ContainSubstring("Running"))
|
||
|
}, "420s", "2s").Should(Succeed())
|
||
|
|
||
|
Eventually(func(g Gomega) {
|
||
2 years ago
|
cmd := "kubectl --kubeconfig=" + cc.KubeConfigFile + " exec -t dnsutils -- nslookup kubernetes.default"
|
||
|
res, _ := tf.RunCommand(cmd)
|
||
2 years ago
|
g.Expect(res).Should(ContainSubstring("kubernetes.default.svc.cluster.local"))
|
||
|
}, "420s", "2s").Should(Succeed())
|
||
|
})
|
||
|
})
|
||
|
})
|
||
|
|
||
|
var _ = AfterEach(func() {
|
||
2 years ago
|
failed = failed || CurrentSpecReport().Failed()
|
||
2 years ago
|
})
|
||
|
|
||
|
var _ = BeforeEach(func() {
|
||
2 years ago
|
failed = failed || CurrentSpecReport().Failed()
|
||
2 years ago
|
if *destroy {
|
||
|
Skip("Cluster is being Deleted")
|
||
|
}
|
||
|
})
|
||
2 years ago
|
|
||
2 years ago
|
var _ = AfterSuite(func() {
|
||
|
if failed {
|
||
|
fmt.Println("FAILED!")
|
||
|
} else {
|
||
|
fmt.Println("PASSED!")
|
||
|
}
|
||
|
if *destroy {
|
||
|
status, err := cc.BuildCluster(&testing.T{}, *tfVars, *destroy, terraformOptions)
|
||
|
Expect(err).NotTo(HaveOccurred())
|
||
|
Expect(status).To(Equal("cluster destroyed"))
|
||
|
}
|
||
|
})
|