mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-20 02:11:09 +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.
|
// See if there's actually an update here.
|
||||||
currentEndpoints, err := e.endpointsLister.Endpoints(service.Namespace).Get(service.Name)
|
currentEndpoints, err := e.endpointsLister.Endpoints(service.Namespace).Get(service.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.IsNotFound(err) {
|
if !errors.IsNotFound(err) {
|
||||||
currentEndpoints = &v1.Endpoints{
|
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
|
||||||
Name: service.Name,
|
|
||||||
Labels: service.Labels,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
currentEndpoints = &v1.Endpoints{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: service.Name,
|
||||||
|
Labels: service.Labels,
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
createEndpoints := len(currentEndpoints.ResourceVersion) == 0
|
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 {
|
func endpointPortFromServicePort(servicePort *v1.ServicePort, portNum int) *v1.EndpointPort {
|
||||||
epp := &v1.EndpointPort{
|
return &v1.EndpointPort{
|
||||||
Name: servicePort.Name,
|
Name: servicePort.Name,
|
||||||
Port: int32(portNum),
|
Port: int32(portNum),
|
||||||
Protocol: servicePort.Protocol,
|
Protocol: servicePort.Protocol,
|
||||||
AppProtocol: servicePort.AppProtocol,
|
AppProtocol: servicePort.AppProtocol,
|
||||||
}
|
}
|
||||||
return epp
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// capacityAnnotationSetCorrectly returns false if number of endpoints is greater than maxCapacity or
|
// 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)
|
service, err := c.serviceLister.Services(namespace).Get(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if apierrors.IsNotFound(err) {
|
if !apierrors.IsNotFound(err) {
|
||||||
c.triggerTimeTracker.DeleteService(namespace, name)
|
return err
|
||||||
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
|
|
||||||
}
|
}
|
||||||
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 {
|
if service.Spec.Selector == nil {
|
||||||
|
@ -781,16 +781,17 @@ func TestPodOrphaningAndAdoptionWhenLabelsChange(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
// If the pod is not found, it means the RS picks the pod for deletion (it is extra)
|
// 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
|
// Verify there is only one pod in namespace and it has ControllerRef to the RS
|
||||||
if apierrors.IsNotFound(err) {
|
if !apierrors.IsNotFound(err) {
|
||||||
pods := getPods(t, podClient, labelMap())
|
return false, err
|
||||||
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
|
|
||||||
}
|
}
|
||||||
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
|
// Always update the pod so that we can save a GET call to API server later
|
||||||
pod = newPod
|
pod = newPod
|
||||||
|
@ -682,16 +682,17 @@ func TestPodOrphaningAndAdoptionWhenLabelsChange(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
// If the pod is not found, it means the RC picks the pod for deletion (it is extra)
|
// 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
|
// Verify there is only one pod in namespace and it has ControllerRef to the RC
|
||||||
if apierrors.IsNotFound(err) {
|
if !apierrors.IsNotFound(err) {
|
||||||
pods := getPods(t, podClient, labelMap())
|
return false, err
|
||||||
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
|
|
||||||
}
|
}
|
||||||
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
|
// Always update the pod so that we can save a GET call to API server later
|
||||||
pod = newPod
|
pod = newPod
|
||||||
|
Loading…
Reference in New Issue
Block a user