github.phpd.cn/cilium/cilium@v1.6.12/test/k8sT/microscope.go (about) 1 // Copyright 2018 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 "time" 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("K8sMicroscope", func() { 27 var ( 28 kubectl *helpers.Kubectl 29 ) 30 31 BeforeAll(func() { 32 kubectl = helpers.CreateKubectl(helpers.K8s1VMName(), logger) 33 DeployCiliumAndDNS(kubectl) 34 }) 35 36 AfterFailed(func() { 37 kubectl.CiliumReport(helpers.KubeSystemNamespace, 38 "cilium endpoint list") 39 }) 40 41 AfterAll(func() { 42 ExpectAllPodsTerminated(kubectl) 43 kubectl.CloseSSHClient() 44 }) 45 46 It("Runs microscope", func() { 47 if !helpers.EnableMicroscope { 48 Skip("Microscope is disabled") 49 } 50 51 microscopeErr, microscopeCancel := kubectl.MicroscopeStart() 52 Expect(microscopeErr).To(BeNil(), "Microscope cannot be started") 53 54 err := helpers.WithTimeout(func() bool { 55 res := kubectl.ExecPodCmd("kube-system", "microscope", "pgrep -f microscope") 56 return res.WasSuccessful() 57 }, "running microscope processes not found", 58 &helpers.TimeoutConfig{ 59 Ticker: 5 * time.Second, 60 Timeout: 120 * time.Second, 61 }) 62 63 Expect(err).To(BeNil()) 64 65 kubectl.ValidateNoErrorsInLogs(CurrentGinkgoTestDescription().Duration) 66 Expect(microscopeCancel()).To(BeNil(), "cannot stop microscope") 67 68 err = helpers.WithTimeout(func() bool { 69 res := kubectl.ExecPodCmd("kube-system", "microscope", "pgrep -f microscope") 70 return !res.WasSuccessful() 71 }, "found running microscope processes; no microscope processes should be running", 72 &helpers.TimeoutConfig{ 73 Ticker: 5 * time.Second, 74 Timeout: 120 * time.Second, 75 }) 76 Expect(err).To(BeNil()) 77 }) 78 })