istio.io/istio@v0.0.0-20240520182934-d79c90f27776/tests/integration/pilot/grpc_probe_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 "strconv" 22 "testing" 23 "time" 24 25 "istio.io/api/annotation" 26 "istio.io/istio/pkg/config/protocol" 27 "istio.io/istio/pkg/test/framework" 28 "istio.io/istio/pkg/test/framework/components/echo" 29 "istio.io/istio/pkg/test/framework/components/echo/deployment" 30 "istio.io/istio/pkg/test/framework/components/namespace" 31 ) 32 33 func TestGRPCProbe(t *testing.T) { 34 framework.NewTest(t). 35 Run(func(t framework.TestContext) { 36 if !t.Clusters().Default().MinKubeVersion(23) { 37 t.Skip("gRPC probe not supported") 38 } 39 40 ns := namespace.NewOrFail(t, t, namespace.Config{Prefix: "grpc-probe", Inject: true}) 41 // apply strict mtls 42 t.ConfigKube(t.Clusters().Configs()...).YAML(ns.Name(), ` 43 apiVersion: security.istio.io/v1beta1 44 kind: PeerAuthentication 45 metadata: 46 name: grpc-probe-mtls 47 spec: 48 mtls: 49 mode: STRICT`).ApplyOrFail(t) 50 51 for _, testCase := range []struct { 52 name string 53 rewrite bool 54 ready bool 55 openPort bool 56 }{ 57 {name: "rewrite-ready", rewrite: true, ready: true, openPort: true}, 58 } { 59 t.NewSubTest(testCase.name).Run(func(t framework.TestContext) { 60 runGRPCProbeDeployment(t, ns, testCase.name, testCase.rewrite, testCase.ready, testCase.openPort) 61 }) 62 } 63 }) 64 } 65 66 func runGRPCProbeDeployment(ctx framework.TestContext, ns namespace.Instance, //nolint:interfacer 67 name string, rewrite bool, wantReady bool, openPort bool, 68 ) { 69 ctx.Helper() 70 71 var grpcProbe echo.Instance 72 cfg := echo.Config{ 73 Namespace: ns, 74 Service: name, 75 ReadinessGRPCPort: "1234", 76 Subsets: []echo.SubsetConfig{ 77 { 78 Annotations: map[string]string{annotation.SidecarRewriteAppHTTPProbers.Name: strconv.FormatBool(rewrite)}, 79 }, 80 }, 81 } 82 83 if openPort { 84 cfg.Ports = []echo.Port{{ 85 Name: "readiness-grpc-port", 86 Protocol: protocol.GRPC, 87 ServicePort: 1234, 88 WorkloadPort: 1234, 89 }} 90 } 91 92 // Negative test, we expect the grpc readiness check fails, so set a timeout duration. 93 if !wantReady { 94 cfg.ReadinessTimeout = time.Second * 15 95 } 96 _, err := deployment.New(ctx). 97 With(&grpcProbe, cfg). 98 Build() 99 gotReady := err == nil 100 if gotReady != wantReady { 101 ctx.Errorf("grpcProbe app %v, got error %v, want ready = %v", name, err, wantReady) 102 } 103 }