github.com/verrazzano/verrazzano@v1.7.1/tests/e2e/upgrade/pre-upgrade/verify-upgrade-required/verify_upgrade_required_test.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 verify
     5  
     6  import (
     7  	"context"
     8  	"fmt"
     9  	"time"
    10  
    11  	. "github.com/onsi/ginkgo/v2"
    12  	. "github.com/onsi/gomega"
    13  
    14  	"github.com/verrazzano/verrazzano/pkg/k8s/verrazzano"
    15  	"github.com/verrazzano/verrazzano/pkg/k8sutil"
    16  	vzalpha1 "github.com/verrazzano/verrazzano/platform-operator/apis/verrazzano/v1alpha1"
    17  	"github.com/verrazzano/verrazzano/tests/e2e/pkg"
    18  	dump "github.com/verrazzano/verrazzano/tests/e2e/pkg/test/clusterdump"
    19  	"github.com/verrazzano/verrazzano/tests/e2e/pkg/test/framework"
    20  	"github.com/verrazzano/verrazzano/tests/e2e/pkg/test/framework/metrics"
    21  	"sigs.k8s.io/controller-runtime/pkg/client"
    22  )
    23  
    24  var t = framework.NewTestFramework("verify-upgrade-required")
    25  
    26  var waitTimeout = 3 * time.Minute
    27  var pollingInterval = 10 * time.Second
    28  
    29  var beforeSuite = t.BeforeSuiteFunc(func() {
    30  	start := time.Now()
    31  	beforeSuitePassed = true
    32  	metrics.Emit(t.Metrics.With("before_suite_elapsed_time", time.Since(start).Milliseconds()))
    33  })
    34  
    35  var _ = BeforeSuite(beforeSuite)
    36  
    37  var failed = false
    38  var beforeSuitePassed = false
    39  
    40  var _ = t.AfterEach(func() {
    41  	failed = failed || framework.VzCurrentGinkgoTestDescription().Failed()
    42  })
    43  
    44  var afterSuite = t.AfterSuiteFunc(func() {
    45  	start := time.Now()
    46  	if failed || !beforeSuitePassed {
    47  		dump.ExecuteBugReport()
    48  	}
    49  	metrics.Emit(t.Metrics.With("after_suite_elapsed_time", time.Since(start).Milliseconds()))
    50  })
    51  
    52  var _ = AfterSuite(afterSuite)
    53  
    54  var _ = t.Describe("Verify upgrade required when new version is available", Label("f:platform-lcm.upgrade", "f:observability.monitoring.prom"), func() {
    55  
    56  	// This is a very specific check, which expects to run in the situation where we've updated the VPO to a
    57  	// newer version but have not yet run an upgrade.  In that scenario the next CR edit must include an upgrade.
    58  	// This is only valid for Release 1.3+, since before that release most post-install updates were not supported.
    59  
    60  	// Verify that an edit to the system configuration is rejected when an upgrade is available but not yet applied
    61  	// GIVEN a Verrazzano install
    62  	// WHEN an edit is made without specifying an upgrade, but an upgrade to a newer version is available
    63  	// THEN the edit is rejected by the webhook
    64  	t.Context("Verify upgrade-required checks", func() {
    65  		t.It("Upgrade-required validator test", func() {
    66  
    67  			var vz *vzalpha1.Verrazzano
    68  			Eventually(func() (*vzalpha1.Verrazzano, error) {
    69  				var err error
    70  				vz, err = pkg.GetVerrazzano()
    71  				return vz, err
    72  			}).WithPolling(pollingInterval).WithTimeout(waitTimeout).
    73  				ShouldNot(BeNil(), "Unable to get Verrazzano instance")
    74  
    75  			if vz.Spec.Components.Istio == nil {
    76  				vz.Spec.Components.Istio = &vzalpha1.IstioComponent{}
    77  			}
    78  			istio := vz.Spec.Components.Istio
    79  			if istio.Ingress == nil {
    80  				istio.Ingress = &vzalpha1.IstioIngressSection{
    81  					Kubernetes: &vzalpha1.IstioKubernetesSection{},
    82  				}
    83  			}
    84  			if istio.Egress == nil {
    85  				istio.Egress = &vzalpha1.IstioEgressSection{
    86  					Kubernetes: &vzalpha1.IstioKubernetesSection{},
    87  				}
    88  			}
    89  			istio.Ingress.Kubernetes.Replicas = 3
    90  			istio.Egress.Kubernetes.Replicas = 3
    91  
    92  			config, err := k8sutil.GetKubeConfig()
    93  			if err != nil {
    94  				t.Fail(fmt.Sprintf("Error getting kubeconfig: %s", err.Error()))
    95  				return
    96  			}
    97  			vzClient, err := pkg.GetV1Beta1ControllerRuntimeClient(config)
    98  			if err != nil {
    99  				t.Fail(fmt.Sprintf("Error getting Verrazzano client: %s", err.Error()))
   100  				return
   101  			}
   102  
   103  			// This should fail with a webhook validation error
   104  			err = verrazzano.UpdateV1Alpha1(context.TODO(), vzClient, vz, client.DryRunAll)
   105  			if err != nil {
   106  				t.Logs.Infof("Returned error: %s", err.Error())
   107  			}
   108  			Expect(err).Should(HaveOccurred())
   109  		})
   110  	})
   111  })