Delete will remove the control group from each of the subsystems registered
()
| 249 | |
| 250 | // Delete will remove the control group from each of the subsystems registered |
| 251 | func (c *cgroup) Delete() error { |
| 252 | c.mu.Lock() |
| 253 | defer c.mu.Unlock() |
| 254 | if c.err != nil { |
| 255 | return c.err |
| 256 | } |
| 257 | var errs []string |
| 258 | for _, s := range c.subsystems { |
| 259 | // kernel prevents cgroups with running process from being removed, check the tree is empty |
| 260 | procs, err := c.processes(s.Name(), true, cgroupProcs) |
| 261 | if err != nil { |
| 262 | // if the control group does not exist within a subsystem, then proceed to the next subsystem |
| 263 | if errors.Is(err, os.ErrNotExist) { |
| 264 | continue |
| 265 | } |
| 266 | return err |
| 267 | } |
| 268 | if len(procs) > 0 { |
| 269 | errs = append(errs, fmt.Sprintf("%s (contains running processes)", string(s.Name()))) |
| 270 | continue |
| 271 | } |
| 272 | if d, ok := s.(deleter); ok { |
| 273 | sp, err := c.path(s.Name()) |
| 274 | if err != nil { |
| 275 | return err |
| 276 | } |
| 277 | if err := d.Delete(sp); err != nil { |
| 278 | errs = append(errs, string(s.Name())) |
| 279 | } |
| 280 | continue |
| 281 | } |
| 282 | if p, ok := s.(pather); ok { |
| 283 | sp, err := c.path(s.Name()) |
| 284 | if err != nil { |
| 285 | return err |
| 286 | } |
| 287 | path := p.Path(sp) |
| 288 | if err := remove(path); err != nil { |
| 289 | errs = append(errs, path) |
| 290 | } |
| 291 | continue |
| 292 | } |
| 293 | } |
| 294 | if len(errs) > 0 { |
| 295 | return fmt.Errorf("cgroups: unable to remove paths %s", strings.Join(errs, ", ")) |
| 296 | } |
| 297 | c.err = ErrCgroupDeleted |
| 298 | return nil |
| 299 | } |
| 300 | |
| 301 | // Stat returns the current metrics for the cgroup |
| 302 | func (c *cgroup) Stat(handlers ...ErrorHandler) (*v1.Metrics, error) { |