Service Topology implementation

* Implement Service Topology for ipvs and iptables proxier
* Add test files
* API validation
This commit is contained in:
Roc Chan
2019-07-16 17:22:43 +08:00
parent cdaeabfb46
commit c9cf3f5b72
25 changed files with 1006 additions and 43 deletions

View File

@@ -18,6 +18,7 @@ package validation
import (
"bytes"
"fmt"
"math"
"reflect"
"strings"
@@ -9380,6 +9381,7 @@ func TestValidatePodEphemeralContainersUpdate(t *testing.T) {
func TestValidateService(t *testing.T) {
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.SCTPSupport, true)()
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ServiceTopology, true)()
testCases := []struct {
name string
@@ -10058,6 +10060,66 @@ func TestValidateService(t *testing.T) {
},
numErrs: 1,
},
{
name: "valid topology keys",
tweakSvc: func(s *core.Service) {
s.Spec.TopologyKeys = []string{
"kubernetes.io/hostname",
"failure-domain.beta.kubernetes.io/zone",
"failure-domain.beta.kubernetes.io/region",
v1.TopologyKeyAny,
}
},
numErrs: 0,
},
{
name: "invalid topology key",
tweakSvc: func(s *core.Service) {
s.Spec.TopologyKeys = []string{"NoUppercaseOrSpecialCharsLike=Equals"}
},
numErrs: 1,
},
{
name: "too many topology keys",
tweakSvc: func(s *core.Service) {
for i := 0; i < core.MaxServiceTopologyKeys+1; i++ {
s.Spec.TopologyKeys = append(s.Spec.TopologyKeys, fmt.Sprintf("topologykey-%d", i))
}
},
numErrs: 1,
},
{
name: `"Any" was not the last key`,
tweakSvc: func(s *core.Service) {
s.Spec.TopologyKeys = []string{
"kubernetes.io/hostname",
v1.TopologyKeyAny,
"failure-domain.beta.kubernetes.io/zone",
}
},
numErrs: 1,
},
{
name: `duplicate topology key`,
tweakSvc: func(s *core.Service) {
s.Spec.TopologyKeys = []string{
"kubernetes.io/hostname",
"kubernetes.io/hostname",
"failure-domain.beta.kubernetes.io/zone",
}
},
numErrs: 1,
},
{
name: `use topology keys with externalTrafficPolicy=Local`,
tweakSvc: func(s *core.Service) {
s.Spec.ExternalTrafficPolicy = "Local"
s.Spec.TopologyKeys = []string{
"kubernetes.io/hostname",
}
},
numErrs: 2,
},
}
for _, tc := range testCases {