mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-02 16:29:21 +00:00
Merge pull request #9926 from bprashanth/kubelet_race
Fix benign data race in pod workers
This commit is contained in:
commit
c759ef2be0
@ -29,7 +29,9 @@ type Capabilities struct {
|
|||||||
HostNetworkSources []string
|
HostNetworkSources []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Clean these up into a singleton
|
||||||
var once sync.Once
|
var once sync.Once
|
||||||
|
var lock sync.Mutex
|
||||||
var capabilities *Capabilities
|
var capabilities *Capabilities
|
||||||
|
|
||||||
// Initialize the capability set. This can only be done once per binary, subsequent calls are ignored.
|
// Initialize the capability set. This can only be done once per binary, subsequent calls are ignored.
|
||||||
@ -50,11 +52,16 @@ func Setup(allowPrivileged bool, hostNetworkSources []string) {
|
|||||||
|
|
||||||
// SetCapabilitiesForTests. Convenience method for testing. This should only be called from tests.
|
// SetCapabilitiesForTests. Convenience method for testing. This should only be called from tests.
|
||||||
func SetForTests(c Capabilities) {
|
func SetForTests(c Capabilities) {
|
||||||
|
lock.Lock()
|
||||||
|
defer lock.Unlock()
|
||||||
capabilities = &c
|
capabilities = &c
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns a read-only copy of the system capabilities.
|
// Returns a read-only copy of the system capabilities.
|
||||||
func Get() Capabilities {
|
func Get() Capabilities {
|
||||||
|
lock.Lock()
|
||||||
|
defer lock.Unlock()
|
||||||
|
// This check prevents clobbering of capabilities that might've been set via SetForTests
|
||||||
if capabilities == nil {
|
if capabilities == nil {
|
||||||
Initialize(Capabilities{
|
Initialize(Capabilities{
|
||||||
AllowPrivileged: false,
|
AllowPrivileged: false,
|
||||||
|
Loading…
Reference in New Issue
Block a user