github.com/cilium/cilium@v1.16.2/operator/cmd/lifecycle.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright Authors of Cilium
     3  
     4  package cmd
     5  
     6  import (
     7  	"github.com/cilium/hive/cell"
     8  )
     9  
    10  // LeaderLifecycle is the inner lifecycle of the operator that is started when this
    11  // operator instance is elected leader. It implements cell.Lifecycle allowing cells
    12  // to use it.
    13  type LeaderLifecycle struct {
    14  	cell.DefaultLifecycle
    15  }
    16  
    17  func WithLeaderLifecycle(cells ...cell.Cell) cell.Cell {
    18  	return cell.Module(
    19  		"leader-lifecycle",
    20  		"Operator Leader Lifecycle",
    21  
    22  		cell.Provide(
    23  			func() *LeaderLifecycle { return &LeaderLifecycle{} },
    24  		),
    25  		cell.Decorate(
    26  			func(lc *LeaderLifecycle) cell.Lifecycle {
    27  				return lc
    28  			},
    29  			cells...,
    30  		),
    31  	)
    32  
    33  }