Merge pull request #50852 from guangxuli/fix_apiserver_register

Automatic merge from submit-queue (batch tested with PRs 50281, 50747, 50347, 50834, 50852)

fix incorrect logic in admission register

**What this PR does / why we need it**:
There is no issue for this PR, just fix incorrect logic in invocation `func (ps *Plugins) Register(name string, plugin Factory) ` after browsing the code accidentally.  And apparently, the logic exits potential panic.

**Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #
no issue
**Special notes for your reviewer**:
none
**Release note**:
none
pull/6/head
Kubernetes Submit Queue 2017-08-17 16:56:27 -07:00 committed by GitHub
commit 1eb04f6a2a
1 changed files with 7 additions and 5 deletions

View File

@ -67,13 +67,15 @@ func (ps *Plugins) Registered() []string {
func (ps *Plugins) Register(name string, plugin Factory) {
ps.lock.Lock()
defer ps.lock.Unlock()
_, found := ps.registry[name]
if found {
glog.Fatalf("Admission plugin %q was registered twice", name)
}
if ps.registry == nil {
if ps.registry != nil {
_, found := ps.registry[name]
if found {
glog.Fatalf("Admission plugin %q was registered twice", name)
}
} else {
ps.registry = map[string]Factory{}
}
glog.V(1).Infof("Registered admission plugin %q", name)
ps.registry[name] = plugin
}