github.com/verrazzano/verrazzano@v1.7.1/tests/e2e/jaeger/common.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 jaeger
     5  
     6  import (
     7  	"time"
     8  
     9  	"github.com/verrazzano/verrazzano/pkg/k8s/resource"
    10  
    11  	"github.com/onsi/ginkgo/v2"
    12  	"github.com/onsi/gomega"
    13  	"github.com/verrazzano/verrazzano/pkg/k8sutil"
    14  	"github.com/verrazzano/verrazzano/tests/e2e/pkg"
    15  	"github.com/verrazzano/verrazzano/tests/e2e/pkg/test/framework"
    16  	v1 "k8s.io/api/core/v1"
    17  	"k8s.io/apimachinery/pkg/api/errors"
    18  )
    19  
    20  const (
    21  	shortPollingInterval     = 10 * time.Second
    22  	shortWaitTimeout         = 5 * time.Minute
    23  	imagePullWaitTimeout     = 40 * time.Minute
    24  	imagePullPollingInterval = 30 * time.Second
    25  	waitTimeout              = 10 * time.Minute
    26  	pollingInterval          = 30 * time.Second
    27  
    28  	OperatorCondition = "Jaeger Operator Enabled"
    29  )
    30  
    31  func IsJaegerEnabled() (bool, error) {
    32  	kubeconfig, err := k8sutil.GetKubeConfigLocation()
    33  	if err != nil {
    34  		return false, err
    35  	}
    36  	if pkg.IsJaegerOperatorEnabled(kubeconfig) {
    37  		supported, err := pkg.IsVerrazzanoMinVersion("1.3.0", kubeconfig)
    38  		if err != nil {
    39  			return false, err
    40  		}
    41  		return supported, nil
    42  	}
    43  	return false, nil
    44  }
    45  
    46  func WhenJaegerOperatorEnabledIt(t *framework.TestFramework, text string, args ...interface{}) {
    47  	kubeconfig, err := k8sutil.GetKubeConfigLocation()
    48  	if err != nil {
    49  		t.It(text, func() {
    50  			ginkgo.Fail(err.Error())
    51  		})
    52  	}
    53  	if pkg.IsJaegerOperatorEnabled(kubeconfig) {
    54  		t.ItMinimumVersion(text, "1.3.0", kubeconfig, args...)
    55  	}
    56  	t.Logs.Infof("Skipping spec, Jaeger Operator is disabled")
    57  }
    58  
    59  func DeployApplication(namespace, testAppComponentFilePath, testAppConfigurationFilePath string, expectedPods []string) {
    60  	if !IsJaegerOperatorEnabled() {
    61  		pkg.Log(pkg.Info, "Skipping Deploy as Jaeger operator component is disabled")
    62  		return
    63  	}
    64  	gomega.Eventually(func() (*v1.Namespace, error) {
    65  		nsLabels := map[string]string{
    66  			"verrazzano-managed": "true",
    67  			"istio-injection":    "enabled"}
    68  		return pkg.CreateNamespace(namespace, nsLabels)
    69  	}).WithPolling(shortPollingInterval).WithTimeout(shortWaitTimeout).ShouldNot(gomega.BeNil())
    70  
    71  	gomega.Eventually(func() error {
    72  		file, err := pkg.FindTestDataFile(testAppComponentFilePath)
    73  		if err != nil {
    74  			return err
    75  		}
    76  		return resource.CreateOrUpdateResourceFromFileInGeneratedNamespace(file, namespace)
    77  	}).WithPolling(shortPollingInterval).WithTimeout(shortWaitTimeout).ShouldNot(gomega.HaveOccurred())
    78  
    79  	gomega.Eventually(func() error {
    80  		file, err := pkg.FindTestDataFile(testAppConfigurationFilePath)
    81  		if err != nil {
    82  			return err
    83  		}
    84  		return resource.CreateOrUpdateResourceFromFileInGeneratedNamespace(file, namespace)
    85  	}).WithPolling(shortPollingInterval).WithTimeout(shortWaitTimeout).ShouldNot(gomega.HaveOccurred())
    86  
    87  	gomega.Eventually(func() bool {
    88  		return pkg.ContainerImagePullWait(namespace, expectedPods)
    89  	}).WithPolling(imagePullPollingInterval).WithTimeout(imagePullWaitTimeout).Should(gomega.BeTrue())
    90  
    91  	// Verify pods are running
    92  	gomega.Eventually(func() bool {
    93  		result, err := pkg.PodsRunning(namespace, expectedPods)
    94  		if err != nil {
    95  			return false
    96  		}
    97  		return result
    98  	}).WithPolling(pollingInterval).WithTimeout(waitTimeout).Should(gomega.BeTrue())
    99  }
   100  
   101  func UndeployApplication(namespace, testAppComponentFilePath, testAppConfigurationFilePath string, expectedPods []string) {
   102  	if !IsJaegerOperatorEnabled() {
   103  		pkg.Log(pkg.Info, "Skipping Undeploy as Jaeger operator component is disabled")
   104  		return
   105  	}
   106  
   107  	gomega.Eventually(func() error {
   108  		file, err := pkg.FindTestDataFile(testAppComponentFilePath)
   109  		if err != nil {
   110  			return err
   111  		}
   112  		return resource.DeleteResourceFromFileInGeneratedNamespace(file, namespace)
   113  	}).WithPolling(shortPollingInterval).WithTimeout(shortWaitTimeout).ShouldNot(gomega.HaveOccurred())
   114  
   115  	gomega.Eventually(func() error {
   116  		file, err := pkg.FindTestDataFile(testAppConfigurationFilePath)
   117  		if err != nil {
   118  			return err
   119  		}
   120  		return resource.DeleteResourceFromFileInGeneratedNamespace(file, namespace)
   121  	}).WithPolling(shortPollingInterval).WithTimeout(shortWaitTimeout).ShouldNot(gomega.HaveOccurred())
   122  
   123  	gomega.Eventually(func() bool {
   124  		podsTerminated, _ := pkg.PodsNotRunning(namespace, expectedPods)
   125  		return podsTerminated
   126  	}).WithPolling(shortPollingInterval).WithTimeout(shortWaitTimeout).Should(gomega.BeTrue())
   127  
   128  	gomega.Eventually(func() error {
   129  		return pkg.DeleteNamespace(namespace)
   130  	}).WithPolling(shortPollingInterval).WithTimeout(shortWaitTimeout).ShouldNot(gomega.HaveOccurred())
   131  
   132  	gomega.Eventually(func() bool {
   133  		return pkg.CheckNamespaceFinalizerRemoved(namespace)
   134  	}).WithPolling(shortPollingInterval).WithTimeout(shortWaitTimeout).Should(gomega.BeTrue())
   135  
   136  	gomega.Eventually(func() bool {
   137  		_, err := pkg.GetNamespace(namespace)
   138  		return err != nil && errors.IsNotFound(err)
   139  	}).WithPolling(shortPollingInterval).WithTimeout(shortWaitTimeout).Should(gomega.BeTrue())
   140  
   141  }
   142  
   143  func IsJaegerOperatorEnabled() bool {
   144  	kubeconfig, err := k8sutil.GetKubeConfigLocation()
   145  	if err != nil {
   146  		ginkgo.Fail(err.Error())
   147  	}
   148  	return pkg.IsJaegerOperatorEnabled(kubeconfig)
   149  }