Fix virtual machine resource tracking - #904
Conversation
* Count Workload resources for pods by requests, not limits * Do not count init container requests * Prefix Workloads for pods with `pod-`, just like the other types to prevent possible name collisions (closes #787) The previous version of the WorkloadMonitor controller incorrectly summed resource limits on pods, rather than requests. This prevented it from tracking the resource allocation for pods, which only had requests specified, which is particularly the case for kubevirt's virtual machine pods. Additionally, it counted the limits for all containers, including init containers, which are short-lived and do not contribute much to the total resource usage. Signed-off-by: Timofei Larkin <lllamnyp@gmail.com>
WalkthroughThis update modifies the logic for managing Workloads associated with Kubernetes Pods, Services, and PersistentVolumeClaims. The Changes
Sequence Diagram(s)sequenceDiagram
participant WorkloadMonitorController
participant KubernetesAPI
participant WorkloadController
WorkloadMonitorController->>KubernetesAPI: Get Pod/Service/PVC
WorkloadMonitorController->>KubernetesAPI: Create Workload with prefix ("pod-", "svc-", "pvc-")
WorkloadController->>KubernetesAPI: Get Workload
WorkloadController->>KubernetesAPI: Get Monitored Object (by prefix)
alt Monitored Object is nil
WorkloadController->>KubernetesAPI: Delete Workload
else
WorkloadController->>KubernetesAPI: Continue processing
end
Assessment against linked issues
Possibly related PRs
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (3)
🧰 Additional context used🧬 Code Graph Analysis (1)internal/controller/workload_controller_test.go (1)
⏰ Context from checks skipped due to timeout of 90000ms (1)
🔇 Additional comments (7)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
* Count Workload resources for pods by requests, not limits * Do not count init container requests * Prefix Workloads for pods with `pod-`, just like the other types to prevent possible name collisions (closes #787) The previous version of the WorkloadMonitor controller incorrectly summed resource limits on pods, rather than requests. This prevented it from tracking the resource allocation for pods, which only had requests specified, which is particularly the case for kubevirt's virtual machine pods. Additionally, it counted the limits for all containers, including init containers, which are short-lived and do not contribute much to the total resource usage. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Bug Fixes** - Improved handling of workloads with unrecognized prefixes by ensuring they are properly deleted and not processed further. - Corrected resource aggregation for Pods to sum container resource requests instead of limits, and now only includes normal containers. - **New Features** - Added support for monitoring workloads with names prefixed by "pod-". - **Tests** - Introduced unit tests to verify correct handling of workload name prefixes and monitored object creation. <!-- end of auto-generated comment: release notes by coderabbit.ai --> (cherry picked from commit 1e59e5f) Signed-off-by: Timofei Larkin <lllamnyp@gmail.com>
* Count Workload resources for pods by requests, not limits * Do not count init container requests * Prefix Workloads for pods with `pod-`, just like the other types to prevent possible name collisions (closes #787) The previous version of the WorkloadMonitor controller incorrectly summed resource limits on pods, rather than requests. This prevented it from tracking the resource allocation for pods, which only had requests specified, which is particularly the case for kubevirt's virtual machine pods. Additionally, it counted the limits for all containers, including init containers, which are short-lived and do not contribute much to the total resource usage. (cherry picked from commit 1e59e5f) Signed-off-by: Timofei Larkin <lllamnyp@gmail.com>
* Count Workload resources for pods by requests, not limits * Do not count init container requests * Prefix Workloads for pods with `pod-`, just like the other types to prevent possible name collisions (closes #787) The previous version of the WorkloadMonitor controller incorrectly summed resource limits on pods, rather than requests. This prevented it from tracking the resource allocation for pods, which only had requests specified, which is particularly the case for kubevirt's virtual machine pods. Additionally, it counted the limits for all containers, including init containers, which are short-lived and do not contribute much to the total resource usage. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Bug Fixes** - Improved handling of workloads with unrecognized prefixes by ensuring they are properly deleted and not processed further. - Corrected resource aggregation for Pods to sum container resource requests instead of limits, and now only includes normal containers. - **New Features** - Added support for monitoring workloads with names prefixed by "pod-". - **Tests** - Introduced unit tests to verify correct handling of workload name prefixes and monitored object creation. <!-- end of auto-generated comment: release notes by coderabbit.ai --> (cherry picked from commit 1e59e5f) Signed-off-by: Timofei Larkin <lllamnyp@gmail.com>
pod-, just like the other types to prevent possible name collisions (closes Create Workloads for pods with a "pod-" prefix #787)The previous version of the WorkloadMonitor controller incorrectly summed resource limits on pods, rather than requests. This prevented it from tracking the resource allocation for pods, which only had requests specified, which is particularly the case for kubevirt's virtual machine pods. Additionally, it counted the limits for all containers, including init containers, which are short-lived and do not contribute much to the total resource usage.
Summary by CodeRabbit
Bug Fixes
New Features
Tests