-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
sysctl.go
68 lines (55 loc) · 1.49 KB
/
sysctl.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
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Cilium
package tables
import (
"github.com/cilium/cilium/pkg/statedb"
"github.com/cilium/cilium/pkg/statedb/index"
"github.com/cilium/cilium/pkg/statedb/reconciler"
)
var (
SysctlNameIndex = statedb.Index[*Sysctl, string]{
Name: "name",
FromObject: func(s *Sysctl) index.KeySet {
return index.NewKeySet(index.String(s.Name))
},
FromKey: index.String,
Unique: true,
}
SysctlStatusIndex = reconciler.NewStatusIndex[*Sysctl]((*Sysctl).GetStatus)
SysctlTableName = "sysctl-settings"
)
func NewSysctlTable(db *statedb.DB) (statedb.RWTable[*Sysctl], statedb.Index[*Sysctl, reconciler.StatusKind], error) {
tbl, err := statedb.NewTable[*Sysctl](
SysctlTableName,
SysctlNameIndex,
SysctlStatusIndex,
)
return tbl, SysctlStatusIndex, err
}
func (*Sysctl) TableHeader() []string {
return []string{"Name", "Value"}
}
func (s *Sysctl) TableRow() []string {
return []string{s.Name, s.Val}
}
// Sysctl is the representation of a kernel sysctl parameter.
type Sysctl struct {
Name string
Val string
IgnoreErr bool
// Warn if non-empty is the alternative warning log message to use when IgnoreErr is false.
Warn string
Status reconciler.Status
}
func (s *Sysctl) GetStatus() reconciler.Status {
return s.Status
}
func (s *Sysctl) WithStatus(newStatus reconciler.Status) *Sysctl {
return &Sysctl{
Name: s.Name,
Val: s.Val,
IgnoreErr: s.IgnoreErr,
Warn: s.Warn,
Status: newStatus,
}
}