Merge pull request #77429 from tedyu/container-linux-err

Avoid unnecessary concatenation of errors
This commit is contained in:
Kubernetes Prow Robot 2019-07-11 14:33:08 -07:00 committed by GitHub
commit f0d1b10092
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -833,16 +833,12 @@ func getContainer(pid int) (string, error) {
// //
func ensureSystemCgroups(rootCgroupPath string, manager *fs.Manager) error { func ensureSystemCgroups(rootCgroupPath string, manager *fs.Manager) error {
// Move non-kernel PIDs to the system container. // Move non-kernel PIDs to the system container.
attemptsRemaining := 10 // Only keep errors on latest attempt.
var errs []error var finalErr error
for attemptsRemaining >= 0 { for i := 0; i <= 10; i++ {
// Only keep errors on latest attempt.
errs = []error{}
attemptsRemaining--
allPids, err := cmutil.GetPids(rootCgroupPath) allPids, err := cmutil.GetPids(rootCgroupPath)
if err != nil { if err != nil {
errs = append(errs, fmt.Errorf("failed to list PIDs for root: %v", err)) finalErr = fmt.Errorf("failed to list PIDs for root: %v", err)
continue continue
} }
@ -859,23 +855,20 @@ func ensureSystemCgroups(rootCgroupPath string, manager *fs.Manager) error {
// Check if we have moved all the non-kernel PIDs. // Check if we have moved all the non-kernel PIDs.
if len(pids) == 0 { if len(pids) == 0 {
break return nil
} }
klog.Infof("Moving non-kernel processes: %v", pids) klog.Infof("Moving non-kernel processes: %v", pids)
for _, pid := range pids { for _, pid := range pids {
err := manager.Apply(pid) err := manager.Apply(pid)
if err != nil { if err != nil {
errs = append(errs, fmt.Errorf("failed to move PID %d into the system container %q: %v", pid, manager.Cgroups.Name, err)) finalErr = fmt.Errorf("failed to move PID %d into the system container %q: %v", pid, manager.Cgroups.Name, err)
} }
} }
} }
if attemptsRemaining < 0 {
errs = append(errs, fmt.Errorf("ran out of attempts to create system containers %q", manager.Cgroups.Name))
}
return utilerrors.NewAggregate(errs) return finalErr
} }
// Determines whether the specified PID is a kernel PID. // Determines whether the specified PID is a kernel PID.