phase 2: api types + defaulting + validation + disabled fields handling
This commit is contained in:
@@ -9134,6 +9134,7 @@ func TestValidatePodStatusUpdate(t *testing.T) {
|
||||
}
|
||||
|
||||
func makeValidService() core.Service {
|
||||
serviceIPFamily := core.IPv4Protocol
|
||||
return core.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "valid",
|
||||
@@ -9147,6 +9148,7 @@ func makeValidService() core.Service {
|
||||
SessionAffinity: "None",
|
||||
Type: core.ServiceTypeClusterIP,
|
||||
Ports: []core.ServicePort{{Name: "p", Protocol: "TCP", Port: 8675, TargetPort: intstr.FromInt(8675)}},
|
||||
IPFamily: &serviceIPFamily,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -10072,6 +10074,29 @@ func TestValidateService(t *testing.T) {
|
||||
},
|
||||
numErrs: 1,
|
||||
},
|
||||
{
|
||||
name: "valid, nil service IPFamily",
|
||||
tweakSvc: func(s *core.Service) {
|
||||
s.Spec.IPFamily = nil
|
||||
},
|
||||
numErrs: 0,
|
||||
},
|
||||
{
|
||||
name: "valid, service with valid IPFamily",
|
||||
tweakSvc: func(s *core.Service) {
|
||||
ipv4Service := core.IPv4Protocol
|
||||
s.Spec.IPFamily = &ipv4Service
|
||||
},
|
||||
numErrs: 0,
|
||||
},
|
||||
{
|
||||
name: "invalid, service with invalid IPFamily",
|
||||
tweakSvc: func(s *core.Service) {
|
||||
invalidServiceIPFamily := core.IPFamily("not-a-valid-ip-family")
|
||||
s.Spec.IPFamily = &invalidServiceIPFamily
|
||||
},
|
||||
numErrs: 1,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
@@ -11922,6 +11947,80 @@ func TestValidateServiceUpdate(t *testing.T) {
|
||||
},
|
||||
numErrs: 1,
|
||||
},
|
||||
/* Service IP Family */
|
||||
{
|
||||
name: "same ServiceIPFamily",
|
||||
tweakSvc: func(oldSvc, newSvc *core.Service) {
|
||||
ipv4Service := core.IPv4Protocol
|
||||
oldSvc.Spec.Type = core.ServiceTypeClusterIP
|
||||
oldSvc.Spec.IPFamily = &ipv4Service
|
||||
|
||||
newSvc.Spec.Type = core.ServiceTypeClusterIP
|
||||
newSvc.Spec.IPFamily = &ipv4Service
|
||||
},
|
||||
numErrs: 0,
|
||||
},
|
||||
{
|
||||
name: "ExternalName while changing Service IPFamily",
|
||||
tweakSvc: func(oldSvc, newSvc *core.Service) {
|
||||
ipv4Service := core.IPv4Protocol
|
||||
oldSvc.Spec.ExternalName = "somename"
|
||||
oldSvc.Spec.Type = core.ServiceTypeExternalName
|
||||
oldSvc.Spec.IPFamily = &ipv4Service
|
||||
|
||||
ipv6Service := core.IPv6Protocol
|
||||
newSvc.Spec.ExternalName = "somename"
|
||||
newSvc.Spec.Type = core.ServiceTypeExternalName
|
||||
newSvc.Spec.IPFamily = &ipv6Service
|
||||
},
|
||||
numErrs: 0,
|
||||
},
|
||||
{
|
||||
name: "setting ipfamily from nil to v4",
|
||||
tweakSvc: func(oldSvc, newSvc *core.Service) {
|
||||
oldSvc.Spec.IPFamily = nil
|
||||
|
||||
ipv4Service := core.IPv4Protocol
|
||||
newSvc.Spec.ExternalName = "somename"
|
||||
newSvc.Spec.IPFamily = &ipv4Service
|
||||
},
|
||||
numErrs: 0,
|
||||
},
|
||||
{
|
||||
name: "setting ipfamily from nil to v6",
|
||||
tweakSvc: func(oldSvc, newSvc *core.Service) {
|
||||
oldSvc.Spec.IPFamily = nil
|
||||
|
||||
ipv6Service := core.IPv6Protocol
|
||||
newSvc.Spec.ExternalName = "somename"
|
||||
newSvc.Spec.IPFamily = &ipv6Service
|
||||
},
|
||||
numErrs: 0,
|
||||
},
|
||||
{
|
||||
name: "remove ipfamily",
|
||||
tweakSvc: func(oldSvc, newSvc *core.Service) {
|
||||
ipv6Service := core.IPv6Protocol
|
||||
oldSvc.Spec.IPFamily = &ipv6Service
|
||||
|
||||
newSvc.Spec.IPFamily = nil
|
||||
},
|
||||
numErrs: 1,
|
||||
},
|
||||
|
||||
{
|
||||
name: "change ServiceIPFamily",
|
||||
tweakSvc: func(oldSvc, newSvc *core.Service) {
|
||||
ipv4Service := core.IPv4Protocol
|
||||
oldSvc.Spec.Type = core.ServiceTypeClusterIP
|
||||
oldSvc.Spec.IPFamily = &ipv4Service
|
||||
|
||||
ipv6Service := core.IPv6Protocol
|
||||
newSvc.Spec.Type = core.ServiceTypeClusterIP
|
||||
newSvc.Spec.IPFamily = &ipv6Service
|
||||
},
|
||||
numErrs: 1,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
|
Reference in New Issue
Block a user