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

Remove flag to disable leaderElection for simulators #1426

Merged
merged 1 commit into from
Mar 21, 2023
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
6 changes: 1 addition & 5 deletions modules/agent/pkg/agent/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ import (
type Options struct {
DefaultNamespace string
ClusterID string
NoLeaderElect bool
CheckinInterval time.Duration
StartAfter <-chan struct{}
}

// Start the fleet agent
Expand Down Expand Up @@ -66,7 +64,6 @@ func Start(ctx context.Context, kubeConfig, namespace, agentScope string, opts *
}

return controllers.Register(ctx,
!opts.NoLeaderElect,
fleetNamespace,
namespace,
opts.DefaultNamespace,
Expand All @@ -78,8 +75,7 @@ func Start(ctx context.Context, kubeConfig, namespace, agentScope string, opts *
clientConfig,
fleetMapper,
mapper,
discovery,
opts.StartAfter)
discovery)
}

var (
Expand Down
24 changes: 7 additions & 17 deletions modules/agent/pkg/controllers/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,12 @@ func (a *appContext) start(ctx context.Context) error {
return start.All(ctx, 5, a.starters...)
}

func Register(ctx context.Context, leaderElect bool,
func Register(ctx context.Context,
fleetNamespace, agentNamespace, defaultNamespace, agentScope, clusterNamespace, clusterName string,
checkinInterval time.Duration,
fleetConfig *rest.Config, clientConfig clientcmd.ClientConfig,
fleetMapper, mapper meta.RESTMapper,
discovery discovery.CachedDiscoveryInterface,
startChan <-chan struct{}) error {
discovery discovery.CachedDiscoveryInterface) error {
appCtx, err := newContext(fleetNamespace, agentNamespace, clusterNamespace, clusterName,
fleetConfig, clientConfig, fleetMapper, mapper, discovery)
if err != nil {
Expand Down Expand Up @@ -122,20 +121,11 @@ func Register(ctx context.Context, leaderElect bool,
appCtx.Core.Node().Cache(),
appCtx.Fleet.Cluster())

if leaderElect {
leader.RunOrDie(ctx, agentNamespace, "fleet-agent-lock", appCtx.K8s, func(ctx context.Context) {
if err := appCtx.start(ctx); err != nil {
logrus.Fatal(err)
}
})
} else if startChan != nil {
go func() {
<-startChan
logrus.Fatalf("failed to start: %v", appCtx.start(ctx))
}()
} else {
return appCtx.start(ctx)
}
leader.RunOrDie(ctx, agentNamespace, "fleet-agent-lock", appCtx.K8s, func(ctx context.Context) {
if err := appCtx.start(ctx); err != nil {
logrus.Fatal(err)
}
})

return nil
}
Expand Down