istio.io/istio@v0.0.0-20240520182934-d79c90f27776/tests/integration/pilot/label_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 pilot
    19  
    20  import (
    21  	"testing"
    22  
    23  	"istio.io/istio/pkg/test/framework"
    24  	"istio.io/istio/pkg/test/framework/components/echo"
    25  	"istio.io/istio/pkg/test/framework/components/echo/check"
    26  	"istio.io/istio/pkg/test/util/assert"
    27  )
    28  
    29  func TestLabelChanges(t *testing.T) {
    30  	framework.
    31  		NewTest(t).
    32  		Run(func(t framework.TestContext) {
    33  			cfg := `apiVersion: networking.istio.io/v1alpha3
    34  kind: VirtualService
    35  metadata:
    36    name: {{.Destination}}
    37  spec:
    38    hosts:
    39    - {{.Destination}}
    40    http:
    41    - route:
    42      - destination:
    43          host: {{.Destination}}
    44          subset: my-subset
    45  ---
    46  apiVersion: networking.istio.io/v1alpha3
    47  kind: DestinationRule
    48  metadata:
    49    name: {{.Destination}}
    50  spec:
    51    host: {{.Destination}}
    52    subsets:
    53    - name: my-subset
    54      labels:
    55        subset: my-subset`
    56  			t.ConfigIstio().Eval(apps.Namespace.Name(), map[string]string{
    57  				"Destination": "a",
    58  			}, cfg).ApplyOrFail(t)
    59  			from := apps.B[0]
    60  			to := apps.A
    61  
    62  			// First, expect to fail. Subset does not match
    63  			_ = from.CallOrFail(t, echo.CallOptions{
    64  				To: to,
    65  				Port: echo.Port{
    66  					Name: "http",
    67  				},
    68  				Count: 1,
    69  				Check: check.BodyContains("no healthy upstream"),
    70  			})
    71  
    72  			lbls := map[string]string{"subset": "my-subset"}
    73  			assert.NoError(t, to[0].UpdateWorkloadLabel(lbls, nil))
    74  			t.Cleanup(func() {
    75  				assert.NoError(t, to[0].UpdateWorkloadLabel(nil, []string{"subset"}))
    76  			})
    77  
    78  			// Now it should succeed
    79  			_ = from.CallOrFail(t, echo.CallOptions{
    80  				To: to,
    81  				Port: echo.Port{
    82  					Name: "http",
    83  				},
    84  				Count: 1,
    85  				Check: check.OK(),
    86  			})
    87  		})
    88  }