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

support external ips for istio #3720

Closed
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions source/istio_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,12 @@ func (sc *gatewaySource) targetsFromGateway(gateway networkingv1alpha3.Gateway)
targets = append(targets, lb.Hostname)
}
}

if service.Spec.ExternalIPs != nil {
for _, ext := range service.Spec.ExternalIPs {
targets = append(targets, ext)
}
}
}

return
Expand Down
36 changes: 31 additions & 5 deletions source/istio_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,28 @@ func testEndpointsFromGatewayConfig(t *testing.T) {
},
},
},
{
title: "service with externalIPs returns a single endpoint with a targets",
lbServices: []fakeIngressGatewayService{
{
externalIPs: []string{"1.2.3.4"},
namespace: "",
name: "gateway1",
},
},
config: fakeGatewayConfig{
dnsnames: [][]string{
{"foo.bar"}, // Kubernetes requires removal of trailing dot
},
},
expected: []*endpoint.Endpoint{
{
DNSName: "foo.bar",
RecordType: endpoint.RecordTypeA,
Targets: endpoint.Targets{"1.2.3.4"},
},
},
},
} {
ti := ti
t.Run(ti.title, func(t *testing.T) {
Expand Down Expand Up @@ -1256,11 +1278,12 @@ func newTestGatewaySource(loadBalancerList []fakeIngressGatewayService) (*gatewa
}

type fakeIngressGatewayService struct {
ips []string
hostnames []string
namespace string
name string
selector map[string]string
ips []string
hostnames []string
externalIPs []string
namespace string
name string
selector map[string]string
}

func (ig fakeIngressGatewayService) Service() *v1.Service {
Expand Down Expand Up @@ -1289,6 +1312,9 @@ func (ig fakeIngressGatewayService) Service() *v1.Service {
Hostname: hostname,
})
}
for _, ip := range ig.externalIPs {
svc.Spec.ExternalIPs = append(svc.Spec.ExternalIPs, ip)
}

return svc
}
Expand Down
6 changes: 6 additions & 0 deletions source/istio_virtualservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,12 @@ func (sc *virtualServiceSource) targetsFromGateway(gateway *networkingv1alpha3.G
targets = append(targets, lb.Hostname)
}
}

if service.Spec.ExternalIPs != nil {
for _, ext := range service.Spec.ExternalIPs {
targets = append(targets, ext)
}
}
}

return
Expand Down
31 changes: 31 additions & 0 deletions source/istio_virtualservice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,37 @@ func testEndpointsFromVirtualServiceConfig(t *testing.T) {
},
},
},
{
title: "service with externalIPs returns a single endpoint with a targets",
lbServices: []fakeIngressGatewayService{
{
externalIPs: []string{"1.2.3.4"},
namespace: "",
name: "service1",
selector: map[string]string{
"app": "myservice",
},
},
},
gwconfig: fakeGatewayConfig{
name: "mygw",
dnsnames: [][]string{{"foo.bar"}},
selector: map[string]string{
"app": "myservice",
},
},
vsconfig: fakeVirtualServiceConfig{
gateways: []string{"mygw"},
dnsnames: []string{"foo.bar"},
},
expected: []*endpoint.Endpoint{
{
DNSName: "foo.bar",
RecordType: endpoint.RecordTypeA,
Targets: endpoint.Targets{"1.2.3.4"},
},
},
},
} {
ti := ti
t.Run(ti.title, func(t *testing.T) {
Expand Down