mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Don't write out dummy zone hints in clusters with no zones
If you set `trafficDistribution: PreferClose` on a service in a cluster with no defined zones, then it would add hints: forZones: - name: "" to each endpoint. This ended up working anyway since kube-proxy would likewise end up looking for an endpoint for the "" zone, but it's unnecessary, since you'd get exactly the same behavior by just leaving all of the endpoints unhinted. (Of course there's no point in using PreferClose traffic distribution in this case, but this will make PreferSameNode cleaner.)
This commit is contained in:
parent
413af836b3
commit
90c8f9aef1
@ -115,13 +115,19 @@ func (preferCloseHeuristic) needsUpdate(slice *discoveryv1.EndpointSlice) bool {
|
|||||||
if !endpointReady(endpoint) {
|
if !endpointReady(endpoint) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
var zone string
|
|
||||||
if endpoint.Zone != nil {
|
|
||||||
zone = *endpoint.Zone
|
|
||||||
}
|
|
||||||
|
|
||||||
if endpoint.Hints == nil || len(endpoint.Hints.ForZones) != 1 || endpoint.Hints.ForZones[0].Name != zone {
|
if endpoint.Zone != nil {
|
||||||
return true
|
// We want a zone hint.
|
||||||
|
if endpoint.Hints == nil || len(endpoint.Hints.ForZones) != 1 || endpoint.Hints.ForZones[0].Name != *endpoint.Zone {
|
||||||
|
// ...but either it's missing or it's incorrect
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// We don't want a zone hint.
|
||||||
|
if endpoint.Hints != nil && len(endpoint.Hints.ForZones) > 0 {
|
||||||
|
// ...but we have a stale hint.
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
@ -134,10 +140,17 @@ func (preferCloseHeuristic) update(slice *discoveryv1.EndpointSlice) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
var zone string
|
var forZones []discoveryv1.ForZone
|
||||||
if endpoint.Zone != nil {
|
if endpoint.Zone != nil {
|
||||||
zone = *endpoint.Zone
|
forZones = []discoveryv1.ForZone{{Name: *endpoint.Zone}}
|
||||||
|
}
|
||||||
|
|
||||||
|
if forZones != nil {
|
||||||
|
slice.Endpoints[i].Hints = &discoveryv1.EndpointHints{
|
||||||
|
ForZones: forZones,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
slice.Endpoints[i].Hints = nil
|
||||||
}
|
}
|
||||||
slice.Endpoints[i].Hints = &discoveryv1.EndpointHints{ForZones: []discoveryv1.ForZone{{Name: zone}}}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -264,6 +264,131 @@ func TestReconcileHints(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "should not create zone hints if there are no zones",
|
||||||
|
|
||||||
|
trafficDistribution: ptr.To(corev1.ServiceTrafficDistributionPreferClose),
|
||||||
|
slicesToCreate: []*discoveryv1.EndpointSlice{
|
||||||
|
{
|
||||||
|
Endpoints: []discoveryv1.Endpoint{
|
||||||
|
{
|
||||||
|
Addresses: []string{"10.0.0.1"},
|
||||||
|
NodeName: ptr.To("node-1"),
|
||||||
|
Conditions: discoveryv1.EndpointConditions{Ready: ptr.To(true)},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Addresses: []string{"10.0.0.2"},
|
||||||
|
NodeName: ptr.To("node-2"),
|
||||||
|
Conditions: discoveryv1.EndpointConditions{Ready: ptr.To(true)},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Endpoints: []discoveryv1.Endpoint{
|
||||||
|
{
|
||||||
|
Addresses: []string{"10.0.0.3"},
|
||||||
|
NodeName: ptr.To("node-3"),
|
||||||
|
Conditions: discoveryv1.EndpointConditions{Ready: ptr.To(true)},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Addresses: []string{"10.0.0.4"},
|
||||||
|
NodeName: ptr.To("node-4"),
|
||||||
|
Conditions: discoveryv1.EndpointConditions{Ready: ptr.To(true)},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
slicesToUpdate: []*discoveryv1.EndpointSlice{
|
||||||
|
{
|
||||||
|
Endpoints: []discoveryv1.Endpoint{
|
||||||
|
{
|
||||||
|
Addresses: []string{"10.0.0.5"},
|
||||||
|
NodeName: ptr.To("node-5"),
|
||||||
|
Conditions: discoveryv1.EndpointConditions{Ready: ptr.To(true)},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Addresses: []string{"10.0.0.6"},
|
||||||
|
NodeName: ptr.To("node-6"),
|
||||||
|
Conditions: discoveryv1.EndpointConditions{Ready: ptr.To(true)},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Endpoints: []discoveryv1.Endpoint{
|
||||||
|
{
|
||||||
|
Addresses: []string{"10.0.0.7"},
|
||||||
|
NodeName: ptr.To("node-7"),
|
||||||
|
Conditions: discoveryv1.EndpointConditions{Ready: ptr.To(true)},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Addresses: []string{"10.0.0.8"},
|
||||||
|
NodeName: ptr.To("node-8"),
|
||||||
|
Conditions: discoveryv1.EndpointConditions{Ready: ptr.To(true)},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
wantSlicesToCreate: []*discoveryv1.EndpointSlice{
|
||||||
|
{
|
||||||
|
Endpoints: []discoveryv1.Endpoint{
|
||||||
|
{
|
||||||
|
Addresses: []string{"10.0.0.1"},
|
||||||
|
NodeName: ptr.To("node-1"),
|
||||||
|
Conditions: discoveryv1.EndpointConditions{Ready: ptr.To(true)},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Addresses: []string{"10.0.0.2"},
|
||||||
|
NodeName: ptr.To("node-2"),
|
||||||
|
Conditions: discoveryv1.EndpointConditions{Ready: ptr.To(true)},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Endpoints: []discoveryv1.Endpoint{
|
||||||
|
{
|
||||||
|
Addresses: []string{"10.0.0.3"},
|
||||||
|
NodeName: ptr.To("node-3"),
|
||||||
|
Conditions: discoveryv1.EndpointConditions{Ready: ptr.To(true)},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Addresses: []string{"10.0.0.4"},
|
||||||
|
NodeName: ptr.To("node-4"),
|
||||||
|
Conditions: discoveryv1.EndpointConditions{Ready: ptr.To(true)},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
wantSlicesToUpdate: []*discoveryv1.EndpointSlice{
|
||||||
|
{
|
||||||
|
Endpoints: []discoveryv1.Endpoint{
|
||||||
|
{
|
||||||
|
Addresses: []string{"10.0.0.5"},
|
||||||
|
NodeName: ptr.To("node-5"),
|
||||||
|
Conditions: discoveryv1.EndpointConditions{Ready: ptr.To(true)},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Addresses: []string{"10.0.0.6"},
|
||||||
|
NodeName: ptr.To("node-6"),
|
||||||
|
Conditions: discoveryv1.EndpointConditions{Ready: ptr.To(true)},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Endpoints: []discoveryv1.Endpoint{
|
||||||
|
{
|
||||||
|
Addresses: []string{"10.0.0.7"},
|
||||||
|
NodeName: ptr.To("node-7"),
|
||||||
|
Conditions: discoveryv1.EndpointConditions{Ready: ptr.To(true)},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Addresses: []string{"10.0.0.8"},
|
||||||
|
NodeName: ptr.To("node-8"),
|
||||||
|
Conditions: discoveryv1.EndpointConditions{Ready: ptr.To(true)},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "unready endpoints should not trigger updates",
|
name: "unready endpoints should not trigger updates",
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user