Skip to content

Commit

Permalink
API warn non-ExternalName services w/ externalName
Browse files Browse the repository at this point in the history
  • Loading branch information
thockin committed Jul 26, 2023
1 parent 7bd0a85 commit 182a4f8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 3 additions & 0 deletions pkg/api/service/warnings.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ func GetWarningsForService(service, oldService *api.Service) []string {
if service.Spec.Type == api.ServiceTypeExternalName && len(service.Spec.ExternalIPs) > 0 {
warnings = append(warnings, fmt.Sprintf("spec.externalIPs is ignored when spec.type is %q", api.ServiceTypeExternalName))
}
if service.Spec.Type != api.ServiceTypeExternalName && service.Spec.ExternalName != "" {
warnings = append(warnings, fmt.Sprintf("spec.externalName is ignored when spec.type is not %q", api.ServiceTypeExternalName))
}

return warnings
}
Expand Down
11 changes: 9 additions & 2 deletions pkg/api/service/warnings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,22 @@ func TestGetWarningsForService(t *testing.T) {
s.Spec.ExternalIPs = []string{"1.2.3.4"}
},
numWarnings: 1,
}, {
name: "externalName set when type is not ExternalName",
tweakSvc: func(s *api.Service) {
s.Spec.Type = api.ServiceTypeClusterIP
s.Spec.ExternalName = "example.com"
},
numWarnings: 1,
}}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
svc := &api.Service{}
tc.tweakSvc(svc)
warnings := GetWarningsForService(svc, svc)
if len(warnings) != tc.numWarnings {
t.Errorf("Unexpected warning list: %v", warnings)
if want, got := tc.numWarnings, len(warnings); got != want {
t.Errorf("Unexpected warning list: expected %d, got %d\n%q", want, got, warnings)
}
})
}
Expand Down

0 comments on commit 182a4f8

Please sign in to comment.