Merge pull request #99522 from robscott/topology-hints

Adding support for Topology Aware Hints
This commit is contained in:
Kubernetes Prow Robot
2021-03-09 09:19:12 -08:00
committed by GitHub
59 changed files with 4418 additions and 297 deletions

View File

@@ -111,13 +111,17 @@ func (endpointSliceStrategy) AllowUnconditionalUpdate() bool {
// dropDisabledConditionsOnCreate will drop any fields that are disabled.
func dropDisabledFieldsOnCreate(endpointSlice *discovery.EndpointSlice) {
dropTerminating := !utilfeature.DefaultFeatureGate.Enabled(features.EndpointSliceTerminatingCondition)
dropHints := !utilfeature.DefaultFeatureGate.Enabled(features.TopologyAwareHints)
if dropTerminating {
if dropHints || dropTerminating {
for i := range endpointSlice.Endpoints {
if dropTerminating {
endpointSlice.Endpoints[i].Conditions.Serving = nil
endpointSlice.Endpoints[i].Conditions.Terminating = nil
}
if dropHints {
endpointSlice.Endpoints[i].Hints = nil
}
}
}
}
@@ -135,12 +139,25 @@ func dropDisabledFieldsOnUpdate(oldEPS, newEPS *discovery.EndpointSlice) {
}
}
if dropTerminating {
dropHints := !utilfeature.DefaultFeatureGate.Enabled(features.TopologyAwareHints)
if dropHints {
for _, ep := range oldEPS.Endpoints {
if ep.Hints != nil {
dropHints = false
break
}
}
}
if dropHints || dropTerminating {
for i := range newEPS.Endpoints {
if dropTerminating {
newEPS.Endpoints[i].Conditions.Serving = nil
newEPS.Endpoints[i].Conditions.Terminating = nil
}
if dropHints {
newEPS.Endpoints[i].Hints = nil
}
}
}
}

View File

@@ -35,6 +35,7 @@ func Test_dropDisabledFieldsOnCreate(t *testing.T) {
testcases := []struct {
name string
terminatingGateEnabled bool
hintsGateEnabled bool
eps *discovery.EndpointSlice
expectedEPS *discovery.EndpointSlice
}{
@@ -162,6 +163,7 @@ func Test_dropDisabledFieldsOnCreate(t *testing.T) {
for _, testcase := range testcases {
t.Run(testcase.name, func(t *testing.T) {
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.EndpointSliceTerminatingCondition, testcase.terminatingGateEnabled)()
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.TopologyAwareHints, testcase.hintsGateEnabled)()
dropDisabledFieldsOnCreate(testcase.eps)
if !apiequality.Semantic.DeepEqual(testcase.eps, testcase.expectedEPS) {
@@ -177,6 +179,7 @@ func Test_dropDisabledFieldsOnUpdate(t *testing.T) {
testcases := []struct {
name string
terminatingGateEnabled bool
hintsGateEnabled bool
oldEPS *discovery.EndpointSlice
newEPS *discovery.EndpointSlice
expectedEPS *discovery.EndpointSlice
@@ -524,11 +527,138 @@ func Test_dropDisabledFieldsOnUpdate(t *testing.T) {
},
},
},
{
name: "hints gate enabled, set on new EPS",
hintsGateEnabled: true,
oldEPS: &discovery.EndpointSlice{
Endpoints: []discovery.Endpoint{
{
Hints: nil,
},
{
Hints: nil,
},
},
},
newEPS: &discovery.EndpointSlice{
Endpoints: []discovery.Endpoint{
{
Hints: &discovery.EndpointHints{
ForZones: []discovery.ForZone{{Name: "zone-a"}},
},
},
{
Hints: &discovery.EndpointHints{
ForZones: []discovery.ForZone{{Name: "zone-b"}},
},
},
},
},
expectedEPS: &discovery.EndpointSlice{
Endpoints: []discovery.Endpoint{
{
Hints: &discovery.EndpointHints{
ForZones: []discovery.ForZone{{Name: "zone-a"}},
},
},
{
Hints: &discovery.EndpointHints{
ForZones: []discovery.ForZone{{Name: "zone-b"}},
},
},
},
},
},
{
name: "hints gate disabled, set on new EPS",
hintsGateEnabled: false,
oldEPS: &discovery.EndpointSlice{
Endpoints: []discovery.Endpoint{
{
Hints: nil,
},
{
Hints: nil,
},
},
},
newEPS: &discovery.EndpointSlice{
Endpoints: []discovery.Endpoint{
{
Hints: &discovery.EndpointHints{
ForZones: []discovery.ForZone{{Name: "zone-a"}},
},
},
{
Hints: &discovery.EndpointHints{
ForZones: []discovery.ForZone{{Name: "zone-b"}},
},
},
},
},
expectedEPS: &discovery.EndpointSlice{
Endpoints: []discovery.Endpoint{
{
Hints: nil,
},
{
Hints: nil,
},
},
},
},
{
name: "hints gate disabled, set on new and old EPS",
hintsGateEnabled: false,
oldEPS: &discovery.EndpointSlice{
Endpoints: []discovery.Endpoint{
{
Hints: &discovery.EndpointHints{
ForZones: []discovery.ForZone{{Name: "zone-a-old"}},
},
},
{
Hints: &discovery.EndpointHints{
ForZones: []discovery.ForZone{{Name: "zone-b-old"}},
},
},
},
},
newEPS: &discovery.EndpointSlice{
Endpoints: []discovery.Endpoint{
{
Hints: &discovery.EndpointHints{
ForZones: []discovery.ForZone{{Name: "zone-a"}},
},
},
{
Hints: &discovery.EndpointHints{
ForZones: []discovery.ForZone{{Name: "zone-b"}},
},
},
},
},
expectedEPS: &discovery.EndpointSlice{
Endpoints: []discovery.Endpoint{
{
Hints: &discovery.EndpointHints{
ForZones: []discovery.ForZone{{Name: "zone-a"}},
},
},
{
Hints: &discovery.EndpointHints{
ForZones: []discovery.ForZone{{Name: "zone-b"}},
},
},
},
},
},
}
for _, testcase := range testcases {
t.Run(testcase.name, func(t *testing.T) {
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.EndpointSliceTerminatingCondition, testcase.terminatingGateEnabled)()
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.TopologyAwareHints, testcase.hintsGateEnabled)()
dropDisabledFieldsOnUpdate(testcase.oldEPS, testcase.newEPS)
if !apiequality.Semantic.DeepEqual(testcase.newEPS, testcase.expectedEPS) {