mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-14 06:15:45 +00:00
Merge pull request #119310 from thockin/warn_externalname_externalips
API warnings for services with bad combos of ExternalIPs and ExternalName
This commit is contained in:
commit
d3b7391dc2
@ -53,6 +53,13 @@ func GetWarningsForService(service, oldService *api.Service) []string {
|
|||||||
warnings = append(warnings, getWarningsForCIDR(field.NewPath("spec").Child("loadBalancerSourceRanges").Index(i), cidr)...)
|
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))
|
||||||
|
}
|
||||||
|
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
|
return warnings
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,30 +31,41 @@ func TestGetWarningsForService(t *testing.T) {
|
|||||||
name string
|
name string
|
||||||
tweakSvc func(svc *api.Service) // Given a basic valid service, each test case can customize it.
|
tweakSvc func(svc *api.Service) // Given a basic valid service, each test case can customize it.
|
||||||
numWarnings int
|
numWarnings int
|
||||||
}{
|
}{{
|
||||||
{
|
|
||||||
name: "new topology mode set",
|
name: "new topology mode set",
|
||||||
tweakSvc: func(s *api.Service) {
|
tweakSvc: func(s *api.Service) {
|
||||||
s.Annotations = map[string]string{api.AnnotationTopologyMode: "foo"}
|
s.Annotations = map[string]string{api.AnnotationTopologyMode: "foo"}
|
||||||
},
|
},
|
||||||
numWarnings: 0,
|
numWarnings: 0,
|
||||||
},
|
}, {
|
||||||
{
|
|
||||||
name: "deprecated hints annotation set",
|
name: "deprecated hints annotation set",
|
||||||
tweakSvc: func(s *api.Service) {
|
tweakSvc: func(s *api.Service) {
|
||||||
s.Annotations = map[string]string{api.DeprecatedAnnotationTopologyAwareHints: "foo"}
|
s.Annotations = map[string]string{api.DeprecatedAnnotationTopologyAwareHints: "foo"}
|
||||||
},
|
},
|
||||||
numWarnings: 1,
|
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,
|
||||||
|
}, {
|
||||||
|
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 {
|
for _, tc := range testCases {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
svc := &api.Service{}
|
svc := &api.Service{}
|
||||||
tc.tweakSvc(svc)
|
tc.tweakSvc(svc)
|
||||||
warnings := GetWarningsForService(svc, svc)
|
warnings := GetWarningsForService(svc, svc)
|
||||||
if len(warnings) != tc.numWarnings {
|
if want, got := tc.numWarnings, len(warnings); got != want {
|
||||||
t.Errorf("Unexpected warning list: %v", warnings)
|
t.Errorf("Unexpected warning list: expected %d, got %d\n%q", want, got, warnings)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user