Merge pull request #108450 from tnqn/stop-setting-rv-in-endpoints

Stop publishing Pod ResourceVersion in Endpoints and EndpointSlice API
This commit is contained in:
Kubernetes Prow Robot 2022-03-04 17:23:04 -08:00 committed by GitHub
commit da23196df6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 96 additions and 78 deletions

View File

@ -259,7 +259,6 @@ func podToEndpointAddressForService(svc *v1.Service, pod *v1.Pod) (*v1.EndpointA
Namespace: pod.ObjectMeta.Namespace, Namespace: pod.ObjectMeta.Namespace,
Name: pod.ObjectMeta.Name, Name: pod.ObjectMeta.Name,
UID: pod.ObjectMeta.UID, UID: pod.ObjectMeta.UID,
ResourceVersion: pod.ObjectMeta.ResourceVersion,
}, },
}, nil }, nil
} }

View File

@ -66,6 +66,7 @@ func testPod(namespace string, id int, nPorts int, isReady bool, ipFamilies []v1
Namespace: namespace, Namespace: namespace,
Name: fmt.Sprintf("pod%d", id), Name: fmt.Sprintf("pod%d", id),
Labels: map[string]string{"foo": "bar"}, Labels: map[string]string{"foo": "bar"},
ResourceVersion: fmt.Sprint(id),
}, },
Spec: v1.PodSpec{ Spec: v1.PodSpec{
Containers: []v1.Container{{Ports: []v1.ContainerPort{}}}, Containers: []v1.Container{{Ports: []v1.ContainerPort{}}},
@ -1430,16 +1431,16 @@ func TestPodToEndpointAddressForService(t *testing.T) {
t.Fatalf("TargetRef.Kind: expected: %s, got: %s", "Pod", epa.TargetRef.Kind) t.Fatalf("TargetRef.Kind: expected: %s, got: %s", "Pod", epa.TargetRef.Kind)
} }
if epa.TargetRef.Namespace != pod.ObjectMeta.Namespace { if epa.TargetRef.Namespace != pod.ObjectMeta.Namespace {
t.Fatalf("TargetRef.Kind: expected: %s, got: %s", pod.ObjectMeta.Namespace, epa.TargetRef.Namespace) t.Fatalf("TargetRef.Namespace: expected: %s, got: %s", pod.ObjectMeta.Namespace, epa.TargetRef.Namespace)
} }
if epa.TargetRef.Name != pod.ObjectMeta.Name { if epa.TargetRef.Name != pod.ObjectMeta.Name {
t.Fatalf("TargetRef.Kind: expected: %s, got: %s", pod.ObjectMeta.Name, epa.TargetRef.Name) t.Fatalf("TargetRef.Name: expected: %s, got: %s", pod.ObjectMeta.Name, epa.TargetRef.Name)
} }
if epa.TargetRef.UID != pod.ObjectMeta.UID { if epa.TargetRef.UID != pod.ObjectMeta.UID {
t.Fatalf("TargetRef.Kind: expected: %s, got: %s", pod.ObjectMeta.UID, epa.TargetRef.UID) t.Fatalf("TargetRef.UID: expected: %s, got: %s", pod.ObjectMeta.UID, epa.TargetRef.UID)
} }
if epa.TargetRef.ResourceVersion != pod.ObjectMeta.ResourceVersion { if epa.TargetRef.ResourceVersion != "" {
t.Fatalf("TargetRef.Kind: expected: %s, got: %s", pod.ObjectMeta.ResourceVersion, epa.TargetRef.ResourceVersion) t.Fatalf("TargetRef.ResourceVersion: expected empty, got: %s", epa.TargetRef.ResourceVersion)
} }
}) })
} }

View File

@ -57,7 +57,6 @@ func podToEndpoint(pod *corev1.Pod, node *corev1.Node, service *corev1.Service,
Namespace: pod.ObjectMeta.Namespace, Namespace: pod.ObjectMeta.Namespace,
Name: pod.ObjectMeta.Name, Name: pod.ObjectMeta.Name,
UID: pod.ObjectMeta.UID, UID: pod.ObjectMeta.UID,
ResourceVersion: pod.ObjectMeta.ResourceVersion,
}, },
} }

View File

@ -266,7 +266,6 @@ func TestPodToEndpoint(t *testing.T) {
Namespace: ns, Namespace: ns,
Name: readyPod.Name, Name: readyPod.Name,
UID: readyPod.UID, UID: readyPod.UID,
ResourceVersion: readyPod.ResourceVersion,
}, },
}, },
}, },
@ -283,7 +282,6 @@ func TestPodToEndpoint(t *testing.T) {
Namespace: ns, Namespace: ns,
Name: readyPod.Name, Name: readyPod.Name,
UID: readyPod.UID, UID: readyPod.UID,
ResourceVersion: readyPod.ResourceVersion,
}, },
}, },
}, },
@ -300,7 +298,6 @@ func TestPodToEndpoint(t *testing.T) {
Namespace: ns, Namespace: ns,
Name: readyPod.Name, Name: readyPod.Name,
UID: readyPod.UID, UID: readyPod.UID,
ResourceVersion: readyPod.ResourceVersion,
}, },
}, },
}, },
@ -317,7 +314,6 @@ func TestPodToEndpoint(t *testing.T) {
Namespace: ns, Namespace: ns,
Name: readyPod.Name, Name: readyPod.Name,
UID: readyPod.UID, UID: readyPod.UID,
ResourceVersion: readyPod.ResourceVersion,
}, },
}, },
}, },
@ -336,7 +332,6 @@ func TestPodToEndpoint(t *testing.T) {
Namespace: ns, Namespace: ns,
Name: readyPod.Name, Name: readyPod.Name,
UID: readyPod.UID, UID: readyPod.UID,
ResourceVersion: readyPod.ResourceVersion,
}, },
}, },
}, },
@ -355,7 +350,6 @@ func TestPodToEndpoint(t *testing.T) {
Namespace: ns, Namespace: ns,
Name: readyPod.Name, Name: readyPod.Name,
UID: readyPod.UID, UID: readyPod.UID,
ResourceVersion: readyPod.ResourceVersion,
}, },
}, },
}, },
@ -375,7 +369,6 @@ func TestPodToEndpoint(t *testing.T) {
Namespace: ns, Namespace: ns,
Name: readyPodHostname.Name, Name: readyPodHostname.Name,
UID: readyPodHostname.UID, UID: readyPodHostname.UID,
ResourceVersion: readyPodHostname.ResourceVersion,
}, },
}, },
}, },
@ -396,7 +389,6 @@ func TestPodToEndpoint(t *testing.T) {
Namespace: ns, Namespace: ns,
Name: readyPod.Name, Name: readyPod.Name,
UID: readyPod.UID, UID: readyPod.UID,
ResourceVersion: readyPod.ResourceVersion,
}, },
}, },
terminatingGateEnabled: true, terminatingGateEnabled: true,
@ -416,7 +408,6 @@ func TestPodToEndpoint(t *testing.T) {
Namespace: ns, Namespace: ns,
Name: readyPod.Name, Name: readyPod.Name,
UID: readyPod.UID, UID: readyPod.UID,
ResourceVersion: readyPod.ResourceVersion,
}, },
}, },
terminatingGateEnabled: false, terminatingGateEnabled: false,
@ -438,7 +429,6 @@ func TestPodToEndpoint(t *testing.T) {
Namespace: ns, Namespace: ns,
Name: readyPod.Name, Name: readyPod.Name,
UID: readyPod.UID, UID: readyPod.UID,
ResourceVersion: readyPod.ResourceVersion,
}, },
}, },
terminatingGateEnabled: true, terminatingGateEnabled: true,
@ -458,7 +448,6 @@ func TestPodToEndpoint(t *testing.T) {
Namespace: ns, Namespace: ns,
Name: readyPod.Name, Name: readyPod.Name,
UID: readyPod.UID, UID: readyPod.UID,
ResourceVersion: readyPod.ResourceVersion,
}, },
}, },
terminatingGateEnabled: false, terminatingGateEnabled: false,
@ -480,7 +469,6 @@ func TestPodToEndpoint(t *testing.T) {
Namespace: ns, Namespace: ns,
Name: readyPod.Name, Name: readyPod.Name,
UID: readyPod.UID, UID: readyPod.UID,
ResourceVersion: readyPod.ResourceVersion,
}, },
}, },
terminatingGateEnabled: true, terminatingGateEnabled: true,
@ -937,6 +925,7 @@ func newPod(n int, namespace string, ready bool, nPorts int, terminating bool) *
Name: fmt.Sprintf("pod%d", n), Name: fmt.Sprintf("pod%d", n),
Labels: map[string]string{"foo": "bar"}, Labels: map[string]string{"foo": "bar"},
DeletionTimestamp: deletionTimestamp, DeletionTimestamp: deletionTimestamp,
ResourceVersion: fmt.Sprint(n),
}, },
Spec: v1.PodSpec{ Spec: v1.PodSpec{
Containers: []v1.Container{{ Containers: []v1.Container{{

View File

@ -851,6 +851,28 @@ func TestEndpointsEqualBeyondHash(t *testing.T) {
}, },
expected: true, expected: true,
}, },
{
name: "Pod resourceVersion removed",
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", ResourceVersion: "1"},
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: "pod0", ResourceVersion: ""},
Zone: utilpointer.StringPtr("zone-1"),
NodeName: utilpointer.StringPtr("node-1"),
},
expected: true,
},
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
@ -933,6 +955,14 @@ func TestEndpointSubsetsEqualIgnoreResourceVersion(t *testing.T) {
})}, })},
expected: true, expected: true,
}, },
{
name: "Pod ResourceVersion removed",
subsets1: []v1.EndpointSubset{*es1, *es2},
subsets2: []v1.EndpointSubset{*es1, *copyAndMutateEndpointSubset(es2, func(es *v1.EndpointSubset) {
es.Addresses[0].TargetRef.ResourceVersion = ""
})},
expected: true,
},
{ {
name: "Ports changed", name: "Ports changed",
subsets1: []v1.EndpointSubset{*es1, *es2}, subsets1: []v1.EndpointSubset{*es1, *es2},