Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move fake XDS server into dedicated package #28673

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

"istio.io/istio/pilot/pkg/model"
"istio.io/istio/pilot/pkg/simulation"
"istio.io/istio/pilot/pkg/xds"
"istio.io/istio/pilot/pkg/xds/xdsfake"
"istio.io/istio/pilot/test/xdstest"
"istio.io/istio/pkg/test/util/tmpl"
"istio.io/pkg/env"
Expand Down Expand Up @@ -597,16 +597,16 @@ func runGatewayTest(t *testing.T, cases ...simulationTest) {
Metadata: &model.NodeMetadata{Labels: map[string]string{"istio": "ingressgateway"}},
Type: model.Router,
}
runSimulationTest(t, proxy, xds.FakeOptions{}, tt)
runSimulationTest(t, proxy, xdsfake.Options{}, tt)
})
}
}

func runSimulationTest(t *testing.T, proxy *model.Proxy, o xds.FakeOptions, tt simulationTest) {
func runSimulationTest(t *testing.T, proxy *model.Proxy, o xdsfake.Options, tt simulationTest) {
runTest := func(t *testing.T) {
o.ConfigString = tt.config
o.KubernetesObjectString = tt.kubeConfig
s := xds.NewFakeDiscoveryServer(t, o)
s := xdsfake.NewDiscoveryServer(t, o)
sim := simulation.NewSimulation(t, s, s.SetupProxy(proxy))
sim.RunExpectations(tt.calls)
if t.Failed() && debugMode {
Expand Down
14 changes: 7 additions & 7 deletions pilot/pkg/networking/core/v1alpha3/sidecar_simulation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
meshconfig "istio.io/api/mesh/v1alpha1"
"istio.io/istio/pilot/pkg/networking/util"
"istio.io/istio/pilot/pkg/simulation"
"istio.io/istio/pilot/pkg/xds"
"istio.io/istio/pilot/pkg/xds/xdsfake"
"istio.io/istio/pkg/config/mesh"
)

Expand Down Expand Up @@ -58,7 +58,7 @@ spec:
number: 81
---
`
runSimulationTest(t, nil, xds.FakeOptions{}, simulationTest{
runSimulationTest(t, nil, xdsfake.Options{}, simulationTest{
name: "disable",
config: svc + mtlsMode("DISABLE"),
calls: []simulation.Expect{
Expand Down Expand Up @@ -152,7 +152,7 @@ spec:
},
})

runSimulationTest(t, nil, xds.FakeOptions{}, simulationTest{
runSimulationTest(t, nil, xdsfake.Options{}, simulationTest{
name: "permissive",
config: svc + mtlsMode("PERMISSIVE"),
calls: []simulation.Expect{
Expand Down Expand Up @@ -370,7 +370,7 @@ spec:
},
})

runSimulationTest(t, nil, xds.FakeOptions{}, simulationTest{
runSimulationTest(t, nil, xdsfake.Options{}, simulationTest{
name: "strict",
config: svc + mtlsMode("STRICT"),
skipValidation: false,
Expand Down Expand Up @@ -537,7 +537,7 @@ func TestHeadlessServices(t *testing.T) {
},
})
}
runSimulationTest(t, nil, xds.FakeOptions{}, simulationTest{
runSimulationTest(t, nil, xdsfake.Options{}, simulationTest{
kubeConfig: `apiVersion: v1
kind: Service
metadata:
Expand Down Expand Up @@ -625,7 +625,7 @@ func TestPassthroughTraffic(t *testing.T) {
meshconfig.MeshConfig_OutboundTrafficPolicy_ALLOW_ANY,
} {
t.Run(tp.String(), func(t *testing.T) {
o := xds.FakeOptions{
o := xdsfake.Options{
MeshConfig: func() *meshconfig.MeshConfig {
m := mesh.DefaultMeshConfig()
m.OutboundTrafficPolicy.Mode = tp
Expand Down Expand Up @@ -720,7 +720,7 @@ spec:
}

func TestLoop(t *testing.T) {
runSimulationTest(t, nil, xds.FakeOptions{}, simulationTest{
runSimulationTest(t, nil, xdsfake.Options{}, simulationTest{
calls: []simulation.Expect{
{
Name: "direct request to outbound port",
Expand Down
14 changes: 7 additions & 7 deletions pilot/pkg/serviceregistry/serviceregistry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
"istio.io/istio/pilot/pkg/serviceregistry"
kubecontroller "istio.io/istio/pilot/pkg/serviceregistry/kube/controller"
"istio.io/istio/pilot/pkg/serviceregistry/serviceentry"
"istio.io/istio/pilot/pkg/xds"
"istio.io/istio/pilot/pkg/xds/xdsfake"
"istio.io/istio/pilot/test/util"
"istio.io/istio/pilot/test/xdstest"
"istio.io/istio/pkg/config"
Expand Down Expand Up @@ -656,7 +656,7 @@ func TestWorkloadInstances(t *testing.T) {
})

t.Run("Service selects WorkloadEntry: update service", func(t *testing.T) {
s := xds.NewFakeDiscoveryServer(t, xds.FakeOptions{})
s := xdsfake.NewDiscoveryServer(t, xdsfake.Options{})
makeService(t, s.KubeClient(), service)
makeIstioObject(t, s.Store(), workloadEntry)
expectEndpoints(t, s, "outbound|80||service.namespace.svc.cluster.local", []string{"2.3.4.5:80"})
Expand All @@ -679,7 +679,7 @@ func TestWorkloadInstances(t *testing.T) {
})

t.Run("Service selects WorkloadEntry: update workloadEntry", func(t *testing.T) {
s := xds.NewFakeDiscoveryServer(t, xds.FakeOptions{})
s := xdsfake.NewDiscoveryServer(t, xdsfake.Options{})
makeService(t, s.KubeClient(), service)
makeIstioObject(t, s.Store(), workloadEntry)
expectEndpoints(t, s, "outbound|80||service.namespace.svc.cluster.local", []string{"2.3.4.5:80"})
Expand All @@ -696,7 +696,7 @@ func TestWorkloadInstances(t *testing.T) {
})

t.Run("ServiceEntry selects Pod: update service entry", func(t *testing.T) {
s := xds.NewFakeDiscoveryServer(t, xds.FakeOptions{})
s := xdsfake.NewDiscoveryServer(t, xdsfake.Options{})
makeIstioObject(t, s.Store(), serviceEntry)
makePod(t, s.KubeClient(), pod)
expectEndpoints(t, s, "outbound|80||service.namespace.svc.cluster.local", []string{"1.2.3.4:80"})
Expand Down Expand Up @@ -730,7 +730,7 @@ func TestWorkloadInstances(t *testing.T) {
})

t.Run("ServiceEntry selects Pod: update pod", func(t *testing.T) {
s := xds.NewFakeDiscoveryServer(t, xds.FakeOptions{})
s := xdsfake.NewDiscoveryServer(t, xdsfake.Options{})
makeIstioObject(t, s.Store(), serviceEntry)
makePod(t, s.KubeClient(), pod)
expectEndpoints(t, s, "outbound|80||service.namespace.svc.cluster.local", []string{"1.2.3.4:80"})
Expand Down Expand Up @@ -759,7 +759,7 @@ func waitForEdsUpdate(t *testing.T, xdsUpdater *FakeXdsUpdater, expected int) {
}

func TestEndpointsDeduping(t *testing.T) {
s := xds.NewFakeDiscoveryServer(t, xds.FakeOptions{
s := xdsfake.NewDiscoveryServer(t, xdsfake.Options{
KubernetesEndpointMode: kubecontroller.EndpointSliceOnly,
})
namespace := "namespace"
Expand Down Expand Up @@ -834,7 +834,7 @@ type ServiceInstanceResponse struct {
Port uint32
}

func expectEndpoints(t *testing.T, s *xds.FakeDiscoveryServer, cluster string, expected []string) {
func expectEndpoints(t *testing.T, s *xdsfake.DiscoveryServer, cluster string, expected []string) {
t.Helper()
retry.UntilSuccessOrFail(t, func() error {
got := xdstest.ExtractLoadAssignments(s.Endpoints(s.SetupProxy(nil)))
Expand Down
4 changes: 2 additions & 2 deletions pilot/pkg/simulation/traffic.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ import (
"istio.io/istio/pilot/pkg/model"
"istio.io/istio/pilot/pkg/networking/core/v1alpha3"
"istio.io/istio/pilot/pkg/util/sets"
"istio.io/istio/pilot/pkg/xds"
xdsfilters "istio.io/istio/pilot/pkg/xds/filters"
"istio.io/istio/pilot/pkg/xds/xdsfake"
"istio.io/istio/pilot/test/xdstest"
"istio.io/istio/pkg/config/host"
"istio.io/istio/pkg/test"
Expand Down Expand Up @@ -205,7 +205,7 @@ func NewSimulationFromConfigGen(t *testing.T, s *v1alpha3.ConfigGenTest, proxy *
return sim
}

func NewSimulation(t *testing.T, s *xds.FakeDiscoveryServer, proxy *model.Proxy) *Simulation {
func NewSimulation(t *testing.T, s *xdsfake.DiscoveryServer, proxy *model.Proxy) *Simulation {
return NewSimulationFromConfigGen(t, s.ConfigGenTest, proxy)
}

Expand Down
27 changes: 14 additions & 13 deletions pilot/pkg/xds/ads_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"istio.io/istio/pilot/pkg/util/sets"
"istio.io/istio/pilot/pkg/xds"
v3 "istio.io/istio/pilot/pkg/xds/v3"
"istio.io/istio/pilot/pkg/xds/xdsfake"
"istio.io/istio/pilot/test/xdstest"
"istio.io/istio/pkg/adsc"
"istio.io/istio/pkg/config"
Expand Down Expand Up @@ -171,7 +172,7 @@ func testAdscTLS(t *testing.T, creds security.SecretManager) {
}

func TestInternalEvents(t *testing.T) {
s := xds.NewFakeDiscoveryServer(t, xds.FakeOptions{})
s := xdsfake.NewDiscoveryServer(t, xdsfake.Options{})

ads := s.Connect(
&model.Proxy{
Expand Down Expand Up @@ -210,7 +211,7 @@ func TestInternalEvents(t *testing.T) {
}

func TestAdsReconnectAfterRestart(t *testing.T) {
s := xds.NewFakeDiscoveryServer(t, xds.FakeOptions{})
s := xdsfake.NewDiscoveryServer(t, xdsfake.Options{})

ads := s.ConnectADS().WithType(v3.EndpointType)
res := ads.RequestResponseAck(&discovery.DiscoveryRequest{ResourceNames: []string{"fake-cluster"}})
Expand All @@ -227,7 +228,7 @@ func TestAdsReconnectAfterRestart(t *testing.T) {
}

func TestAdsUnsubscribe(t *testing.T) {
s := xds.NewFakeDiscoveryServer(t, xds.FakeOptions{})
s := xdsfake.NewDiscoveryServer(t, xdsfake.Options{})

ads := s.ConnectADS().WithType(v3.EndpointType)
res := ads.RequestResponseAck(&discovery.DiscoveryRequest{ResourceNames: []string{"fake-cluster"}})
Expand All @@ -241,7 +242,7 @@ func TestAdsUnsubscribe(t *testing.T) {

// Regression for envoy restart and overlapping connections
func TestAdsReconnect(t *testing.T) {
s := xds.NewFakeDiscoveryServer(t, xds.FakeOptions{})
s := xdsfake.NewDiscoveryServer(t, xdsfake.Options{})
ads := s.ConnectADS().WithType(v3.ClusterType)
ads.RequestResponseAck(nil)

Expand All @@ -258,7 +259,7 @@ func TestAdsReconnect(t *testing.T) {
}

func TestAdsClusterUpdate(t *testing.T) {
s := xds.NewFakeDiscoveryServer(t, xds.FakeOptions{})
s := xdsfake.NewDiscoveryServer(t, xdsfake.Options{})
ads := s.ConnectADS().WithType(v3.EndpointType)

version := ""
Expand Down Expand Up @@ -288,7 +289,7 @@ func TestAdsClusterUpdate(t *testing.T) {

// nolint: lll
func TestAdsPushScoping(t *testing.T) {
s := xds.NewFakeDiscoveryServer(t, xds.FakeOptions{})
s := xdsfake.NewDiscoveryServer(t, xdsfake.Options{})

const (
svcSuffix = ".testPushScoping.com"
Expand Down Expand Up @@ -692,7 +693,7 @@ func TestAdsPushScoping(t *testing.T) {
}

func TestAdsUpdate(t *testing.T) {
s := xds.NewFakeDiscoveryServer(t, xds.FakeOptions{})
s := xdsfake.NewDiscoveryServer(t, xdsfake.Options{})
ads := s.ConnectADS()

s.Discovery.MemRegistry.AddService("adsupdate.default.svc.cluster.local", &model.Service{
Expand Down Expand Up @@ -739,7 +740,7 @@ func TestAdsUpdate(t *testing.T) {
}

func TestEnvoyRDSProtocolError(t *testing.T) {
s := xds.NewFakeDiscoveryServer(t, xds.FakeOptions{})
s := xdsfake.NewDiscoveryServer(t, xdsfake.Options{})
ads := s.ConnectADS().WithType(v3.RouteType)
ads.RequestResponseAck(&discovery.DiscoveryRequest{ResourceNames: []string{routeA}})

Expand Down Expand Up @@ -769,7 +770,7 @@ func TestBlockedPush(t *testing.T) {
})
t.Run("flow control enabled", func(t *testing.T) {
features.EnableFlowControl = true
s := xds.NewFakeDiscoveryServer(t, xds.FakeOptions{})
s := xdsfake.NewDiscoveryServer(t, xdsfake.Options{})
ads := s.ConnectADS().WithType(v3.ClusterType)
ads.RequestResponseAck(nil)
// Send push, get a response but do not ACK it
Expand Down Expand Up @@ -798,7 +799,7 @@ func TestBlockedPush(t *testing.T) {
t.Run("flow control enabled NACK", func(t *testing.T) {
log.FindScope("ads").SetOutputLevel(log.DebugLevel)
features.EnableFlowControl = true
s := xds.NewFakeDiscoveryServer(t, xds.FakeOptions{})
s := xdsfake.NewDiscoveryServer(t, xdsfake.Options{})
ads := s.ConnectADS().WithType(v3.ClusterType)
ads.RequestResponseAck(nil)

Expand All @@ -817,7 +818,7 @@ func TestBlockedPush(t *testing.T) {
})
t.Run("flow control disabled", func(t *testing.T) {
features.EnableFlowControl = false
s := xds.NewFakeDiscoveryServer(t, xds.FakeOptions{})
s := xdsfake.NewDiscoveryServer(t, xdsfake.Options{})
ads := s.ConnectADS().WithType(v3.ClusterType)
ads.RequestResponseAck(nil)
// Send push, get a response but do not ACK it
Expand All @@ -842,7 +843,7 @@ func TestEnvoyRDSUpdatedRouteRequest(t *testing.T) {
t.Fatalf("expected routes %v got %v", expected, got)
}
}
s := xds.NewFakeDiscoveryServer(t, xds.FakeOptions{})
s := xdsfake.NewDiscoveryServer(t, xdsfake.Options{})
ads := s.ConnectADS().WithType(v3.RouteType)
resp := ads.RequestResponseAck(&discovery.DiscoveryRequest{ResourceNames: []string{routeA}})
expectRoutes(resp, routeA)
Expand Down Expand Up @@ -894,7 +895,7 @@ func TestXdsCache(t *testing.T) {
}
}

s := xds.NewFakeDiscoveryServer(t, xds.FakeOptions{
s := xdsfake.NewDiscoveryServer(t, xdsfake.Options{
Configs: []config.Config{
makeEndpoint([]*networking.WorkloadEntry{
{Address: "1.2.3.4", Locality: "region/zone"},
Expand Down
11 changes: 6 additions & 5 deletions pilot/pkg/xds/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"istio.io/istio/pilot/pkg/networking/util"
kubesecrets "istio.io/istio/pilot/pkg/secrets/kube"
v3 "istio.io/istio/pilot/pkg/xds/v3"
"istio.io/istio/pilot/pkg/xds/xdsfake"
"istio.io/istio/pilot/test/xdstest"
"istio.io/istio/pkg/config"
"istio.io/istio/pkg/config/schema/collections"
Expand Down Expand Up @@ -208,7 +209,7 @@ func BenchmarkSecretGeneration(b *testing.B) {
if err := tmpl.ExecuteTemplate(&buf, tt.Name+".yaml", tt); err != nil {
b.Fatalf("failed to execute template: %v", err)
}
s := NewFakeDiscoveryServer(b, FakeOptions{
s := xdsfake.NewDiscoveryServer(b, xdsfake.Options{
KubernetesObjectString: buf.String(),
})
kubesecrets.DisableAuthorizationForTest(s.KubeClient().Kube().(*fake.Clientset))
Expand Down Expand Up @@ -249,7 +250,7 @@ func BenchmarkEndpointGeneration(b *testing.B) {
var response *discovery.DiscoveryResponse
for _, tt := range tests {
b.Run(fmt.Sprintf("%d/%d", tt.endpoints, tt.services), func(b *testing.B) {
s := NewFakeDiscoveryServer(b, FakeOptions{
s := xdsfake.NewDiscoveryServer(b, xdsfake.Options{
Configs: createEndpoints(tt.endpoints, tt.services),
})
proxy := &model.Proxy{
Expand Down Expand Up @@ -277,7 +278,7 @@ func BenchmarkEndpointGeneration(b *testing.B) {

// Setup test builds a mock test environment. Note: push context is not initialized, to be able to benchmark separately
// most should just call setupAndInitializeTest
func setupTest(t testing.TB, config ConfigInput) (*FakeDiscoveryServer, *model.Proxy) {
func setupTest(t testing.TB, config ConfigInput) (*xdsfake.DiscoveryServer, *model.Proxy) {
proxyType := config.ProxyType
if proxyType == "" {
proxyType = model.SidecarProxy
Expand All @@ -300,7 +301,7 @@ func setupTest(t testing.TB, config ConfigInput) (*FakeDiscoveryServer, *model.P
}

configs := getConfigsWithCache(t, config)
s := NewFakeDiscoveryServer(t, FakeOptions{
s := xdsfake.NewDiscoveryServer(t, xdsfake.Options{
Configs: configs,
})

Expand Down Expand Up @@ -342,7 +343,7 @@ func getConfigsWithCache(t testing.TB, input ConfigInput) []config.Config {
return configs
}

func setupAndInitializeTest(t testing.TB, config ConfigInput) (*FakeDiscoveryServer, *model.Proxy) {
func setupAndInitializeTest(t testing.TB, config ConfigInput) (*xdsfake.DiscoveryServer, *model.Proxy) {
s, proxy := setupTest(t, config)
initPushContext(s.Env(), proxy)
return s, proxy
Expand Down
4 changes: 2 additions & 2 deletions pilot/pkg/xds/cds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ package xds_test
import (
"testing"

"istio.io/istio/pilot/pkg/xds"
v3 "istio.io/istio/pilot/pkg/xds/v3"
"istio.io/istio/pilot/pkg/xds/xdsfake"
)

func TestCDS(t *testing.T) {
s := xds.NewFakeDiscoveryServer(t, xds.FakeOptions{})
s := xdsfake.NewDiscoveryServer(t, xdsfake.Options{})
ads := s.ConnectADS().WithType(v3.ClusterType)
ads.RequestResponseAck(nil)
}