mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	remove format pods func, instead with klog.Kobjs
This commit is contained in:
		@@ -254,16 +254,16 @@ func (s *podStorage) merge(source string, change interface{}) (adds, updates, de
 | 
				
			|||||||
	switch update.Op {
 | 
						switch update.Op {
 | 
				
			||||||
	case kubetypes.ADD, kubetypes.UPDATE, kubetypes.DELETE:
 | 
						case kubetypes.ADD, kubetypes.UPDATE, kubetypes.DELETE:
 | 
				
			||||||
		if update.Op == kubetypes.ADD {
 | 
							if update.Op == kubetypes.ADD {
 | 
				
			||||||
			klog.V(4).InfoS("Adding new pods from source", "source", source, "pods", format.Pods(update.Pods))
 | 
								klog.V(4).InfoS("Adding new pods from source", "source", source, "pods", klog.KObjs(update.Pods))
 | 
				
			||||||
		} else if update.Op == kubetypes.DELETE {
 | 
							} else if update.Op == kubetypes.DELETE {
 | 
				
			||||||
			klog.V(4).InfoS("Gracefully deleting pods from source", "source", source, "pods", format.Pods(update.Pods))
 | 
								klog.V(4).InfoS("Gracefully deleting pods from source", "source", source, "pods", klog.KObjs(update.Pods))
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			klog.V(4).InfoS("Updating pods from source", "source", source, "pods", format.Pods(update.Pods))
 | 
								klog.V(4).InfoS("Updating pods from source", "source", source, "pods", klog.KObjs(update.Pods))
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		updatePodsFunc(update.Pods, pods, pods)
 | 
							updatePodsFunc(update.Pods, pods, pods)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	case kubetypes.REMOVE:
 | 
						case kubetypes.REMOVE:
 | 
				
			||||||
		klog.V(4).InfoS("Removing pods from source", "source", source, "pods", format.Pods(update.Pods))
 | 
							klog.V(4).InfoS("Removing pods from source", "source", source, "pods", klog.KObjs(update.Pods))
 | 
				
			||||||
		for _, value := range update.Pods {
 | 
							for _, value := range update.Pods {
 | 
				
			||||||
			if existing, found := pods[value.UID]; found {
 | 
								if existing, found := pods[value.UID]; found {
 | 
				
			||||||
				// this is a delete
 | 
									// this is a delete
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -38,7 +38,6 @@ import (
 | 
				
			|||||||
	"k8s.io/kubernetes/pkg/kubelet/metrics"
 | 
						"k8s.io/kubernetes/pkg/kubelet/metrics"
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/kubelet/server/stats"
 | 
						"k8s.io/kubernetes/pkg/kubelet/server/stats"
 | 
				
			||||||
	kubelettypes "k8s.io/kubernetes/pkg/kubelet/types"
 | 
						kubelettypes "k8s.io/kubernetes/pkg/kubelet/types"
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/kubelet/util/format"
 | 
					 | 
				
			||||||
	"k8s.io/utils/clock"
 | 
						"k8s.io/utils/clock"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -196,7 +195,7 @@ func (m *managerImpl) Start(diskInfoProvider DiskInfoProvider, podFunc ActivePod
 | 
				
			|||||||
	go func() {
 | 
						go func() {
 | 
				
			||||||
		for {
 | 
							for {
 | 
				
			||||||
			if evictedPods := m.synchronize(diskInfoProvider, podFunc); evictedPods != nil {
 | 
								if evictedPods := m.synchronize(diskInfoProvider, podFunc); evictedPods != nil {
 | 
				
			||||||
				klog.InfoS("Eviction manager: pods evicted, waiting for pod to be cleaned up", "pods", format.Pods(evictedPods))
 | 
									klog.InfoS("Eviction manager: pods evicted, waiting for pod to be cleaned up", "pods", klog.KObjs(evictedPods))
 | 
				
			||||||
				m.waitForPodsCleanup(podCleanedUpFunc, evictedPods)
 | 
									m.waitForPodsCleanup(podCleanedUpFunc, evictedPods)
 | 
				
			||||||
			} else {
 | 
								} else {
 | 
				
			||||||
				time.Sleep(monitoringInterval)
 | 
									time.Sleep(monitoringInterval)
 | 
				
			||||||
@@ -365,7 +364,7 @@ func (m *managerImpl) synchronize(diskInfoProvider DiskInfoProvider, podFunc Act
 | 
				
			|||||||
	// rank the running pods for eviction for the specified resource
 | 
						// rank the running pods for eviction for the specified resource
 | 
				
			||||||
	rank(activePods, statsFunc)
 | 
						rank(activePods, statsFunc)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	klog.InfoS("Eviction manager: pods ranked for eviction", "pods", format.Pods(activePods))
 | 
						klog.InfoS("Eviction manager: pods ranked for eviction", "pods", klog.KObjs(activePods))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	//record age of metrics for met thresholds that we are using for evictions.
 | 
						//record age of metrics for met thresholds that we are using for evictions.
 | 
				
			||||||
	for _, t := range thresholds {
 | 
						for _, t := range thresholds {
 | 
				
			||||||
@@ -400,7 +399,7 @@ func (m *managerImpl) waitForPodsCleanup(podCleanedUpFunc PodCleanedUpFunc, pods
 | 
				
			|||||||
	for {
 | 
						for {
 | 
				
			||||||
		select {
 | 
							select {
 | 
				
			||||||
		case <-timeout.C():
 | 
							case <-timeout.C():
 | 
				
			||||||
			klog.InfoS("Eviction manager: timed out waiting for pods to be cleaned up", "pods", format.Pods(pods))
 | 
								klog.InfoS("Eviction manager: timed out waiting for pods to be cleaned up", "pods", klog.KObjs(pods))
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
		case <-ticker.C():
 | 
							case <-ticker.C():
 | 
				
			||||||
			for i, pod := range pods {
 | 
								for i, pod := range pods {
 | 
				
			||||||
@@ -408,7 +407,7 @@ func (m *managerImpl) waitForPodsCleanup(podCleanedUpFunc PodCleanedUpFunc, pods
 | 
				
			|||||||
					break
 | 
										break
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				if i == len(pods)-1 {
 | 
									if i == len(pods)-1 {
 | 
				
			||||||
					klog.InfoS("Eviction manager: pods successfully cleaned up", "pods", format.Pods(pods))
 | 
										klog.InfoS("Eviction manager: pods successfully cleaned up", "pods", klog.KObjs(pods))
 | 
				
			||||||
					return
 | 
										return
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2052,23 +2052,23 @@ func (kl *Kubelet) syncLoopIteration(configCh <-chan kubetypes.PodUpdate, handle
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		switch u.Op {
 | 
							switch u.Op {
 | 
				
			||||||
		case kubetypes.ADD:
 | 
							case kubetypes.ADD:
 | 
				
			||||||
			klog.V(2).InfoS("SyncLoop ADD", "source", u.Source, "pods", format.Pods(u.Pods))
 | 
								klog.V(2).InfoS("SyncLoop ADD", "source", u.Source, "pods", klog.KObjs(u.Pods))
 | 
				
			||||||
			// After restarting, kubelet will get all existing pods through
 | 
								// After restarting, kubelet will get all existing pods through
 | 
				
			||||||
			// ADD as if they are new pods. These pods will then go through the
 | 
								// ADD as if they are new pods. These pods will then go through the
 | 
				
			||||||
			// admission process and *may* be rejected. This can be resolved
 | 
								// admission process and *may* be rejected. This can be resolved
 | 
				
			||||||
			// once we have checkpointing.
 | 
								// once we have checkpointing.
 | 
				
			||||||
			handler.HandlePodAdditions(u.Pods)
 | 
								handler.HandlePodAdditions(u.Pods)
 | 
				
			||||||
		case kubetypes.UPDATE:
 | 
							case kubetypes.UPDATE:
 | 
				
			||||||
			klog.V(2).InfoS("SyncLoop UPDATE", "source", u.Source, "pods", format.Pods(u.Pods))
 | 
								klog.V(2).InfoS("SyncLoop UPDATE", "source", u.Source, "pods", klog.KObjs(u.Pods))
 | 
				
			||||||
			handler.HandlePodUpdates(u.Pods)
 | 
								handler.HandlePodUpdates(u.Pods)
 | 
				
			||||||
		case kubetypes.REMOVE:
 | 
							case kubetypes.REMOVE:
 | 
				
			||||||
			klog.V(2).InfoS("SyncLoop REMOVE", "source", u.Source, "pods", format.Pods(u.Pods))
 | 
								klog.V(2).InfoS("SyncLoop REMOVE", "source", u.Source, "pods", klog.KObjs(u.Pods))
 | 
				
			||||||
			handler.HandlePodRemoves(u.Pods)
 | 
								handler.HandlePodRemoves(u.Pods)
 | 
				
			||||||
		case kubetypes.RECONCILE:
 | 
							case kubetypes.RECONCILE:
 | 
				
			||||||
			klog.V(4).InfoS("SyncLoop RECONCILE", "source", u.Source, "pods", format.Pods(u.Pods))
 | 
								klog.V(4).InfoS("SyncLoop RECONCILE", "source", u.Source, "pods", klog.KObjs(u.Pods))
 | 
				
			||||||
			handler.HandlePodReconcile(u.Pods)
 | 
								handler.HandlePodReconcile(u.Pods)
 | 
				
			||||||
		case kubetypes.DELETE:
 | 
							case kubetypes.DELETE:
 | 
				
			||||||
			klog.V(2).InfoS("SyncLoop DELETE", "source", u.Source, "pods", format.Pods(u.Pods))
 | 
								klog.V(2).InfoS("SyncLoop DELETE", "source", u.Source, "pods", klog.KObjs(u.Pods))
 | 
				
			||||||
			// DELETE is treated as a UPDATE because of graceful deletion.
 | 
								// DELETE is treated as a UPDATE because of graceful deletion.
 | 
				
			||||||
			handler.HandlePodUpdates(u.Pods)
 | 
								handler.HandlePodUpdates(u.Pods)
 | 
				
			||||||
		case kubetypes.SET:
 | 
							case kubetypes.SET:
 | 
				
			||||||
@@ -2109,7 +2109,7 @@ func (kl *Kubelet) syncLoopIteration(configCh <-chan kubetypes.PodUpdate, handle
 | 
				
			|||||||
		if len(podsToSync) == 0 {
 | 
							if len(podsToSync) == 0 {
 | 
				
			||||||
			break
 | 
								break
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		klog.V(4).InfoS("SyncLoop (SYNC) pods", "total", len(podsToSync), "pods", format.Pods(podsToSync))
 | 
							klog.V(4).InfoS("SyncLoop (SYNC) pods", "total", len(podsToSync), "pods", klog.KObjs(podsToSync))
 | 
				
			||||||
		handler.HandlePodSyncs(podsToSync)
 | 
							handler.HandlePodSyncs(podsToSync)
 | 
				
			||||||
	case update := <-kl.livenessManager.Updates():
 | 
						case update := <-kl.livenessManager.Updates():
 | 
				
			||||||
		if update.Result == proberesults.Failure {
 | 
							if update.Result == proberesults.Failure {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,7 +22,6 @@ import (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	v1 "k8s.io/api/core/v1"
 | 
						v1 "k8s.io/api/core/v1"
 | 
				
			||||||
	"k8s.io/apimachinery/pkg/types"
 | 
						"k8s.io/apimachinery/pkg/types"
 | 
				
			||||||
	"k8s.io/klog/v2"
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Pod returns a string representing a pod in a consistent human readable format,
 | 
					// Pod returns a string representing a pod in a consistent human readable format,
 | 
				
			||||||
@@ -54,14 +53,3 @@ func PodWithDeletionTimestamp(pod *v1.Pod) string {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	return Pod(pod) + deletionTimestamp
 | 
						return Pod(pod) + deletionTimestamp
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
// Pods returns a list of pods as ObjectRef
 | 
					 | 
				
			||||||
func Pods(pods []*v1.Pod) []klog.ObjectRef {
 | 
					 | 
				
			||||||
	podKObjs := make([]klog.ObjectRef, 0, len(pods))
 | 
					 | 
				
			||||||
	for _, p := range pods {
 | 
					 | 
				
			||||||
		if p != nil {
 | 
					 | 
				
			||||||
			podKObjs = append(podKObjs, klog.KObj(p))
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return podKObjs
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
@@ -25,7 +25,6 @@ import (
 | 
				
			|||||||
	v1 "k8s.io/api/core/v1"
 | 
						v1 "k8s.io/api/core/v1"
 | 
				
			||||||
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
						metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
				
			||||||
	"k8s.io/apimachinery/pkg/types"
 | 
						"k8s.io/apimachinery/pkg/types"
 | 
				
			||||||
	"k8s.io/klog/v2"
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func fakeCreatePod(name, namespace string, uid types.UID) *v1.Pod {
 | 
					func fakeCreatePod(name, namespace string, uid types.UID) *v1.Pod {
 | 
				
			||||||
@@ -113,33 +112,3 @@ func TestPodWithDeletionTimestamp(t *testing.T) {
 | 
				
			|||||||
		assert.Equalf(t, testCase.expectedValue, realPodWithDeletionTimestamp, "Failed to test: %s", testCase.caseName)
 | 
							assert.Equalf(t, testCase.expectedValue, realPodWithDeletionTimestamp, "Failed to test: %s", testCase.caseName)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
func TestPods(t *testing.T) {
 | 
					 | 
				
			||||||
	pod1 := fakeCreatePod("pod1", metav1.NamespaceDefault, "551f5a43-9f2f-11e7-a589-fa163e148d75")
 | 
					 | 
				
			||||||
	pod2 := fakeCreatePod("pod2", metav1.NamespaceDefault, "e84a99bf-d1f9-43c2-9fa5-044ac85f794b")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	pod1Obj := klog.ObjectRef{
 | 
					 | 
				
			||||||
		Name:      "pod1",
 | 
					 | 
				
			||||||
		Namespace: metav1.NamespaceDefault,
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	pod2Obj := klog.ObjectRef{
 | 
					 | 
				
			||||||
		Name:      "pod2",
 | 
					 | 
				
			||||||
		Namespace: metav1.NamespaceDefault,
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	testCases := []struct {
 | 
					 | 
				
			||||||
		caseName      string
 | 
					 | 
				
			||||||
		pods          []*v1.Pod
 | 
					 | 
				
			||||||
		expectedValue []klog.ObjectRef
 | 
					 | 
				
			||||||
	}{
 | 
					 | 
				
			||||||
		{"input_nil_case", nil, []klog.ObjectRef{}},
 | 
					 | 
				
			||||||
		{"input_empty_case", []*v1.Pod{}, []klog.ObjectRef{}},
 | 
					 | 
				
			||||||
		{"input_length_one_case", []*v1.Pod{pod1, nil}, []klog.ObjectRef{pod1Obj}},
 | 
					 | 
				
			||||||
		{"input_length_more_than_one_case", []*v1.Pod{pod1, pod2}, []klog.ObjectRef{pod1Obj, pod2Obj}},
 | 
					 | 
				
			||||||
		{"input_include_nil_case", []*v1.Pod{pod1, nil}, []klog.ObjectRef{pod1Obj}},
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	for _, testCase := range testCases {
 | 
					 | 
				
			||||||
		realPods := Pods(testCase.pods)
 | 
					 | 
				
			||||||
		assert.Equalf(t, testCase.expectedValue, realPods, "Failed to test: %s", testCase.caseName)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user