@@ -105,49 +105,48 @@ func (app *RecommenderApp) Run(ctx context.Context, leaderElection componentbase
105105
106106 if ! leaderElection .LeaderElect {
107107 return app .run (ctx , stopCh , healthCheck )
108- } else {
109- id , err := os .Hostname ()
110- if err != nil {
111- return fmt .Errorf ("unable to get hostname: %w" , err )
112- }
108+ }
109+ id , err := os .Hostname ()
110+ if err != nil {
111+ return fmt .Errorf ("unable to get hostname: %w" , err )
112+ }
113113
114- id = id + "_" + string (uuid .NewUUID ())
114+ id = id + "_" + string (uuid .NewUUID ())
115115
116- config := common .CreateKubeConfigOrDie (app .config .CommonFlags .KubeConfig , float32 (app .config .CommonFlags .KubeApiQps ), int (app .config .CommonFlags .KubeApiBurst ))
117- kubeClient := kube_client .NewForConfigOrDie (config )
116+ config := common .CreateKubeConfigOrDie (app .config .CommonFlags .KubeConfig , float32 (app .config .CommonFlags .KubeApiQps ), int (app .config .CommonFlags .KubeApiBurst ))
117+ kubeClient := kube_client .NewForConfigOrDie (config )
118118
119- lock , err := resourcelock .New (
120- leaderElection .ResourceLock ,
121- leaderElection .ResourceNamespace ,
122- leaderElection .ResourceName ,
123- kubeClient .CoreV1 (),
124- kubeClient .CoordinationV1 (),
125- resourcelock.ResourceLockConfig {
126- Identity : id ,
127- },
128- )
129- if err != nil {
130- return fmt .Errorf ("unable to create leader election lock: %w" , err )
131- }
119+ lock , err := resourcelock .New (
120+ leaderElection .ResourceLock ,
121+ leaderElection .ResourceNamespace ,
122+ leaderElection .ResourceName ,
123+ kubeClient .CoreV1 (),
124+ kubeClient .CoordinationV1 (),
125+ resourcelock.ResourceLockConfig {
126+ Identity : id ,
127+ },
128+ )
129+ if err != nil {
130+ return fmt .Errorf ("unable to create leader election lock: %w" , err )
131+ }
132132
133- leaderelection .RunOrDie (ctx , leaderelection.LeaderElectionConfig {
134- Lock : lock ,
135- LeaseDuration : leaderElection .LeaseDuration .Duration ,
136- RenewDeadline : leaderElection .RenewDeadline .Duration ,
137- RetryPeriod : leaderElection .RetryPeriod .Duration ,
138- ReleaseOnCancel : true ,
139- Callbacks : leaderelection.LeaderCallbacks {
140- OnStartedLeading : func (_ context.Context ) {
141- if err := app .run (ctx , stopCh , healthCheck ); err != nil {
142- klog .Fatalf ("Error running recommender: %v" , err )
143- }
144- },
145- OnStoppedLeading : func () {
146- klog .Fatal ("lost master" )
147- },
133+ leaderelection .RunOrDie (ctx , leaderelection.LeaderElectionConfig {
134+ Lock : lock ,
135+ LeaseDuration : leaderElection .LeaseDuration .Duration ,
136+ RenewDeadline : leaderElection .RenewDeadline .Duration ,
137+ RetryPeriod : leaderElection .RetryPeriod .Duration ,
138+ ReleaseOnCancel : true ,
139+ Callbacks : leaderelection.LeaderCallbacks {
140+ OnStartedLeading : func (_ context.Context ) {
141+ if err := app .run (ctx , stopCh , healthCheck ); err != nil {
142+ klog .Fatalf ("Error running recommender: %v" , err )
143+ }
148144 },
149- })
150- }
145+ OnStoppedLeading : func () {
146+ klog .Fatal ("lost master" )
147+ },
148+ },
149+ })
151150
152151 return nil
153152}
0 commit comments