mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-07-17 11:28:58 +00:00
Use DeepCopy in GetLimits to avoid returning direct references to resource quantities, ensuring that changes to the returned ResourceList do not affect the original spec
This commit is contained in:
@@ -84,7 +84,7 @@ func GetLimits(res *ResourceOpts) v1.ResourceList {
|
||||
if containerResources == nil || containerResources.Limits == nil {
|
||||
return v1.ResourceList{}
|
||||
}
|
||||
return containerResources.Limits
|
||||
return containerResources.Limits.DeepCopy()
|
||||
}
|
||||
|
||||
containerLimits := limitsOrEmpty(res.ContainerResources)
|
||||
@@ -99,13 +99,13 @@ func GetLimits(res *ResourceOpts) v1.ResourceList {
|
||||
// When container-level CPU limit is not set, the pod-level
|
||||
// limit CPU is applied at container-level
|
||||
if containerLimits.Cpu().IsZero() && !podLevelLimits.Cpu().IsZero() {
|
||||
containerLimits[v1.ResourceCPU] = podLevelLimits[v1.ResourceCPU]
|
||||
containerLimits[v1.ResourceCPU] = podLevelLimits[v1.ResourceCPU].DeepCopy()
|
||||
}
|
||||
|
||||
// When container-level Memory limit is not set, the pod-level
|
||||
// limit Memory is applied at container-level
|
||||
if containerLimits.Memory().IsZero() && !podLevelLimits.Memory().IsZero() {
|
||||
containerLimits[v1.ResourceMemory] = podLevelLimits[v1.ResourceMemory]
|
||||
containerLimits[v1.ResourceMemory] = podLevelLimits[v1.ResourceMemory].DeepCopy()
|
||||
}
|
||||
return containerLimits
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user