Skip to content

Commit 9d8a87b

Browse files
authored
Merge pull request kubernetes#93442 from robscott/endpointslicemirroring-labels
Updating EndpointSliceMirroring controller to copy labels from Endpoints
2 parents 1a05ebe + 52894d7 commit 9d8a87b

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

pkg/controller/endpointslicemirroring/utils.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,7 @@ func newEndpointSlice(endpoints *corev1.Endpoints, ports []discovery.EndpointPor
8888
ownerRef := metav1.NewControllerRef(endpoints, gvk)
8989
epSlice := &discovery.EndpointSlice{
9090
ObjectMeta: metav1.ObjectMeta{
91-
Labels: map[string]string{
92-
discovery.LabelServiceName: endpoints.Name,
93-
discovery.LabelManagedBy: controllerName,
94-
},
91+
Labels: map[string]string{},
9592
OwnerReferences: []metav1.OwnerReference{*ownerRef},
9693
Namespace: endpoints.Namespace,
9794
},
@@ -100,6 +97,13 @@ func newEndpointSlice(endpoints *corev1.Endpoints, ports []discovery.EndpointPor
10097
Endpoints: []discovery.Endpoint{},
10198
}
10299

100+
for label, val := range endpoints.Labels {
101+
epSlice.Labels[label] = val
102+
}
103+
104+
epSlice.Labels[discovery.LabelServiceName] = endpoints.Name
105+
epSlice.Labels[discovery.LabelManagedBy] = controllerName
106+
103107
if sliceName == "" {
104108
epSlice.GenerateName = getEndpointSlicePrefix(endpoints.Name)
105109
} else {

pkg/controller/endpointslicemirroring/utils_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ func TestNewEndpointSlice(t *testing.T) {
3939
addrType := discovery.AddressTypeIPv4
4040

4141
endpoints := v1.Endpoints{
42-
ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "test"},
42+
ObjectMeta: metav1.ObjectMeta{
43+
Name: "foo",
44+
Namespace: "test",
45+
Labels: map[string]string{"foo": "bar"},
46+
},
4347
Subsets: []v1.EndpointSubset{{
4448
Ports: []v1.EndpointPort{{Port: 80}},
4549
}},
@@ -51,6 +55,7 @@ func TestNewEndpointSlice(t *testing.T) {
5155
expectedSlice := discovery.EndpointSlice{
5256
ObjectMeta: metav1.ObjectMeta{
5357
Labels: map[string]string{
58+
"foo": "bar",
5459
discovery.LabelServiceName: endpoints.Name,
5560
discovery.LabelManagedBy: controllerName,
5661
},
@@ -65,6 +70,10 @@ func TestNewEndpointSlice(t *testing.T) {
6570
generatedSlice := newEndpointSlice(&endpoints, ports, addrType, "")
6671

6772
assert.EqualValues(t, expectedSlice, *generatedSlice)
73+
74+
if len(endpoints.Labels) > 1 {
75+
t.Errorf("Expected Endpoints labels to not be modified, got %+v", endpoints.Labels)
76+
}
6877
}
6978

7079
// Test helpers

0 commit comments

Comments
 (0)