github.com/cilium/cilium@v1.16.2/pkg/maps/nodemap/cell.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright Authors of Cilium 3 4 package nodemap 5 6 import ( 7 "fmt" 8 9 "github.com/cilium/hive/cell" 10 "github.com/spf13/pflag" 11 12 "github.com/cilium/cilium/pkg/bpf" 13 "github.com/cilium/cilium/pkg/logging" 14 "github.com/cilium/cilium/pkg/logging/logfields" 15 "github.com/cilium/cilium/pkg/maps/encrypt" 16 ) 17 18 var log = logging.DefaultLogger.WithField(logfields.LogSubsys, "NodeMap") 19 20 // Cell provides the nodemap.MapV2 which contains information about node IDs, SPIs, and their IP addresses. 21 var Cell = cell.Module( 22 "node-map", 23 "eBPF map which contains information about node IDs and their IP addresses", 24 25 cell.Provide(newNodeMap), 26 cell.Config(defaultConfig), 27 ) 28 29 type Config struct { 30 NodeMapMax uint32 `mapstructure:"bpf-node-map-max"` 31 } 32 33 func (c Config) Flags(fs *pflag.FlagSet) { 34 fs.Uint32("bpf-node-map-max", defaultConfig.NodeMapMax, 35 "Sets size of node bpf map which will be the max number of unique Node IPs in the cluster") 36 } 37 38 var defaultConfig = Config{ 39 NodeMapMax: DefaultMaxEntries, 40 } 41 42 func newNodeMap(lifecycle cell.Lifecycle, conf Config) (bpf.MapOut[MapV2], error) { 43 if conf.NodeMapMax < DefaultMaxEntries { 44 return bpf.MapOut[MapV2]{}, fmt.Errorf("creating node map: bpf-node-map-max cannot be less than %d (%d)", 45 DefaultMaxEntries, conf.NodeMapMax) 46 } 47 nodeMap := newMapV2(MapNameV2, MapName, conf) 48 49 lifecycle.Append(cell.Hook{ 50 OnStart: func(context cell.HookContext) error { 51 if err := nodeMap.init(); err != nil { 52 return err 53 } 54 55 // do v1 to v2 map migration if necessary 56 return nodeMap.migrateV1(MapName, encrypt.MapName) 57 }, 58 OnStop: func(context cell.HookContext) error { 59 return nodeMap.close() 60 }, 61 }) 62 63 return bpf.NewMapOut(MapV2(nodeMap)), nil 64 }