mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 11:21:47 +00:00
Delete duplicate resource.Quantity.Copy()
This commit is contained in:
parent
f4521bf5a2
commit
49f50484b8
@ -29,7 +29,7 @@ import (
|
|||||||
func addResourceList(list, new v1.ResourceList) {
|
func addResourceList(list, new v1.ResourceList) {
|
||||||
for name, quantity := range new {
|
for name, quantity := range new {
|
||||||
if value, ok := list[name]; !ok {
|
if value, ok := list[name]; !ok {
|
||||||
list[name] = *quantity.Copy()
|
list[name] = quantity.DeepCopy()
|
||||||
} else {
|
} else {
|
||||||
value.Add(quantity)
|
value.Add(quantity)
|
||||||
list[name] = value
|
list[name] = value
|
||||||
@ -42,11 +42,11 @@ func addResourceList(list, new v1.ResourceList) {
|
|||||||
func maxResourceList(list, new v1.ResourceList) {
|
func maxResourceList(list, new v1.ResourceList) {
|
||||||
for name, quantity := range new {
|
for name, quantity := range new {
|
||||||
if value, ok := list[name]; !ok {
|
if value, ok := list[name]; !ok {
|
||||||
list[name] = *quantity.Copy()
|
list[name] = quantity.DeepCopy()
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
if quantity.Cmp(value) > 0 {
|
if quantity.Cmp(value) > 0 {
|
||||||
list[name] = *quantity.Copy()
|
list[name] = quantity.DeepCopy()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -197,7 +197,7 @@ func MergeContainerResourceLimits(container *v1.Container,
|
|||||||
for _, resource := range []v1.ResourceName{v1.ResourceCPU, v1.ResourceMemory, v1.ResourceEphemeralStorage} {
|
for _, resource := range []v1.ResourceName{v1.ResourceCPU, v1.ResourceMemory, v1.ResourceEphemeralStorage} {
|
||||||
if quantity, exists := container.Resources.Limits[resource]; !exists || quantity.IsZero() {
|
if quantity, exists := container.Resources.Limits[resource]; !exists || quantity.IsZero() {
|
||||||
if cap, exists := allocatable[resource]; exists {
|
if cap, exists := allocatable[resource]; exists {
|
||||||
container.Resources.Limits[resource] = *cap.Copy()
|
container.Resources.Limits[resource] = cap.DeepCopy()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -133,14 +133,14 @@ var Funcs = func(codecs runtimeserializer.CodecFactory) []interface{} {
|
|||||||
q.Limits = make(core.ResourceList)
|
q.Limits = make(core.ResourceList)
|
||||||
q.Requests = make(core.ResourceList)
|
q.Requests = make(core.ResourceList)
|
||||||
cpuLimit := randomQuantity()
|
cpuLimit := randomQuantity()
|
||||||
q.Limits[core.ResourceCPU] = *cpuLimit.Copy()
|
q.Limits[core.ResourceCPU] = cpuLimit.DeepCopy()
|
||||||
q.Requests[core.ResourceCPU] = *cpuLimit.Copy()
|
q.Requests[core.ResourceCPU] = cpuLimit.DeepCopy()
|
||||||
memoryLimit := randomQuantity()
|
memoryLimit := randomQuantity()
|
||||||
q.Limits[core.ResourceMemory] = *memoryLimit.Copy()
|
q.Limits[core.ResourceMemory] = memoryLimit.DeepCopy()
|
||||||
q.Requests[core.ResourceMemory] = *memoryLimit.Copy()
|
q.Requests[core.ResourceMemory] = memoryLimit.DeepCopy()
|
||||||
storageLimit := randomQuantity()
|
storageLimit := randomQuantity()
|
||||||
q.Limits[core.ResourceStorage] = *storageLimit.Copy()
|
q.Limits[core.ResourceStorage] = storageLimit.DeepCopy()
|
||||||
q.Requests[core.ResourceStorage] = *storageLimit.Copy()
|
q.Requests[core.ResourceStorage] = storageLimit.DeepCopy()
|
||||||
},
|
},
|
||||||
func(q *core.LimitRangeItem, c fuzz.Continue) {
|
func(q *core.LimitRangeItem, c fuzz.Continue) {
|
||||||
var cpuLimit resource.Quantity
|
var cpuLimit resource.Quantity
|
||||||
@ -148,16 +148,16 @@ var Funcs = func(codecs runtimeserializer.CodecFactory) []interface{} {
|
|||||||
|
|
||||||
q.Type = core.LimitTypeContainer
|
q.Type = core.LimitTypeContainer
|
||||||
q.Default = make(core.ResourceList)
|
q.Default = make(core.ResourceList)
|
||||||
q.Default[core.ResourceCPU] = *(cpuLimit.Copy())
|
q.Default[core.ResourceCPU] = cpuLimit.DeepCopy()
|
||||||
|
|
||||||
q.DefaultRequest = make(core.ResourceList)
|
q.DefaultRequest = make(core.ResourceList)
|
||||||
q.DefaultRequest[core.ResourceCPU] = *(cpuLimit.Copy())
|
q.DefaultRequest[core.ResourceCPU] = cpuLimit.DeepCopy()
|
||||||
|
|
||||||
q.Max = make(core.ResourceList)
|
q.Max = make(core.ResourceList)
|
||||||
q.Max[core.ResourceCPU] = *(cpuLimit.Copy())
|
q.Max[core.ResourceCPU] = cpuLimit.DeepCopy()
|
||||||
|
|
||||||
q.Min = make(core.ResourceList)
|
q.Min = make(core.ResourceList)
|
||||||
q.Min[core.ResourceCPU] = *(cpuLimit.Copy())
|
q.Min[core.ResourceCPU] = cpuLimit.DeepCopy()
|
||||||
|
|
||||||
q.MaxLimitRequestRatio = make(core.ResourceList)
|
q.MaxLimitRequestRatio = make(core.ResourceList)
|
||||||
q.MaxLimitRequestRatio[core.ResourceCPU] = resource.MustParse("10")
|
q.MaxLimitRequestRatio[core.ResourceCPU] = resource.MustParse("10")
|
||||||
|
@ -49,12 +49,12 @@ func GetPodQOS(pod *core.Pod) core.PodQOSClass {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if quantity.Cmp(zeroQuantity) == 1 {
|
if quantity.Cmp(zeroQuantity) == 1 {
|
||||||
delta := quantity.Copy()
|
delta := quantity.DeepCopy()
|
||||||
if _, exists := requests[name]; !exists {
|
if _, exists := requests[name]; !exists {
|
||||||
requests[name] = *delta
|
requests[name] = delta
|
||||||
} else {
|
} else {
|
||||||
delta.Add(requests[name])
|
delta.Add(requests[name])
|
||||||
requests[name] = *delta
|
requests[name] = delta
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -66,12 +66,12 @@ func GetPodQOS(pod *core.Pod) core.PodQOSClass {
|
|||||||
}
|
}
|
||||||
if quantity.Cmp(zeroQuantity) == 1 {
|
if quantity.Cmp(zeroQuantity) == 1 {
|
||||||
qosLimitsFound.Insert(string(name))
|
qosLimitsFound.Insert(string(name))
|
||||||
delta := quantity.Copy()
|
delta := quantity.DeepCopy()
|
||||||
if _, exists := limits[name]; !exists {
|
if _, exists := limits[name]; !exists {
|
||||||
limits[name] = *delta
|
limits[name] = delta
|
||||||
} else {
|
} else {
|
||||||
delta.Add(limits[name])
|
delta.Add(limits[name])
|
||||||
limits[name] = *delta
|
limits[name] = delta
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -208,12 +208,12 @@ func TestResourceListConversion(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{ // Large values should still be accurate.
|
{ // Large values should still be accurate.
|
||||||
input: v1.ResourceList{
|
input: v1.ResourceList{
|
||||||
v1.ResourceCPU: *bigMilliQuantity.Copy(),
|
v1.ResourceCPU: bigMilliQuantity.DeepCopy(),
|
||||||
v1.ResourceStorage: *bigMilliQuantity.Copy(),
|
v1.ResourceStorage: bigMilliQuantity.DeepCopy(),
|
||||||
},
|
},
|
||||||
expected: core.ResourceList{
|
expected: core.ResourceList{
|
||||||
core.ResourceCPU: *bigMilliQuantity.Copy(),
|
core.ResourceCPU: bigMilliQuantity.DeepCopy(),
|
||||||
core.ResourceStorage: *bigMilliQuantity.Copy(),
|
core.ResourceStorage: bigMilliQuantity.DeepCopy(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -141,7 +141,7 @@ func SetDefaults_Pod(obj *v1.Pod) {
|
|||||||
}
|
}
|
||||||
for key, value := range obj.Spec.Containers[i].Resources.Limits {
|
for key, value := range obj.Spec.Containers[i].Resources.Limits {
|
||||||
if _, exists := obj.Spec.Containers[i].Resources.Requests[key]; !exists {
|
if _, exists := obj.Spec.Containers[i].Resources.Requests[key]; !exists {
|
||||||
obj.Spec.Containers[i].Resources.Requests[key] = *(value.Copy())
|
obj.Spec.Containers[i].Resources.Requests[key] = value.DeepCopy()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -153,7 +153,7 @@ func SetDefaults_Pod(obj *v1.Pod) {
|
|||||||
}
|
}
|
||||||
for key, value := range obj.Spec.InitContainers[i].Resources.Limits {
|
for key, value := range obj.Spec.InitContainers[i].Resources.Limits {
|
||||||
if _, exists := obj.Spec.InitContainers[i].Resources.Requests[key]; !exists {
|
if _, exists := obj.Spec.InitContainers[i].Resources.Requests[key]; !exists {
|
||||||
obj.Spec.InitContainers[i].Resources.Requests[key] = *(value.Copy())
|
obj.Spec.InitContainers[i].Resources.Requests[key] = value.DeepCopy()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -315,7 +315,7 @@ func SetDefaults_NodeStatus(obj *v1.NodeStatus) {
|
|||||||
if obj.Allocatable == nil && obj.Capacity != nil {
|
if obj.Allocatable == nil && obj.Capacity != nil {
|
||||||
obj.Allocatable = make(v1.ResourceList, len(obj.Capacity))
|
obj.Allocatable = make(v1.ResourceList, len(obj.Capacity))
|
||||||
for key, value := range obj.Capacity {
|
for key, value := range obj.Capacity {
|
||||||
obj.Allocatable[key] = *(value.Copy())
|
obj.Allocatable[key] = value.DeepCopy()
|
||||||
}
|
}
|
||||||
obj.Allocatable = obj.Capacity
|
obj.Allocatable = obj.Capacity
|
||||||
}
|
}
|
||||||
@ -339,19 +339,19 @@ func SetDefaults_LimitRangeItem(obj *v1.LimitRangeItem) {
|
|||||||
// If a default limit is unspecified, but the max is specified, default the limit to the max
|
// If a default limit is unspecified, but the max is specified, default the limit to the max
|
||||||
for key, value := range obj.Max {
|
for key, value := range obj.Max {
|
||||||
if _, exists := obj.Default[key]; !exists {
|
if _, exists := obj.Default[key]; !exists {
|
||||||
obj.Default[key] = *(value.Copy())
|
obj.Default[key] = value.DeepCopy()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If a default limit is specified, but the default request is not, default request to limit
|
// If a default limit is specified, but the default request is not, default request to limit
|
||||||
for key, value := range obj.Default {
|
for key, value := range obj.Default {
|
||||||
if _, exists := obj.DefaultRequest[key]; !exists {
|
if _, exists := obj.DefaultRequest[key]; !exists {
|
||||||
obj.DefaultRequest[key] = *(value.Copy())
|
obj.DefaultRequest[key] = value.DeepCopy()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If a default request is not specified, but the min is provided, default request to the min
|
// If a default request is not specified, but the min is provided, default request to the min
|
||||||
for key, value := range obj.Min {
|
for key, value := range obj.Min {
|
||||||
if _, exists := obj.DefaultRequest[key]; !exists {
|
if _, exists := obj.DefaultRequest[key]; !exists {
|
||||||
obj.DefaultRequest[key] = *(value.Copy())
|
obj.DefaultRequest[key] = value.DeepCopy()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1394,7 +1394,7 @@ func TestSetDefaultNodeStatusAllocatable(t *testing.T) {
|
|||||||
}
|
}
|
||||||
copy := make(v1.ResourceList, len(rl))
|
copy := make(v1.ResourceList, len(rl))
|
||||||
for k, v := range rl {
|
for k, v := range rl {
|
||||||
copy[k] = *v.Copy()
|
copy[k] = v.DeepCopy()
|
||||||
}
|
}
|
||||||
return copy
|
return copy
|
||||||
}
|
}
|
||||||
|
@ -51,12 +51,12 @@ func GetPodQOS(pod *v1.Pod) v1.PodQOSClass {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if quantity.Cmp(zeroQuantity) == 1 {
|
if quantity.Cmp(zeroQuantity) == 1 {
|
||||||
delta := quantity.Copy()
|
delta := quantity.DeepCopy()
|
||||||
if _, exists := requests[name]; !exists {
|
if _, exists := requests[name]; !exists {
|
||||||
requests[name] = *delta
|
requests[name] = delta
|
||||||
} else {
|
} else {
|
||||||
delta.Add(requests[name])
|
delta.Add(requests[name])
|
||||||
requests[name] = *delta
|
requests[name] = delta
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -68,12 +68,12 @@ func GetPodQOS(pod *v1.Pod) v1.PodQOSClass {
|
|||||||
}
|
}
|
||||||
if quantity.Cmp(zeroQuantity) == 1 {
|
if quantity.Cmp(zeroQuantity) == 1 {
|
||||||
qosLimitsFound.Insert(string(name))
|
qosLimitsFound.Insert(string(name))
|
||||||
delta := quantity.Copy()
|
delta := quantity.DeepCopy()
|
||||||
if _, exists := limits[name]; !exists {
|
if _, exists := limits[name]; !exists {
|
||||||
limits[name] = *delta
|
limits[name] = delta
|
||||||
} else {
|
} else {
|
||||||
delta.Add(limits[name])
|
delta.Add(limits[name])
|
||||||
limits[name] = *delta
|
limits[name] = delta
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -177,7 +177,7 @@ func (cm *containerManagerImpl) getNodeAllocatableAbsolute() v1.ResourceList {
|
|||||||
func (cm *containerManagerImpl) getNodeAllocatableAbsoluteImpl(capacity v1.ResourceList) v1.ResourceList {
|
func (cm *containerManagerImpl) getNodeAllocatableAbsoluteImpl(capacity v1.ResourceList) v1.ResourceList {
|
||||||
result := make(v1.ResourceList)
|
result := make(v1.ResourceList)
|
||||||
for k, v := range capacity {
|
for k, v := range capacity {
|
||||||
value := *(v.Copy())
|
value := v.DeepCopy()
|
||||||
if cm.NodeConfig.SystemReserved != nil {
|
if cm.NodeConfig.SystemReserved != nil {
|
||||||
value.Sub(cm.NodeConfig.SystemReserved[k])
|
value.Sub(cm.NodeConfig.SystemReserved[k])
|
||||||
}
|
}
|
||||||
|
@ -93,7 +93,8 @@ type Threshold struct {
|
|||||||
// GetThresholdQuantity returns the expected quantity value for a thresholdValue
|
// GetThresholdQuantity returns the expected quantity value for a thresholdValue
|
||||||
func GetThresholdQuantity(value ThresholdValue, capacity *resource.Quantity) *resource.Quantity {
|
func GetThresholdQuantity(value ThresholdValue, capacity *resource.Quantity) *resource.Quantity {
|
||||||
if value.Quantity != nil {
|
if value.Quantity != nil {
|
||||||
return value.Quantity.Copy()
|
res := value.Quantity.DeepCopy()
|
||||||
|
return &res
|
||||||
}
|
}
|
||||||
return resource.NewQuantity(int64(float64(capacity.Value())*float64(value.Percentage)), resource.BinarySI)
|
return resource.NewQuantity(int64(float64(capacity.Value())*float64(value.Percentage)), resource.BinarySI)
|
||||||
}
|
}
|
||||||
|
@ -320,7 +320,7 @@ func MachineInfo(nodeName string,
|
|||||||
}
|
}
|
||||||
allocatableReservation := nodeAllocatableReservationFunc()
|
allocatableReservation := nodeAllocatableReservationFunc()
|
||||||
for k, v := range node.Status.Capacity {
|
for k, v := range node.Status.Capacity {
|
||||||
value := *(v.Copy())
|
value := v.DeepCopy()
|
||||||
if res, exists := allocatableReservation[k]; exists {
|
if res, exists := allocatableReservation[k]; exists {
|
||||||
value.Sub(res)
|
value.Sub(res)
|
||||||
}
|
}
|
||||||
@ -343,7 +343,7 @@ func MachineInfo(nodeName string,
|
|||||||
for k, v := range node.Status.Capacity {
|
for k, v := range node.Status.Capacity {
|
||||||
if v1helper.IsHugePageResourceName(k) {
|
if v1helper.IsHugePageResourceName(k) {
|
||||||
allocatableMemory := node.Status.Allocatable[v1.ResourceMemory]
|
allocatableMemory := node.Status.Allocatable[v1.ResourceMemory]
|
||||||
value := *(v.Copy())
|
value := v.DeepCopy()
|
||||||
allocatableMemory.Sub(value)
|
allocatableMemory.Sub(value)
|
||||||
if allocatableMemory.Sign() < 0 {
|
if allocatableMemory.Sign() < 0 {
|
||||||
// Negative Allocatable resources don't make sense.
|
// Negative Allocatable resources don't make sense.
|
||||||
|
@ -86,15 +86,15 @@ func Max(a corev1.ResourceList, b corev1.ResourceList) corev1.ResourceList {
|
|||||||
for key, value := range a {
|
for key, value := range a {
|
||||||
if other, found := b[key]; found {
|
if other, found := b[key]; found {
|
||||||
if value.Cmp(other) <= 0 {
|
if value.Cmp(other) <= 0 {
|
||||||
result[key] = *other.Copy()
|
result[key] = other.DeepCopy()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result[key] = *value.Copy()
|
result[key] = value.DeepCopy()
|
||||||
}
|
}
|
||||||
for key, value := range b {
|
for key, value := range b {
|
||||||
if _, found := result[key]; !found {
|
if _, found := result[key]; !found {
|
||||||
result[key] = *value.Copy()
|
result[key] = value.DeepCopy()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
@ -104,7 +104,7 @@ func Max(a corev1.ResourceList, b corev1.ResourceList) corev1.ResourceList {
|
|||||||
func Add(a corev1.ResourceList, b corev1.ResourceList) corev1.ResourceList {
|
func Add(a corev1.ResourceList, b corev1.ResourceList) corev1.ResourceList {
|
||||||
result := corev1.ResourceList{}
|
result := corev1.ResourceList{}
|
||||||
for key, value := range a {
|
for key, value := range a {
|
||||||
quantity := *value.Copy()
|
quantity := value.DeepCopy()
|
||||||
if other, found := b[key]; found {
|
if other, found := b[key]; found {
|
||||||
quantity.Add(other)
|
quantity.Add(other)
|
||||||
}
|
}
|
||||||
@ -112,8 +112,7 @@ func Add(a corev1.ResourceList, b corev1.ResourceList) corev1.ResourceList {
|
|||||||
}
|
}
|
||||||
for key, value := range b {
|
for key, value := range b {
|
||||||
if _, found := result[key]; !found {
|
if _, found := result[key]; !found {
|
||||||
quantity := *value.Copy()
|
result[key] = value.DeepCopy()
|
||||||
result[key] = quantity
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
@ -126,7 +125,7 @@ func SubtractWithNonNegativeResult(a corev1.ResourceList, b corev1.ResourceList)
|
|||||||
|
|
||||||
result := corev1.ResourceList{}
|
result := corev1.ResourceList{}
|
||||||
for key, value := range a {
|
for key, value := range a {
|
||||||
quantity := *value.Copy()
|
quantity := value.DeepCopy()
|
||||||
if other, found := b[key]; found {
|
if other, found := b[key]; found {
|
||||||
quantity.Sub(other)
|
quantity.Sub(other)
|
||||||
}
|
}
|
||||||
@ -149,7 +148,7 @@ func SubtractWithNonNegativeResult(a corev1.ResourceList, b corev1.ResourceList)
|
|||||||
func Subtract(a corev1.ResourceList, b corev1.ResourceList) corev1.ResourceList {
|
func Subtract(a corev1.ResourceList, b corev1.ResourceList) corev1.ResourceList {
|
||||||
result := corev1.ResourceList{}
|
result := corev1.ResourceList{}
|
||||||
for key, value := range a {
|
for key, value := range a {
|
||||||
quantity := *value.Copy()
|
quantity := value.DeepCopy()
|
||||||
if other, found := b[key]; found {
|
if other, found := b[key]; found {
|
||||||
quantity.Sub(other)
|
quantity.Sub(other)
|
||||||
}
|
}
|
||||||
@ -157,7 +156,7 @@ func Subtract(a corev1.ResourceList, b corev1.ResourceList) corev1.ResourceList
|
|||||||
}
|
}
|
||||||
for key, value := range b {
|
for key, value := range b {
|
||||||
if _, found := result[key]; !found {
|
if _, found := result[key]; !found {
|
||||||
quantity := *value.Copy()
|
quantity := value.DeepCopy()
|
||||||
quantity.Neg()
|
quantity.Neg()
|
||||||
result[key] = quantity
|
result[key] = quantity
|
||||||
}
|
}
|
||||||
@ -171,7 +170,7 @@ func Mask(resources corev1.ResourceList, names []corev1.ResourceName) corev1.Res
|
|||||||
result := corev1.ResourceList{}
|
result := corev1.ResourceList{}
|
||||||
for key, value := range resources {
|
for key, value := range resources {
|
||||||
if nameSet.Has(string(key)) {
|
if nameSet.Has(string(key)) {
|
||||||
result[key] = *value.Copy()
|
result[key] = value.DeepCopy()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
|
@ -219,12 +219,10 @@ func defaultContainerResourceRequirements(limitRange *corev1.LimitRange) api.Res
|
|||||||
limit := limitRange.Spec.Limits[i]
|
limit := limitRange.Spec.Limits[i]
|
||||||
if limit.Type == corev1.LimitTypeContainer {
|
if limit.Type == corev1.LimitTypeContainer {
|
||||||
for k, v := range limit.DefaultRequest {
|
for k, v := range limit.DefaultRequest {
|
||||||
value := v.Copy()
|
requirements.Requests[api.ResourceName(k)] = v.DeepCopy()
|
||||||
requirements.Requests[api.ResourceName(k)] = *value
|
|
||||||
}
|
}
|
||||||
for k, v := range limit.Default {
|
for k, v := range limit.Default {
|
||||||
value := v.Copy()
|
requirements.Limits[api.ResourceName(k)] = v.DeepCopy()
|
||||||
requirements.Limits[api.ResourceName(k)] = *value
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -244,14 +242,14 @@ func mergeContainerResources(container *api.Container, defaultRequirements *api.
|
|||||||
for k, v := range defaultRequirements.Limits {
|
for k, v := range defaultRequirements.Limits {
|
||||||
_, found := container.Resources.Limits[k]
|
_, found := container.Resources.Limits[k]
|
||||||
if !found {
|
if !found {
|
||||||
container.Resources.Limits[k] = *v.Copy()
|
container.Resources.Limits[k] = v.DeepCopy()
|
||||||
setLimits = append(setLimits, string(k))
|
setLimits = append(setLimits, string(k))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for k, v := range defaultRequirements.Requests {
|
for k, v := range defaultRequirements.Requests {
|
||||||
_, found := container.Resources.Requests[k]
|
_, found := container.Resources.Requests[k]
|
||||||
if !found {
|
if !found {
|
||||||
container.Resources.Requests[k] = *v.Copy()
|
container.Resources.Requests[k] = v.DeepCopy()
|
||||||
setRequests = append(setRequests, string(k))
|
setRequests = append(setRequests, string(k))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -726,21 +726,3 @@ func (q *Quantity) SetScaled(value int64, scale Scale) {
|
|||||||
q.d.Dec = nil
|
q.d.Dec = nil
|
||||||
q.i = int64Amount{value: value, scale: scale}
|
q.i = int64Amount{value: value, scale: scale}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy is a convenience function that makes a deep copy for you. Non-deep
|
|
||||||
// copies of quantities share pointers and you will regret that.
|
|
||||||
func (q *Quantity) Copy() *Quantity {
|
|
||||||
if q.d.Dec == nil {
|
|
||||||
return &Quantity{
|
|
||||||
s: q.s,
|
|
||||||
i: q.i,
|
|
||||||
Format: q.Format,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
tmp := &inf.Dec{}
|
|
||||||
return &Quantity{
|
|
||||||
s: q.s,
|
|
||||||
d: infDecAmount{tmp.Set(q.d.Dec)},
|
|
||||||
Format: q.Format,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -94,11 +94,11 @@ func TestQuantityAddZeroPreservesSuffix(t *testing.T) {
|
|||||||
zero := MustParse("0")
|
zero := MustParse("0")
|
||||||
for _, testValue := range testValues {
|
for _, testValue := range testValues {
|
||||||
value := MustParse(testValue)
|
value := MustParse(testValue)
|
||||||
v1 := *value.Copy()
|
v1 := value.DeepCopy()
|
||||||
// ensure non-zero + zero = non-zero (suffix preserved)
|
// ensure non-zero + zero = non-zero (suffix preserved)
|
||||||
v1.Add(zero)
|
v1.Add(zero)
|
||||||
// ensure zero + non-zero = non-zero (suffix preserved)
|
// ensure zero + non-zero = non-zero (suffix preserved)
|
||||||
v2 := *zero.Copy()
|
v2 := zero.DeepCopy()
|
||||||
v2.Add(value)
|
v2.Add(value)
|
||||||
|
|
||||||
if v1.String() != testValue {
|
if v1.String() != testValue {
|
||||||
@ -118,7 +118,7 @@ func TestQuantitySubZeroPreservesSuffix(t *testing.T) {
|
|||||||
zero := MustParse("0")
|
zero := MustParse("0")
|
||||||
for _, testValue := range testValues {
|
for _, testValue := range testValues {
|
||||||
value := MustParse(testValue)
|
value := MustParse(testValue)
|
||||||
v1 := *value.Copy()
|
v1 := value.DeepCopy()
|
||||||
// ensure non-zero - zero = non-zero (suffix preserved)
|
// ensure non-zero - zero = non-zero (suffix preserved)
|
||||||
v1.Sub(zero)
|
v1.Sub(zero)
|
||||||
// ensure we preserved the input value
|
// ensure we preserved the input value
|
||||||
@ -127,9 +127,9 @@ func TestQuantitySubZeroPreservesSuffix(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ensure zero - non-zero = -non-zero (suffix preserved)
|
// ensure zero - non-zero = -non-zero (suffix preserved)
|
||||||
v2 := *zero.Copy()
|
v2 := zero.DeepCopy()
|
||||||
v2.Sub(value)
|
v2.Sub(value)
|
||||||
negVal := *value.Copy()
|
negVal := value.DeepCopy()
|
||||||
negVal.Neg()
|
negVal.Neg()
|
||||||
if v2.String() != negVal.String() {
|
if v2.String() != negVal.String() {
|
||||||
t.Errorf("Expected %v, actual %v", negVal.String(), v2.String())
|
t.Errorf("Expected %v, actual %v", negVal.String(), v2.String())
|
||||||
@ -523,7 +523,7 @@ func TestQuantityRoundUp(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
expect := *item.expect.Copy()
|
expect := item.expect.DeepCopy()
|
||||||
if asDec {
|
if asDec {
|
||||||
got.AsDec()
|
got.AsDec()
|
||||||
}
|
}
|
||||||
@ -580,7 +580,7 @@ func TestQuantityCmpInt64AndDec(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, item := range table {
|
for _, item := range table {
|
||||||
a, b := *item.a.Copy(), *item.b.Copy()
|
a, b := item.a.DeepCopy(), item.b.DeepCopy()
|
||||||
a.AsDec()
|
a.AsDec()
|
||||||
if cmp := a.Cmp(b); cmp != item.cmp {
|
if cmp := a.Cmp(b); cmp != item.cmp {
|
||||||
t.Errorf("%#v: unexpected Cmp: %d", item, cmp)
|
t.Errorf("%#v: unexpected Cmp: %d", item, cmp)
|
||||||
@ -591,7 +591,7 @@ func TestQuantityCmpInt64AndDec(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, item := range table {
|
for _, item := range table {
|
||||||
a, b := *item.a.Copy(), *item.b.Copy()
|
a, b := item.a.DeepCopy(), item.b.DeepCopy()
|
||||||
b.AsDec()
|
b.AsDec()
|
||||||
if cmp := a.Cmp(b); cmp != item.cmp {
|
if cmp := a.Cmp(b); cmp != item.cmp {
|
||||||
t.Errorf("%#v: unexpected Cmp: %d", item, cmp)
|
t.Errorf("%#v: unexpected Cmp: %d", item, cmp)
|
||||||
@ -602,7 +602,7 @@ func TestQuantityCmpInt64AndDec(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, item := range table {
|
for _, item := range table {
|
||||||
a, b := *item.a.Copy(), *item.b.Copy()
|
a, b := item.a.DeepCopy(), item.b.DeepCopy()
|
||||||
a.AsDec()
|
a.AsDec()
|
||||||
b.AsDec()
|
b.AsDec()
|
||||||
if cmp := a.Cmp(b); cmp != item.cmp {
|
if cmp := a.Cmp(b); cmp != item.cmp {
|
||||||
@ -624,7 +624,7 @@ func TestQuantityNeg(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i, item := range table {
|
for i, item := range table {
|
||||||
out := *item.a.Copy()
|
out := item.a.DeepCopy()
|
||||||
out.Neg()
|
out.Neg()
|
||||||
if out.Cmp(item.a) == 0 {
|
if out.Cmp(item.a) == 0 {
|
||||||
t.Errorf("%d: negating an item should not mutate the source: %s", i, out.String())
|
t.Errorf("%d: negating an item should not mutate the source: %s", i, out.String())
|
||||||
@ -1045,14 +1045,14 @@ func TestUninitializedNoCrash(t *testing.T) {
|
|||||||
|
|
||||||
q.Value()
|
q.Value()
|
||||||
q.MilliValue()
|
q.MilliValue()
|
||||||
q.Copy()
|
q.DeepCopy()
|
||||||
_ = q.String()
|
_ = q.String()
|
||||||
q.MarshalJSON()
|
q.MarshalJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCopy(t *testing.T) {
|
func TestDeepCopy(t *testing.T) {
|
||||||
q := NewQuantity(5, DecimalSI)
|
q := NewQuantity(5, DecimalSI)
|
||||||
c := q.Copy()
|
c := q.DeepCopy()
|
||||||
c.Set(6)
|
c.Set(6)
|
||||||
if q.Value() == 6 {
|
if q.Value() == 6 {
|
||||||
t.Errorf("Copy didn't")
|
t.Errorf("Copy didn't")
|
||||||
@ -1097,7 +1097,7 @@ func TestNeg(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i, test := range tests {
|
for i, test := range tests {
|
||||||
a := test.a.Copy()
|
a := test.a.DeepCopy()
|
||||||
a.Neg()
|
a.Neg()
|
||||||
// ensure value is same
|
// ensure value is same
|
||||||
if a.Cmp(test.expected) != 0 {
|
if a.Cmp(test.expected) != 0 {
|
||||||
@ -1172,7 +1172,7 @@ func TestNegateRoundTrip(t *testing.T) {
|
|||||||
q.AsDec()
|
q.AsDec()
|
||||||
}
|
}
|
||||||
|
|
||||||
b := q.Copy()
|
b := q.DeepCopy()
|
||||||
b.Neg()
|
b.Neg()
|
||||||
b.Neg()
|
b.Neg()
|
||||||
if b.Cmp(q) != 0 {
|
if b.Cmp(q) != 0 {
|
||||||
@ -1322,7 +1322,7 @@ func BenchmarkQuantityCopy(b *testing.B) {
|
|||||||
values := benchmarkQuantities()
|
values := benchmarkQuantities()
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
values[i%len(values)].Copy()
|
values[i%len(values)].DeepCopy()
|
||||||
}
|
}
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
}
|
}
|
||||||
|
@ -3369,7 +3369,7 @@ func getPodsTotalRequestsAndLimits(podList *corev1.PodList) (reqs map[corev1.Res
|
|||||||
podReqs, podLimits := resourcehelper.PodRequestsAndLimits(&pod)
|
podReqs, podLimits := resourcehelper.PodRequestsAndLimits(&pod)
|
||||||
for podReqName, podReqValue := range podReqs {
|
for podReqName, podReqValue := range podReqs {
|
||||||
if value, ok := reqs[podReqName]; !ok {
|
if value, ok := reqs[podReqName]; !ok {
|
||||||
reqs[podReqName] = *podReqValue.Copy()
|
reqs[podReqName] = podReqValue.DeepCopy()
|
||||||
} else {
|
} else {
|
||||||
value.Add(podReqValue)
|
value.Add(podReqValue)
|
||||||
reqs[podReqName] = value
|
reqs[podReqName] = value
|
||||||
@ -3377,7 +3377,7 @@ func getPodsTotalRequestsAndLimits(podList *corev1.PodList) (reqs map[corev1.Res
|
|||||||
}
|
}
|
||||||
for podLimitName, podLimitValue := range podLimits {
|
for podLimitName, podLimitValue := range podLimits {
|
||||||
if value, ok := limits[podLimitName]; !ok {
|
if value, ok := limits[podLimitName]; !ok {
|
||||||
limits[podLimitName] = *podLimitValue.Copy()
|
limits[podLimitName] = podLimitValue.DeepCopy()
|
||||||
} else {
|
} else {
|
||||||
value.Add(podLimitValue)
|
value.Add(podLimitValue)
|
||||||
limits[podLimitName] = value
|
limits[podLimitName] = value
|
||||||
|
@ -44,12 +44,12 @@ func GetPodQOS(pod *corev1.Pod) corev1.PodQOSClass {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if quantity.Cmp(zeroQuantity) == 1 {
|
if quantity.Cmp(zeroQuantity) == 1 {
|
||||||
delta := quantity.Copy()
|
delta := quantity.DeepCopy()
|
||||||
if _, exists := requests[name]; !exists {
|
if _, exists := requests[name]; !exists {
|
||||||
requests[name] = *delta
|
requests[name] = delta
|
||||||
} else {
|
} else {
|
||||||
delta.Add(requests[name])
|
delta.Add(requests[name])
|
||||||
requests[name] = *delta
|
requests[name] = delta
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -61,12 +61,12 @@ func GetPodQOS(pod *corev1.Pod) corev1.PodQOSClass {
|
|||||||
}
|
}
|
||||||
if quantity.Cmp(zeroQuantity) == 1 {
|
if quantity.Cmp(zeroQuantity) == 1 {
|
||||||
qosLimitsFound.Insert(string(name))
|
qosLimitsFound.Insert(string(name))
|
||||||
delta := quantity.Copy()
|
delta := quantity.DeepCopy()
|
||||||
if _, exists := limits[name]; !exists {
|
if _, exists := limits[name]; !exists {
|
||||||
limits[name] = *delta
|
limits[name] = delta
|
||||||
} else {
|
} else {
|
||||||
delta.Add(limits[name])
|
delta.Add(limits[name])
|
||||||
limits[name] = *delta
|
limits[name] = delta
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ func PodRequestsAndLimits(pod *corev1.Pod) (reqs, limits corev1.ResourceList) {
|
|||||||
func addResourceList(list, new corev1.ResourceList) {
|
func addResourceList(list, new corev1.ResourceList) {
|
||||||
for name, quantity := range new {
|
for name, quantity := range new {
|
||||||
if value, ok := list[name]; !ok {
|
if value, ok := list[name]; !ok {
|
||||||
list[name] = *quantity.Copy()
|
list[name] = quantity.DeepCopy()
|
||||||
} else {
|
} else {
|
||||||
value.Add(quantity)
|
value.Add(quantity)
|
||||||
list[name] = value
|
list[name] = value
|
||||||
@ -60,11 +60,11 @@ func addResourceList(list, new corev1.ResourceList) {
|
|||||||
func maxResourceList(list, new corev1.ResourceList) {
|
func maxResourceList(list, new corev1.ResourceList) {
|
||||||
for name, quantity := range new {
|
for name, quantity := range new {
|
||||||
if value, ok := list[name]; !ok {
|
if value, ok := list[name]; !ok {
|
||||||
list[name] = *quantity.Copy()
|
list[name] = quantity.DeepCopy()
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
if quantity.Cmp(value) > 0 {
|
if quantity.Cmp(value) > 0 {
|
||||||
list[name] = *quantity.Copy()
|
list[name] = quantity.DeepCopy()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,7 @@ func checkNodeAllocatableTest(f *framework.Framework) {
|
|||||||
e2elog.Logf("nodeMem says: %+v", nodeMem)
|
e2elog.Logf("nodeMem says: %+v", nodeMem)
|
||||||
|
|
||||||
// calculate the allocatable mem based on capacity - reserved amounts
|
// calculate the allocatable mem based on capacity - reserved amounts
|
||||||
calculatedNodeAlloc := nodeMem.capacity.Copy()
|
calculatedNodeAlloc := nodeMem.capacity.DeepCopy()
|
||||||
calculatedNodeAlloc.Sub(nodeMem.systemReserve)
|
calculatedNodeAlloc.Sub(nodeMem.systemReserve)
|
||||||
calculatedNodeAlloc.Sub(nodeMem.kubeReserve)
|
calculatedNodeAlloc.Sub(nodeMem.kubeReserve)
|
||||||
calculatedNodeAlloc.Sub(nodeMem.softEviction)
|
calculatedNodeAlloc.Sub(nodeMem.softEviction)
|
||||||
|
@ -94,7 +94,7 @@ func getLocalNodeCPUDetails(f *framework.Framework) (cpuCapVal int64, cpuAllocVa
|
|||||||
cpuCap := localNodeCap[v1.ResourceCPU]
|
cpuCap := localNodeCap[v1.ResourceCPU]
|
||||||
localNodeAlloc := getLocalNode(f).Status.Allocatable
|
localNodeAlloc := getLocalNode(f).Status.Allocatable
|
||||||
cpuAlloc := localNodeAlloc[v1.ResourceCPU]
|
cpuAlloc := localNodeAlloc[v1.ResourceCPU]
|
||||||
cpuRes := cpuCap.Copy()
|
cpuRes := cpuCap.DeepCopy()
|
||||||
cpuRes.Sub(cpuAlloc)
|
cpuRes.Sub(cpuAlloc)
|
||||||
|
|
||||||
// RoundUp reserved CPUs to get only integer cores.
|
// RoundUp reserved CPUs to get only integer cores.
|
||||||
|
@ -89,11 +89,13 @@ func getAllocatableLimits(cpu, memory, pids string, capacity v1.ResourceList) (*
|
|||||||
// Total cpu reservation is 200m.
|
// Total cpu reservation is 200m.
|
||||||
for k, v := range capacity {
|
for k, v := range capacity {
|
||||||
if k == v1.ResourceCPU {
|
if k == v1.ResourceCPU {
|
||||||
allocatableCPU = v.Copy()
|
c := v.DeepCopy()
|
||||||
|
allocatableCPU = &c
|
||||||
allocatableCPU.Sub(resource.MustParse(cpu))
|
allocatableCPU.Sub(resource.MustParse(cpu))
|
||||||
}
|
}
|
||||||
if k == v1.ResourceMemory {
|
if k == v1.ResourceMemory {
|
||||||
allocatableMemory = v.Copy()
|
c := v.DeepCopy()
|
||||||
|
allocatableMemory = &c
|
||||||
allocatableMemory.Sub(resource.MustParse(memory))
|
allocatableMemory.Sub(resource.MustParse(memory))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user