|
| 1 | +// This test verifies that two nodes, which can't connect using the local network, are |
| 2 | +// able to still connect using the node-external-ip. In real life, node-external-ip |
| 3 | +// would be a public IP. In the test, we create two networks, one sets the node |
| 4 | +// internal-ip and the other sets the node-external-ip. Traffic is blocked on the former |
| 5 | + |
| 6 | +package multus |
| 7 | + |
| 8 | +import ( |
| 9 | + "flag" |
| 10 | + "fmt" |
| 11 | + "os" |
| 12 | + "testing" |
| 13 | + "time" |
| 14 | + |
| 15 | + "github.com/k3s-io/k3s/tests" |
| 16 | + "github.com/k3s-io/k3s/tests/e2e" |
| 17 | + . "github.com/onsi/ginkgo/v2" |
| 18 | + . "github.com/onsi/gomega" |
| 19 | +) |
| 20 | + |
| 21 | +// Valid nodeOS: bento/ubuntu-24.04, opensuse/Leap-15.6.x86_64 |
| 22 | +var nodeOS = flag.String("nodeOS", "bento/ubuntu-24.04", "VM operating system") |
| 23 | +var serverCount = flag.Int("serverCount", 1, "number of server nodes") |
| 24 | +var agentCount = flag.Int("agentCount", 1, "number of agent nodes") |
| 25 | +var ci = flag.Bool("ci", false, "running on CI") |
| 26 | +var local = flag.Bool("local", false, "deploy a locally built K3s binary") |
| 27 | + |
| 28 | +func Test_E2EMultus(t *testing.T) { |
| 29 | + flag.Parse() |
| 30 | + RegisterFailHandler(Fail) |
| 31 | + suiteConfig, reporterConfig := GinkgoConfiguration() |
| 32 | + RunSpecs(t, "Multus config Suite", suiteConfig, reporterConfig) |
| 33 | + |
| 34 | +} |
| 35 | + |
| 36 | +var tc *e2e.TestConfig |
| 37 | + |
| 38 | +var _ = ReportAfterEach(e2e.GenReport) |
| 39 | + |
| 40 | +var _ = Describe("Verify Multus config", Ordered, func() { |
| 41 | + Context("Cluster comes up with Multus enabled", func() { |
| 42 | + It("Starts up with no issues", func() { |
| 43 | + var err error |
| 44 | + if *local { |
| 45 | + tc, err = e2e.CreateLocalCluster(*nodeOS, *serverCount, *agentCount) |
| 46 | + } else { |
| 47 | + tc, err = e2e.CreateCluster(*nodeOS, *serverCount, *agentCount) |
| 48 | + } |
| 49 | + Expect(err).NotTo(HaveOccurred(), e2e.GetVagrantLog(err)) |
| 50 | + By("CLUSTER CONFIG") |
| 51 | + By("OS: " + *nodeOS) |
| 52 | + By(tc.Status()) |
| 53 | + }) |
| 54 | + |
| 55 | + It("Checks Node Status", func() { |
| 56 | + Eventually(func() error { |
| 57 | + return tests.NodesReady(tc.KubeconfigFile, e2e.VagrantSlice(tc.AllNodes())) |
| 58 | + }, "620s", "5s").Should(Succeed()) |
| 59 | + e2e.DumpNodes(tc.KubeconfigFile) |
| 60 | + }) |
| 61 | + |
| 62 | + It("Checks pod status", func() { |
| 63 | + By("Fetching pod status") |
| 64 | + Eventually(func() error { |
| 65 | + return tests.AllPodsUp(tc.KubeconfigFile, "kube-system") |
| 66 | + }, "620s", "10s").Should(Succeed()) |
| 67 | + }) |
| 68 | + }) |
| 69 | + Context("Deploy workloads to check cluster connectivity of the nodes", func() { |
| 70 | + It("Verifies that each node has vagrant IP", func() { |
| 71 | + nodeIPs, err := e2e.GetNodeIPs(tc.KubeconfigFile) |
| 72 | + fmt.Printf("nodeIPs: %v", nodeIPs) |
| 73 | + Expect(err).NotTo(HaveOccurred()) |
| 74 | + for _, node := range nodeIPs { |
| 75 | + Expect(node.IPv4).Should(ContainSubstring("10.10.")) |
| 76 | + } |
| 77 | + }) |
| 78 | + It("Verifies that each pod has vagrant IP or clusterCIDR IP", func() { |
| 79 | + podIPs, err := e2e.GetPodIPs(tc.KubeconfigFile) |
| 80 | + Expect(err).NotTo(HaveOccurred()) |
| 81 | + for _, pod := range podIPs { |
| 82 | + Expect(pod.IPv4).Should(Or(ContainSubstring("10.10."), ContainSubstring("10.42.")), pod.Name) |
| 83 | + } |
| 84 | + }) |
| 85 | + It("Verifies multus daemonset comes up", func() { |
| 86 | + Eventually(func() (string, error) { |
| 87 | + cmd := "kubectl get ds multus -n kube-system -o jsonpath='{.status.numberReady}' --kubeconfig=" + tc.KubeconfigFile |
| 88 | + return e2e.RunCommand(cmd) |
| 89 | + }, "120s", "5s").Should(ContainSubstring("2")) |
| 90 | + }) |
| 91 | + It("Deploys Multus NetworkAttachmentDefinition and test pods", func() { |
| 92 | + _, err := tc.DeployWorkload("multus_test.yaml") |
| 93 | + Expect(err).NotTo(HaveOccurred()) |
| 94 | + time.Sleep(5 * time.Second) |
| 95 | + }) |
| 96 | + It("Verifies internode connectivity over multus network", func() { |
| 97 | + cmd := "kubectl exec pod-macvlan --kubeconfig=" + tc.KubeconfigFile + " -- ping -c 1 -w 2 10.1.1.102" |
| 98 | + Eventually(func() (string, error) { |
| 99 | + return e2e.RunCommand(cmd) |
| 100 | + }, "20s", "3s").Should(ContainSubstring("0% packet loss"), "failed cmd: "+cmd) |
| 101 | + }) |
| 102 | + }) |
| 103 | +}) |
| 104 | + |
| 105 | +var failed bool |
| 106 | +var _ = AfterEach(func() { |
| 107 | + failed = failed || CurrentSpecReport().Failed() |
| 108 | +}) |
| 109 | + |
| 110 | +var _ = AfterSuite(func() { |
| 111 | + if failed { |
| 112 | + Expect(e2e.SaveJournalLogs(tc.AllNodes())).To(Succeed()) |
| 113 | + Expect(e2e.TailPodLogs(50, tc.AllNodes())).To(Succeed()) |
| 114 | + } else { |
| 115 | + Expect(e2e.GetCoverageReport(tc.AllNodes())).To(Succeed()) |
| 116 | + } |
| 117 | + if !failed || *ci { |
| 118 | + Expect(e2e.DestroyCluster()).To(Succeed()) |
| 119 | + Expect(os.Remove(tc.KubeconfigFile)).To(Succeed()) |
| 120 | + } |
| 121 | +}) |
0 commit comments