mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	endpoints: If namespace is terminating, drop item immediately
Avoid sending an event to the namespace that is being terminated, since it will be rejected.
This commit is contained in:
		@@ -506,6 +506,11 @@ func (e *EndpointController) syncService(key string) error {
 | 
				
			|||||||
			// 2. policy is misconfigured, in which case no service would function anywhere.
 | 
								// 2. policy is misconfigured, in which case no service would function anywhere.
 | 
				
			||||||
			// Given the frequency of 1, we log at a lower level.
 | 
								// Given the frequency of 1, we log at a lower level.
 | 
				
			||||||
			klog.V(5).Infof("Forbidden from creating endpoints: %v", err)
 | 
								klog.V(5).Infof("Forbidden from creating endpoints: %v", err)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								// If the namespace is terminating, creates will continue to fail. Simply drop the item.
 | 
				
			||||||
 | 
								if errors.HasStatusCause(err, v1.NamespaceTerminatingCause) {
 | 
				
			||||||
 | 
									return nil
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if createEndpoints {
 | 
							if createEndpoints {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -23,6 +23,7 @@ import (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	corev1 "k8s.io/api/core/v1"
 | 
						corev1 "k8s.io/api/core/v1"
 | 
				
			||||||
	discovery "k8s.io/api/discovery/v1alpha1"
 | 
						discovery "k8s.io/api/discovery/v1alpha1"
 | 
				
			||||||
 | 
						"k8s.io/apimachinery/pkg/api/errors"
 | 
				
			||||||
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
						metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
				
			||||||
	utilerrors "k8s.io/apimachinery/pkg/util/errors"
 | 
						utilerrors "k8s.io/apimachinery/pkg/util/errors"
 | 
				
			||||||
	"k8s.io/apimachinery/pkg/util/sets"
 | 
						"k8s.io/apimachinery/pkg/util/sets"
 | 
				
			||||||
@@ -150,6 +151,10 @@ func (r *reconciler) finalize(
 | 
				
			|||||||
		addTriggerTimeAnnotation(endpointSlice, triggerTime)
 | 
							addTriggerTimeAnnotation(endpointSlice, triggerTime)
 | 
				
			||||||
		_, err := r.client.DiscoveryV1alpha1().EndpointSlices(service.Namespace).Create(endpointSlice)
 | 
							_, err := r.client.DiscoveryV1alpha1().EndpointSlices(service.Namespace).Create(endpointSlice)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
 | 
								// If the namespace is terminating, creates will continue to fail. Simply drop the item.
 | 
				
			||||||
 | 
								if errors.HasStatusCause(err, corev1.NamespaceTerminatingCause) {
 | 
				
			||||||
 | 
									return nil
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
			errs = append(errs, fmt.Errorf("Error creating EndpointSlice for Service %s/%s: %v", service.Namespace, service.Name, err))
 | 
								errs = append(errs, fmt.Errorf("Error creating EndpointSlice for Service %s/%s: %v", service.Namespace, service.Name, err))
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user