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

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright Authors of Cilium
     3  
     4  package ciliumenvoyconfig
     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  	operatorOption "github.com/cilium/cilium/operator/option"
    15  )
    16  
    17  // Cell manages the CiliumEnvoyConfig related controllers.
    18  var Cell = cell.Module(
    19  	"ciliumenvoyconfig",
    20  	"Manages the CiliumEnvoyConfig controllers",
    21  
    22  	cell.Config(l7LoadBalancerConfig{
    23  		LoadBalancerL7Ports:     []string{},
    24  		LoadBalancerL7Algorithm: "round_robin",
    25  	}),
    26  	cell.Invoke(registerL7LoadBalancingController),
    27  )
    28  
    29  type l7LoadBalancerConfig struct {
    30  	LoadBalancerL7Algorithm string
    31  	LoadBalancerL7Ports     []string
    32  }
    33  
    34  func (r l7LoadBalancerConfig) Flags(flags *pflag.FlagSet) {
    35  	flags.String("loadbalancer-l7-algorithm", r.LoadBalancerL7Algorithm, "Default LB algorithm for services that do not specify related annotation")
    36  	flags.StringSlice("loadbalancer-l7-ports", r.LoadBalancerL7Ports, "List of service ports that will be automatically redirected to backend.")
    37  }
    38  
    39  type l7LoadbalancerParams struct {
    40  	cell.In
    41  
    42  	Logger             logrus.FieldLogger
    43  	CtrlRuntimeManager ctrlRuntime.Manager
    44  	Config             l7LoadBalancerConfig
    45  }
    46  
    47  func registerL7LoadBalancingController(params l7LoadbalancerParams) error {
    48  	if operatorOption.Config.LoadBalancerL7 != "envoy" {
    49  		return nil
    50  	}
    51  
    52  	params.Logger.Info("Register Envoy load balancer reconciler")
    53  
    54  	reconciler := newCiliumEnvoyConfigReconciler(
    55  		params.CtrlRuntimeManager.GetClient(),
    56  		params.Logger,
    57  		params.Config.LoadBalancerL7Algorithm,
    58  		params.Config.LoadBalancerL7Ports,
    59  		10,
    60  		operatorOption.Config.ProxyIdleTimeoutSeconds,
    61  	)
    62  
    63  	if err := reconciler.SetupWithManager(params.CtrlRuntimeManager); err != nil {
    64  		return fmt.Errorf("failed to setup Envoy load balancer reconciler: %w", err)
    65  	}
    66  
    67  	return nil
    68  }