mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	Cleanup unused cacheless PLEG code
This commit is contained in:
		@@ -121,6 +121,9 @@ type podRecords map[types.UID]*podRecord
 | 
				
			|||||||
func NewGenericPLEG(logger klog.Logger, runtime kubecontainer.Runtime, eventChannel chan *PodLifecycleEvent,
 | 
					func NewGenericPLEG(logger klog.Logger, runtime kubecontainer.Runtime, eventChannel chan *PodLifecycleEvent,
 | 
				
			||||||
	relistDuration *RelistDuration, cache kubecontainer.Cache,
 | 
						relistDuration *RelistDuration, cache kubecontainer.Cache,
 | 
				
			||||||
	clock clock.Clock) PodLifecycleEventGenerator {
 | 
						clock clock.Clock) PodLifecycleEventGenerator {
 | 
				
			||||||
 | 
						if cache == nil {
 | 
				
			||||||
 | 
							panic("cache cannot be nil")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	return &GenericPLEG{
 | 
						return &GenericPLEG{
 | 
				
			||||||
		logger:         logger,
 | 
							logger:         logger,
 | 
				
			||||||
		relistDuration: relistDuration,
 | 
							relistDuration: relistDuration,
 | 
				
			||||||
@@ -265,16 +268,13 @@ func (g *GenericPLEG) Relist() {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var needsReinspection map[types.UID]*kubecontainer.Pod
 | 
						needsReinspection := make(map[types.UID]*kubecontainer.Pod)
 | 
				
			||||||
	if g.cacheEnabled() {
 | 
					 | 
				
			||||||
		needsReinspection = make(map[types.UID]*kubecontainer.Pod)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// If there are events associated with a pod, we should update the
 | 
						// If there are events associated with a pod, we should update the
 | 
				
			||||||
	// podCache.
 | 
						// podCache.
 | 
				
			||||||
	for pid, events := range eventsByPodID {
 | 
						for pid, events := range eventsByPodID {
 | 
				
			||||||
		pod := g.podRecords.getCurrent(pid)
 | 
							pod := g.podRecords.getCurrent(pid)
 | 
				
			||||||
		if g.cacheEnabled() {
 | 
					
 | 
				
			||||||
		// updateCache() will inspect the pod and update the cache. If an
 | 
							// updateCache() will inspect the pod and update the cache. If an
 | 
				
			||||||
		// error occurs during the inspection, we want PLEG to retry again
 | 
							// error occurs during the inspection, we want PLEG to retry again
 | 
				
			||||||
		// in the next relist. To achieve this, we do not update the
 | 
							// in the next relist. To achieve this, we do not update the
 | 
				
			||||||
@@ -303,7 +303,7 @@ func (g *GenericPLEG) Relist() {
 | 
				
			|||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		}
 | 
					
 | 
				
			||||||
		// Update the internal storage and send out the events.
 | 
							// Update the internal storage and send out the events.
 | 
				
			||||||
		g.podRecords.update(pid)
 | 
							g.podRecords.update(pid)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -324,7 +324,7 @@ func (g *GenericPLEG) Relist() {
 | 
				
			|||||||
			// Log exit code of containers when they finished in a particular event
 | 
								// Log exit code of containers when they finished in a particular event
 | 
				
			||||||
			if events[i].Type == ContainerDied {
 | 
								if events[i].Type == ContainerDied {
 | 
				
			||||||
				// Fill up containerExitCode map for ContainerDied event when first time appeared
 | 
									// Fill up containerExitCode map for ContainerDied event when first time appeared
 | 
				
			||||||
				if len(containerExitCode) == 0 && pod != nil && g.cache != nil {
 | 
									if len(containerExitCode) == 0 && pod != nil {
 | 
				
			||||||
					// Get updated podStatus
 | 
										// Get updated podStatus
 | 
				
			||||||
					status, err := g.cache.Get(pod.ID)
 | 
										status, err := g.cache.Get(pod.ID)
 | 
				
			||||||
					if err == nil {
 | 
										if err == nil {
 | 
				
			||||||
@@ -342,7 +342,6 @@ func (g *GenericPLEG) Relist() {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if g.cacheEnabled() {
 | 
					 | 
				
			||||||
	// reinspect any pods that failed inspection during the previous relist
 | 
						// reinspect any pods that failed inspection during the previous relist
 | 
				
			||||||
	if len(g.podsToReinspect) > 0 {
 | 
						if len(g.podsToReinspect) > 0 {
 | 
				
			||||||
		g.logger.V(5).Info("GenericPLEG: Reinspecting pods that previously failed inspection")
 | 
							g.logger.V(5).Info("GenericPLEG: Reinspecting pods that previously failed inspection")
 | 
				
			||||||
@@ -358,7 +357,6 @@ func (g *GenericPLEG) Relist() {
 | 
				
			|||||||
	// Update the cache timestamp.  This needs to happen *after*
 | 
						// Update the cache timestamp.  This needs to happen *after*
 | 
				
			||||||
	// all pods have been properly updated in the cache.
 | 
						// all pods have been properly updated in the cache.
 | 
				
			||||||
	g.cache.UpdateTime(timestamp)
 | 
						g.cache.UpdateTime(timestamp)
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// make sure we retain the list of pods that need reinspecting the next time relist is called
 | 
						// make sure we retain the list of pods that need reinspecting the next time relist is called
 | 
				
			||||||
	g.podsToReinspect = needsReinspection
 | 
						g.podsToReinspect = needsReinspection
 | 
				
			||||||
@@ -402,10 +400,6 @@ func computeEvents(logger klog.Logger, oldPod, newPod *kubecontainer.Pod, cid *k
 | 
				
			|||||||
	return generateEvents(logger, pid, cid.ID, oldState, newState)
 | 
						return generateEvents(logger, pid, cid.ID, oldState, newState)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (g *GenericPLEG) cacheEnabled() bool {
 | 
					 | 
				
			||||||
	return g.cache != nil
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// getPodIP preserves an older cached status' pod IP if the new status has no pod IPs
 | 
					// getPodIP preserves an older cached status' pod IP if the new status has no pod IPs
 | 
				
			||||||
// and its sandboxes have exited
 | 
					// and its sandboxes have exited
 | 
				
			||||||
func (g *GenericPLEG) getPodIPs(pid types.UID, status *kubecontainer.PodStatus) []string {
 | 
					func (g *GenericPLEG) getPodIPs(pid types.UID, status *kubecontainer.PodStatus) []string {
 | 
				
			||||||
@@ -488,9 +482,6 @@ func (g *GenericPLEG) updateCache(ctx context.Context, pod *kubecontainer.Pod, p
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func (g *GenericPLEG) UpdateCache(pod *kubecontainer.Pod, pid types.UID) (error, bool) {
 | 
					func (g *GenericPLEG) UpdateCache(pod *kubecontainer.Pod, pid types.UID) (error, bool) {
 | 
				
			||||||
	ctx := context.Background()
 | 
						ctx := context.Background()
 | 
				
			||||||
	if !g.cacheEnabled() {
 | 
					 | 
				
			||||||
		return fmt.Errorf("pod cache disabled"), false
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if pod == nil {
 | 
						if pod == nil {
 | 
				
			||||||
		return fmt.Errorf("pod cannot be nil"), false
 | 
							return fmt.Errorf("pod cannot be nil"), false
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -32,6 +32,7 @@ import (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	"k8s.io/apimachinery/pkg/types"
 | 
						"k8s.io/apimachinery/pkg/types"
 | 
				
			||||||
	"k8s.io/component-base/metrics/testutil"
 | 
						"k8s.io/component-base/metrics/testutil"
 | 
				
			||||||
 | 
						"k8s.io/klog/v2"
 | 
				
			||||||
	kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
 | 
						kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
 | 
				
			||||||
	containertest "k8s.io/kubernetes/pkg/kubelet/container/testing"
 | 
						containertest "k8s.io/kubernetes/pkg/kubelet/container/testing"
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/kubelet/metrics"
 | 
						"k8s.io/kubernetes/pkg/kubelet/metrics"
 | 
				
			||||||
@@ -57,16 +58,18 @@ func newTestGenericPLEG() *TestGenericPLEG {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func newTestGenericPLEGWithChannelSize(eventChannelCap int) *TestGenericPLEG {
 | 
					func newTestGenericPLEGWithChannelSize(eventChannelCap int) *TestGenericPLEG {
 | 
				
			||||||
	fakeRuntime := &containertest.FakeRuntime{}
 | 
						fakeRuntime := &containertest.FakeRuntime{}
 | 
				
			||||||
 | 
						fakeCache := containertest.NewFakeCache(fakeRuntime)
 | 
				
			||||||
	clock := testingclock.NewFakeClock(time.Time{})
 | 
						clock := testingclock.NewFakeClock(time.Time{})
 | 
				
			||||||
	// The channel capacity should be large enough to hold all events in a
 | 
						// The channel capacity should be large enough to hold all events in a
 | 
				
			||||||
	// single test.
 | 
						// single test.
 | 
				
			||||||
	pleg := &GenericPLEG{
 | 
						pleg := NewGenericPLEG(
 | 
				
			||||||
		relistDuration: &RelistDuration{RelistPeriod: time.Hour, RelistThreshold: 3 * time.Minute},
 | 
							klog.Logger{},
 | 
				
			||||||
		runtime:        fakeRuntime,
 | 
							fakeRuntime,
 | 
				
			||||||
		eventChannel:   make(chan *PodLifecycleEvent, eventChannelCap),
 | 
							make(chan *PodLifecycleEvent, eventChannelCap),
 | 
				
			||||||
		podRecords:     make(podRecords),
 | 
							&RelistDuration{RelistPeriod: time.Hour, RelistThreshold: 3 * time.Minute},
 | 
				
			||||||
		clock:          clock,
 | 
							fakeCache,
 | 
				
			||||||
	}
 | 
							clock,
 | 
				
			||||||
 | 
						).(*GenericPLEG)
 | 
				
			||||||
	return &TestGenericPLEG{pleg: pleg, runtime: fakeRuntime, clock: clock}
 | 
						return &TestGenericPLEG{pleg: pleg, runtime: fakeRuntime, clock: clock}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user