mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-19 09:52:49 +00:00
clean up code
This commit is contained in:
parent
a0fe0d6b37
commit
e536d565ea
@ -463,16 +463,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
|
||||
@ -618,13 +617,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
|
||||
|
@ -326,14 +326,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 {
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user