-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexecutor.go
More file actions
64 lines (52 loc) · 1.6 KB
/
executor.go
File metadata and controls
64 lines (52 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package executor
import (
"fmt"
"os"
"github.com/pmarchini/giogo/internal/core"
"github.com/pmarchini/giogo/internal/limiter"
specs "github.com/opencontainers/runtime-spec/specs-go"
)
type Executor struct {
Limiters []limiter.ResourceLimiter
NetworkLimiter *limiter.NetworkLimiter
}
func NewExecutor(limiters []limiter.ResourceLimiter) *Executor {
executor := &Executor{
Limiters: limiters,
}
// Extract NetworkLimiter if present for special handling
for _, l := range limiters {
if netLimiter, ok := l.(*limiter.NetworkLimiter); ok {
executor.NetworkLimiter = netLimiter
break
}
}
return executor
}
func (e *Executor) RunCommand(args []string) error {
var resources specs.LinuxResources
for _, l := range e.Limiters {
l.Apply(&resources)
}
// Set up traffic control if network limiter with bandwidth is configured
if e.NetworkLimiter != nil && e.NetworkLimiter.MaxBandwidth > 0 {
// Get default interface - in production this could be configurable
iface := limiter.GetDefaultInterface()
// Setup tc before running the command
if err := e.NetworkLimiter.SetupTrafficControl(iface); err != nil {
return fmt.Errorf("failed to setup traffic control: %v", err)
}
// Ensure cleanup happens when we're done
defer func() {
if err := e.NetworkLimiter.CleanupTrafficControl(iface); err != nil {
// Non-fatal: log the error but don't fail the command
fmt.Fprintf(os.Stderr, "Warning: failed to cleanup traffic control: %v\n", err)
}
}()
}
coreModule, err := core.NewCore(resources)
if err != nil {
return err
}
return coreModule.RunCommand(args)
}