-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
defines.go
52 lines (42 loc) · 1.29 KB
/
defines.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
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Cilium
package defines
import (
"fmt"
"github.com/cilium/cilium/pkg/hive/cell"
)
// Map is the type containing the key-value pairs representing extra define
// directives for datapath node configuration.
type Map map[string]string
func (m Map) Merge(other Map) error {
for key, value := range other {
if _, ok := m[key]; ok {
return fmt.Errorf("extra node define overwrites key %q", key)
}
m[key] = value
}
return nil
}
// NodeOut allows injecting configuration into the datapath.
type NodeOut struct {
cell.Out
NodeDefines Map `group:"header-node-defines"`
}
// Fn is a function returning the key-value pairs representing extra define
// directives for datapath node configuration.
type Fn func() (Map, error)
// NodeFnOut allows injecting configuration into the datapath
// by invoking a callback.
//
// Prefer using [NodeOut] if possible since it has a valid zero value.
type NodeFnOut struct {
cell.Out
// Fn must not be nil.
Fn `group:"header-node-define-fns"`
}
// NewNodeFnOut wraps a function returning the key-value pairs representing
// extra define directives for datapath node configuration, so that it can be
// provided through the hive framework.
func NewNodeFnOut(fn Fn) NodeFnOut {
return NodeFnOut{Fn: fn}
}