diff --git a/pkg/controller/endpoint/endpoints_controller.go b/pkg/controller/endpoint/endpoints_controller.go index 1ceff54e0e9..1d1d8f20a9a 100644 --- a/pkg/controller/endpoint/endpoints_controller.go +++ b/pkg/controller/endpoint/endpoints_controller.go @@ -449,16 +449,15 @@ func (e *Controller) syncService(ctx context.Context, key string) error { // See if there's actually an update here. currentEndpoints, err := e.endpointsLister.Endpoints(service.Namespace).Get(service.Name) if err != nil { - if errors.IsNotFound(err) { - currentEndpoints = &v1.Endpoints{ - ObjectMeta: metav1.ObjectMeta{ - Name: service.Name, - Labels: service.Labels, - }, - } - } else { + if !errors.IsNotFound(err) { return err } + currentEndpoints = &v1.Endpoints{ + ObjectMeta: metav1.ObjectMeta{ + Name: service.Name, + Labels: service.Labels, + }, + } } createEndpoints := len(currentEndpoints.ResourceVersion) == 0 @@ -604,13 +603,12 @@ func addEndpointSubset(subsets []v1.EndpointSubset, pod *v1.Pod, epa v1.Endpoint } func endpointPortFromServicePort(servicePort *v1.ServicePort, portNum int) *v1.EndpointPort { - epp := &v1.EndpointPort{ + return &v1.EndpointPort{ Name: servicePort.Name, Port: int32(portNum), Protocol: servicePort.Protocol, AppProtocol: servicePort.AppProtocol, } - return epp } // capacityAnnotationSetCorrectly returns false if number of endpoints is greater than maxCapacity or diff --git a/pkg/controller/endpointslice/endpointslice_controller.go b/pkg/controller/endpointslice/endpointslice_controller.go index 5b9db597346..1e21a6fac49 100644 --- a/pkg/controller/endpointslice/endpointslice_controller.go +++ b/pkg/controller/endpointslice/endpointslice_controller.go @@ -317,14 +317,15 @@ func (c *Controller) syncService(key string) error { service, err := c.serviceLister.Services(namespace).Get(name) if err != nil { - if apierrors.IsNotFound(err) { - c.triggerTimeTracker.DeleteService(namespace, name) - c.reconciler.deleteService(namespace, name) - c.endpointSliceTracker.DeleteService(namespace, name) - // The service has been deleted, return nil so that it won't be retried. - return nil + if !apierrors.IsNotFound(err) { + return err } - return err + + c.triggerTimeTracker.DeleteService(namespace, name) + c.reconciler.deleteService(namespace, name) + c.endpointSliceTracker.DeleteService(namespace, name) + // The service has been deleted, return nil so that it won't be retried. + return nil } if service.Spec.Selector == nil { diff --git a/test/integration/replicaset/replicaset_test.go b/test/integration/replicaset/replicaset_test.go index 167b34ad276..ab0efa6b7ca 100644 --- a/test/integration/replicaset/replicaset_test.go +++ b/test/integration/replicaset/replicaset_test.go @@ -781,16 +781,17 @@ func TestPodOrphaningAndAdoptionWhenLabelsChange(t *testing.T) { if err != nil { // If the pod is not found, it means the RS picks the pod for deletion (it is extra) // Verify there is only one pod in namespace and it has ControllerRef to the RS - if apierrors.IsNotFound(err) { - pods := getPods(t, podClient, labelMap()) - if len(pods.Items) != 1 { - return false, fmt.Errorf("Expected 1 pod in current namespace, got %d", len(pods.Items)) - } - // Set the pod accordingly - pod = &pods.Items[0] - return true, nil + if !apierrors.IsNotFound(err) { + return false, err } - return false, err + + pods := getPods(t, podClient, labelMap()) + if len(pods.Items) != 1 { + return false, fmt.Errorf("Expected 1 pod in current namespace, got %d", len(pods.Items)) + } + // Set the pod accordingly + pod = &pods.Items[0] + return true, nil } // Always update the pod so that we can save a GET call to API server later pod = newPod diff --git a/test/integration/replicationcontroller/replicationcontroller_test.go b/test/integration/replicationcontroller/replicationcontroller_test.go index fd2751849de..aa3893889a0 100644 --- a/test/integration/replicationcontroller/replicationcontroller_test.go +++ b/test/integration/replicationcontroller/replicationcontroller_test.go @@ -682,16 +682,17 @@ func TestPodOrphaningAndAdoptionWhenLabelsChange(t *testing.T) { if err != nil { // If the pod is not found, it means the RC picks the pod for deletion (it is extra) // Verify there is only one pod in namespace and it has ControllerRef to the RC - if apierrors.IsNotFound(err) { - pods := getPods(t, podClient, labelMap()) - if len(pods.Items) != 1 { - return false, fmt.Errorf("Expected 1 pod in current namespace, got %d", len(pods.Items)) - } - // Set the pod accordingly - pod = &pods.Items[0] - return true, nil + if !apierrors.IsNotFound(err) { + return false, err } - return false, err + + pods := getPods(t, podClient, labelMap()) + if len(pods.Items) != 1 { + return false, fmt.Errorf("Expected 1 pod in current namespace, got %d", len(pods.Items)) + } + // Set the pod accordingly + pod = &pods.Items[0] + return true, nil } // Always update the pod so that we can save a GET call to API server later pod = newPod