Skip to content

⚠️ Remove defaulting for leader election ID #446

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

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
5 changes: 3 additions & 2 deletions pkg/leaderelection/leader_election.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package leaderelection

import (
"errors"
"fmt"
"io/ioutil"
"os"
Expand Down Expand Up @@ -52,9 +53,9 @@ func NewResourceLock(config *rest.Config, recorderProvider recorder.Provider, op
return nil, nil
}

// Default the LeaderElectionID
// LeaderElectionID must be provided to prevent clashes
if options.LeaderElectionID == "" {
options.LeaderElectionID = "controller-leader-election-helper"
return nil, errors.New("LeaderElectionID must be configured")
}

// Default the namespace (if running in cluster)
Expand Down
5 changes: 3 additions & 2 deletions pkg/manager/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,16 @@ var _ = Describe("manger.Manager", func() {
m, err := New(cfg, Options{
LeaderElection: true,
LeaderElectionNamespace: "default",
LeaderElectionID: "test-leader-election-id",
Copy link
Contributor

Choose a reason for hiding this comment

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

lol, this test should have a different name now. I'll fix it elsewhere.

newResourceLock: func(config *rest.Config, recorderProvider recorder.Provider, options leaderelection.Options) (resourcelock.Interface, error) {
var err error
rl, err = leaderelection.NewResourceLock(config, recorderProvider, options)
return rl, err
},
})
Expect(m).ToNot(BeNil())
Expect(err).ToNot(HaveOccurred())
Expect(rl.Describe()).To(Equal("default/controller-leader-election-helper"))
Expect(m).ToNot(BeNil())
Expect(rl.Describe()).To(Equal("default/test-leader-election-id"))
})

It("should return an error if namespace not set and not running in cluster", func() {
Expand Down