mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-29 13:24:42 +00:00
Merge pull request #93442 from robscott/endpointslicemirroring-labels
Updating EndpointSliceMirroring controller to copy labels from Endpoints
This commit is contained in:
commit
9d8a87b5c7
@ -88,10 +88,7 @@ func newEndpointSlice(endpoints *corev1.Endpoints, ports []discovery.EndpointPor
|
|||||||
ownerRef := metav1.NewControllerRef(endpoints, gvk)
|
ownerRef := metav1.NewControllerRef(endpoints, gvk)
|
||||||
epSlice := &discovery.EndpointSlice{
|
epSlice := &discovery.EndpointSlice{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{},
|
||||||
discovery.LabelServiceName: endpoints.Name,
|
|
||||||
discovery.LabelManagedBy: controllerName,
|
|
||||||
},
|
|
||||||
OwnerReferences: []metav1.OwnerReference{*ownerRef},
|
OwnerReferences: []metav1.OwnerReference{*ownerRef},
|
||||||
Namespace: endpoints.Namespace,
|
Namespace: endpoints.Namespace,
|
||||||
},
|
},
|
||||||
@ -100,6 +97,13 @@ func newEndpointSlice(endpoints *corev1.Endpoints, ports []discovery.EndpointPor
|
|||||||
Endpoints: []discovery.Endpoint{},
|
Endpoints: []discovery.Endpoint{},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for label, val := range endpoints.Labels {
|
||||||
|
epSlice.Labels[label] = val
|
||||||
|
}
|
||||||
|
|
||||||
|
epSlice.Labels[discovery.LabelServiceName] = endpoints.Name
|
||||||
|
epSlice.Labels[discovery.LabelManagedBy] = controllerName
|
||||||
|
|
||||||
if sliceName == "" {
|
if sliceName == "" {
|
||||||
epSlice.GenerateName = getEndpointSlicePrefix(endpoints.Name)
|
epSlice.GenerateName = getEndpointSlicePrefix(endpoints.Name)
|
||||||
} else {
|
} else {
|
||||||
|
@ -39,7 +39,11 @@ func TestNewEndpointSlice(t *testing.T) {
|
|||||||
addrType := discovery.AddressTypeIPv4
|
addrType := discovery.AddressTypeIPv4
|
||||||
|
|
||||||
endpoints := v1.Endpoints{
|
endpoints := v1.Endpoints{
|
||||||
ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "test"},
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "foo",
|
||||||
|
Namespace: "test",
|
||||||
|
Labels: map[string]string{"foo": "bar"},
|
||||||
|
},
|
||||||
Subsets: []v1.EndpointSubset{{
|
Subsets: []v1.EndpointSubset{{
|
||||||
Ports: []v1.EndpointPort{{Port: 80}},
|
Ports: []v1.EndpointPort{{Port: 80}},
|
||||||
}},
|
}},
|
||||||
@ -51,6 +55,7 @@ func TestNewEndpointSlice(t *testing.T) {
|
|||||||
expectedSlice := discovery.EndpointSlice{
|
expectedSlice := discovery.EndpointSlice{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
|
"foo": "bar",
|
||||||
discovery.LabelServiceName: endpoints.Name,
|
discovery.LabelServiceName: endpoints.Name,
|
||||||
discovery.LabelManagedBy: controllerName,
|
discovery.LabelManagedBy: controllerName,
|
||||||
},
|
},
|
||||||
@ -65,6 +70,10 @@ func TestNewEndpointSlice(t *testing.T) {
|
|||||||
generatedSlice := newEndpointSlice(&endpoints, ports, addrType, "")
|
generatedSlice := newEndpointSlice(&endpoints, ports, addrType, "")
|
||||||
|
|
||||||
assert.EqualValues(t, expectedSlice, *generatedSlice)
|
assert.EqualValues(t, expectedSlice, *generatedSlice)
|
||||||
|
|
||||||
|
if len(endpoints.Labels) > 1 {
|
||||||
|
t.Errorf("Expected Endpoints labels to not be modified, got %+v", endpoints.Labels)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test helpers
|
// Test helpers
|
||||||
|
Loading…
Reference in New Issue
Block a user