Skip to content

Commit

Permalink
Add resource limit verification before adding memoryLimit to pods
Browse files Browse the repository at this point in the history
Signed-off-by: Netanel Levine <[email protected]>
  • Loading branch information
netanellevine committed Jan 20, 2025
1 parent dfab4bb commit d04eb62
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/webhook/sparkpod_defaulter.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ func addMemoryLimit(pod *corev1.Pod, app *v1beta2.SparkApplication) error {
return fmt.Errorf("failed to parse memory limit %s: %v", *memoryLimit, err)
}

if pod.Spec.Containers[i].Resources.Limits == nil {
pod.Spec.Containers[i].Resources.Limits = corev1.ResourceList{}
}

// Apply the memory limit to the container's resources
logger.Info(fmt.Sprintf("Adding memory limit %s to container in pod %s", *memoryLimit, pod.Name))
pod.Spec.Containers[i].Resources.Limits[corev1.ResourceMemory] = limitQuantity
Expand Down

0 comments on commit d04eb62

Please sign in to comment.