Skip to content

Commit

Permalink
Merge pull request kubernetes#2736 from erictune/register_race
Browse files Browse the repository at this point in the history
Fix race that drops the first event on restart.
  • Loading branch information
lavalamp committed Dec 3, 2014
2 parents 4acc23c + 0c2a430 commit 7d9a721
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions cmd/kube-proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,21 @@ func main() {
serviceConfig := config.NewServiceConfig()
endpointsConfig := config.NewEndpointsConfig()

protocol := iptables.ProtocolIpv4
if net.IP(bindAddress).To4() == nil {
protocol = iptables.ProtocolIpv6
}
loadBalancer := proxy.NewLoadBalancerRR()
proxier := proxy.NewProxier(loadBalancer, net.IP(bindAddress), iptables.New(exec.New(), protocol))
// Wire proxier to handle changes to services
serviceConfig.RegisterHandler(proxier)
// And wire loadBalancer to handle changes to endpoints to services
endpointsConfig.RegisterHandler(loadBalancer)

// Note: RegisterHandler() calls need to happen before creation of Sources because sources
// only notify on changes, and the initial update (on process start) may be lost if no handlers
// are registered yet.

// define api config source
if clientConfig.Host != "" {
glog.Infof("Using api calls to get config %v", clientConfig.Host)
Expand Down Expand Up @@ -113,17 +128,6 @@ func main() {
}, 5*time.Second)
}

protocol := iptables.ProtocolIpv4
if net.IP(bindAddress).To4() == nil {
protocol = iptables.ProtocolIpv6
}
loadBalancer := proxy.NewLoadBalancerRR()
proxier := proxy.NewProxier(loadBalancer, net.IP(bindAddress), iptables.New(exec.New(), protocol))
// Wire proxier to handle changes to services
serviceConfig.RegisterHandler(proxier)
// And wire loadBalancer to handle changes to endpoints to services
endpointsConfig.RegisterHandler(loadBalancer)

// Just loop forever for now...
proxier.SyncLoop()
}

0 comments on commit 7d9a721

Please sign in to comment.