Updating EndpointSlice controllers to support NodeName field

This commit is contained in:
Rob Scott
2020-11-10 17:50:39 -08:00
parent e9573eef4c
commit d985438772
6 changed files with 120 additions and 1 deletions

View File

@@ -27,10 +27,12 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
utilfeature "k8s.io/apiserver/pkg/util/feature"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/leaderelection/resourcelock"
"k8s.io/kubernetes/pkg/apis/discovery/validation"
endpointutil "k8s.io/kubernetes/pkg/controller/util/endpoint"
"k8s.io/kubernetes/pkg/features"
)
// addrTypePortMapKey is used to uniquely identify groups of endpoint ports and
@@ -138,6 +140,9 @@ func addressToEndpoint(address corev1.EndpointAddress, ready bool) *discovery.En
endpoint.Topology = map[string]string{
"kubernetes.io/hostname": *address.NodeName,
}
if utilfeature.DefaultFeatureGate.Enabled(features.EndpointSliceNodeName) {
endpoint.NodeName = address.NodeName
}
}
if address.Hostname != "" {
endpoint.Hostname = &address.Hostname