Skip to content

Commit

Permalink
API warn ExternalName services with externalIPs
Browse files Browse the repository at this point in the history
  • Loading branch information
thockin committed Jul 26, 2023
1 parent a6776f4 commit 7bd0a85
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
4 changes: 4 additions & 0 deletions pkg/api/service/warnings.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ func GetWarningsForService(service, oldService *api.Service) []string {
warnings = append(warnings, getWarningsForCIDR(field.NewPath("spec").Child("loadBalancerSourceRanges").Index(i), cidr)...)
}

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))
}

return warnings
}

Expand Down
32 changes: 18 additions & 14 deletions pkg/api/service/warnings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,26 @@ func TestGetWarningsForService(t *testing.T) {
name string
tweakSvc func(svc *api.Service) // Given a basic valid service, each test case can customize it.
numWarnings int
}{
{
name: "new topology mode set",
tweakSvc: func(s *api.Service) {
s.Annotations = map[string]string{api.AnnotationTopologyMode: "foo"}
},
numWarnings: 0,
}{{
name: "new topology mode set",
tweakSvc: func(s *api.Service) {
s.Annotations = map[string]string{api.AnnotationTopologyMode: "foo"}
},
{
name: "deprecated hints annotation set",
tweakSvc: func(s *api.Service) {
s.Annotations = map[string]string{api.DeprecatedAnnotationTopologyAwareHints: "foo"}
},
numWarnings: 1,
numWarnings: 0,
}, {
name: "deprecated hints annotation set",
tweakSvc: func(s *api.Service) {
s.Annotations = map[string]string{api.DeprecatedAnnotationTopologyAwareHints: "foo"}
},
}
numWarnings: 1,
}, {
name: "externalIPs set when type is ExternalName",
tweakSvc: func(s *api.Service) {
s.Spec.Type = api.ServiceTypeExternalName
s.Spec.ExternalIPs = []string{"1.2.3.4"}
},
numWarnings: 1,
}}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
Expand Down

0 comments on commit 7bd0a85

Please sign in to comment.