github.phpd.cn/cilium/cilium@v1.6.12/test/k8sT/Health.go (about) 1 // Copyright 2018-2019 Authors of Cilium 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package k8sTest 16 17 import ( 18 "fmt" 19 20 . "github.com/cilium/cilium/test/ginkgo-ext" 21 "github.com/cilium/cilium/test/helpers" 22 23 . "github.com/onsi/gomega" 24 ) 25 26 var _ = Describe("K8sHealthTest", func() { 27 28 var ( 29 kubectl *helpers.Kubectl 30 ) 31 32 BeforeAll(func() { 33 kubectl = helpers.CreateKubectl(helpers.K8s1VMName(), logger) 34 DeployCiliumAndDNS(kubectl) 35 }) 36 37 AfterFailed(func() { 38 kubectl.CiliumReport(helpers.KubeSystemNamespace, 39 "cilium endpoint list") 40 }) 41 42 JustAfterEach(func() { 43 kubectl.ValidateNoErrorsInLogs(CurrentGinkgoTestDescription().Duration) 44 }) 45 46 AfterEach(func() { 47 ExpectAllPodsTerminated(kubectl) 48 }) 49 50 AfterAll(func() { 51 kubectl.CloseSSHClient() 52 }) 53 54 getCilium := func(node string) (pod, ip string) { 55 pod, err := kubectl.GetCiliumPodOnNode(helpers.KubeSystemNamespace, node) 56 Expect(err).Should(BeNil()) 57 58 res, err := kubectl.Get( 59 helpers.KubeSystemNamespace, 60 fmt.Sprintf("pod %s", pod)).Filter("{.status.podIP}") 61 Expect(err).Should(BeNil()) 62 ip = res.String() 63 64 return pod, ip 65 } 66 67 checkIP := func(pod, ip string) { 68 jsonpath := fmt.Sprintf("{.nodes[*].host.primary-address.ip}") 69 ciliumCmd := fmt.Sprintf("cilium-health status -o jsonpath='%s'", jsonpath) 70 71 err := kubectl.CiliumExecUntilMatch(pod, ciliumCmd, ip) 72 ExpectWithOffset(1, err).NotTo(HaveOccurred(), "Never saw cilium-health ip %s in pod %s", ip, pod) 73 } 74 75 It("checks cilium-health status between nodes", func() { 76 SkipIfFlannel() 77 78 cilium1, cilium1IP := getCilium(helpers.K8s1) 79 cilium2, cilium2IP := getCilium(helpers.K8s2) 80 81 By("checking that cilium API exposes health instances") 82 checkIP(cilium1, cilium1IP) 83 checkIP(cilium1, cilium2IP) 84 checkIP(cilium2, cilium1IP) 85 checkIP(cilium2, cilium2IP) 86 87 By("checking that `cilium-health --probe` succeeds") 88 healthCmd := fmt.Sprintf("cilium-health status --probe -o json") 89 status := kubectl.CiliumExec(cilium1, healthCmd) 90 Expect(status.Output()).ShouldNot(ContainSubstring("error")) 91 status.ExpectSuccess() 92 93 apiPaths := []string{ 94 "endpoint.icmp", 95 "endpoint.http", 96 "host.primary-address.icmp", 97 "host.primary-address.http", 98 } 99 for node := 0; node <= 1; node++ { 100 healthCmd := "cilium-health status -o json" 101 status := kubectl.CiliumExec(cilium1, healthCmd) 102 status.ExpectSuccess("Cannot retrieve health status") 103 for _, path := range apiPaths { 104 filter := fmt.Sprintf("{.nodes[%d].%s}", node, path) 105 By("checking API response for %q", filter) 106 data, err := status.Filter(filter) 107 Expect(err).To(BeNil(), "cannot retrieve filter %q from health output", filter) 108 Expect(data.String()).Should(Not((BeEmpty()))) 109 statusFilter := fmt.Sprintf("{.nodes[%d].%s.status}", node, path) 110 By("checking API status response for %q", statusFilter) 111 data, err = status.Filter(statusFilter) 112 Expect(err).To(BeNil(), "cannot retrieve filter %q from health output", statusFilter) 113 Expect(data.String()).Should(BeEmpty()) 114 } 115 } 116 }, 30) 117 })