openyurtio/openyurt

[BUG] ServiceTopology does not take effect in k8s 1.21 version

Closed this issue · 2 comments

What happened:
when k8s version is 1.21, service topology was not take effect

What you expected to happen:
The service takes effect in the new version

How to reproduce it (as minimally and precisely as possible):

Anything else we need to know?:

if serviceTopologyType == AnnotationServiceTopologyValueNode {
	for i := range endpointSlice.Endpoints {
		if endpointSlice.Endpoints[i].Topology[v1.LabelHostname] == fh.nodeName {
			newEps = append(newEps, endpointSlice.Endpoints[i])
		}
	}
	endpointSlice.Endpoints = newEps
} else if serviceTopologyType == AnnotationServiceTopologyValueNodePool || serviceTopologyType == AnnotationServiceTopologyValueZone {
	// if type of service Topology is openyurt.io/nodepool
	// filter the endpoint just on the node which is in the same nodepool with current node
	currentNode, err := fh.nodeGetter(fh.nodeName)
	if err != nil {
		klog.Infof("skip reassemble endpointSlice, failed to get current node %s, err: %v", fh.nodeName, err)
		return endpointSlice
	}
	if nodePoolName, ok := currentNode.Labels[nodepoolv1alpha1.LabelCurrentNodePool]; ok {
		nodePool, err := fh.nodePoolLister.Get(nodePoolName)
		if err != nil {
			klog.Infof("skip reassemble endpointSlice, failed to get nodepool %s, err: %v", nodePoolName, err)
			return endpointSlice
		}
		for i := range endpointSlice.Endpoints {
			if inSameNodePool(endpointSlice.Endpoints[i].Topology[v1.LabelHostname], nodePool.Status.Nodes) {
				newEps = append(newEps, endpointSlice.Endpoints[i])
			}
		}
		endpointSlice.Endpoints = newEps
	}
}

As we can see, the code has used endpointSlice.Endpoints[i].Topology to make sure the service success, but in 1.21 version, the per endpoint topology was effectively removed in favor of the dedicated fields nodeName and zone.

Environment:

  • OpenYurt version: v0.6.0
  • Kubernetes version (use kubectl version): 1.21
  • OS (e.g: cat /etc/os-release):
  • Kernel (e.g. uname -a):
  • Install tools:
  • Others:

others

/kind bug

@JameKeal Thank you for raising issue. how about make a pull request to fix this bug.

OK,I'll do it