-
Notifications
You must be signed in to change notification settings - Fork 418
feat: add containerd event listener for real-time container lifecycle #2230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a containerd event listener to enhance the real-time monitoring of container lifecycle events in the CRI adapter, reducing reliance on periodic polling. Key changes include the addition of new functions (getContainerType, containerdEventListener, and criRuntimeRecover) in cri_adapter.go, and the conditional launch of the event listener in container_discover_controller.go.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
pkg/helper/containercenter/cri_adapter.go | Added event listener functions and helper methods to process container lifecycle events using containerd events |
pkg/helper/containercenter/container_discover_controller.go | Updated sync logic to conditionally launch the new event listener based on nativeClient availability |
if errorCount > 10 && containerCenterInstance != nil { | ||
logger.Info(context.Background(), "containerd listener fails and docker wrapper is valid", "stop containerd listener") | ||
break | ||
} | ||
// if always error, sleep 300 secs | ||
if errorCount > 30 { | ||
time.Sleep(time.Duration(300) * time.Second) | ||
} else { | ||
time.Sleep(time.Duration(10) * time.Second) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider replacing the magic numbers (e.g., 10 and 30) used in errorCount thresholds and the subsequent sleep durations with named constants to improve code readability and maintainability.
if errorCount > 10 && containerCenterInstance != nil { | |
logger.Info(context.Background(), "containerd listener fails and docker wrapper is valid", "stop containerd listener") | |
break | |
} | |
// if always error, sleep 300 secs | |
if errorCount > 30 { | |
time.Sleep(time.Duration(300) * time.Second) | |
} else { | |
time.Sleep(time.Duration(10) * time.Second) | |
if errorCount > errorThreshold && containerCenterInstance != nil { | |
logger.Info(context.Background(), "containerd listener fails and docker wrapper is valid", "stop containerd listener") | |
break | |
} | |
// if always error, sleep for a longer duration | |
if errorCount > highErrorThreshold { | |
time.Sleep(longSleepDuration) | |
} else { | |
time.Sleep(shortSleepDuration) |
Copilot uses AI. Check for mistakes.
} else { | ||
continue | ||
} | ||
default: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] It might be beneficial to log unhandled event types in the default case to aid future debugging efforts if unexpected events are received.
default: | |
default: | |
logger.Warnf(context.Background(), "CONTAINERD_EVENT_UNHANDLED", "Unhandled containerd event type: %T", evt) |
Copilot uses AI. Check for mistakes.
目前在 cri_adapter.go 中,containerd类型容器状态的更新主要依赖于定时轮询(如 syncContainers)。为了提高状态感知的实时性和性能,实现基于containerd容器生命周期事件的监听与处理。