mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 04:08:16 +00:00 
			
		
		
		
	do not store context
This commit is contained in:
		@@ -71,7 +71,6 @@ func NewPodGC(ctx context.Context, kubeClient clientset.Interface, podInformer c
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	gcc := &PodGCController{
 | 
						gcc := &PodGCController{
 | 
				
			||||||
		kubeClient:             kubeClient,
 | 
							kubeClient:             kubeClient,
 | 
				
			||||||
		ctx:                    ctx,
 | 
					 | 
				
			||||||
		terminatedPodThreshold: terminatedPodThreshold,
 | 
							terminatedPodThreshold: terminatedPodThreshold,
 | 
				
			||||||
		podLister:              podInformer.Lister(),
 | 
							podLister:              podInformer.Lister(),
 | 
				
			||||||
		podListerSynced:        podInformer.Informer().HasSynced,
 | 
							podListerSynced:        podInformer.Informer().HasSynced,
 | 
				
			||||||
@@ -83,9 +82,9 @@ func NewPodGC(ctx context.Context, kubeClient clientset.Interface, podInformer c
 | 
				
			|||||||
	return gcc
 | 
						return gcc
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (gcc *PodGCController) deletePod(namespace, name string) error {
 | 
					func (gcc *PodGCController) deletePod(ctx context.Context, namespace, name string) error {
 | 
				
			||||||
	klog.InfoS("PodGC is force deleting Pod", "pod", klog.KRef(namespace, name))
 | 
						klog.InfoS("PodGC is force deleting Pod", "pod", klog.KRef(namespace, name))
 | 
				
			||||||
	return gcc.kubeClient.CoreV1().Pods(namespace).Delete(gcc.ctx, name, *metav1.NewDeleteOptions(0))
 | 
						return gcc.kubeClient.CoreV1().Pods(namespace).Delete(ctx, name, *metav1.NewDeleteOptions(0))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (gcc *PodGCController) Run(ctx context.Context) {
 | 
					func (gcc *PodGCController) Run(ctx context.Context) {
 | 
				
			||||||
@@ -116,13 +115,13 @@ func (gcc *PodGCController) gc(ctx context.Context) {
 | 
				
			|||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if gcc.terminatedPodThreshold > 0 {
 | 
						if gcc.terminatedPodThreshold > 0 {
 | 
				
			||||||
		gcc.gcTerminated(pods)
 | 
							gcc.gcTerminated(ctx, pods)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if utilfeature.DefaultFeatureGate.Enabled(features.NodeOutOfServiceVolumeDetach) {
 | 
						if utilfeature.DefaultFeatureGate.Enabled(features.NodeOutOfServiceVolumeDetach) {
 | 
				
			||||||
		gcc.gcTerminating(pods)
 | 
							gcc.gcTerminating(ctx, pods)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	gcc.gcOrphaned(ctx, pods, nodes)
 | 
						gcc.gcOrphaned(ctx, pods, nodes)
 | 
				
			||||||
	gcc.gcUnscheduledTerminating(pods)
 | 
						gcc.gcUnscheduledTerminating(ctx, pods)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func isPodTerminated(pod *v1.Pod) bool {
 | 
					func isPodTerminated(pod *v1.Pod) bool {
 | 
				
			||||||
@@ -137,7 +136,7 @@ func isPodTerminating(pod *v1.Pod) bool {
 | 
				
			|||||||
	return pod.ObjectMeta.DeletionTimestamp != nil
 | 
						return pod.ObjectMeta.DeletionTimestamp != nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (gcc *PodGCController) gcTerminating(pods []*v1.Pod) {
 | 
					func (gcc *PodGCController) gcTerminating(ctx context.Context, pods []*v1.Pod) {
 | 
				
			||||||
	klog.V(4).Info("GC'ing terminating pods that are on out-of-service nodes")
 | 
						klog.V(4).Info("GC'ing terminating pods that are on out-of-service nodes")
 | 
				
			||||||
	terminatingPods := []*v1.Pod{}
 | 
						terminatingPods := []*v1.Pod{}
 | 
				
			||||||
	for _, pod := range pods {
 | 
						for _, pod := range pods {
 | 
				
			||||||
@@ -170,7 +169,7 @@ func (gcc *PodGCController) gcTerminating(pods []*v1.Pod) {
 | 
				
			|||||||
		wait.Add(1)
 | 
							wait.Add(1)
 | 
				
			||||||
		go func(namespace string, name string) {
 | 
							go func(namespace string, name string) {
 | 
				
			||||||
			defer wait.Done()
 | 
								defer wait.Done()
 | 
				
			||||||
			if err := gcc.deletePod(namespace, name); err != nil {
 | 
								if err := gcc.deletePod(ctx, namespace, name); err != nil {
 | 
				
			||||||
				// ignore not founds
 | 
									// ignore not founds
 | 
				
			||||||
				utilruntime.HandleError(err)
 | 
									utilruntime.HandleError(err)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
@@ -179,7 +178,7 @@ func (gcc *PodGCController) gcTerminating(pods []*v1.Pod) {
 | 
				
			|||||||
	wait.Wait()
 | 
						wait.Wait()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (gcc *PodGCController) gcTerminated(pods []*v1.Pod) {
 | 
					func (gcc *PodGCController) gcTerminated(ctx context.Context, pods []*v1.Pod) {
 | 
				
			||||||
	terminatedPods := []*v1.Pod{}
 | 
						terminatedPods := []*v1.Pod{}
 | 
				
			||||||
	for _, pod := range pods {
 | 
						for _, pod := range pods {
 | 
				
			||||||
		if isPodTerminated(pod) {
 | 
							if isPodTerminated(pod) {
 | 
				
			||||||
@@ -202,7 +201,7 @@ func (gcc *PodGCController) gcTerminated(pods []*v1.Pod) {
 | 
				
			|||||||
		wait.Add(1)
 | 
							wait.Add(1)
 | 
				
			||||||
		go func(namespace string, name string) {
 | 
							go func(namespace string, name string) {
 | 
				
			||||||
			defer wait.Done()
 | 
								defer wait.Done()
 | 
				
			||||||
			if err := gcc.deletePod(namespace, name); err != nil {
 | 
								if err := gcc.deletePod(ctx, namespace, name); err != nil {
 | 
				
			||||||
				// ignore not founds
 | 
									// ignore not founds
 | 
				
			||||||
				defer utilruntime.HandleError(err)
 | 
									defer utilruntime.HandleError(err)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
@@ -235,7 +234,7 @@ func (gcc *PodGCController) gcOrphaned(ctx context.Context, pods []*v1.Pod, node
 | 
				
			|||||||
			continue
 | 
								continue
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		klog.V(2).InfoS("Found orphaned Pod assigned to the Node, deleting.", "pod", klog.KObj(pod), "node", pod.Spec.NodeName)
 | 
							klog.V(2).InfoS("Found orphaned Pod assigned to the Node, deleting.", "pod", klog.KObj(pod), "node", pod.Spec.NodeName)
 | 
				
			||||||
		if err := gcc.deletePod(pod.Namespace, pod.Name); err != nil {
 | 
							if err := gcc.deletePod(ctx, pod.Namespace, pod.Name); err != nil {
 | 
				
			||||||
			utilruntime.HandleError(err)
 | 
								utilruntime.HandleError(err)
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			klog.V(0).InfoS("Forced deletion of orphaned Pod succeeded", "pod", klog.KObj(pod))
 | 
								klog.V(0).InfoS("Forced deletion of orphaned Pod succeeded", "pod", klog.KObj(pod))
 | 
				
			||||||
@@ -275,7 +274,7 @@ func (gcc *PodGCController) checkIfNodeExists(ctx context.Context, name string)
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// gcUnscheduledTerminating deletes pods that are terminating and haven't been scheduled to a particular node.
 | 
					// gcUnscheduledTerminating deletes pods that are terminating and haven't been scheduled to a particular node.
 | 
				
			||||||
func (gcc *PodGCController) gcUnscheduledTerminating(pods []*v1.Pod) {
 | 
					func (gcc *PodGCController) gcUnscheduledTerminating(ctx context.Context, pods []*v1.Pod) {
 | 
				
			||||||
	klog.V(4).Infof("GC'ing unscheduled pods which are terminating.")
 | 
						klog.V(4).Infof("GC'ing unscheduled pods which are terminating.")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for _, pod := range pods {
 | 
						for _, pod := range pods {
 | 
				
			||||||
@@ -284,7 +283,7 @@ func (gcc *PodGCController) gcUnscheduledTerminating(pods []*v1.Pod) {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		klog.V(2).InfoS("Found unscheduled terminating Pod not assigned to any Node, deleting.", "pod", klog.KObj(pod))
 | 
							klog.V(2).InfoS("Found unscheduled terminating Pod not assigned to any Node, deleting.", "pod", klog.KObj(pod))
 | 
				
			||||||
		if err := gcc.deletePod(pod.Namespace, pod.Name); err != nil {
 | 
							if err := gcc.deletePod(ctx, pod.Namespace, pod.Name); err != nil {
 | 
				
			||||||
			utilruntime.HandleError(err)
 | 
								utilruntime.HandleError(err)
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			klog.V(0).InfoS("Forced deletion of unscheduled terminating Pod succeeded", "pod", klog.KObj(pod))
 | 
								klog.V(0).InfoS("Forced deletion of unscheduled terminating Pod succeeded", "pod", klog.KObj(pod))
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -433,7 +433,7 @@ func TestGCUnscheduledTerminating(t *testing.T) {
 | 
				
			|||||||
				t.Errorf("Error while listing all Pods: %v", err)
 | 
									t.Errorf("Error while listing all Pods: %v", err)
 | 
				
			||||||
				return
 | 
									return
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			gcc.gcUnscheduledTerminating(pods)
 | 
								gcc.gcUnscheduledTerminating(context.TODO(), pods)
 | 
				
			||||||
			deletedPodNames := getDeletedPodNames(client)
 | 
								deletedPodNames := getDeletedPodNames(client)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if pass := compareStringSetToList(test.deletedPodNames, deletedPodNames); !pass {
 | 
								if pass := compareStringSetToList(test.deletedPodNames, deletedPodNames); !pass {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user