github.com/verrazzano/verrazzano@v1.7.1/tests/e2e/pkg/springboot.go (about)

     1  // Copyright (c) 2022, 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/verrazzano/verrazzano/pkg/k8s/resource"
    11  
    12  	"github.com/onsi/gomega"
    13  	v1 "k8s.io/api/core/v1"
    14  	"k8s.io/apimachinery/pkg/api/errors"
    15  )
    16  
    17  //const SpringbootNamespace = "springboot"
    18  
    19  const (
    20  	springbootPollingInterval = 10 * time.Second
    21  	springbootWaitTimeout     = 5 * time.Minute
    22  
    23  	springbootComponentYaml = "examples/springboot-app/springboot-comp.yaml"
    24  	springbootAppYaml       = "examples/springboot-app/springboot-app.yaml"
    25  )
    26  
    27  var expectedPodsSpringBootApp = []string{"springboot-workload"}
    28  
    29  // DeploySpringBootApplication deploys the Springboot example application.
    30  func DeploySpringBootApplication(namespace string, istioInjection string) {
    31  	Log(Info, "Deploy Spring Boot Application")
    32  	Log(Info, fmt.Sprintf("Create namespace %s", namespace))
    33  	gomega.Eventually(func() (*v1.Namespace, error) {
    34  		nsLabels := map[string]string{
    35  			"verrazzano-managed": "true",
    36  			"istio-injection":    istioInjection}
    37  		return CreateNamespace(namespace, nsLabels)
    38  	}, springbootWaitTimeout, springbootPollingInterval).ShouldNot(gomega.BeNil())
    39  
    40  	Log(Info, "Create Spring Boot component resource")
    41  	gomega.Eventually(func() error {
    42  		file, err := FindTestDataFile(springbootComponentYaml)
    43  		if err != nil {
    44  			return err
    45  		}
    46  		return resource.CreateOrUpdateResourceFromFileInGeneratedNamespace(file, namespace)
    47  	}, springbootWaitTimeout, springbootPollingInterval).ShouldNot(gomega.HaveOccurred())
    48  
    49  	Log(Info, "Create Spring Boot application resource")
    50  	gomega.Eventually(func() error {
    51  		file, err := FindTestDataFile(springbootAppYaml)
    52  		if err != nil {
    53  			return err
    54  		}
    55  		return resource.CreateOrUpdateResourceFromFileInGeneratedNamespace(file, namespace)
    56  	}, springbootWaitTimeout, springbootPollingInterval).ShouldNot(gomega.HaveOccurred())
    57  }
    58  
    59  // UndeploySpringBootApplication undeploys the Springboot example application.
    60  func UndeploySpringBootApplication(namespace string) {
    61  	Log(Info, "Undeploy Spring Boot Application")
    62  	if exists, _ := DoesNamespaceExist(namespace); exists {
    63  		Log(Info, "Delete Spring Boot application")
    64  		gomega.Eventually(func() error {
    65  			file, err := FindTestDataFile(springbootAppYaml)
    66  			if err != nil {
    67  				return err
    68  			}
    69  			return resource.DeleteResourceFromFileInGeneratedNamespace(file, namespace)
    70  		}, springbootWaitTimeout, springbootPollingInterval).ShouldNot(gomega.HaveOccurred())
    71  
    72  		Log(Info, "Delete Spring Boot components")
    73  		gomega.Eventually(func() error {
    74  			file, err := FindTestDataFile(springbootComponentYaml)
    75  			if err != nil {
    76  				return err
    77  			}
    78  			return resource.DeleteResourceFromFileInGeneratedNamespace(file, namespace)
    79  		}, springbootWaitTimeout, springbootPollingInterval).ShouldNot(gomega.HaveOccurred())
    80  
    81  		Log(Info, "Wait for application pods to terminate")
    82  		gomega.Eventually(func() bool {
    83  			podsTerminated, _ := PodsNotRunning(namespace, expectedPodsSpringBootApp)
    84  			return podsTerminated
    85  		}, springbootWaitTimeout, springbootPollingInterval).Should(gomega.BeTrue())
    86  
    87  		Log(Info, fmt.Sprintf("Delete namespace %s", namespace))
    88  		gomega.Eventually(func() error {
    89  			return DeleteNamespace(namespace)
    90  		}, springbootWaitTimeout, springbootPollingInterval).ShouldNot(gomega.HaveOccurred())
    91  
    92  		Log(Info, "Wait for namespace finalizer to be removed")
    93  		gomega.Eventually(func() bool {
    94  			return CheckNamespaceFinalizerRemoved(namespace)
    95  		}, springbootWaitTimeout, springbootPollingInterval).Should(gomega.BeTrue())
    96  
    97  		Log(Info, "Wait for namespace to be deleted")
    98  		gomega.Eventually(func() bool {
    99  			_, err := GetNamespace(namespace)
   100  			return err != nil && errors.IsNotFound(err)
   101  		}, springbootWaitTimeout, springbootPollingInterval).Should(gomega.BeTrue())
   102  	}
   103  }