Merge pull request #91716 from kadisi/append_mutations_kubelet

fix unexpected append mutations about pkg/kubelet package
This commit is contained in:
Kubernetes Prow Robot 2020-06-19 21:51:08 -07:00 committed by GitHub
commit 86ab25f038
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 5 additions and 8 deletions

View File

@ -69,10 +69,7 @@ func NewCgroupName(base CgroupName, components ...string) CgroupName {
panic(fmt.Errorf("invalid character in component [%q] of CgroupName", component))
}
}
// copy data from the base cgroup to eliminate cases where CgroupNames share underlying slices. See #68416
baseCopy := make([]string, len(base))
copy(baseCopy, base)
return CgroupName(append(baseCopy, components...))
return CgroupName(append(append([]string{}, base...), components...))
}
func escapeSystemdCgroupName(part string) string {

View File

@ -73,7 +73,7 @@ func (m *unsupportedCgroupManager) ReduceCPULimits(cgroupName CgroupName) error
var RootCgroupName = CgroupName([]string{})
func NewCgroupName(base CgroupName, components ...string) CgroupName {
return CgroupName(append(base, components...))
return append(append([]string{}, base...), components...)
}
func (cgroupName CgroupName) ToSystemd() string {

View File

@ -164,7 +164,7 @@ func addAllocatableThresholds(thresholds []evictionapi.Threshold) []evictionapi.
})
}
}
return append(thresholds, additionalThresholds...)
return append(append([]evictionapi.Threshold{}, thresholds...), additionalThresholds...)
}
// parseThresholdStatements parses the input statements into a list of Threshold objects.

View File

@ -135,7 +135,7 @@ func (p *cadvisorStatsProvider) ListPodStats() ([]statsapi.PodStats, error) {
if vstats, found := p.resourceAnalyzer.GetPodVolumeStats(podUID); found {
ephemeralStats = make([]statsapi.VolumeStats, len(vstats.EphemeralVolumes))
copy(ephemeralStats, vstats.EphemeralVolumes)
podStats.VolumeStats = append(vstats.EphemeralVolumes, vstats.PersistentVolumes...)
podStats.VolumeStats = append(append([]statsapi.VolumeStats{}, vstats.EphemeralVolumes...), vstats.PersistentVolumes...)
}
podStats.EphemeralStorage = calcEphemeralStorage(podStats.Containers, ephemeralStats, &rootFsInfo, nil, false)
// Lookup the pod-level cgroup's CPU and memory stats

View File

@ -412,7 +412,7 @@ func (p *criStatsProvider) makePodStorageStats(s *statsapi.PodStats, rootFsInfo
}
ephemeralStats := make([]statsapi.VolumeStats, len(vstats.EphemeralVolumes))
copy(ephemeralStats, vstats.EphemeralVolumes)
s.VolumeStats = append(vstats.EphemeralVolumes, vstats.PersistentVolumes...)
s.VolumeStats = append(append([]statsapi.VolumeStats{}, vstats.EphemeralVolumes...), vstats.PersistentVolumes...)
s.EphemeralStorage = calcEphemeralStorage(s.Containers, ephemeralStats, rootFsInfo, logStats, true)
}