Change:
}}, slice.Endpoints) } <del> func TestEnsureSetupManagedByAnnotation(t *testing.T) { serviceName := "testing-1" testCases := map[string]struct { serviceAnnotation   string startingSliceLabels map[string]string expectedSliceLabels map[string]string }{ "already-labeled": { serviceAnnotation: "foo", startingSliceLabels: map[string]string{ discovery.LabelServiceName: serviceName, discovery.LabelManagedBy:   controllerName, }, expectedSliceLabels: map[string]string{ discovery.LabelServiceName: serviceName, discovery.LabelManagedBy:   controllerName, }, }, "already-annotated": { serviceAnnotation: managedBySetupCompleteValue, startingSliceLabels: map[string]string{ discovery.LabelServiceName: serviceName, discovery.LabelManagedBy:   "other-controller", }, expectedSliceLabels: map[string]string{ discovery.LabelServiceName: serviceName, discovery.LabelManagedBy:   "other-controller", }, }, "missing-and-extra-label": { serviceAnnotation: "foo", startingSliceLabels: map[string]string{ discovery.LabelServiceName: serviceName, "foo":                      "bar", }, expectedSliceLabels: map[string]string{ discovery.LabelServiceName: serviceName, discovery.LabelManagedBy:   controllerName, "foo":                      "bar", }, }, "different-service": { serviceAnnotation: "foo", startingSliceLabels: map[string]string{ discovery.LabelServiceName: "something-else", }, expectedSliceLabels: map[string]string{ discovery.LabelServiceName: "something-else", }, }, } for name, testCase := range testCases { t.Run(name, func(t *testing.T) { client, esController := newController([]string{"node-1"}) ns := metav1.NamespaceDefault service := createService(t, esController, ns, serviceName, testCase.serviceAnnotation) endpointSlice := &discovery.EndpointSlice{ ObjectMeta: metav1.ObjectMeta{ Name:      "testing", Namespace: ns, Labels:    testCase.startingSliceLabels, }, } err := esController.endpointSliceStore.Add(endpointSlice) if err != nil { t.Fatalf("Expected no error adding EndpointSlice: %v", err) } _, err = client.DiscoveryV1beta1().EndpointSlices(ns).Create(endpointSlice) if err != nil { t.Fatalf("Expected no error creating EndpointSlice: %v", err) } esController.ensureSetupManagedByAnnotation(service) updatedService, err := client.CoreV1().Services(ns).Get(service.Name, metav1.GetOptions{}) if err != nil { t.Fatalf("Expected no error getting Service: %v", err) } if updatedService.Annotations[managedBySetupAnnotation] != managedBySetupCompleteValue { t.Errorf("Expected managedBySetupAnnotation: %+v, got: %+v", managedBySetupCompleteValue, updatedService.Annotations[managedBySetupAnnotation]) } updatedSlice, err := client.DiscoveryV1beta1().EndpointSlices(ns).Get(endpointSlice.Name, metav1.GetOptions{}) if err != nil { t.Fatalf("Expected no error getting EndpointSlice: %v", err) } if !reflect.DeepEqual(updatedSlice.Labels, testCase.expectedSliceLabels) { t.Errorf("Expected labels: %+v, got: %+v", updatedSlice.Labels, testCase.expectedSliceLabels) } }) } } </del> // Test helpers func standardSyncService(t *testing.T, esController *endpointSliceController, namespace, serviceName, managedBySetup string) {

Discussion:
What happened: kube-controller-manager panic for What you expected to happen: no panic. How to reproduce it (as minimally and precisely as possible): No idea. I guess it's hard to reproduce. Anything else we need to know?: Found from here: Environment: Kubernetes version (use ): Cloud provider or hardware configuration: OS (e.g: ): Kernel (e.g. ): Install tools: Network plugin and version (if this is a network-related bug): Others: /assign cc Should we do something for v1.17? (v1.17 code freeze now, but still have the opportunity to fix) can be removed safely in v1.18, right?
/sig scheduling
Working on this in /sig network /priority critical-urgent /assign
Sorry, I didn't realize it. I should have a search before firing an issue. I recommend adding this issue to your PR. e.g. `
Updated, thanks!
/triage unresolved Comment when the issue is assessed and confirmed. I am a bot run by vllry. ‍
This seems to be writing to a cached (should be const) service. I think we need to DeepCopy() it before we mutate the Go type. does that sound right? Is this still our best state of the art?
yes, copy before change
we have a tool to catch this (the cache mutation detector), but it got disabled in our test runs two years ago (xref )
yes great catch - I was always convinced this is enabled...