Adding validation for topology annotations
Change-Id: I50b3b05b859c69e98daca7c8fca0d3a76024eb80
This commit is contained in:
@@ -31,6 +31,10 @@ func GetWarningsForService(service, oldService *api.Service) []string {
|
||||
}
|
||||
var warnings []string
|
||||
|
||||
if _, ok := service.Annotations[api.DeprecatedAnnotationTopologyAwareHints]; ok {
|
||||
warnings = append(warnings, fmt.Sprintf("annotation %s is deprecated, please use %s instead", api.DeprecatedAnnotationTopologyAwareHints, api.AnnotationTopologyMode))
|
||||
}
|
||||
|
||||
if helper.IsServiceIPSet(service) {
|
||||
for i, clusterIP := range service.Spec.ClusterIPs {
|
||||
warnings = append(warnings, getWarningsForIP(field.NewPath("spec").Child("clusterIPs").Index(i), clusterIP)...)
|
||||
|
@@ -26,6 +26,40 @@ import (
|
||||
api "k8s.io/kubernetes/pkg/apis/core"
|
||||
)
|
||||
|
||||
func TestGetWarningsForService(t *testing.T) {
|
||||
testCases := []struct {
|
||||
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: "deprecated hints annotation set",
|
||||
tweakSvc: func(s *api.Service) {
|
||||
s.Annotations = map[string]string{api.DeprecatedAnnotationTopologyAwareHints: "foo"}
|
||||
},
|
||||
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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetWarningsForServiceClusterIPs(t *testing.T) {
|
||||
service := func(clusterIPs []string) *api.Service {
|
||||
svc := api.Service{
|
||||
|
Reference in New Issue
Block a user