github.com/cilium/cilium@v1.16.2/pkg/datapath/linux/config/defines/defines.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright Authors of Cilium
     3  
     4  package defines
     5  
     6  import (
     7  	"fmt"
     8  
     9  	"github.com/cilium/hive/cell"
    10  )
    11  
    12  // Map is the type containing the key-value pairs representing extra define
    13  // directives for datapath node configuration.
    14  type Map map[string]string
    15  
    16  func (m Map) Merge(other Map) error {
    17  	for key, value := range other {
    18  		if _, ok := m[key]; ok {
    19  			return fmt.Errorf("extra node define overwrites key %q", key)
    20  		}
    21  
    22  		m[key] = value
    23  	}
    24  	return nil
    25  }
    26  
    27  // NodeOut allows injecting configuration into the datapath.
    28  type NodeOut struct {
    29  	cell.Out
    30  	NodeDefines Map `group:"header-node-defines"`
    31  }
    32  
    33  // Fn is a function returning the key-value pairs representing extra define
    34  // directives for datapath node configuration.
    35  type Fn func() (Map, error)
    36  
    37  // NodeFnOut allows injecting configuration into the datapath
    38  // by invoking a callback.
    39  //
    40  // Prefer using [NodeOut] if possible since it has a valid zero value.
    41  type NodeFnOut struct {
    42  	cell.Out
    43  	// Fn must not be nil.
    44  	Fn `group:"header-node-define-fns"`
    45  }
    46  
    47  // NewNodeFnOut wraps a function returning the key-value pairs representing
    48  // extra define directives for datapath node configuration, so that it can be
    49  // provided through the hive framework.
    50  func NewNodeFnOut(fn Fn) NodeFnOut {
    51  	return NodeFnOut{Fn: fn}
    52  }