mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-01 07:47:56 +00:00
fix data race in config.go. This is a hard one.
This commit is contained in:
parent
aa808a6505
commit
b351578ddd
@ -94,8 +94,8 @@ type ServiceConfig struct {
|
|||||||
endpointsNotifyChannel chan string
|
endpointsNotifyChannel chan string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServiceConfig() ServiceConfig {
|
func NewServiceConfig() *ServiceConfig {
|
||||||
config := ServiceConfig{
|
config := &ServiceConfig{
|
||||||
serviceConfigSources: make(map[string]chan ServiceUpdate),
|
serviceConfigSources: make(map[string]chan ServiceUpdate),
|
||||||
endpointsConfigSources: make(map[string]chan EndpointsUpdate),
|
endpointsConfigSources: make(map[string]chan EndpointsUpdate),
|
||||||
serviceHandlers: make([]ServiceConfigHandler, 10),
|
serviceHandlers: make([]ServiceConfigHandler, 10),
|
||||||
@ -130,6 +130,7 @@ func (impl *ServiceConfig) ServiceChannelListener(source string, listenChannel c
|
|||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case update := <-listenChannel:
|
case update := <-listenChannel:
|
||||||
|
impl.configLock.Lock()
|
||||||
switch update.Op {
|
switch update.Op {
|
||||||
case ADD:
|
case ADD:
|
||||||
glog.Infof("Adding new service from source %s : %v", source, update.Services)
|
glog.Infof("Adding new service from source %s : %v", source, update.Services)
|
||||||
@ -152,7 +153,6 @@ func (impl *ServiceConfig) ServiceChannelListener(source string, listenChannel c
|
|||||||
glog.Infof("Received invalid update type: %v", update)
|
glog.Infof("Received invalid update type: %v", update)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
impl.configLock.Lock()
|
|
||||||
impl.serviceConfig[source] = serviceMap
|
impl.serviceConfig[source] = serviceMap
|
||||||
impl.configLock.Unlock()
|
impl.configLock.Unlock()
|
||||||
impl.serviceNotifyChannel <- source
|
impl.serviceNotifyChannel <- source
|
||||||
@ -165,6 +165,7 @@ func (impl *ServiceConfig) EndpointsChannelListener(source string, listenChannel
|
|||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case update := <-listenChannel:
|
case update := <-listenChannel:
|
||||||
|
impl.configLock.Lock()
|
||||||
switch update.Op {
|
switch update.Op {
|
||||||
case ADD:
|
case ADD:
|
||||||
glog.Infof("Adding a new endpoint %v", update)
|
glog.Infof("Adding a new endpoint %v", update)
|
||||||
@ -188,7 +189,6 @@ func (impl *ServiceConfig) EndpointsChannelListener(source string, listenChannel
|
|||||||
glog.Infof("Received invalid update type: %v", update)
|
glog.Infof("Received invalid update type: %v", update)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
impl.configLock.Lock()
|
|
||||||
impl.endpointConfig[source] = endpointMap
|
impl.endpointConfig[source] = endpointMap
|
||||||
impl.configLock.Unlock()
|
impl.configLock.Unlock()
|
||||||
impl.endpointsNotifyChannel <- source
|
impl.endpointsNotifyChannel <- source
|
||||||
|
Loading…
Reference in New Issue
Block a user