Skip to content

Commit

Permalink
Merge pull request #69 from maxlaverse/fix_zero_memory_limit
Browse files Browse the repository at this point in the history
fix the case where memory limit is 0
  • Loading branch information
maxlaverse authored Apr 21, 2023
2 parents b3283bc + 7d35262 commit 6de168a
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,14 @@ func identifyContainersCloseToMemoryLimit(ctx context.Context, podMetrics metric
}

if containerDefinition.Resources.Limits == nil {
klog.V(3).Infof("No limits found for container '%s/%s/%s'", podMetrics.Namespace, podMetrics.Name, containerMetric.Name)
continue
} else if containerDefinition.Resources.Limits.Memory() == nil {
klog.V(3).Infof("No memory limit found for container '%s/%s/%s'", podMetrics.Namespace, podMetrics.Name, containerMetric.Name)
continue
} else if containerDefinition.Resources.Limits.Memory().IsZero() {
klog.V(3).Infof("Memory limit is 0 for container '%s/%s/%s'", podMetrics.Namespace, podMetrics.Name, containerMetric.Name)
continue
}
memoryUsagePercent := 100 * containerMetric.Usage.Memory().AsApproximateFloat64() / containerDefinition.Resources.Limits.Memory().AsApproximateFloat64()
klog.V(1).Infof("Memory usage for '%s/%s/%s' is %.1f%%\n", podMetrics.Namespace, podMetrics.Name, containerMetric.Name, memoryUsagePercent)
Expand Down

0 comments on commit 6de168a

Please sign in to comment.