Change:
}, }, }, <ins> { name:      "v1 request, updated endpoints with topology node names + other topology fields", v1Request: true, originalEPS: &discovery.EndpointSlice{ Endpoints: []discovery.Endpoint{ { Hostname:           utilpointer.StringPtr("hostname-1"), DeprecatedTopology: map[string]string{corev1.LabelHostname: "node-1", "other": "value"}, }, { Hostname:           utilpointer.StringPtr("hostname-1"), DeprecatedTopology: map[string]string{corev1.LabelHostname: "node-1", "foo": "bar"}, }, }, }, newEPS: &discovery.EndpointSlice{ Endpoints: []discovery.Endpoint{ { Hostname:           utilpointer.StringPtr("hostname-1a"), DeprecatedTopology: map[string]string{corev1.LabelHostname: "node-1", "other": "value"}, }, { Hostname:           utilpointer.StringPtr("hostname-1b"), DeprecatedTopology: map[string]string{corev1.LabelHostname: "node-1", "foo": "bar"}, }, }, }, expectedEPS: &discovery.EndpointSlice{ Endpoints: []discovery.Endpoint{ { Hostname: utilpointer.StringPtr("hostname-1a"), NodeName: utilpointer.StringPtr("node-1"), }, { Hostname: utilpointer.StringPtr("hostname-1b"), NodeName: utilpointer.StringPtr("node-1"), }, }, }, }, { name:      "v1 request, updated endpoints with topology node names", v1Request: true, originalEPS: &discovery.EndpointSlice{ Endpoints: []discovery.Endpoint{ { Hostname:           utilpointer.StringPtr("hostname-1"), DeprecatedTopology: map[string]string{corev1.LabelHostname: "node-1"}, }, { Hostname:           utilpointer.StringPtr("hostname-1"), DeprecatedTopology: map[string]string{corev1.LabelHostname: "node-1"}, }, }, }, newEPS: &discovery.EndpointSlice{ Endpoints: []discovery.Endpoint{ { Hostname:           utilpointer.StringPtr("hostname-1a"), DeprecatedTopology: map[string]string{corev1.LabelHostname: "node-1"}, }, { Hostname:           utilpointer.StringPtr("hostname-1b"), DeprecatedTopology: map[string]string{corev1.LabelHostname: "node-1"}, }, }, }, expectedEPS: &discovery.EndpointSlice{ Endpoints: []discovery.Endpoint{ { Hostname: utilpointer.StringPtr("hostname-1a"), NodeName: utilpointer.StringPtr("node-1"), }, { Hostname: utilpointer.StringPtr("hostname-1b"), NodeName: utilpointer.StringPtr("node-1"), }, }, }, }, { name:      "v1 request, updated endpoints with topology node names swapped", v1Request: true, originalEPS: &discovery.EndpointSlice{ Endpoints: []discovery.Endpoint{ { Hostname:           utilpointer.StringPtr("hostname-1"), DeprecatedTopology: map[string]string{corev1.LabelHostname: "node-1"}, }, { Hostname:           utilpointer.StringPtr("hostname-1"), DeprecatedTopology: map[string]string{corev1.LabelHostname: "node-2"}, }, }, }, newEPS: &discovery.EndpointSlice{ Endpoints: []discovery.Endpoint{ { Hostname:           utilpointer.StringPtr("hostname-1a"), DeprecatedTopology: map[string]string{corev1.LabelHostname: "node-2"}, }, { Hostname:           utilpointer.StringPtr("hostname-1b"), DeprecatedTopology: map[string]string{corev1.LabelHostname: "node-1"}, }, }, }, expectedEPS: &discovery.EndpointSlice{ Endpoints: []discovery.Endpoint{ { Hostname: utilpointer.StringPtr("hostname-1a"), NodeName: utilpointer.StringPtr("node-2"), }, { Hostname: utilpointer.StringPtr("hostname-1b"), NodeName: utilpointer.StringPtr("node-1"), }, }, }, }, { name:      "v1 request, updated endpoints with new topology node name", v1Request: true, originalEPS: &discovery.EndpointSlice{ Endpoints: []discovery.Endpoint{ { Hostname:           utilpointer.StringPtr("hostname-1"), DeprecatedTopology: map[string]string{corev1.LabelHostname: "node-1"}, }, { Hostname:           utilpointer.StringPtr("hostname-1"), DeprecatedTopology: map[string]string{corev1.LabelHostname: "node-2"}, }, }, }, newEPS: &discovery.EndpointSlice{ Endpoints: []discovery.Endpoint{ { Hostname: utilpointer.StringPtr("hostname-1a"), // Invalid node name because it did not exist in previous version of EndpointSlice DeprecatedTopology: map[string]string{corev1.LabelHostname: "node-3"}, }, { Hostname:           utilpointer.StringPtr("hostname-1b"), DeprecatedTopology: map[string]string{corev1.LabelHostname: "node-1"}, }, }, }, expectedEPS: &discovery.EndpointSlice{ Endpoints: []discovery.Endpoint{ { Hostname: utilpointer.StringPtr("hostname-1a"), }, { Hostname: utilpointer.StringPtr("hostname-1b"), NodeName: utilpointer.StringPtr("node-1"), }, }, }, }, { name:      "v1 request, updated endpoints with topology node names + 1 new node name", v1Request: true, originalEPS: &discovery.EndpointSlice{ Endpoints: []discovery.Endpoint{ { Hostname:           utilpointer.StringPtr("hostname-1"), DeprecatedTopology: map[string]string{corev1.LabelHostname: "node-1"}, }, { Hostname:           utilpointer.StringPtr("hostname-1"), DeprecatedTopology: map[string]string{corev1.LabelHostname: "node-1"}, }, }, }, newEPS: &discovery.EndpointSlice{ Endpoints: []discovery.Endpoint{ { Hostname:           utilpointer.StringPtr("hostname-1a"), DeprecatedTopology: map[string]string{corev1.LabelHostname: "node-1"}, }, { Hostname:           utilpointer.StringPtr("hostname-1b"), NodeName:           utilpointer.StringPtr("node-2"), DeprecatedTopology: map[string]string{corev1.LabelHostname: "node-1"}, }, }, }, expectedEPS: &discovery.EndpointSlice{ Endpoints: []discovery.Endpoint{ { Hostname: utilpointer.StringPtr("hostname-1a"), NodeName: utilpointer.StringPtr("node-1"), }, { Hostname: utilpointer.StringPtr("hostname-1b"), NodeName: utilpointer.StringPtr("node-2"), }, }, }, }, { name:      "v1 request, updated endpoints with topology node names + new node names", v1Request: true, originalEPS: &discovery.EndpointSlice{ Endpoints: []discovery.Endpoint{ { Hostname:           utilpointer.StringPtr("hostname-1"), DeprecatedTopology: map[string]string{corev1.LabelHostname: "node-1"}, }, { Hostname:           utilpointer.StringPtr("hostname-1"), DeprecatedTopology: map[string]string{corev1.LabelHostname: "node-1"}, }, }, }, newEPS: &discovery.EndpointSlice{ Endpoints: []discovery.Endpoint{ { Hostname:           utilpointer.StringPtr("hostname-1a"), DeprecatedTopology: map[string]string{corev1.LabelHostname: "node-1"}, NodeName:           utilpointer.StringPtr("node-1"), }, { Hostname:           utilpointer.StringPtr("hostname-1b"), NodeName:           utilpointer.StringPtr("node-2"), DeprecatedTopology: map[string]string{corev1.LabelHostname: "node-1"}, }, }, }, expectedEPS: &discovery.EndpointSlice{ Endpoints: []discovery.Endpoint{ { Hostname: utilpointer.StringPtr("hostname-1a"), NodeName: utilpointer.StringPtr("node-1"), }, { Hostname: utilpointer.StringPtr("hostname-1b"), NodeName: utilpointer.StringPtr("node-2"), }, }, }, }, { name:      "v1 request, invalid node name label", v1Request: true, originalEPS: &discovery.EndpointSlice{ Endpoints: []discovery.Endpoint{ { Hostname:           utilpointer.StringPtr("hostname-1"), DeprecatedTopology: map[string]string{corev1.LabelHostname: "valid-node-1"}, }, { Hostname:           utilpointer.StringPtr("hostname-2"), DeprecatedTopology: map[string]string{corev1.LabelHostname: "invalid node-2"}, }, { Hostname:           utilpointer.StringPtr("hostname-3"), DeprecatedTopology: map[string]string{corev1.LabelHostname: "valid-node-3"}, }, { Hostname:           utilpointer.StringPtr("hostname-4"), DeprecatedTopology: map[string]string{corev1.LabelHostname: "invalid node-4"}, }, }, }, newEPS: &discovery.EndpointSlice{ Endpoints: []discovery.Endpoint{ { Hostname:           utilpointer.StringPtr("hostname-1"), DeprecatedTopology: map[string]string{corev1.LabelHostname: "valid-node-1"}, }, { Hostname:           utilpointer.StringPtr("hostname-2"), DeprecatedTopology: map[string]string{corev1.LabelHostname: "invalid node-2"}, }, { Hostname: utilpointer.StringPtr("hostname-3"), NodeName: utilpointer.StringPtr("node-3"), }, { Hostname: utilpointer.StringPtr("hostname-4"), NodeName: utilpointer.StringPtr("node-4"), }, }, }, expectedEPS: &discovery.EndpointSlice{ Endpoints: []discovery.Endpoint{ { Hostname: utilpointer.StringPtr("hostname-1"), NodeName: utilpointer.StringPtr("valid-node-1"), }, { Hostname: utilpointer.StringPtr("hostname-2"), }, { Hostname: utilpointer.StringPtr("hostname-3"), NodeName: utilpointer.StringPtr("node-3"), }, { Hostname: utilpointer.StringPtr("hostname-4"), NodeName: utilpointer.StringPtr("node-4"), }, }, }, }, </ins> } for _, tc := range testcases {

Discussion:
On the first update of an EndpointSlice using the v1 API, we drop deprecatedTopology with EndpointSlice strategy. Although we only do this if at least 1 endpoint has been modified, there is no guarantee that node name has been populated for all endpoints within the EndpointSlice. This is most noticeable if the first update using the v1 API is only adding endpoint(s). In that case the EndpointSlice controller does not update EndpointSlices and instead just adds the new endpoint(s). That will cause node names to be dropped from the deprecated topology field without having the newer node name field populated. Node name to be retained in deprecated topology until the new field was populated. an EndpointSlice with the v1beta1 API. an endpoint in that EndpointSlice: No response This is most notable after upgrading a 1.20 cluster to 1.21, but can technically occur in any 1.21 or newer cluster. Any Any Any N/A N/A
I'm working on a fix for this, hoping to have it out later today. /triage accepted /sig network /cc
I think this is better characterized as a controller bug, but is the safest mitigation I can think of in the short term, since we don't want to rewrite 100% of endpointslices on startup. Can you open a separate issue to work through the controller reconciliation so that v1 clients can depend on the nodeName field more reliably?