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

service source uses externalIPs in ExternalName type if available #4007

Merged
merged 2 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion docs/sources/service.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,6 @@ as one of the values.

### ExternalName

Creates a target with the value of the Service's `externalName` field.
1. If the Service has one or more `spec.externalIPs`, uses the values in that field.
2. Otherwise, creates a target with the value of the Service's `externalName` field.

3 changes: 3 additions & 0 deletions source/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,9 @@ func extractServiceIps(svc *v1.Service) endpoint.Targets {
}

func extractServiceExternalName(svc *v1.Service) endpoint.Targets {
if len(svc.Spec.ExternalIPs) > 0 {
return svc.Spec.ExternalIPs
}
return endpoint.Targets{svc.Spec.ExternalName}
}

Expand Down
25 changes: 25 additions & 0 deletions source/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3545,6 +3545,7 @@ func TestExternalServices(t *testing.T) {
labels map[string]string
annotations map[string]string
externalName string
externalIPs []string
expected []*endpoint.Endpoint
expectError bool
}{
Expand All @@ -3562,6 +3563,7 @@ func TestExternalServices(t *testing.T) {
hostnameAnnotationKey: "service.example.org",
},
"111.111.111.111",
[]string{},
[]*endpoint.Endpoint{
{DNSName: "service.example.org", Targets: endpoint.Targets{"111.111.111.111"}, RecordType: endpoint.RecordTypeA},
},
Expand All @@ -3581,6 +3583,7 @@ func TestExternalServices(t *testing.T) {
hostnameAnnotationKey: "service.example.org",
},
"2001:db8::111",
[]string{},
[]*endpoint.Endpoint{
{DNSName: "service.example.org", Targets: endpoint.Targets{"2001:db8::111"}, RecordType: endpoint.RecordTypeAAAA},
},
Expand All @@ -3600,11 +3603,32 @@ func TestExternalServices(t *testing.T) {
hostnameAnnotationKey: "service.example.org",
},
"remote.example.com",
[]string{},
[]*endpoint.Endpoint{
{DNSName: "service.example.org", Targets: endpoint.Targets{"remote.example.com"}, RecordType: endpoint.RecordTypeCNAME},
},
false,
},
{
"annotated ExternalName service with externalIPs returns a single endpoint with multiple targets",
"",
"testing",
"foo",
v1.ServiceTypeExternalName,
"",
"",
false,
map[string]string{"component": "foo"},
map[string]string{
hostnameAnnotationKey: "service.example.org",
},
"service.example.org",
[]string{"10.2.3.4", "11.2.3.4"},
szuecs marked this conversation as resolved.
Show resolved Hide resolved
[]*endpoint.Endpoint{
{DNSName: "service.example.org", RecordType: endpoint.RecordTypeA, Targets: endpoint.Targets{"10.2.3.4", "11.2.3.4"}},
},
false,
},
} {
tc := tc
t.Run(tc.title, func(t *testing.T) {
Expand All @@ -3617,6 +3641,7 @@ func TestExternalServices(t *testing.T) {
Spec: v1.ServiceSpec{
Type: tc.svcType,
ExternalName: tc.externalName,
ExternalIPs: tc.externalIPs,
},
ObjectMeta: metav1.ObjectMeta{
Namespace: tc.svcNamespace,
Expand Down
Loading