Skip to content

Commit

Permalink
operator: allow to configure the lock name #3162
Browse files Browse the repository at this point in the history
  • Loading branch information
lburgazzoli committed Apr 20, 2022
1 parent 876cd54 commit 7f25953
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 33 deletions.
11 changes: 7 additions & 4 deletions pkg/cmd/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/spf13/cobra"

"github.com/apache/camel-k/pkg/cmd/operator"
"github.com/apache/camel-k/pkg/platform"
)

const operatorCommand = "operator"
Expand All @@ -40,16 +41,18 @@ func newCmdOperator() (*cobra.Command, *operatorCmdOptions) {
cmd.Flags().Int32("health-port", 8081, "The port of the health endpoint")
cmd.Flags().Int32("monitoring-port", 8080, "The port of the metrics endpoint")
cmd.Flags().Bool("leader-election", true, "Use leader election")
cmd.Flags().String("leader-election-id", platform.OperatorLockName, "Use the given id as leader election discriminator")

return &cmd, &options
}

type operatorCmdOptions struct {
HealthPort int32 `mapstructure:"health-port"`
MonitoringPort int32 `mapstructure:"monitoring-port"`
LeaderElection bool `mapstructure:"leader-election"`
HealthPort int32 `mapstructure:"health-port"`
MonitoringPort int32 `mapstructure:"monitoring-port"`
LeaderElection bool `mapstructure:"leader-election"`
LeaderElectionID string `mapstructure:"leader-election-id"`
}

func (o *operatorCmdOptions) run(_ *cobra.Command, _ []string) {
operator.Run(o.HealthPort, o.MonitoringPort, o.LeaderElection)
operator.Run(o.HealthPort, o.MonitoringPort, o.LeaderElection, o.LeaderElectionID)
}
4 changes: 2 additions & 2 deletions pkg/cmd/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func printVersion() {
}

// Run starts the Camel K operator.
func Run(healthPort, monitoringPort int32, leaderElection bool) {
func Run(healthPort, monitoringPort int32, leaderElection bool, leaderElectionID string) {
rand.Seed(time.Now().UTC().UnixNano())

flag.Parse()
Expand Down Expand Up @@ -158,7 +158,7 @@ func Run(healthPort, monitoringPort int32, leaderElection bool) {
EventBroadcaster: broadcaster,
LeaderElection: leaderElection,
LeaderElectionNamespace: operatorNamespace,
LeaderElectionID: platform.OperatorLockName,
LeaderElectionID: leaderElectionID,
LeaderElectionResourceLock: resourcelock.LeasesResourceLock,
LeaderElectionReleaseOnCancel: true,
HealthProbeBindAddress: ":" + strconv.Itoa(int(healthPort)),
Expand Down
Loading

0 comments on commit 7f25953

Please sign in to comment.