istio.io/istio@v0.0.0-20240520182934-d79c90f27776/tests/integration/helm/upgrade/helm_upgrade_test.go (about)

     1  //go:build integ
     2  // +build integ
     3  
     4  // Copyright Istio Authors
     5  //
     6  // Licensed under the Apache License, Version 2.0 (the "License");
     7  // you may not use this file except in compliance with the License.
     8  // You may obtain a copy of the License at
     9  //
    10  //     http://www.apache.org/licenses/LICENSE-2.0
    11  //
    12  // Unless required by applicable law or agreed to in writing, software
    13  // distributed under the License is distributed on an "AS IS" BASIS,
    14  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15  // See the License for the specific language governing permissions and
    16  // limitations under the License.
    17  
    18  package helmupgrade
    19  
    20  import (
    21  	"testing"
    22  
    23  	"github.com/Masterminds/semver/v3"
    24  
    25  	"istio.io/istio/pkg/test/env"
    26  	"istio.io/istio/pkg/test/framework"
    27  	"istio.io/istio/pkg/test/framework/resource"
    28  	"istio.io/istio/pkg/util/image"
    29  	helmtest "istio.io/istio/tests/integration/helm"
    30  )
    31  
    32  var (
    33  	previousSupportedVersion string
    34  	nMinusTwoVersion         string
    35  )
    36  
    37  const imageToCheck = "gcr.io/istio-release/pilot"
    38  
    39  func initVersions(ctx resource.Context) error {
    40  	versionFromFile, err := env.ReadVersion()
    41  	if err != nil {
    42  		return err
    43  	}
    44  
    45  	v, err := semver.NewVersion(versionFromFile)
    46  	if err != nil {
    47  		return err
    48  	}
    49  
    50  	previousVersion := semver.New(v.Major(), v.Minor()-1, v.Patch(), v.Prerelease(), v.Metadata())
    51  
    52  	// If the previous version is not published yet, use the latest one
    53  	if exists, err := image.Exists(imageToCheck + ":" + previousVersion.String()); err != nil {
    54  		return err
    55  	} else if !exists {
    56  		previousVersion = semver.New(v.Major(), v.Minor()-2, v.Patch(), v.Prerelease(), v.Metadata())
    57  	}
    58  
    59  	previousSupportedVersion = previousVersion.String()
    60  	nMinusTwoVersion = semver.New(previousVersion.Major(), previousVersion.Minor()-1, previousVersion.Patch(),
    61  		previousVersion.Prerelease(), previousVersion.Metadata()).String()
    62  
    63  	return nil
    64  }
    65  
    66  // TestDefaultInPlaceUpgradeFromPreviousMinorRelease tests Istio upgrade using Helm with default options for Istio 1.(n-1)
    67  func TestDefaultInPlaceUpgradeFromPreviousMinorRelease(t *testing.T) {
    68  	framework.
    69  		NewTest(t).
    70  		Run(performInPlaceUpgradeFunc(previousSupportedVersion, false))
    71  }
    72  
    73  // TestCanaryUpgradeFromPreviousMinorRelease tests Istio upgrade using Helm with default options for Istio 1.(n-1)
    74  func TestCanaryUpgradeFromPreviousMinorRelease(t *testing.T) {
    75  	framework.
    76  		NewTest(t).
    77  		Run(performCanaryUpgradeFunc(helmtest.DefaultNamespaceConfig, previousSupportedVersion))
    78  }
    79  
    80  // TestCanaryUpgradeFromTwoMinorRelease tests Istio upgrade using Helm with default options for Istio 1.(n-2)
    81  func TestCanaryUpgradeFromTwoMinorRelease(t *testing.T) {
    82  	framework.
    83  		NewTest(t).
    84  		Run(performCanaryUpgradeFunc(helmtest.DefaultNamespaceConfig, nMinusTwoVersion))
    85  }
    86  
    87  // TestStableRevisionLabelsUpgradeFromPreviousMinorRelease tests Istio upgrade using Helm with default options for Istio 1.(n-1)
    88  func TestStableRevisionLabelsUpgradeFromPreviousMinorRelease(t *testing.T) {
    89  	framework.
    90  		NewTest(t).
    91  		Run(performRevisionTagsUpgradeFunc(previousSupportedVersion))
    92  }
    93  
    94  // TestStableRevisionLabelsUpgradeFromTwoMinorRelease tests Istio upgrade using Helm with default options for Istio 1.(n-2)
    95  func TestStableRevisionLabelsUpgradeFromTwoMinorRelease(t *testing.T) {
    96  	framework.
    97  		NewTest(t).
    98  		Run(performRevisionTagsUpgradeFunc(nMinusTwoVersion))
    99  }
   100  
   101  // TestAmbientInPlaceUpgradeFromPreviousMinorRelease tests Istio upgrade using Helm with ambient profile for Istio 1.(n-1)
   102  func TestAmbientInPlaceUpgradeFromPreviousMinorRelease(t *testing.T) {
   103  	framework.
   104  		NewTest(t).
   105  		Run(performInPlaceUpgradeFunc(previousSupportedVersion, true))
   106  }