mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 22:17:14 +00:00
do not store context
This commit is contained in:
parent
4a3d51359a
commit
2730d285cf
@ -71,7 +71,6 @@ func NewPodGC(ctx context.Context, kubeClient clientset.Interface, podInformer c
|
||||
}
|
||||
gcc := &PodGCController{
|
||||
kubeClient: kubeClient,
|
||||
ctx: ctx,
|
||||
terminatedPodThreshold: terminatedPodThreshold,
|
||||
podLister: podInformer.Lister(),
|
||||
podListerSynced: podInformer.Informer().HasSynced,
|
||||
@ -83,9 +82,9 @@ func NewPodGC(ctx context.Context, kubeClient clientset.Interface, podInformer c
|
||||
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))
|
||||
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) {
|
||||
@ -116,13 +115,13 @@ func (gcc *PodGCController) gc(ctx context.Context) {
|
||||
return
|
||||
}
|
||||
if gcc.terminatedPodThreshold > 0 {
|
||||
gcc.gcTerminated(pods)
|
||||
gcc.gcTerminated(ctx, pods)
|
||||
}
|
||||
if utilfeature.DefaultFeatureGate.Enabled(features.NodeOutOfServiceVolumeDetach) {
|
||||
gcc.gcTerminating(pods)
|
||||
gcc.gcTerminating(ctx, pods)
|
||||
}
|
||||
gcc.gcOrphaned(ctx, pods, nodes)
|
||||
gcc.gcUnscheduledTerminating(pods)
|
||||
gcc.gcUnscheduledTerminating(ctx, pods)
|
||||
}
|
||||
|
||||
func isPodTerminated(pod *v1.Pod) bool {
|
||||
@ -137,7 +136,7 @@ func isPodTerminating(pod *v1.Pod) bool {
|
||||
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")
|
||||
terminatingPods := []*v1.Pod{}
|
||||
for _, pod := range pods {
|
||||
@ -170,7 +169,7 @@ func (gcc *PodGCController) gcTerminating(pods []*v1.Pod) {
|
||||
wait.Add(1)
|
||||
go func(namespace string, name string) {
|
||||
defer wait.Done()
|
||||
if err := gcc.deletePod(namespace, name); err != nil {
|
||||
if err := gcc.deletePod(ctx, namespace, name); err != nil {
|
||||
// ignore not founds
|
||||
utilruntime.HandleError(err)
|
||||
}
|
||||
@ -179,7 +178,7 @@ func (gcc *PodGCController) gcTerminating(pods []*v1.Pod) {
|
||||
wait.Wait()
|
||||
}
|
||||
|
||||
func (gcc *PodGCController) gcTerminated(pods []*v1.Pod) {
|
||||
func (gcc *PodGCController) gcTerminated(ctx context.Context, pods []*v1.Pod) {
|
||||
terminatedPods := []*v1.Pod{}
|
||||
for _, pod := range pods {
|
||||
if isPodTerminated(pod) {
|
||||
@ -202,7 +201,7 @@ func (gcc *PodGCController) gcTerminated(pods []*v1.Pod) {
|
||||
wait.Add(1)
|
||||
go func(namespace string, name string) {
|
||||
defer wait.Done()
|
||||
if err := gcc.deletePod(namespace, name); err != nil {
|
||||
if err := gcc.deletePod(ctx, namespace, name); err != nil {
|
||||
// ignore not founds
|
||||
defer utilruntime.HandleError(err)
|
||||
}
|
||||
@ -235,7 +234,7 @@ func (gcc *PodGCController) gcOrphaned(ctx context.Context, pods []*v1.Pod, node
|
||||
continue
|
||||
}
|
||||
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)
|
||||
} else {
|
||||
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.
|
||||
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.")
|
||||
|
||||
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))
|
||||
if err := gcc.deletePod(pod.Namespace, pod.Name); err != nil {
|
||||
if err := gcc.deletePod(ctx, pod.Namespace, pod.Name); err != nil {
|
||||
utilruntime.HandleError(err)
|
||||
} else {
|
||||
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)
|
||||
return
|
||||
}
|
||||
gcc.gcUnscheduledTerminating(pods)
|
||||
gcc.gcUnscheduledTerminating(context.TODO(), pods)
|
||||
deletedPodNames := getDeletedPodNames(client)
|
||||
|
||||
if pass := compareStringSetToList(test.deletedPodNames, deletedPodNames); !pass {
|
||||
|
Loading…
Reference in New Issue
Block a user