mirror of https://github.com/k3s-io/k3s
Add RWMutex to address controller
Fixes race condition when address map is updated by multiple goroutines
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
(cherry picked from commit 0d23cfe038
)
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
release-1.24
v1.24.17+k3s1
parent
0d646e40a2
commit
026bb0ec39
|
@ -2,6 +2,7 @@ package cluster
|
|||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
"github.com/k3s-io/k3s/pkg/util"
|
||||
controllerv1 "github.com/rancher/wrangler/pkg/generated/controllers/core/v1"
|
||||
|
@ -26,6 +27,8 @@ func registerAddressHandlers(ctx context.Context, c *Cluster) {
|
|||
}
|
||||
|
||||
type addressesHandler struct {
|
||||
sync.RWMutex
|
||||
|
||||
nodeController controllerv1.NodeController
|
||||
allowed map[string]bool
|
||||
}
|
||||
|
@ -37,6 +40,9 @@ func (a *addressesHandler) filterCN(cns ...string) []string {
|
|||
return cns
|
||||
}
|
||||
|
||||
a.RLock()
|
||||
defer a.RUnlock()
|
||||
|
||||
filteredCNs := make([]string, 0, len(cns))
|
||||
for _, cn := range cns {
|
||||
if a.allowed[cn] {
|
||||
|
@ -52,6 +58,9 @@ func (a *addressesHandler) filterCN(cns ...string) []string {
|
|||
func (a *addressesHandler) sync(key string, node *v1.Node) (*v1.Node, error) {
|
||||
if node != nil {
|
||||
if node.Labels[util.ControlPlaneRoleLabelKey] != "" || node.Labels[util.ETCDRoleLabelKey] != "" {
|
||||
a.Lock()
|
||||
defer a.Unlock()
|
||||
|
||||
for _, address := range node.Status.Addresses {
|
||||
a.allowed[address.String()] = true
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue