mirror of https://github.com/k3s-io/k3s
Merge pull request #49491 from eparis/make-plus-append-is-bad
Automatic merge from submit-queue (batch tested with PRs 49898, 49897, 49919, 48860, 49491) Fix usage a make(struct, len()) followed by append() A couple of places in the code we allocate with make() but then use append(), instead of copy() or direct assignment. This results in a slice with len() zero elements at the front followed by the expected data. The correct form for such usage is `make(struct, 0, len())`. I found these by running: ``` $ git grep -EI -A7 'make\([^,]*, len\(' | grep 'append(' -B7 | grep -v vendor ``` And then manually looking through the results. I'm sure something better could exist. **Release note**: ```release-note NONE ```pull/6/head
commit
23bb765498
|
@ -282,7 +282,7 @@ func TestStatefulPodControlUpdatesPodStorage(t *testing.T) {
|
|||
pvcLister := corelisters.NewPersistentVolumeClaimLister(pvcIndexer)
|
||||
control := NewRealStatefulPodControl(fakeClient, nil, nil, pvcLister, recorder)
|
||||
pvcs := getPersistentVolumeClaims(set, pod)
|
||||
volumes := make([]v1.Volume, len(pod.Spec.Volumes))
|
||||
volumes := make([]v1.Volume, 0, len(pod.Spec.Volumes))
|
||||
for i := range pod.Spec.Volumes {
|
||||
if _, contains := pvcs[pod.Spec.Volumes[i].Name]; !contains {
|
||||
volumes = append(volumes, pod.Spec.Volumes[i])
|
||||
|
@ -329,7 +329,7 @@ func TestStatefulPodControlUpdatePodStorageFailure(t *testing.T) {
|
|||
pvcLister := corelisters.NewPersistentVolumeClaimLister(pvcIndexer)
|
||||
control := NewRealStatefulPodControl(fakeClient, nil, nil, pvcLister, recorder)
|
||||
pvcs := getPersistentVolumeClaims(set, pod)
|
||||
volumes := make([]v1.Volume, len(pod.Spec.Volumes))
|
||||
volumes := make([]v1.Volume, 0, len(pod.Spec.Volumes))
|
||||
for i := range pod.Spec.Volumes {
|
||||
if _, contains := pvcs[pod.Spec.Volumes[i].Name]; !contains {
|
||||
volumes = append(volumes, pod.Spec.Volumes[i])
|
||||
|
|
|
@ -83,9 +83,9 @@ func computePercentiles(timeSeries []ResourceUsagePerContainer, percentilesToCom
|
|||
for name, data := range timeSeries[i] {
|
||||
if dataMap[name] == nil {
|
||||
dataMap[name] = &usageDataPerContainer{
|
||||
cpuData: make([]float64, len(timeSeries)),
|
||||
memUseData: make([]uint64, len(timeSeries)),
|
||||
memWorkSetData: make([]uint64, len(timeSeries)),
|
||||
cpuData: make([]float64, 0, len(timeSeries)),
|
||||
memUseData: make([]uint64, 0, len(timeSeries)),
|
||||
memWorkSetData: make([]uint64, 0, len(timeSeries)),
|
||||
}
|
||||
}
|
||||
dataMap[name].cpuData = append(dataMap[name].cpuData, data.CPUUsageInCores)
|
||||
|
|
Loading…
Reference in New Issue