github.com/verrazzano/verrazzano@v1.7.1/tests/e2e/verify-install/velero/velero_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 velero
     5  
     6  import (
     7  	"fmt"
     8  	"strings"
     9  	"time"
    10  
    11  	. "github.com/onsi/ginkgo/v2"
    12  	. "github.com/onsi/gomega"
    13  	pkgConstants "github.com/verrazzano/verrazzano/pkg/constants"
    14  	"github.com/verrazzano/verrazzano/pkg/k8sutil"
    15  	"github.com/verrazzano/verrazzano/platform-operator/constants"
    16  	"github.com/verrazzano/verrazzano/tests/e2e/pkg"
    17  	"github.com/verrazzano/verrazzano/tests/e2e/pkg/test/framework"
    18  )
    19  
    20  const (
    21  	waitTimeout                  = 3 * time.Minute
    22  	pollingInterval              = 10 * time.Second
    23  	veleroRestoreHelperConfigMap = "restic-restore-action-config"
    24  	resticHelperImage            = "velero-restic-restore-helper"
    25  )
    26  
    27  var (
    28  	veleroCrds = []string{
    29  		"backups.velero.io",
    30  		"backupstoragelocations.velero.io",
    31  		"deletebackuprequests.velero.io",
    32  		"downloadrequests.velero.io",
    33  		"podvolumebackups.velero.io",
    34  		"podvolumerestores.velero.io",
    35  		"resticrepositories.velero.io",
    36  		"restores.velero.io",
    37  		"schedules.velero.io",
    38  		"serverstatusrequests.velero.io",
    39  		"volumesnapshotlocations.velero.io",
    40  	}
    41  
    42  	imagePrefix = pkg.GetImagePrefix()
    43  )
    44  
    45  var t = framework.NewTestFramework("velero")
    46  
    47  func isVeleroEnabled() bool {
    48  	kubeconfigPath, err := k8sutil.GetKubeConfigLocation()
    49  	if err != nil {
    50  		AbortSuite(fmt.Sprintf("Failed to get default kubeconfig path: %s", err.Error()))
    51  	}
    52  	return pkg.IsVeleroEnabled(kubeconfigPath)
    53  }
    54  
    55  // 'It' Wrapper to only run spec if the Velero is supported on the current Verrazzano version
    56  func WhenVeleroInstalledIt(description string, f func()) {
    57  	kubeconfigPath, err := k8sutil.GetKubeConfigLocation()
    58  	if err != nil {
    59  		t.It(description, func() {
    60  			Fail(fmt.Sprintf("Failed to get default kubeconfig path: %s", err.Error()))
    61  		})
    62  	}
    63  	supported, err := pkg.IsVerrazzanoMinVersion("1.4.0", kubeconfigPath)
    64  	if err != nil {
    65  		t.It(description, func() {
    66  			Fail(fmt.Sprintf("Failed to check Verrazzano version 1.4.0: %s", err.Error()))
    67  		})
    68  	}
    69  	if supported {
    70  		t.It(description, f)
    71  	} else {
    72  		t.Logs.Infof("Skipping check '%v', the Velero is not supported", description)
    73  	}
    74  }
    75  
    76  var _ = t.Describe("Velero", Label("f:platform-lcm.install"), func() {
    77  	t.Context("after successful installation", func() {
    78  		// GIVEN the Velero is installed
    79  		// WHEN we check to make sure the namespace exists
    80  		// THEN we successfully find the namespace
    81  		WhenVeleroInstalledIt("should have a velero namespace", func() {
    82  			Eventually(func() (bool, error) {
    83  				if !isVeleroEnabled() {
    84  					return true, nil
    85  				}
    86  				return pkg.DoesNamespaceExist(constants.VeleroNameSpace)
    87  			}, waitTimeout, pollingInterval).Should(BeTrue())
    88  		})
    89  
    90  		// GIVEN the Velero is installed
    91  		// WHEN we check to make sure the restore helper configmap is created in velero namespace
    92  		// THEN we see that configmap data has the right image set
    93  		WhenVeleroInstalledIt("should have restore configmap created with valid velero image", func() {
    94  			verifyImages := func() bool {
    95  				if isVeleroEnabled() {
    96  
    97  					cfgMap, err := pkg.GetConfigMap(fmt.Sprintf("%s-%s", pkgConstants.Velero, veleroRestoreHelperConfigMap), constants.VeleroNameSpace)
    98  					if err != nil {
    99  						pkg.Log(pkg.Error, fmt.Sprintf("Unable to retrieve configmap %s in the namespace: %s, error: %v", veleroRestoreHelperConfigMap, constants.VeleroNameSpace, err))
   100  						return false
   101  					}
   102  					expectedResticHelperImage := fmt.Sprintf("%s/verrazzano/%s", imagePrefix, resticHelperImage)
   103  					if !strings.HasPrefix(cfgMap.Data["image"], expectedResticHelperImage) {
   104  						pkg.Log(pkg.Error, fmt.Sprintf("Configmap %s does not have the expected image %s in the namespace: %s. Image found = %s ", veleroRestoreHelperConfigMap, expectedResticHelperImage, constants.VeleroNameSpace, cfgMap.Data["image"]))
   105  						return false
   106  					}
   107  				}
   108  				return true
   109  			}
   110  			Eventually(verifyImages, waitTimeout, pollingInterval).Should(BeTrue())
   111  		})
   112  
   113  		WhenVeleroInstalledIt("should have the correct velero CRDs", func() {
   114  			verifyCRDList := func() (bool, error) {
   115  				if isVeleroEnabled() {
   116  					for _, crd := range veleroCrds {
   117  						exists, err := pkg.DoesCRDExist(crd)
   118  						if err != nil || !exists {
   119  							return exists, err
   120  						}
   121  					}
   122  					return true, nil
   123  				}
   124  				return true, nil
   125  			}
   126  			Eventually(verifyCRDList, waitTimeout, pollingInterval).Should(BeTrue())
   127  		})
   128  	})
   129  })