Skip to content

Commit 86ab25f

Browse files
authored
Merge pull request kubernetes#91716 from kadisi/append_mutations_kubelet
fix unexpected append mutations about pkg/kubelet package
2 parents 9c3f648 + a75323c commit 86ab25f

File tree

5 files changed

+5
-8
lines changed

5 files changed

+5
-8
lines changed

pkg/kubelet/cm/cgroup_manager_linux.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,7 @@ func NewCgroupName(base CgroupName, components ...string) CgroupName {
6969
panic(fmt.Errorf("invalid character in component [%q] of CgroupName", component))
7070
}
7171
}
72-
// copy data from the base cgroup to eliminate cases where CgroupNames share underlying slices. See #68416
73-
baseCopy := make([]string, len(base))
74-
copy(baseCopy, base)
75-
return CgroupName(append(baseCopy, components...))
72+
return CgroupName(append(append([]string{}, base...), components...))
7673
}
7774

7875
func escapeSystemdCgroupName(part string) string {

pkg/kubelet/cm/cgroup_manager_unsupported.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (m *unsupportedCgroupManager) ReduceCPULimits(cgroupName CgroupName) error
7373
var RootCgroupName = CgroupName([]string{})
7474

7575
func NewCgroupName(base CgroupName, components ...string) CgroupName {
76-
return CgroupName(append(base, components...))
76+
return append(append([]string{}, base...), components...)
7777
}
7878

7979
func (cgroupName CgroupName) ToSystemd() string {

pkg/kubelet/eviction/helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func addAllocatableThresholds(thresholds []evictionapi.Threshold) []evictionapi.
164164
})
165165
}
166166
}
167-
return append(thresholds, additionalThresholds...)
167+
return append(append([]evictionapi.Threshold{}, thresholds...), additionalThresholds...)
168168
}
169169

170170
// parseThresholdStatements parses the input statements into a list of Threshold objects.

pkg/kubelet/stats/cadvisor_stats_provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func (p *cadvisorStatsProvider) ListPodStats() ([]statsapi.PodStats, error) {
135135
if vstats, found := p.resourceAnalyzer.GetPodVolumeStats(podUID); found {
136136
ephemeralStats = make([]statsapi.VolumeStats, len(vstats.EphemeralVolumes))
137137
copy(ephemeralStats, vstats.EphemeralVolumes)
138-
podStats.VolumeStats = append(vstats.EphemeralVolumes, vstats.PersistentVolumes...)
138+
podStats.VolumeStats = append(append([]statsapi.VolumeStats{}, vstats.EphemeralVolumes...), vstats.PersistentVolumes...)
139139
}
140140
podStats.EphemeralStorage = calcEphemeralStorage(podStats.Containers, ephemeralStats, &rootFsInfo, nil, false)
141141
// Lookup the pod-level cgroup's CPU and memory stats

pkg/kubelet/stats/cri_stats_provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ func (p *criStatsProvider) makePodStorageStats(s *statsapi.PodStats, rootFsInfo
412412
}
413413
ephemeralStats := make([]statsapi.VolumeStats, len(vstats.EphemeralVolumes))
414414
copy(ephemeralStats, vstats.EphemeralVolumes)
415-
s.VolumeStats = append(vstats.EphemeralVolumes, vstats.PersistentVolumes...)
415+
s.VolumeStats = append(append([]statsapi.VolumeStats{}, vstats.EphemeralVolumes...), vstats.PersistentVolumes...)
416416
s.EphemeralStorage = calcEphemeralStorage(s.Containers, ephemeralStats, rootFsInfo, logStats, true)
417417
}
418418

0 commit comments

Comments
 (0)