github.com/cilium/cilium@v1.16.2/pkg/datapath/tables/sysctl.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright Authors of Cilium 3 4 package tables 5 6 import ( 7 "strings" 8 9 "github.com/cilium/statedb" 10 "github.com/cilium/statedb/index" 11 "github.com/cilium/statedb/reconciler" 12 ) 13 14 var ( 15 SysctlNameIndex = statedb.Index[*Sysctl, string]{ 16 Name: "name", 17 FromObject: func(s *Sysctl) index.KeySet { 18 return index.NewKeySet(index.String(strings.Join(s.Name, "."))) 19 }, 20 FromKey: index.String, 21 Unique: true, 22 } 23 24 SysctlStatusIndex = reconciler.NewStatusIndex((*Sysctl).GetStatus) 25 26 SysctlTableName = "sysctl" 27 ) 28 29 func NewSysctlTable(db *statedb.DB) (statedb.RWTable[*Sysctl], statedb.Index[*Sysctl, reconciler.StatusKind], error) { 30 tbl, err := statedb.NewTable( 31 SysctlTableName, 32 SysctlNameIndex, 33 SysctlStatusIndex, 34 ) 35 return tbl, SysctlStatusIndex, err 36 } 37 38 func (*Sysctl) TableHeader() []string { 39 return []string{"Name", "Value", "Status"} 40 } 41 42 func (s *Sysctl) TableRow() []string { 43 return []string{strings.Join(s.Name, "."), s.Val, s.Status.String()} 44 } 45 46 // Sysctl is the representation of a kernel sysctl parameter. 47 type Sysctl struct { 48 Name []string 49 Val string 50 IgnoreErr bool 51 52 // Warn if non-empty is the alternative warning log message to use when IgnoreErr is false. 53 Warn string 54 55 Status reconciler.Status 56 } 57 58 func (s *Sysctl) Clone() *Sysctl { 59 s2 := *s 60 return &s2 61 } 62 63 func (s *Sysctl) GetStatus() reconciler.Status { 64 return s.Status 65 } 66 67 func (s *Sysctl) SetStatus(newStatus reconciler.Status) *Sysctl { 68 s.Status = newStatus 69 return s 70 }