github.com/cilium/cilium@v1.16.2/operator/pkg/nodeipam/cell.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright Authors of Cilium
     3  
     4  package nodeipam
     5  
     6  import (
     7  	"fmt"
     8  
     9  	"github.com/cilium/hive/cell"
    10  	"github.com/sirupsen/logrus"
    11  	"github.com/spf13/pflag"
    12  	ctrlRuntime "sigs.k8s.io/controller-runtime"
    13  
    14  	k8sClient "github.com/cilium/cilium/pkg/k8s/client"
    15  )
    16  
    17  var Cell = cell.Module(
    18  	"nodeipam",
    19  	"Node-IPAM",
    20  
    21  	cell.Config(nodeIpamConfig{}),
    22  	cell.Invoke(registerNodeSvcLBReconciler),
    23  )
    24  
    25  type nodeipamCellParams struct {
    26  	cell.In
    27  
    28  	Logger             logrus.FieldLogger
    29  	Clientset          k8sClient.Clientset
    30  	CtrlRuntimeManager ctrlRuntime.Manager
    31  	Config             nodeIpamConfig
    32  }
    33  
    34  type nodeIpamConfig struct {
    35  	EnableNodeIPAM bool
    36  }
    37  
    38  func (r nodeIpamConfig) Flags(flags *pflag.FlagSet) {
    39  	flags.Bool("enable-node-ipam", r.EnableNodeIPAM, "Enable Node IPAM")
    40  }
    41  
    42  func registerNodeSvcLBReconciler(params nodeipamCellParams) error {
    43  	if !params.Clientset.IsEnabled() || !params.Config.EnableNodeIPAM {
    44  		return nil
    45  	}
    46  
    47  	if err := newNodeSvcLBReconciler(params.CtrlRuntimeManager, params.Logger).SetupWithManager(params.CtrlRuntimeManager); err != nil {
    48  		return fmt.Errorf("Failed to register NodeSvcLBReconciler: %w", err)
    49  	}
    50  
    51  	return nil
    52  }