mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 04:08:16 +00:00 
			
		
		
		
	Merge pull request #108123 from tnqn/fix-EndpointsEqualBeyondHash
Fix incorrect parameters in EndpointsEqualBeyondHash
This commit is contained in:
		@@ -281,11 +281,11 @@ func (sl portsInOrder) Less(i, j int) bool {
 | 
				
			|||||||
// but excludes equality checks that would have already been covered with
 | 
					// but excludes equality checks that would have already been covered with
 | 
				
			||||||
// endpoint hashing (see hashEndpoint func for more info).
 | 
					// endpoint hashing (see hashEndpoint func for more info).
 | 
				
			||||||
func EndpointsEqualBeyondHash(ep1, ep2 *discovery.Endpoint) bool {
 | 
					func EndpointsEqualBeyondHash(ep1, ep2 *discovery.Endpoint) bool {
 | 
				
			||||||
	if stringPtrChanged(ep1.NodeName, ep1.NodeName) {
 | 
						if stringPtrChanged(ep1.NodeName, ep2.NodeName) {
 | 
				
			||||||
		return false
 | 
							return false
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if stringPtrChanged(ep1.Zone, ep1.Zone) {
 | 
						if stringPtrChanged(ep1.Zone, ep2.Zone) {
 | 
				
			||||||
		return false
 | 
							return false
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -23,11 +23,13 @@ import (
 | 
				
			|||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	v1 "k8s.io/api/core/v1"
 | 
						v1 "k8s.io/api/core/v1"
 | 
				
			||||||
 | 
						discovery "k8s.io/api/discovery/v1"
 | 
				
			||||||
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
						metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
				
			||||||
	"k8s.io/apimachinery/pkg/labels"
 | 
						"k8s.io/apimachinery/pkg/labels"
 | 
				
			||||||
	"k8s.io/apimachinery/pkg/util/sets"
 | 
						"k8s.io/apimachinery/pkg/util/sets"
 | 
				
			||||||
	"k8s.io/client-go/informers"
 | 
						"k8s.io/client-go/informers"
 | 
				
			||||||
	"k8s.io/client-go/kubernetes/fake"
 | 
						"k8s.io/client-go/kubernetes/fake"
 | 
				
			||||||
 | 
						utilpointer "k8s.io/utils/pointer"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestDetermineNeededServiceUpdates(t *testing.T) {
 | 
					func TestDetermineNeededServiceUpdates(t *testing.T) {
 | 
				
			||||||
@@ -663,3 +665,124 @@ func Test_podChanged(t *testing.T) {
 | 
				
			|||||||
		})
 | 
							})
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestEndpointsEqualBeyondHash(t *testing.T) {
 | 
				
			||||||
 | 
						tests := []struct {
 | 
				
			||||||
 | 
							name     string
 | 
				
			||||||
 | 
							ep1      *discovery.Endpoint
 | 
				
			||||||
 | 
							ep2      *discovery.Endpoint
 | 
				
			||||||
 | 
							expected bool
 | 
				
			||||||
 | 
						}{
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								name: "No change",
 | 
				
			||||||
 | 
								ep1: &discovery.Endpoint{
 | 
				
			||||||
 | 
									Conditions: discovery.EndpointConditions{
 | 
				
			||||||
 | 
										Ready: utilpointer.BoolPtr(true),
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
									Addresses: []string{"10.0.0.1"},
 | 
				
			||||||
 | 
									TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod0"},
 | 
				
			||||||
 | 
									NodeName:  utilpointer.StringPtr("node-1"),
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								ep2: &discovery.Endpoint{
 | 
				
			||||||
 | 
									Conditions: discovery.EndpointConditions{
 | 
				
			||||||
 | 
										Ready: utilpointer.BoolPtr(true),
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
									Addresses: []string{"10.0.0.1"},
 | 
				
			||||||
 | 
									TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod0"},
 | 
				
			||||||
 | 
									NodeName:  utilpointer.StringPtr("node-1"),
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								expected: true,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								name: "NodeName changed",
 | 
				
			||||||
 | 
								ep1: &discovery.Endpoint{
 | 
				
			||||||
 | 
									Conditions: discovery.EndpointConditions{
 | 
				
			||||||
 | 
										Ready: utilpointer.BoolPtr(true),
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
									Addresses: []string{"10.0.0.1"},
 | 
				
			||||||
 | 
									TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod0"},
 | 
				
			||||||
 | 
									NodeName:  utilpointer.StringPtr("node-1"),
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								ep2: &discovery.Endpoint{
 | 
				
			||||||
 | 
									Conditions: discovery.EndpointConditions{
 | 
				
			||||||
 | 
										Ready: utilpointer.BoolPtr(true),
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
									Addresses: []string{"10.0.0.1"},
 | 
				
			||||||
 | 
									TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod0"},
 | 
				
			||||||
 | 
									NodeName:  utilpointer.StringPtr("node-2"),
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								expected: false,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								name: "Zone changed",
 | 
				
			||||||
 | 
								ep1: &discovery.Endpoint{
 | 
				
			||||||
 | 
									Conditions: discovery.EndpointConditions{
 | 
				
			||||||
 | 
										Ready: utilpointer.BoolPtr(true),
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
									Addresses: []string{"10.0.0.1"},
 | 
				
			||||||
 | 
									TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod0"},
 | 
				
			||||||
 | 
									Zone:      utilpointer.StringPtr("zone-1"),
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								ep2: &discovery.Endpoint{
 | 
				
			||||||
 | 
									Conditions: discovery.EndpointConditions{
 | 
				
			||||||
 | 
										Ready: utilpointer.BoolPtr(true),
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
									Addresses: []string{"10.0.0.1"},
 | 
				
			||||||
 | 
									TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod0"},
 | 
				
			||||||
 | 
									Zone:      utilpointer.StringPtr("zone-2"),
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								expected: false,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								name: "Ready condition changed",
 | 
				
			||||||
 | 
								ep1: &discovery.Endpoint{
 | 
				
			||||||
 | 
									Conditions: discovery.EndpointConditions{
 | 
				
			||||||
 | 
										Ready: utilpointer.BoolPtr(true),
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
									Addresses: []string{"10.0.0.1"},
 | 
				
			||||||
 | 
									TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod0"},
 | 
				
			||||||
 | 
									Zone:      utilpointer.StringPtr("zone-1"),
 | 
				
			||||||
 | 
									NodeName:  utilpointer.StringPtr("node-1"),
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								ep2: &discovery.Endpoint{
 | 
				
			||||||
 | 
									Conditions: discovery.EndpointConditions{
 | 
				
			||||||
 | 
										Ready: utilpointer.BoolPtr(false),
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
									Addresses: []string{"10.0.0.1"},
 | 
				
			||||||
 | 
									TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod0"},
 | 
				
			||||||
 | 
									Zone:      utilpointer.StringPtr("zone-1"),
 | 
				
			||||||
 | 
									NodeName:  utilpointer.StringPtr("node-1"),
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								expected: false,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								name: "Pod name changed",
 | 
				
			||||||
 | 
								ep1: &discovery.Endpoint{
 | 
				
			||||||
 | 
									Conditions: discovery.EndpointConditions{
 | 
				
			||||||
 | 
										Ready: utilpointer.BoolPtr(true),
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
									Addresses: []string{"10.0.0.1"},
 | 
				
			||||||
 | 
									TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod0"},
 | 
				
			||||||
 | 
									Zone:      utilpointer.StringPtr("zone-1"),
 | 
				
			||||||
 | 
									NodeName:  utilpointer.StringPtr("node-1"),
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								ep2: &discovery.Endpoint{
 | 
				
			||||||
 | 
									Conditions: discovery.EndpointConditions{
 | 
				
			||||||
 | 
										Ready: utilpointer.BoolPtr(true),
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
									Addresses: []string{"10.0.0.1"},
 | 
				
			||||||
 | 
									TargetRef: &v1.ObjectReference{Kind: "Pod", Namespace: "default", Name: "pod1"},
 | 
				
			||||||
 | 
									Zone:      utilpointer.StringPtr("zone-1"),
 | 
				
			||||||
 | 
									NodeName:  utilpointer.StringPtr("node-1"),
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								expected: false,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						for _, tt := range tests {
 | 
				
			||||||
 | 
							t.Run(tt.name, func(t *testing.T) {
 | 
				
			||||||
 | 
								if got := EndpointsEqualBeyondHash(tt.ep1, tt.ep2); got != tt.expected {
 | 
				
			||||||
 | 
									t.Errorf("EndpointsEqualBeyondHash() = %v, want %v", got, tt.expected)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user