mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-09 12:07:47 +00:00
API warn non-ExternalName services w/ externalName
This commit is contained in:
parent
7bd0a857e3
commit
182a4f858a
@ -56,6 +56,9 @@ func GetWarningsForService(service, oldService *api.Service) []string {
|
|||||||
if service.Spec.Type == api.ServiceTypeExternalName && len(service.Spec.ExternalIPs) > 0 {
|
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))
|
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
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,13 @@ func TestGetWarningsForService(t *testing.T) {
|
|||||||
s.Spec.ExternalIPs = []string{"1.2.3.4"}
|
s.Spec.ExternalIPs = []string{"1.2.3.4"}
|
||||||
},
|
},
|
||||||
numWarnings: 1,
|
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 {
|
||||||
@ -57,8 +64,8 @@ func TestGetWarningsForService(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