-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
cell.go
72 lines (54 loc) · 1.64 KB
/
cell.go
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
65
66
67
68
69
70
71
72
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Cilium
//go:build linux
// NOTE: We can only build on linux because we import bwmap which in turn imports pkg/ebpf and pkg/bpf
// which throw build errors when building on non-linux platforms.
package bandwidth
import (
"github.com/sirupsen/logrus"
"github.com/spf13/pflag"
"github.com/cilium/cilium/pkg/datapath/linux/config/defines"
"github.com/cilium/cilium/pkg/hive/cell"
"github.com/cilium/cilium/pkg/option"
)
var Cell = cell.Module(
"bandwidth-manager",
"Linux Bandwidth Manager for EDT-based pacing",
cell.Config(Config{false, false}),
cell.Provide(newBandwidthManager),
)
type Config struct {
// EnableBandwidthManager enables EDT-based pacing
EnableBandwidthManager bool
// EnableBBR enables BBR TCP congestion control for the node including Pods
EnableBBR bool
}
func (def Config) Flags(flags *pflag.FlagSet) {
flags.Bool("enable-bandwidth-manager", def.EnableBandwidthManager, "Enable BPF bandwidth manager")
flags.Bool(EnableBBR, def.EnableBBR, "Enable BBR for the bandwidth manager")
}
func newBandwidthManager(lc cell.Lifecycle, p bandwidthManagerParams) (Manager, defines.NodeFnOut) {
m := &manager{params: p}
if !option.Config.DryMode {
lc.Append(m)
}
return m, defines.NewNodeFnOut(m.defines)
}
func (m *manager) Start(cell.HookContext) error {
err := m.probe()
if err != nil {
return err
} else if !m.enabled {
return nil
}
return m.init()
}
func (*manager) Stop(cell.HookContext) error {
return nil
}
type bandwidthManagerParams struct {
cell.In
Log logrus.FieldLogger
Config Config
DaemonConfig *option.DaemonConfig
}