istio.io/istio@v0.0.0-20240520182934-d79c90f27776/tests/integration/pilot/revisions/revisions_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 revisions
    19  
    20  import (
    21  	"testing"
    22  	"time"
    23  
    24  	"istio.io/istio/pkg/config/protocol"
    25  	"istio.io/istio/pkg/test/framework"
    26  	"istio.io/istio/pkg/test/framework/components/echo"
    27  	"istio.io/istio/pkg/test/framework/components/echo/check"
    28  	"istio.io/istio/pkg/test/framework/components/echo/deployment"
    29  	"istio.io/istio/pkg/test/framework/components/echo/echotest"
    30  	"istio.io/istio/pkg/test/framework/components/echo/match"
    31  	"istio.io/istio/pkg/test/framework/components/istio"
    32  	"istio.io/istio/pkg/test/framework/components/namespace"
    33  	"istio.io/istio/pkg/test/framework/label"
    34  	"istio.io/istio/pkg/test/framework/resource"
    35  	"istio.io/istio/pkg/test/util/retry"
    36  )
    37  
    38  // TestMain defines the entrypoint for pilot tests using a standard Istio installation.
    39  // If a test requires a custom install it should go into its own package, otherwise it should go
    40  // here to reuse a single install across tests.
    41  func TestMain(m *testing.M) {
    42  	// nolint: staticcheck
    43  	framework.
    44  		NewSuite(m).
    45  		RequireMultiPrimary().
    46  		// Requires two CPs with specific names to be configured.
    47  		Label(label.CustomSetup).
    48  		Setup(istio.Setup(nil, func(_ resource.Context, cfg *istio.Config) {
    49  			cfg.ControlPlaneValues = `
    50  revision: stable
    51  `
    52  		})).
    53  		Setup(istio.Setup(nil, func(_ resource.Context, cfg *istio.Config) {
    54  			cfg.ControlPlaneValues = `
    55  profile: empty
    56  revision: canary
    57  components:
    58    pilot:
    59      enabled: true
    60  `
    61  		})).
    62  		Run()
    63  }
    64  
    65  // TestMultiRevision Sets up a simple client -> server call, where the client and server
    66  // belong to different control planes.
    67  func TestMultiRevision(t *testing.T) {
    68  	framework.NewTest(t).
    69  		Run(func(t framework.TestContext) {
    70  			stable := namespace.NewOrFail(t, t, namespace.Config{
    71  				Prefix:   "stable",
    72  				Inject:   true,
    73  				Revision: "stable",
    74  			})
    75  			canary := namespace.NewOrFail(t, t, namespace.Config{
    76  				Prefix:   "canary",
    77  				Inject:   true,
    78  				Revision: "canary",
    79  			})
    80  
    81  			echos := deployment.New(t).
    82  				WithClusters(t.Clusters()...).
    83  				WithConfig(echo.Config{
    84  					Service:   "client",
    85  					Namespace: stable,
    86  					Ports:     []echo.Port{},
    87  				}).
    88  				WithConfig(echo.Config{
    89  					Service:   "server",
    90  					Namespace: canary,
    91  					Ports: []echo.Port{
    92  						{
    93  							Name:         "http",
    94  							Protocol:     protocol.HTTP,
    95  							WorkloadPort: 8090,
    96  						},
    97  					},
    98  				}).
    99  				WithConfig(echo.Config{
   100  					Service:    "vm",
   101  					Namespace:  canary,
   102  					DeployAsVM: true,
   103  					Ports:      []echo.Port{},
   104  				}).
   105  				BuildOrFail(t)
   106  
   107  			echotest.New(t, echos).
   108  				ConditionallyTo(echotest.ReachableDestinations).
   109  				ToMatch(match.ServiceName(echo.NamespacedName{Name: "server", Namespace: canary})).
   110  				Run(func(t framework.TestContext, from echo.Instance, to echo.Target) {
   111  					retry.UntilSuccessOrFail(t, func() error {
   112  						result, err := from.Call(echo.CallOptions{
   113  							To: to,
   114  							Port: echo.Port{
   115  								Name: "http",
   116  							},
   117  							Retry: echo.Retry{
   118  								NoRetry: true,
   119  							},
   120  							Check: check.And(
   121  								check.OK(),
   122  								check.ReachedTargetClusters(t),
   123  							),
   124  						})
   125  						return check.And(
   126  							check.NoError(),
   127  							check.OK()).Check(result, err)
   128  					}, retry.Delay(time.Millisecond*100))
   129  				})
   130  		})
   131  }