github.com/verrazzano/verrazzano@v1.7.1/tests/e2e/pkg/hello_helidon.go (about) 1 // Copyright (c) 2022, 2023, 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 package pkg 5 6 import ( 7 "fmt" 8 "time" 9 10 "github.com/onsi/gomega" 11 "github.com/verrazzano/verrazzano/pkg/k8s/resource" 12 v1 "k8s.io/api/core/v1" 13 "k8s.io/apimachinery/pkg/api/errors" 14 ) 15 16 const ( 17 helidonPollingInterval = 10 * time.Second 18 helidonWaitTimeout = 5 * time.Minute 19 ) 20 21 var expectedPodsHelloHelidon = []string{"hello-helidon-deployment"} 22 var helidonAppYaml = "examples/hello-helidon/hello-helidon-app.yaml" 23 var helidonComponentYaml = "examples/hello-helidon/hello-helidon-comp.yaml" 24 25 // DeployHelloHelidonApplication deploys the Hello Helidon example application. It accepts an optional 26 // OCI Log ID that is added as an annotation on the namespace to test the OCI Logging service integration. 27 func DeployHelloHelidonApplication(namespace string, ociLogID string, istioInjection string, customComponent string, customAppConfig string) { 28 Log(Info, "Deploy Hello Helidon Application") 29 Log(Info, fmt.Sprintf("Create namespace %s", namespace)) 30 31 // use custom Hello-Helidon Component if it is passed in 32 if customComponent != "" { 33 Log(Info, fmt.Sprintf("Deploying Hello Helidon with custom Component: %s", customComponent)) 34 helidonComponentYaml = customComponent 35 } 36 37 // use custom Hello-Helidon Application Configuration if it is passed in 38 if customAppConfig != "" { 39 Log(Info, fmt.Sprintf("Deploying Hello Helidon with custom Application Configuration: %s", customAppConfig)) 40 helidonAppYaml = customAppConfig 41 } 42 gomega.Eventually(func() (*v1.Namespace, error) { 43 nsLabels := map[string]string{ 44 "verrazzano-managed": "true", 45 "istio-injection": istioInjection} 46 47 var annotations map[string]string 48 if len(ociLogID) > 0 { 49 annotations = make(map[string]string) 50 annotations["verrazzano.io/oci-log-id"] = ociLogID 51 } 52 53 return CreateNamespaceWithAnnotations(namespace, nsLabels, annotations) 54 }, helidonWaitTimeout, helidonPollingInterval).ShouldNot(gomega.BeNil(), fmt.Sprintf("Failed to create namespace %s", namespace)) 55 56 Log(Info, "Create Hello Helidon component resource") 57 gomega.Eventually(func() error { 58 file, err := FindTestDataFile(helidonComponentYaml) 59 if err != nil { 60 return err 61 } 62 return resource.CreateOrUpdateResourceFromFileInGeneratedNamespace(file, namespace) 63 }, helidonWaitTimeout, helidonPollingInterval).ShouldNot(gomega.HaveOccurred(), "Failed to create hello-helidon component resource") 64 65 Log(Info, "Create Hello Helidon application resource") 66 gomega.Eventually(func() error { 67 file, err := FindTestDataFile(helidonAppYaml) 68 if err != nil { 69 return err 70 } 71 return resource.CreateOrUpdateResourceFromFileInGeneratedNamespace(file, namespace) 72 }, helidonWaitTimeout, helidonPollingInterval).ShouldNot(gomega.HaveOccurred(), "Failed to create hello-helidon application resource") 73 } 74 75 // UndeployHelloHelidonApplication undeploys the Hello Helidon example application. 76 func UndeployHelloHelidonApplication(namespace string, customComponent string, customAppConfig string) { 77 Log(Info, "Undeploy Hello Helidon Application") 78 79 // use custom Hello-Helidon Component if it is passed in 80 if customComponent != "" { 81 helidonComponentYaml = customComponent 82 } 83 84 // use custom Hello-Helidon Component if it is passed in 85 if customAppConfig != "" { 86 helidonAppYaml = customAppConfig 87 } 88 89 if exists, _ := DoesNamespaceExist(namespace); exists { 90 Log(Info, "Delete Hello Helidon application") 91 gomega.Eventually(func() error { 92 file, err := FindTestDataFile(helidonAppYaml) 93 if err != nil { 94 return err 95 } 96 return resource.DeleteResourceFromFileInGeneratedNamespace(file, namespace) 97 }, helidonWaitTimeout, helidonPollingInterval).ShouldNot(gomega.HaveOccurred(), "Failed to create hello-helidon application resource") 98 99 Log(Info, "Delete Hello Helidon components") 100 gomega.Eventually(func() error { 101 file, err := FindTestDataFile(helidonComponentYaml) 102 if err != nil { 103 return err 104 } 105 return resource.DeleteResourceFromFileInGeneratedNamespace(file, namespace) 106 }, helidonWaitTimeout, helidonPollingInterval).ShouldNot(gomega.HaveOccurred(), "Failed to create hello-helidon component resource") 107 108 Log(Info, "Wait for application pods to terminate") 109 gomega.Eventually(func() bool { 110 podsTerminated, _ := PodsNotRunning(namespace, expectedPodsHelloHelidon) 111 return podsTerminated 112 }, helidonWaitTimeout, helidonPollingInterval).Should(gomega.BeTrue()) 113 114 Log(Info, fmt.Sprintf("Delete namespace %s", namespace)) 115 gomega.Eventually(func() error { 116 return DeleteNamespace(namespace) 117 }, helidonWaitTimeout, helidonPollingInterval).ShouldNot(gomega.HaveOccurred(), fmt.Sprintf("Failed to deleted namespace %s", namespace)) 118 119 Log(Info, "Wait for namespace finalizer to be removed") 120 gomega.Eventually(func() bool { 121 return CheckNamespaceFinalizerRemoved(namespace) 122 }, helidonWaitTimeout, helidonPollingInterval).Should(gomega.BeTrue()) 123 124 Log(Info, "Wait for namespace to be deleted") 125 gomega.Eventually(func() bool { 126 _, err := GetNamespace(namespace) 127 return err != nil && errors.IsNotFound(err) 128 }, helidonWaitTimeout, helidonPollingInterval).Should(gomega.BeTrue()) 129 } 130 }