istio.io/istio@v0.0.0-20240520182934-d79c90f27776/tests/integration/pilot/cross_revision_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 "fmt" 22 "os" 23 "strings" 24 "testing" 25 26 "istio.io/istio/pkg/test/framework" 27 "istio.io/istio/pkg/test/framework/components/echo" 28 "istio.io/istio/pkg/test/framework/components/echo/common/ports" 29 "istio.io/istio/pkg/test/framework/components/echo/deployment" 30 "istio.io/istio/pkg/test/framework/components/namespace" 31 ) 32 33 // TestRevisionTraffic checks that traffic between all revisions specified works. 34 // This is similar to TestMultiVersionRevision, except it doesn't actually install the version of Istio under test. 35 // This allows a conformance-style tests against existing installations in the cluster. 36 // The test is completely skipped if ISTIO_TEST_EXTRA_REVISIONS is not set 37 // To run, add each revision to test. eg `ISTIO_TEST_EXTRA_REVISIONS=canary,my-rev`. 38 func TestRevisionTraffic(t *testing.T) { 39 rawExtraRevs, f := os.LookupEnv("ISTIO_TEST_EXTRA_REVISIONS") 40 if !f { 41 t.Skip("ISTIO_TEST_EXTRA_REVISIONS not specified") 42 } 43 extraRevs := strings.Split(rawExtraRevs, ",") 44 45 // nolint: staticcheck 46 framework.NewTest(t). 47 RequiresSingleCluster(). 48 RequiresLocalControlPlane(). 49 Run(func(t framework.TestContext) { 50 namespaces := make([]revisionedNamespace, 0, len(extraRevs)) 51 for _, rev := range extraRevs { 52 namespaces = append(namespaces, revisionedNamespace{ 53 revision: rev, 54 namespace: namespace.NewOrFail(t, t, namespace.Config{ 55 Prefix: fmt.Sprintf("revision-%s", rev), 56 Inject: true, 57 Revision: rev, 58 }), 59 }) 60 } 61 // Allow all namespaces so we do not hit passthrough cluster 62 t.ConfigIstio().YAML(apps.Namespace.Name(), `apiVersion: networking.istio.io/v1alpha3 63 kind: Sidecar 64 metadata: 65 name: allow-cross-namespaces 66 spec: 67 workloadSelector: 68 labels: 69 app: a 70 egress: 71 - hosts: 72 - "*/*"`).ApplyOrFail(t) 73 // create an echo instance in each revisioned namespace, all these echo 74 // instances will be injected with proxies from their respective versions 75 builder := deployment.New(t).WithClusters(t.Clusters()...) 76 for _, ns := range namespaces { 77 builder = builder.WithConfig(echo.Config{ 78 Service: ns.revision, 79 Namespace: ns.namespace, 80 Ports: ports.All(), 81 Subsets: []echo.SubsetConfig{{}}, 82 }) 83 } 84 instances := builder.BuildOrFail(t) 85 // Add our existing revision to the instances list 86 instances = append(instances, apps.A...) 87 testAllEchoCalls(t, instances) 88 }) 89 }