Merge pull request #50098 from nikhita/crd-data-race

Automatic merge from submit-queue (batch tested with PRs 46685, 49863, 50098, 50070, 50096)

apiextensions: fix data race in storage

Fixes data race in CRD storage.

Copy to a new map because we cannot write to storageMap without a race as it is used without locking elsewhere.

**Release note**:

```release-note
NONE
```

/cc @sttts
This commit is contained in:
Kubernetes Submit Queue 2017-08-04 00:20:55 -07:00 committed by GitHub
commit c66d2499da

View File

@ -343,8 +343,17 @@ func (r *crdHandler) getServingInfoFor(crd *apiextensions.CustomResourceDefiniti
storage: storage,
requestScope: requestScope,
}
storageMap[crd.UID] = ret
r.customStorage.Store(storageMap)
storageMap2 := make(crdStorageMap, len(storageMap))
// Copy because we cannot write to storageMap without a race
// as it is used without locking elsewhere
for k, v := range storageMap {
storageMap2[k] = v
}
storageMap2[crd.UID] = ret
r.customStorage.Store(storageMap2)
return ret
}