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

@@ -917,7 +917,7 @@ func TestReconcileEndpointSlicesReplaceDeprecated(t *testing.T) {
namespace := "test"
svc, endpointMeta := newServiceAndEndpointMeta("foo", namespace)
endpointMeta.AddressType = discovery.AddressTypeIP
endpointMeta.AddressType = discovery.AddressType("IP")
existingSlices := []*discovery.EndpointSlice{}
pods := []*corev1.Pod{}

View File

@@ -87,6 +87,10 @@ func podToEndpoint(pod *corev1.Pod, node *corev1.Node, service *corev1.Service,
ep.Conditions.Terminating = &terminating
}
if pod.Spec.NodeName != "" && utilfeature.DefaultFeatureGate.Enabled(features.EndpointSliceNodeName) {
ep.NodeName = &pod.Spec.NodeName
}
if endpointutil.ShouldSetHostname(pod, service) {
ep.Hostname = &pod.Spec.Hostname
}

View File

@@ -252,6 +252,7 @@ func TestPodToEndpoint(t *testing.T) {
expectedEndpoint discovery.Endpoint
publishNotReadyAddresses bool
terminatingGateEnabled bool
nodeNameGateEnabled bool
}{
{
name: "Ready pod",
@@ -321,6 +322,25 @@ func TestPodToEndpoint(t *testing.T) {
},
},
},
{
name: "Ready pod + node name gate enabled",
pod: readyPod,
svc: &svc,
nodeNameGateEnabled: true,
expectedEndpoint: discovery.Endpoint{
Addresses: []string{"1.2.3.5"},
Conditions: discovery.EndpointConditions{Ready: utilpointer.BoolPtr(true)},
Topology: map[string]string{"kubernetes.io/hostname": "node-1"},
NodeName: utilpointer.StringPtr("node-1"),
TargetRef: &v1.ObjectReference{
Kind: "Pod",
Namespace: ns,
Name: readyPod.Name,
UID: readyPod.UID,
ResourceVersion: readyPod.ResourceVersion,
},
},
},
{
name: "Ready pod + node labels",
pod: readyPod,
@@ -499,6 +519,7 @@ func TestPodToEndpoint(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.EndpointSliceNodeName, testCase.nodeNameGateEnabled)()
endpoint := podToEndpoint(testCase.pod, testCase.node, testCase.svc, discovery.AddressTypeIPv4)
if !reflect.DeepEqual(testCase.expectedEndpoint, endpoint) {