@@ -27,13 +27,16 @@ import (
2727 "context"
2828 "fmt"
2929 "net/http"
30+ "net/netip"
3031 "sort"
3132 "strings"
3233 "testing"
3334 "time"
3435
3536 "github.com/prometheus/common/model"
37+ "github.com/stretchr/testify/assert"
3638 "istio.io/api/label"
39+ "istio.io/api/networking/v1alpha3"
3740 "istio.io/istio/pkg/config/constants"
3841 "istio.io/istio/pkg/test"
3942 echot "istio.io/istio/pkg/test/echo"
@@ -43,6 +46,9 @@ import (
4346 "istio.io/istio/pkg/test/framework/components/echo"
4447 "istio.io/istio/pkg/test/framework/components/echo/check"
4548 "istio.io/istio/pkg/test/framework/components/echo/common/ports"
49+ "istio.io/istio/pkg/test/framework/components/echo/config"
50+ "istio.io/istio/pkg/test/framework/components/echo/config/param"
51+ "istio.io/istio/pkg/test/framework/components/echo/echotest"
4652 "istio.io/istio/pkg/test/framework/components/echo/util/traffic"
4753 "istio.io/istio/pkg/test/framework/components/prometheus"
4854 testKube "istio.io/istio/pkg/test/kube"
@@ -941,3 +947,157 @@ func TestServiceRestart(t *testing.T) {
941947 }
942948 })
943949}
950+
951+ func TestServiceEntryInlinedWorkloadEntry (t * testing.T ) {
952+ framework .NewTest (t ).
953+ Run (func (t framework.TestContext ) {
954+ testCases := []struct {
955+ location v1alpha3.ServiceEntry_Location
956+ resolution v1alpha3.ServiceEntry_Resolution
957+ to echo.Instances
958+ }{
959+ {
960+ location : v1alpha3 .ServiceEntry_MESH_INTERNAL ,
961+ resolution : v1alpha3 .ServiceEntry_STATIC ,
962+ },
963+ {
964+ location : v1alpha3 .ServiceEntry_MESH_EXTERNAL ,
965+ resolution : v1alpha3 .ServiceEntry_STATIC ,
966+ },
967+ }
968+
969+ // Configure a gateway with one app as the destination to be accessible through the ingress
970+ t .ConfigIstio ().Eval (apps .Namespace .Name (), map [string ]string {
971+ "Destination" : apps .All [0 ].Config ().Service ,
972+ }, `apiVersion: networking.istio.io/v1alpha3
973+ kind: Gateway
974+ metadata:
975+ name: gateway
976+ spec:
977+ selector:
978+ istio: ingressgateway
979+ servers:
980+ - port:
981+ number: 80
982+ name: http
983+ protocol: HTTP
984+ hosts: ["*"]
985+ ---
986+ apiVersion: networking.istio.io/v1alpha3
987+ kind: VirtualService
988+ metadata:
989+ name: route
990+ spec:
991+ gateways:
992+ - gateway
993+ hosts:
994+ - "*"
995+ http:
996+ - route:
997+ - destination:
998+ host: "{{.Destination}}"
999+ ` ).ApplyOrFail (t )
1000+
1001+ cfg := config .YAML (`
1002+ {{ $to := .To }}
1003+ apiVersion: networking.istio.io/v1beta1
1004+ kind: ServiceEntry
1005+ metadata:
1006+ name: test-se-v4
1007+ spec:
1008+ hosts:
1009+ - dummy-v4.example.com
1010+ addresses:
1011+ - 240.240.240.255
1012+ ports:
1013+ - number: 80
1014+ name: http
1015+ protocol: HTTP
1016+ targetPort: {{.IngressHttpPort}}
1017+ resolution: {{.Resolution}}
1018+ location: {{.Location}}
1019+ endpoints:
1020+ # we send directly to a Pod IP here. This is essentially headless
1021+ - address: {{.IngressIp}} # TODO won't work with DNS resolution tests
1022+ ports:
1023+ http: {{.IngressHttpPort}}
1024+ ---
1025+ apiVersion: networking.istio.io/v1beta1
1026+ kind: ServiceEntry
1027+ metadata:
1028+ name: test-se-v6
1029+ spec:
1030+ hosts:
1031+ - dummy-v6.example.com
1032+ addresses:
1033+ - 2001:2::f0f0:255
1034+ ports:
1035+ - number: 80
1036+ name: http
1037+ protocol: HTTP
1038+ targetPort: {{.IngressHttpPort}}
1039+ resolution: {{.Resolution}}
1040+ location: {{.Location}}
1041+ endpoints:
1042+ # we send directly to a Pod IP here. This is essentially headless
1043+ - address: {{.IngressIp}} # TODO won't work with DNS resolution tests
1044+ ports:
1045+ http: {{.IngressHttpPort}}
1046+ ---
1047+ ` ).
1048+ WithParams (param.Params {}.SetWellKnown (param .Namespace , apps .Namespace ))
1049+
1050+ v4 , v6 := getSupportedIPFamilies (t )
1051+ ips , ports := defaultIngress (t , t ).HTTPAddresses ()
1052+ for _ , tc := range testCases {
1053+ tc := tc
1054+ for i , ip := range ips {
1055+ t .NewSubTestf ("%s %s %d" , tc .location , tc .resolution , i ).Run (func (t framework.TestContext ) {
1056+ echotest .
1057+ New (t , apps .All ).
1058+ Config (cfg .WithParams (param.Params {
1059+ "Resolution" : tc .resolution .String (),
1060+ "Location" : tc .location .String (),
1061+ "IngressIp" : ip ,
1062+ "IngressHttpPort" : ports [i ],
1063+ })).
1064+ Run (func (t framework.TestContext , from echo.Instance , to echo.Target ) {
1065+ if v4 {
1066+ from .CallOrFail (t , echo.CallOptions {
1067+ Address : "240.240.240.255" ,
1068+ Port : to .PortForName ("http" ),
1069+ // If request is sent before service is processed it will hit 10s timeout, so fail faster
1070+ Timeout : time .Millisecond * 500 ,
1071+ })
1072+ }
1073+ if v6 {
1074+ from .CallOrFail (t , echo.CallOptions {
1075+ Address : "2001:2::f0f0:255" ,
1076+ Port : to .PortForName ("http" ),
1077+ // If request is sent before service is processed it will hit 10s timeout, so fail faster
1078+ Timeout : time .Millisecond * 500 ,
1079+ })
1080+ }
1081+ })
1082+ })
1083+ }
1084+ }
1085+ })
1086+ }
1087+
1088+ func getSupportedIPFamilies (t framework.TestContext ) (v4 bool , v6 bool ) {
1089+ addrs := apps .All .WorkloadsOrFail (t ).Addresses ()
1090+ for _ , a := range addrs {
1091+ ip , err := netip .ParseAddr (a )
1092+ assert .NoError (t , err )
1093+ if ip .Is4 () {
1094+ v4 = true
1095+ } else if ip .Is6 () {
1096+ v6 = true
1097+ }
1098+ }
1099+ if ! v4 && ! v6 {
1100+ t .Fatalf ("pod is neither v4 nor v6? %v" , addrs )
1101+ }
1102+ return
1103+ }
0 commit comments