github.com/verrazzano/verrazzano@v1.7.1/tests/e2e/verify-analyze-tool/image/image_test.go (about) 1 // Copyright (c) 2023, 2024, Oracle and/or its affiliates. 2 // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 3 4 // This is an e2e test to plant image related issues and validates it 5 // Followed by reverting the issues to normal state and validates it 6 package image 7 8 import ( 9 "fmt" 10 "time" 11 12 . "github.com/onsi/ginkgo/v2" 13 . "github.com/onsi/gomega" 14 k8util "github.com/verrazzano/verrazzano/pkg/k8sutil" 15 "github.com/verrazzano/verrazzano/tests/e2e/pkg/test/framework" 16 utility "github.com/verrazzano/verrazzano/tests/e2e/verify-analyze-tool" 17 "k8s.io/client-go/kubernetes" 18 ) 19 20 var ( 21 waitTimeout = 10 * time.Second 22 pollingInterval = 10 * time.Second 23 ) 24 25 var t = framework.NewTestFramework("Vz Analysis Tool Image Issues") 26 27 var err error 28 var issuesToBeDiagnosed = []string{utility.ImagePullBackOff, utility.ImagePullNotFound} 29 var client = &kubernetes.Clientset{} 30 31 // Get the K8s Client to fetch deployment info 32 var _ = BeforeSuite(beforeSuite) 33 var beforeSuite = t.BeforeSuiteFunc(func() { 34 client, err = k8util.GetKubernetesClientset() 35 if err != nil { 36 Fail(err.Error()) 37 } 38 39 err := patch() 40 if err != nil { 41 Fail(fmt.Sprintf("error while patching verrazzano-related resources: %v", err.Error())) 42 } 43 }) 44 45 // patches an image for all the issues listed into 'issuesToBeDiagnosed' 46 func patch() error { 47 for i := 0; i < len(issuesToBeDiagnosed); i++ { 48 switch issuesToBeDiagnosed[i] { 49 case utility.ImagePullNotFound: 50 patchErr := utility.PatchImage(client, utility.DeploymentToBePatched, utility.ImagePullNotFound, "X") 51 if patchErr != nil { 52 return patchErr 53 } 54 case utility.ImagePullBackOff: 55 patchErr := utility.PatchImage(client, utility.DeploymentToBePatched, utility.ImagePullBackOff, "nginxx/nginx:1.14.0") 56 if patchErr != nil { 57 return patchErr 58 } 59 } 60 if i < len(issuesToBeDiagnosed)-1 { 61 time.Sleep(time.Second * 20) 62 } 63 } 64 return nil 65 } 66 67 var _ = t.Describe("VZ Tools", Label("f:vz-tools-image-issues"), func() { 68 t.Context("During Image Issue Analysis", func() { 69 t.It("Should Have ImagePullNotFound Issue Post Bad Image Injection", func() { 70 Eventually(func() bool { 71 return utility.VerifyIssue(utility.ReportAnalysis[utility.ImagePullNotFound][0], utility.ImagePullNotFound) 72 }, waitTimeout, pollingInterval).Should(BeTrue()) 73 }) 74 t.It("Should Not Have ImagePullNotFound Issue Post Reviving Bad Image", func() { 75 Eventually(func() bool { 76 return utility.VerifyIssue(utility.ReportAnalysis[utility.ImagePullNotFound][1], utility.ImagePullNotFound) 77 }, waitTimeout, pollingInterval).Should(BeFalse()) 78 }) 79 80 t.It("Should Have ImagePullBackOff Issue Post Bad Image Injection", func() { 81 Eventually(func() bool { 82 return utility.VerifyIssue(utility.ReportAnalysis[utility.ImagePullBackOff][0], utility.ImagePullBackOff) 83 }, waitTimeout, pollingInterval).Should(BeTrue()) 84 }) 85 t.It("Should Not Have ImagePullBackOff Issue Post Reviving Bad Image", func() { 86 Eventually(func() bool { 87 return utility.VerifyIssue(utility.ReportAnalysis[utility.ImagePullBackOff][1], utility.ImagePullBackOff) 88 }, waitTimeout, pollingInterval).Should(BeFalse()) 89 }) 90 }) 91 })