Keep PLEG interruptions in a separate interface

Signed-off-by: Harshal Patil <harpatil@redhat.com>
Co-authored-by: Ed Bartosh <eduard.bartosh@intel.com>
This commit is contained in:
Harshal Patil 2023-04-26 10:47:43 -04:00
parent c471f03ea3
commit 05f04f866e
3 changed files with 21 additions and 8 deletions

View File

@ -734,8 +734,11 @@ func NewMainKubelet(kubeCfg *kubeletconfiginternal.KubeletConfiguration,
RelistPeriod: genericPlegRelistPeriod, RelistPeriod: genericPlegRelistPeriod,
RelistThreshold: genericPlegRelistThreshold, RelistThreshold: genericPlegRelistThreshold,
} }
klet.eventedPleg = pleg.NewEventedPLEG(klet.containerRuntime, klet.runtimeService, eventChannel, klet.eventedPleg, err = pleg.NewEventedPLEG(klet.containerRuntime, klet.runtimeService, eventChannel,
klet.podCache, klet.pleg, eventedPlegMaxStreamRetries, eventedRelistDuration, clock.RealClock{}) klet.podCache, klet.pleg, eventedPlegMaxStreamRetries, eventedRelistDuration, clock.RealClock{})
if err != nil {
return nil, err
}
} else { } else {
genericRelistDuration := &pleg.RelistDuration{ genericRelistDuration := &pleg.RelistDuration{
RelistPeriod: genericPlegRelistPeriod, RelistPeriod: genericPlegRelistPeriod,

View File

@ -71,7 +71,7 @@ type EventedPLEG struct {
// For testability. // For testability.
clock clock.Clock clock clock.Clock
// GenericPLEG is used to force relist when required. // GenericPLEG is used to force relist when required.
genericPleg PodLifecycleEventGenerator genericPleg podLifecycleEventGeneratorHandler
// The maximum number of retries when getting container events from the runtime. // The maximum number of retries when getting container events from the runtime.
eventedPlegMaxStreamRetries int eventedPlegMaxStreamRetries int
// Indicates relisting related parameters // Indicates relisting related parameters
@ -87,17 +87,21 @@ type EventedPLEG struct {
// NewEventedPLEG instantiates a new EventedPLEG object and return it. // NewEventedPLEG instantiates a new EventedPLEG object and return it.
func NewEventedPLEG(runtime kubecontainer.Runtime, runtimeService internalapi.RuntimeService, eventChannel chan *PodLifecycleEvent, func NewEventedPLEG(runtime kubecontainer.Runtime, runtimeService internalapi.RuntimeService, eventChannel chan *PodLifecycleEvent,
cache kubecontainer.Cache, genericPleg PodLifecycleEventGenerator, eventedPlegMaxStreamRetries int, cache kubecontainer.Cache, genericPleg PodLifecycleEventGenerator, eventedPlegMaxStreamRetries int,
relistDuration *RelistDuration, clock clock.Clock) PodLifecycleEventGenerator { relistDuration *RelistDuration, clock clock.Clock) (PodLifecycleEventGenerator, error) {
handler, ok := genericPleg.(podLifecycleEventGeneratorHandler)
if !ok {
return nil, fmt.Errorf("%v doesn't implement podLifecycleEventGeneratorHandler interface", genericPleg)
}
return &EventedPLEG{ return &EventedPLEG{
runtime: runtime, runtime: runtime,
runtimeService: runtimeService, runtimeService: runtimeService,
eventChannel: eventChannel, eventChannel: eventChannel,
cache: cache, cache: cache,
genericPleg: genericPleg, genericPleg: handler,
eventedPlegMaxStreamRetries: eventedPlegMaxStreamRetries, eventedPlegMaxStreamRetries: eventedPlegMaxStreamRetries,
relistDuration: relistDuration, relistDuration: relistDuration,
clock: clock, clock: clock,
} }, nil
} }
// Watch returns a channel from which the subscriber can receive PodLifecycleEvent events. // Watch returns a channel from which the subscriber can receive PodLifecycleEvent events.

View File

@ -64,10 +64,16 @@ type PodLifecycleEvent struct {
// PodLifecycleEventGenerator contains functions for generating pod life cycle events. // PodLifecycleEventGenerator contains functions for generating pod life cycle events.
type PodLifecycleEventGenerator interface { type PodLifecycleEventGenerator interface {
Start() Start()
Stop()
Update(relistDuration *RelistDuration)
Watch() chan *PodLifecycleEvent Watch() chan *PodLifecycleEvent
Healthy() (bool, error) Healthy() (bool, error)
Relist()
UpdateCache(*kubecontainer.Pod, types.UID) (error, bool) UpdateCache(*kubecontainer.Pod, types.UID) (error, bool)
} }
// podLifecycleEventGeneratorHandler contains functions that are useful for different PLEGs
// and need not be exposed to rest of the kubelet
type podLifecycleEventGeneratorHandler interface {
PodLifecycleEventGenerator
Stop()
Update(relistDuration *RelistDuration)
Relist()
}