Skip to content
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

node: Fix race condition on labels' getter/setter #17217

Merged
merged 1 commit into from
Sep 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion pkg/node/host_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,31 @@

package node

import (
"github.com/cilium/cilium/pkg/lock"
)

const (
templateHostEndpointID = uint64(0xffff)
)

var (
labels map[string]string
labelsMu lock.RWMutex
endpointID = templateHostEndpointID
)

// GetLabels returns the labels of this node.
func GetLabels() map[string]string {
labelsMu.RLock()
defer labelsMu.RUnlock()
return labels
}

// SetLabels sets the labels of this node.
func SetLabels(l map[string]string) {
labelsMu.Lock()
defer labelsMu.Unlock()
labels = l
}

pchaigno marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -27,7 +36,7 @@ func GetEndpointID() uint64 {
return endpointID
}

// SetLabels sets the ID of the host endpoint this node.
// SetEndpointID sets the ID of the host endpoint this node.
func SetEndpointID(id uint64) {
endpointID = id
}