mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 11:21:47 +00:00
Merge pull request #81627 from tallclair/copy
Delete duplicate resource.Quantity.Copy()
This commit is contained in:
commit
6b47754740
@ -31,7 +31,7 @@ import (
|
||||
func addResourceList(list, newList v1.ResourceList) {
|
||||
for name, quantity := range newList {
|
||||
if value, ok := list[name]; !ok {
|
||||
list[name] = *quantity.Copy()
|
||||
list[name] = quantity.DeepCopy()
|
||||
} else {
|
||||
value.Add(quantity)
|
||||
list[name] = value
|
||||
@ -44,11 +44,11 @@ func addResourceList(list, newList v1.ResourceList) {
|
||||
func maxResourceList(list, new v1.ResourceList) {
|
||||
for name, quantity := range new {
|
||||
if value, ok := list[name]; !ok {
|
||||
list[name] = *quantity.Copy()
|
||||
list[name] = quantity.DeepCopy()
|
||||
continue
|
||||
} else {
|
||||
if quantity.Cmp(value) > 0 {
|
||||
list[name] = *quantity.Copy()
|
||||
list[name] = quantity.DeepCopy()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -243,7 +243,7 @@ func MergeContainerResourceLimits(container *v1.Container,
|
||||
for _, resource := range []v1.ResourceName{v1.ResourceCPU, v1.ResourceMemory, v1.ResourceEphemeralStorage} {
|
||||
if quantity, exists := container.Resources.Limits[resource]; !exists || quantity.IsZero() {
|
||||
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.Requests = make(core.ResourceList)
|
||||
cpuLimit := randomQuantity()
|
||||
q.Limits[core.ResourceCPU] = *cpuLimit.Copy()
|
||||
q.Requests[core.ResourceCPU] = *cpuLimit.Copy()
|
||||
q.Limits[core.ResourceCPU] = cpuLimit.DeepCopy()
|
||||
q.Requests[core.ResourceCPU] = cpuLimit.DeepCopy()
|
||||
memoryLimit := randomQuantity()
|
||||
q.Limits[core.ResourceMemory] = *memoryLimit.Copy()
|
||||
q.Requests[core.ResourceMemory] = *memoryLimit.Copy()
|
||||
q.Limits[core.ResourceMemory] = memoryLimit.DeepCopy()
|
||||
q.Requests[core.ResourceMemory] = memoryLimit.DeepCopy()
|
||||
storageLimit := randomQuantity()
|
||||
q.Limits[core.ResourceStorage] = *storageLimit.Copy()
|
||||
q.Requests[core.ResourceStorage] = *storageLimit.Copy()
|
||||
q.Limits[core.ResourceStorage] = storageLimit.DeepCopy()
|
||||
q.Requests[core.ResourceStorage] = storageLimit.DeepCopy()
|
||||
},
|
||||
func(q *core.LimitRangeItem, c fuzz.Continue) {
|
||||
var cpuLimit resource.Quantity
|
||||
@ -148,16 +148,16 @@ var Funcs = func(codecs runtimeserializer.CodecFactory) []interface{} {
|
||||
|
||||
q.Type = core.LimitTypeContainer
|
||||
q.Default = make(core.ResourceList)
|
||||
q.Default[core.ResourceCPU] = *(cpuLimit.Copy())
|
||||
q.Default[core.ResourceCPU] = cpuLimit.DeepCopy()
|
||||
|
||||
q.DefaultRequest = make(core.ResourceList)
|
||||
q.DefaultRequest[core.ResourceCPU] = *(cpuLimit.Copy())
|
||||
q.DefaultRequest[core.ResourceCPU] = cpuLimit.DeepCopy()
|
||||
|
||||
q.Max = make(core.ResourceList)
|
||||
q.Max[core.ResourceCPU] = *(cpuLimit.Copy())
|
||||
q.Max[core.ResourceCPU] = cpuLimit.DeepCopy()
|
||||
|
||||
q.Min = make(core.ResourceList)
|
||||
q.Min[core.ResourceCPU] = *(cpuLimit.Copy())
|
||||
q.Min[core.ResourceCPU] = cpuLimit.DeepCopy()
|
||||
|
||||
q.MaxLimitRequestRatio = make(core.ResourceList)
|
||||
q.MaxLimitRequestRatio[core.ResourceCPU] = resource.MustParse("10")
|
||||
|
@ -49,12 +49,12 @@ func GetPodQOS(pod *core.Pod) core.PodQOSClass {
|
||||
continue
|
||||
}
|
||||
if quantity.Cmp(zeroQuantity) == 1 {
|
||||
delta := quantity.Copy()
|
||||
delta := quantity.DeepCopy()
|
||||
if _, exists := requests[name]; !exists {
|
||||
requests[name] = *delta
|
||||
requests[name] = delta
|
||||
} else {
|
||||
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 {
|
||||
qosLimitsFound.Insert(string(name))
|
||||
delta := quantity.Copy()
|
||||
delta := quantity.DeepCopy()
|
||||
if _, exists := limits[name]; !exists {
|
||||
limits[name] = *delta
|
||||
limits[name] = delta
|
||||
} else {
|
||||
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.
|
||||
input: v1.ResourceList{
|
||||
v1.ResourceCPU: *bigMilliQuantity.Copy(),
|
||||
v1.ResourceStorage: *bigMilliQuantity.Copy(),
|
||||
v1.ResourceCPU: bigMilliQuantity.DeepCopy(),
|
||||
v1.ResourceStorage: bigMilliQuantity.DeepCopy(),
|
||||
},
|
||||
expected: core.ResourceList{
|
||||
core.ResourceCPU: *bigMilliQuantity.Copy(),
|
||||
core.ResourceStorage: *bigMilliQuantity.Copy(),
|
||||
core.ResourceCPU: bigMilliQuantity.DeepCopy(),
|
||||
core.ResourceStorage: bigMilliQuantity.DeepCopy(),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -141,7 +141,7 @@ func SetDefaults_Pod(obj *v1.Pod) {
|
||||
}
|
||||
for key, value := range obj.Spec.Containers[i].Resources.Limits {
|
||||
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 {
|
||||
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 {
|
||||
obj.Allocatable = make(v1.ResourceList, len(obj.Capacity))
|
||||
for key, value := range obj.Capacity {
|
||||
obj.Allocatable[key] = *(value.Copy())
|
||||
obj.Allocatable[key] = value.DeepCopy()
|
||||
}
|
||||
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
|
||||
for key, value := range obj.Max {
|
||||
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
|
||||
for key, value := range obj.Default {
|
||||
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
|
||||
for key, value := range obj.Min {
|
||||
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))
|
||||
for k, v := range rl {
|
||||
copy[k] = *v.Copy()
|
||||
copy[k] = v.DeepCopy()
|
||||
}
|
||||
return copy
|
||||
}
|
||||
|
@ -51,12 +51,12 @@ func GetPodQOS(pod *v1.Pod) v1.PodQOSClass {
|
||||
continue
|
||||
}
|
||||
if quantity.Cmp(zeroQuantity) == 1 {
|
||||
delta := quantity.Copy()
|
||||
delta := quantity.DeepCopy()
|
||||
if _, exists := requests[name]; !exists {
|
||||
requests[name] = *delta
|
||||
requests[name] = delta
|
||||
} else {
|
||||
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 {
|
||||
qosLimitsFound.Insert(string(name))
|
||||
delta := quantity.Copy()
|
||||
delta := quantity.DeepCopy()
|
||||
if _, exists := limits[name]; !exists {
|
||||
limits[name] = *delta
|
||||
limits[name] = delta
|
||||
} else {
|
||||
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 {
|
||||
result := make(v1.ResourceList)
|
||||
for k, v := range capacity {
|
||||
value := *(v.Copy())
|
||||
value := v.DeepCopy()
|
||||
if cm.NodeConfig.SystemReserved != nil {
|
||||
value.Sub(cm.NodeConfig.SystemReserved[k])
|
||||
}
|
||||
|
@ -93,7 +93,8 @@ type Threshold struct {
|
||||
// GetThresholdQuantity returns the expected quantity value for a thresholdValue
|
||||
func GetThresholdQuantity(value ThresholdValue, capacity *resource.Quantity) *resource.Quantity {
|
||||
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)
|
||||
}
|
||||
|
@ -332,7 +332,7 @@ func MachineInfo(nodeName string,
|
||||
}
|
||||
allocatableReservation := nodeAllocatableReservationFunc()
|
||||
for k, v := range node.Status.Capacity {
|
||||
value := *(v.Copy())
|
||||
value := v.DeepCopy()
|
||||
if res, exists := allocatableReservation[k]; exists {
|
||||
value.Sub(res)
|
||||
}
|
||||
@ -355,7 +355,7 @@ func MachineInfo(nodeName string,
|
||||
for k, v := range node.Status.Capacity {
|
||||
if v1helper.IsHugePageResourceName(k) {
|
||||
allocatableMemory := node.Status.Allocatable[v1.ResourceMemory]
|
||||
value := *(v.Copy())
|
||||
value := v.DeepCopy()
|
||||
allocatableMemory.Sub(value)
|
||||
if allocatableMemory.Sign() < 0 {
|
||||
// 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 {
|
||||
if other, found := b[key]; found {
|
||||
if value.Cmp(other) <= 0 {
|
||||
result[key] = *other.Copy()
|
||||
result[key] = other.DeepCopy()
|
||||
continue
|
||||
}
|
||||
}
|
||||
result[key] = *value.Copy()
|
||||
result[key] = value.DeepCopy()
|
||||
}
|
||||
for key, value := range b {
|
||||
if _, found := result[key]; !found {
|
||||
result[key] = *value.Copy()
|
||||
result[key] = value.DeepCopy()
|
||||
}
|
||||
}
|
||||
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 {
|
||||
result := corev1.ResourceList{}
|
||||
for key, value := range a {
|
||||
quantity := *value.Copy()
|
||||
quantity := value.DeepCopy()
|
||||
if other, found := b[key]; found {
|
||||
quantity.Add(other)
|
||||
}
|
||||
@ -112,8 +112,7 @@ func Add(a corev1.ResourceList, b corev1.ResourceList) corev1.ResourceList {
|
||||
}
|
||||
for key, value := range b {
|
||||
if _, found := result[key]; !found {
|
||||
quantity := *value.Copy()
|
||||
result[key] = quantity
|
||||
result[key] = value.DeepCopy()
|
||||
}
|
||||
}
|
||||
return result
|
||||
@ -126,7 +125,7 @@ func SubtractWithNonNegativeResult(a corev1.ResourceList, b corev1.ResourceList)
|
||||
|
||||
result := corev1.ResourceList{}
|
||||
for key, value := range a {
|
||||
quantity := *value.Copy()
|
||||
quantity := value.DeepCopy()
|
||||
if other, found := b[key]; found {
|
||||
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 {
|
||||
result := corev1.ResourceList{}
|
||||
for key, value := range a {
|
||||
quantity := *value.Copy()
|
||||
quantity := value.DeepCopy()
|
||||
if other, found := b[key]; found {
|
||||
quantity.Sub(other)
|
||||
}
|
||||
@ -157,7 +156,7 @@ func Subtract(a corev1.ResourceList, b corev1.ResourceList) corev1.ResourceList
|
||||
}
|
||||
for key, value := range b {
|
||||
if _, found := result[key]; !found {
|
||||
quantity := *value.Copy()
|
||||
quantity := value.DeepCopy()
|
||||
quantity.Neg()
|
||||
result[key] = quantity
|
||||
}
|
||||
@ -171,7 +170,7 @@ func Mask(resources corev1.ResourceList, names []corev1.ResourceName) corev1.Res
|
||||
result := corev1.ResourceList{}
|
||||
for key, value := range resources {
|
||||
if nameSet.Has(string(key)) {
|
||||
result[key] = *value.Copy()
|
||||
result[key] = value.DeepCopy()
|
||||
}
|
||||
}
|
||||
return result
|
||||
|
@ -220,12 +220,10 @@ func defaultContainerResourceRequirements(limitRange *corev1.LimitRange) api.Res
|
||||
limit := limitRange.Spec.Limits[i]
|
||||
if limit.Type == corev1.LimitTypeContainer {
|
||||
for k, v := range limit.DefaultRequest {
|
||||
value := v.Copy()
|
||||
requirements.Requests[api.ResourceName(k)] = *value
|
||||
requirements.Requests[api.ResourceName(k)] = v.DeepCopy()
|
||||
}
|
||||
for k, v := range limit.Default {
|
||||
value := v.Copy()
|
||||
requirements.Limits[api.ResourceName(k)] = *value
|
||||
requirements.Limits[api.ResourceName(k)] = v.DeepCopy()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -245,14 +243,14 @@ func mergeContainerResources(container *api.Container, defaultRequirements *api.
|
||||
for k, v := range defaultRequirements.Limits {
|
||||
_, found := container.Resources.Limits[k]
|
||||
if !found {
|
||||
container.Resources.Limits[k] = *v.Copy()
|
||||
container.Resources.Limits[k] = v.DeepCopy()
|
||||
setLimits = append(setLimits, string(k))
|
||||
}
|
||||
}
|
||||
for k, v := range defaultRequirements.Requests {
|
||||
_, found := container.Resources.Requests[k]
|
||||
if !found {
|
||||
container.Resources.Requests[k] = *v.Copy()
|
||||
container.Resources.Requests[k] = v.DeepCopy()
|
||||
setRequests = append(setRequests, string(k))
|
||||
}
|
||||
}
|
||||
|
@ -726,21 +726,3 @@ func (q *Quantity) SetScaled(value int64, scale Scale) {
|
||||
q.d.Dec = nil
|
||||
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")
|
||||
for _, testValue := range testValues {
|
||||
value := MustParse(testValue)
|
||||
v1 := *value.Copy()
|
||||
v1 := value.DeepCopy()
|
||||
// ensure non-zero + zero = non-zero (suffix preserved)
|
||||
v1.Add(zero)
|
||||
// ensure zero + non-zero = non-zero (suffix preserved)
|
||||
v2 := *zero.Copy()
|
||||
v2 := zero.DeepCopy()
|
||||
v2.Add(value)
|
||||
|
||||
if v1.String() != testValue {
|
||||
@ -118,7 +118,7 @@ func TestQuantitySubZeroPreservesSuffix(t *testing.T) {
|
||||
zero := MustParse("0")
|
||||
for _, testValue := range testValues {
|
||||
value := MustParse(testValue)
|
||||
v1 := *value.Copy()
|
||||
v1 := value.DeepCopy()
|
||||
// ensure non-zero - zero = non-zero (suffix preserved)
|
||||
v1.Sub(zero)
|
||||
// ensure we preserved the input value
|
||||
@ -127,9 +127,9 @@ func TestQuantitySubZeroPreservesSuffix(t *testing.T) {
|
||||
}
|
||||
|
||||
// ensure zero - non-zero = -non-zero (suffix preserved)
|
||||
v2 := *zero.Copy()
|
||||
v2 := zero.DeepCopy()
|
||||
v2.Sub(value)
|
||||
negVal := *value.Copy()
|
||||
negVal := value.DeepCopy()
|
||||
negVal.Neg()
|
||||
if v2.String() != negVal.String() {
|
||||
t.Errorf("Expected %v, actual %v", negVal.String(), v2.String())
|
||||
@ -523,7 +523,7 @@ func TestQuantityRoundUp(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
expect := *item.expect.Copy()
|
||||
expect := item.expect.DeepCopy()
|
||||
if asDec {
|
||||
got.AsDec()
|
||||
}
|
||||
@ -580,7 +580,7 @@ func TestQuantityCmpInt64AndDec(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, item := range table {
|
||||
a, b := *item.a.Copy(), *item.b.Copy()
|
||||
a, b := item.a.DeepCopy(), item.b.DeepCopy()
|
||||
a.AsDec()
|
||||
if cmp := a.Cmp(b); cmp != item.cmp {
|
||||
t.Errorf("%#v: unexpected Cmp: %d", item, cmp)
|
||||
@ -591,7 +591,7 @@ func TestQuantityCmpInt64AndDec(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, item := range table {
|
||||
a, b := *item.a.Copy(), *item.b.Copy()
|
||||
a, b := item.a.DeepCopy(), item.b.DeepCopy()
|
||||
b.AsDec()
|
||||
if cmp := a.Cmp(b); cmp != item.cmp {
|
||||
t.Errorf("%#v: unexpected Cmp: %d", item, cmp)
|
||||
@ -602,7 +602,7 @@ func TestQuantityCmpInt64AndDec(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, item := range table {
|
||||
a, b := *item.a.Copy(), *item.b.Copy()
|
||||
a, b := item.a.DeepCopy(), item.b.DeepCopy()
|
||||
a.AsDec()
|
||||
b.AsDec()
|
||||
if cmp := a.Cmp(b); cmp != item.cmp {
|
||||
@ -624,7 +624,7 @@ func TestQuantityNeg(t *testing.T) {
|
||||
}
|
||||
|
||||
for i, item := range table {
|
||||
out := *item.a.Copy()
|
||||
out := item.a.DeepCopy()
|
||||
out.Neg()
|
||||
if out.Cmp(item.a) == 0 {
|
||||
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.MilliValue()
|
||||
q.Copy()
|
||||
q.DeepCopy()
|
||||
_ = q.String()
|
||||
q.MarshalJSON()
|
||||
}
|
||||
|
||||
func TestCopy(t *testing.T) {
|
||||
func TestDeepCopy(t *testing.T) {
|
||||
q := NewQuantity(5, DecimalSI)
|
||||
c := q.Copy()
|
||||
c := q.DeepCopy()
|
||||
c.Set(6)
|
||||
if q.Value() == 6 {
|
||||
t.Errorf("Copy didn't")
|
||||
@ -1097,7 +1097,7 @@ func TestNeg(t *testing.T) {
|
||||
}
|
||||
|
||||
for i, test := range tests {
|
||||
a := test.a.Copy()
|
||||
a := test.a.DeepCopy()
|
||||
a.Neg()
|
||||
// ensure value is same
|
||||
if a.Cmp(test.expected) != 0 {
|
||||
@ -1172,7 +1172,7 @@ func TestNegateRoundTrip(t *testing.T) {
|
||||
q.AsDec()
|
||||
}
|
||||
|
||||
b := q.Copy()
|
||||
b := q.DeepCopy()
|
||||
b.Neg()
|
||||
b.Neg()
|
||||
if b.Cmp(q) != 0 {
|
||||
@ -1322,7 +1322,7 @@ func BenchmarkQuantityCopy(b *testing.B) {
|
||||
values := benchmarkQuantities()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
values[i%len(values)].Copy()
|
||||
values[i%len(values)].DeepCopy()
|
||||
}
|
||||
b.StopTimer()
|
||||
}
|
||||
|
@ -3373,7 +3373,7 @@ func getPodsTotalRequestsAndLimits(podList *corev1.PodList) (reqs map[corev1.Res
|
||||
podReqs, podLimits := resourcehelper.PodRequestsAndLimits(&pod)
|
||||
for podReqName, podReqValue := range podReqs {
|
||||
if value, ok := reqs[podReqName]; !ok {
|
||||
reqs[podReqName] = *podReqValue.Copy()
|
||||
reqs[podReqName] = podReqValue.DeepCopy()
|
||||
} else {
|
||||
value.Add(podReqValue)
|
||||
reqs[podReqName] = value
|
||||
@ -3381,7 +3381,7 @@ func getPodsTotalRequestsAndLimits(podList *corev1.PodList) (reqs map[corev1.Res
|
||||
}
|
||||
for podLimitName, podLimitValue := range podLimits {
|
||||
if value, ok := limits[podLimitName]; !ok {
|
||||
limits[podLimitName] = *podLimitValue.Copy()
|
||||
limits[podLimitName] = podLimitValue.DeepCopy()
|
||||
} else {
|
||||
value.Add(podLimitValue)
|
||||
limits[podLimitName] = value
|
||||
|
@ -44,12 +44,12 @@ func GetPodQOS(pod *corev1.Pod) corev1.PodQOSClass {
|
||||
continue
|
||||
}
|
||||
if quantity.Cmp(zeroQuantity) == 1 {
|
||||
delta := quantity.Copy()
|
||||
delta := quantity.DeepCopy()
|
||||
if _, exists := requests[name]; !exists {
|
||||
requests[name] = *delta
|
||||
requests[name] = delta
|
||||
} else {
|
||||
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 {
|
||||
qosLimitsFound.Insert(string(name))
|
||||
delta := quantity.Copy()
|
||||
delta := quantity.DeepCopy()
|
||||
if _, exists := limits[name]; !exists {
|
||||
limits[name] = *delta
|
||||
limits[name] = delta
|
||||
} else {
|
||||
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) {
|
||||
for name, quantity := range new {
|
||||
if value, ok := list[name]; !ok {
|
||||
list[name] = *quantity.Copy()
|
||||
list[name] = quantity.DeepCopy()
|
||||
} else {
|
||||
value.Add(quantity)
|
||||
list[name] = value
|
||||
@ -60,11 +60,11 @@ func addResourceList(list, new corev1.ResourceList) {
|
||||
func maxResourceList(list, new corev1.ResourceList) {
|
||||
for name, quantity := range new {
|
||||
if value, ok := list[name]; !ok {
|
||||
list[name] = *quantity.Copy()
|
||||
list[name] = quantity.DeepCopy()
|
||||
continue
|
||||
} else {
|
||||
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)
|
||||
|
||||
// calculate the allocatable mem based on capacity - reserved amounts
|
||||
calculatedNodeAlloc := nodeMem.capacity.Copy()
|
||||
calculatedNodeAlloc := nodeMem.capacity.DeepCopy()
|
||||
calculatedNodeAlloc.Sub(nodeMem.systemReserve)
|
||||
calculatedNodeAlloc.Sub(nodeMem.kubeReserve)
|
||||
calculatedNodeAlloc.Sub(nodeMem.softEviction)
|
||||
|
@ -94,7 +94,7 @@ func getLocalNodeCPUDetails(f *framework.Framework) (cpuCapVal int64, cpuAllocVa
|
||||
cpuCap := localNodeCap[v1.ResourceCPU]
|
||||
localNodeAlloc := getLocalNode(f).Status.Allocatable
|
||||
cpuAlloc := localNodeAlloc[v1.ResourceCPU]
|
||||
cpuRes := cpuCap.Copy()
|
||||
cpuRes := cpuCap.DeepCopy()
|
||||
cpuRes.Sub(cpuAlloc)
|
||||
|
||||
// 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.
|
||||
for k, v := range capacity {
|
||||
if k == v1.ResourceCPU {
|
||||
allocatableCPU = v.Copy()
|
||||
c := v.DeepCopy()
|
||||
allocatableCPU = &c
|
||||
allocatableCPU.Sub(resource.MustParse(cpu))
|
||||
}
|
||||
if k == v1.ResourceMemory {
|
||||
allocatableMemory = v.Copy()
|
||||
c := v.DeepCopy()
|
||||
allocatableMemory = &c
|
||||
allocatableMemory.Sub(resource.MustParse(memory))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user