Merge pull request #51144 from joelsmith/skip-endpoints-update

Fix unready endpoints bug introduced in #50934
This commit is contained in:
Eric Paris 2017-08-22 19:56:17 -04:00 committed by GitHub
commit 2b08d1e5a1
2 changed files with 29 additions and 15 deletions

View File

@ -215,7 +215,14 @@ func podToEndpointAddress(pod *v1.Pod) *v1.EndpointAddress {
}} }}
} }
func podAddressChanged(oldPod, newPod *v1.Pod) bool { func podChanged(oldPod, newPod *v1.Pod) bool {
// If the pod's readiness has changed, the associated endpoint address
// will move from the unready endpoints set to the ready endpoints.
// So for the purposes of an endpoint, a readiness change on a pod
// means we have a changed pod.
if podutil.IsPodReady(oldPod) != podutil.IsPodReady(newPod) {
return true
}
// Convert the pod to an EndpointAddress, clear inert fields, // Convert the pod to an EndpointAddress, clear inert fields,
// and see if they are the same. // and see if they are the same.
newEndpointAddress := podToEndpointAddress(newPod) newEndpointAddress := podToEndpointAddress(newPod)
@ -257,7 +264,7 @@ func (e *EndpointController) updatePod(old, cur interface{}) {
return return
} }
podChanged := podAddressChanged(oldPod, newPod) podChangedFlag := podChanged(oldPod, newPod)
// Check if the pod labels have changed, indicating a possibe // Check if the pod labels have changed, indicating a possibe
// change in the service membership // change in the service membership
@ -268,7 +275,7 @@ func (e *EndpointController) updatePod(old, cur interface{}) {
} }
// If both the pod and labels are unchanged, no update is needed // If both the pod and labels are unchanged, no update is needed
if !podChanged && !labelsChanged { if !podChangedFlag && !labelsChanged {
return return
} }
@ -284,7 +291,7 @@ func (e *EndpointController) updatePod(old, cur interface{}) {
utilruntime.HandleError(fmt.Errorf("Unable to get pod %v/%v's service memberships: %v", oldPod.Namespace, oldPod.Name, err)) utilruntime.HandleError(fmt.Errorf("Unable to get pod %v/%v's service memberships: %v", oldPod.Namespace, oldPod.Name, err))
return return
} }
services = determineNeededServiceUpdates(oldServices, services, podChanged) services = determineNeededServiceUpdates(oldServices, services, podChangedFlag)
} }
for key := range services { for key := range services {

View File

@ -992,7 +992,7 @@ func TestPodToEndpointAddress(t *testing.T) {
} }
} }
func TestPodAddressChanged(t *testing.T) { func TestPodChanged(t *testing.T) {
podStore := cache.NewStore(cache.DeletionHandlingMetaNamespaceKeyFunc) podStore := cache.NewStore(cache.DeletionHandlingMetaNamespaceKeyFunc)
ns := "test" ns := "test"
addPods(podStore, ns, 1, 1, 0) addPods(podStore, ns, 1, 1, 0)
@ -1004,33 +1004,40 @@ func TestPodAddressChanged(t *testing.T) {
oldPod := pods[0].(*v1.Pod) oldPod := pods[0].(*v1.Pod)
newPod := oldPod.DeepCopy() newPod := oldPod.DeepCopy()
if podAddressChanged(oldPod, newPod) { if podChanged(oldPod, newPod) {
t.Errorf("Expected address to be unchanged for copied pod") t.Errorf("Expected pod to be unchanged for copied pod")
} }
newPod.Spec.NodeName = "changed" newPod.Spec.NodeName = "changed"
if !podAddressChanged(oldPod, newPod) { if !podChanged(oldPod, newPod) {
t.Errorf("Expected address to be changed for pod with NodeName changed") t.Errorf("Expected pod to be changed for pod with NodeName changed")
} }
newPod.Spec.NodeName = oldPod.Spec.NodeName newPod.Spec.NodeName = oldPod.Spec.NodeName
newPod.ObjectMeta.ResourceVersion = "changed" newPod.ObjectMeta.ResourceVersion = "changed"
if podAddressChanged(oldPod, newPod) { if podChanged(oldPod, newPod) {
t.Errorf("Expected address to be unchanged for pod with only ResourceVersion changed") t.Errorf("Expected pod to be unchanged for pod with only ResourceVersion changed")
} }
newPod.ObjectMeta.ResourceVersion = oldPod.ObjectMeta.ResourceVersion newPod.ObjectMeta.ResourceVersion = oldPod.ObjectMeta.ResourceVersion
newPod.Status.PodIP = "1.2.3.1" newPod.Status.PodIP = "1.2.3.1"
if !podAddressChanged(oldPod, newPod) { if !podChanged(oldPod, newPod) {
t.Errorf("Expected address to be changed with pod IP address change") t.Errorf("Expected pod to be changed with pod IP address change")
} }
newPod.Status.PodIP = oldPod.Status.PodIP newPod.Status.PodIP = oldPod.Status.PodIP
newPod.ObjectMeta.Name = "wrong-name" newPod.ObjectMeta.Name = "wrong-name"
if !podAddressChanged(oldPod, newPod) { if !podChanged(oldPod, newPod) {
t.Errorf("Expected address to be changed with pod name change") t.Errorf("Expected pod to be changed with pod name change")
} }
newPod.ObjectMeta.Name = oldPod.ObjectMeta.Name newPod.ObjectMeta.Name = oldPod.ObjectMeta.Name
saveConditions := oldPod.Status.Conditions
oldPod.Status.Conditions = nil
if !podChanged(oldPod, newPod) {
t.Errorf("Expected pod to be changed with pod readiness change")
}
oldPod.Status.Conditions = saveConditions
} }
func TestDetermineNeededServiceUpdates(t *testing.T) { func TestDetermineNeededServiceUpdates(t *testing.T) {