github.com/verrazzano/verrazzano@v1.7.1/tests/e2e/verify-install/rancherbackup/rancher_backup_test.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 rancherbackup
     5  
     6  import (
     7  	"fmt"
     8  	"time"
     9  
    10  	. "github.com/onsi/ginkgo/v2"
    11  	. "github.com/onsi/gomega"
    12  	"github.com/verrazzano/verrazzano/pkg/k8sutil"
    13  	"github.com/verrazzano/verrazzano/platform-operator/constants"
    14  	"github.com/verrazzano/verrazzano/tests/e2e/pkg"
    15  	"github.com/verrazzano/verrazzano/tests/e2e/pkg/test/framework"
    16  )
    17  
    18  const (
    19  	waitTimeout               = 3 * time.Minute
    20  	pollingInterval           = 10 * time.Second
    21  	rancherBackupOperatorName = "rancher-backup"
    22  )
    23  
    24  var (
    25  	cattleCrds = []string{
    26  		"backups.resources.cattle.io",
    27  		"resourcesets.resources.cattle.io",
    28  		"restores.resources.cattle.io",
    29  	}
    30  )
    31  
    32  var t = framework.NewTestFramework("rancherbackup")
    33  
    34  func isRancherBackupEnabled() bool {
    35  	kubeconfigPath, err := k8sutil.GetKubeConfigLocation()
    36  	if err != nil {
    37  		AbortSuite(fmt.Sprintf("Failed to get default kubeconfig path: %s", err.Error()))
    38  	}
    39  	return pkg.IsRancherBackupEnabled(kubeconfigPath)
    40  }
    41  
    42  // 'It' Wrapper to only run spec if the Rancher Backup is supported on the current Verrazzano version
    43  func WhenRancherBackupInstalledIt(description string, f func()) {
    44  	kubeconfigPath, err := k8sutil.GetKubeConfigLocation()
    45  	if err != nil {
    46  		t.It(description, func() {
    47  			Fail(fmt.Sprintf("Failed to get default kubeconfig path: %s", err.Error()))
    48  		})
    49  	}
    50  	supported, err := pkg.IsVerrazzanoMinVersion("1.4.0", kubeconfigPath)
    51  	if err != nil {
    52  		t.It(description, func() {
    53  			Fail(fmt.Sprintf("Failed to check Verrazzano version 1.4.0: %s", err.Error()))
    54  		})
    55  	}
    56  	if supported {
    57  		t.It(description, f)
    58  	} else {
    59  		t.Logs.Infof("Skipping check '%v', the Rancher Backup is not supported", description)
    60  	}
    61  }
    62  
    63  var _ = t.Describe("Rancher Backup", Label("f:platform-lcm.install"), func() {
    64  	t.Context("after successful installation", func() {
    65  		// GIVEN the Rancher Backup is installed
    66  		// WHEN we check to make sure the namespace exists
    67  		// THEN we successfully find the namespace
    68  		WhenRancherBackupInstalledIt(fmt.Sprintf("should have a %s namespace", constants.RancherBackupNamesSpace), func() {
    69  			Eventually(func() (bool, error) {
    70  				if !isRancherBackupEnabled() {
    71  					return true, nil
    72  				}
    73  				return pkg.DoesNamespaceExist(constants.RancherBackupNamesSpace)
    74  			}, waitTimeout, pollingInterval).Should(BeTrue())
    75  		})
    76  
    77  		// GIVEN the Jaeger Operator is installed
    78  		// WHEN we check to make sure the pods are running
    79  		// THEN we successfully find the running pods
    80  		WhenRancherBackupInstalledIt("should have running pods", func() {
    81  			rancherBackupPodsRunning := func() bool {
    82  				if !isRancherBackupEnabled() {
    83  					return true
    84  				}
    85  				result, err := pkg.PodsRunning(constants.RancherBackupNamesSpace, []string{rancherBackupOperatorName})
    86  				if err != nil {
    87  					AbortSuite(fmt.Sprintf("Pod %v is not running in the namespace: %v, error: %v", rancherBackupOperatorName, constants.RancherBackupNamesSpace, err))
    88  				}
    89  				return result
    90  			}
    91  			Eventually(rancherBackupPodsRunning, waitTimeout, pollingInterval).Should(BeTrue())
    92  		})
    93  
    94  		// GIVEN the Rancher Backup is installed
    95  		// WHEN we check to make sure cattle crds are created
    96  		// THEN we see that correct set of rancher backup crds are set up
    97  		WhenRancherBackupInstalledIt("should have the correct rancher backup CRDs", func() {
    98  			verifyCRDList := func() (bool, error) {
    99  				if isRancherBackupEnabled() {
   100  					for _, crd := range cattleCrds {
   101  						exists, err := pkg.DoesCRDExist(crd)
   102  						if err != nil || !exists {
   103  							return exists, err
   104  						}
   105  					}
   106  					return true, nil
   107  				}
   108  				return true, nil
   109  			}
   110  			Eventually(verifyCRDList, waitTimeout, pollingInterval).Should(BeTrue())
   111  		})
   112  	})
   113  })