Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

operator: allow to configure the lock name #3163

Merged
merged 2 commits into from
Apr 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 the leader election Lease name")

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to check if that parameter exists, and, if not, fallback to platform.OperatorLockName (which I'd call at this stage as platform.OperatorDefaultLockName)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should already happen when the flag is initialized, by default it should be that value

}
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
2 changes: 1 addition & 1 deletion script/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ CSV_PATH := config/manifests/bases/$(CSV_FILENAME)
# Used to push pre-release artifacts
STAGING_IMAGE_NAME := docker.io/camelk/camel-k

STAGING_RUNTIME_REPO := https://repository.apache.org/content/repositories/orgapachecamel-1425
STAGING_RUNTIME_REPO := https://repository.apache.org/content/repositories/orgapachecamel-1427

# Define here the repo containing the default Kamelet catalog (if any)
KAMELET_CATALOG_REPO := https://github.com/apache/camel-kamelets.git
Expand Down