Skip to content

Commit

Permalink
fix missing gateway services (#44443)
Browse files Browse the repository at this point in the history
  • Loading branch information
dddddai committed Apr 20, 2023
1 parent d257806 commit c80ed1d
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 15 deletions.
6 changes: 1 addition & 5 deletions pilot/pkg/model/push_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -1526,11 +1526,7 @@ func (ps *PushContext) initVirtualServices(env *Environment) {
for _, gw := range gwNames {
ps.virtualServiceIndex.publicByGateway[gw] = append(ps.virtualServiceIndex.publicByGateway[gw], virtualService)
}
continue
} else if exportToMap[visibility.None] {
// not possible
continue
} else {
} else if !exportToMap[visibility.None] {
// . or other namespaces
for exportTo := range exportToMap {
if exportTo == visibility.Private || string(exportTo) == ns {
Expand Down
111 changes: 101 additions & 10 deletions pilot/pkg/model/push_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2363,19 +2363,21 @@ func TestVirtualServiceWithExportTo(t *testing.T) {
}

func TestInitVirtualService(t *testing.T) {
test.SetForTest(t, &features.FilterGatewayClusterConfig, true)
ps := NewPushContext()
env := &Environment{Watcher: mesh.NewFixedWatcher(&meshconfig.MeshConfig{RootNamespace: "istio-system"})}
ps.Mesh = env.Mesh()
configStore := NewFakeStore()
gatewayName := "ns1/gateway"

vs1 := config.Config{
root := config.Config{
Meta: config.Meta{
GroupVersionKind: gvk.VirtualService,
Name: "vs1",
Name: "root",
Namespace: "ns1",
},
Spec: &networking.VirtualService{
ExportTo: []string{"*"},
Hosts: []string{"*.org"},
Gateways: []string{"gateway"},
Http: []*networking.HTTPRoute{
Expand All @@ -2393,28 +2395,106 @@ func TestInitVirtualService(t *testing.T) {
},
},
Delegate: &networking.Delegate{
Name: "vs2",
Name: "delegate",
Namespace: "ns2",
},
},
},
},
}
vs2 := config.Config{
delegate := config.Config{
Meta: config.Meta{
GroupVersionKind: gvk.VirtualService,
Name: "vs2",
Name: "delegate",
Namespace: "ns2",
},
Spec: &networking.VirtualService{
ExportTo: []string{"*"},
Hosts: []string{},
Gateways: []string{gatewayName},
Http: []*networking.HTTPRoute{
{
Route: []*networking.HTTPRouteDestination{
{
Destination: &networking.Destination{
Host: "test",
Host: "delegate",
Port: &networking.PortSelector{
Number: 80,
},
},
},
},
},
},
},
}
public := config.Config{
Meta: config.Meta{
GroupVersionKind: gvk.VirtualService,
Name: "public",
Namespace: "ns3",
},
Spec: &networking.VirtualService{
Hosts: []string{"*.org"},
Gateways: []string{gatewayName},
Http: []*networking.HTTPRoute{
{
Route: []*networking.HTTPRouteDestination{
{
Destination: &networking.Destination{
Host: "public",
Port: &networking.PortSelector{
Number: 80,
},
},
},
},
},
},
},
}
private := config.Config{
Meta: config.Meta{
GroupVersionKind: gvk.VirtualService,
Name: "private",
Namespace: "ns1",
},
Spec: &networking.VirtualService{
ExportTo: []string{".", "ns2"},
Hosts: []string{"*.org"},
Gateways: []string{gatewayName},
Http: []*networking.HTTPRoute{
{
Route: []*networking.HTTPRouteDestination{
{
Destination: &networking.Destination{
Host: "private",
Port: &networking.PortSelector{
Number: 80,
},
},
},
},
},
},
},
}
invisible := config.Config{
Meta: config.Meta{
GroupVersionKind: gvk.VirtualService,
Name: "invisible",
Namespace: "ns5",
},
Spec: &networking.VirtualService{
ExportTo: []string{".", "ns3"},
Hosts: []string{"*.org"},
Gateways: []string{"gateway", "mesh"},
Http: []*networking.HTTPRoute{
{
Route: []*networking.HTTPRouteDestination{
{
Destination: &networking.Destination{
Host: "invisible",
Port: &networking.PortSelector{
Number: 80,
},
Expand All @@ -2426,7 +2506,7 @@ func TestInitVirtualService(t *testing.T) {
},
}

for _, c := range []config.Config{vs1, vs2} {
for _, c := range []config.Config{root, delegate, public, private, invisible} {
if _, err := configStore.Create(c); err != nil {
t.Fatalf("could not create %v", c.Name)
}
Expand All @@ -2438,8 +2518,8 @@ func TestInitVirtualService(t *testing.T) {

t.Run("resolve shortname", func(t *testing.T) {
rules := ps.VirtualServicesForGateway("ns1", gatewayName)
if len(rules) != 1 {
t.Fatalf("wanted 1 virtualservice for gateway %s, actually got %d", gatewayName, len(rules))
if len(rules) != 3 {
t.Fatalf("wanted 3 virtualservice for gateway %s, actually got %d", gatewayName, len(rules))
}
gotHTTPHosts := make([]string, 0)
for _, r := range rules {
Expand All @@ -2450,10 +2530,21 @@ func TestInitVirtualService(t *testing.T) {
}
}
}
if !reflect.DeepEqual(gotHTTPHosts, []string{"test.ns2"}) {
if !reflect.DeepEqual(gotHTTPHosts, []string{"private.ns1", "public.ns3", "delegate.ns2"}) {
t.Errorf("got %+v", gotHTTPHosts)
}
})

t.Run("destinations by gateway", func(t *testing.T) {
got := ps.virtualServiceIndex.destinationsByGateway
want := map[string]sets.String{
gatewayName: sets.New("delegate.ns2", "public.ns3", "private.ns1"),
"ns5/gateway": sets.New("invisible.ns5"),
}
if !reflect.DeepEqual(got, want) {
t.Errorf("destinationsByGateway: got %+v", got)
}
})
}

func TestServiceWithExportTo(t *testing.T) {
Expand Down
8 changes: 8 additions & 0 deletions releasenotes/notes/44439.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: release-notes/v2
kind: bug-fix
area: traffic-management
issue:
- https://github.com/istio/istio/issues/44439
releaseNotes:
- |
**Fixed** a bug where services are missing in gateways if PILOT_FILTER_GATEWAY_CLUSTER_CONFIG is enabled.

0 comments on commit c80ed1d

Please sign in to comment.