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

Avoid issues with goroutines updating fields #1392

Merged
merged 1 commit into from
Sep 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions core/pkg/ingress/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"strconv"
"strings"
"sync"
"sync/atomic"
"time"

"github.com/golang/glog"
Expand Down Expand Up @@ -110,9 +111,9 @@ type GenericController struct {
// runningConfig contains the running configuration in the Backend
runningConfig *ingress.Configuration

forceReload bool
forceReload int32

initialSyncDone bool
initialSyncDone int32
}

// Configuration contains all the settings required by an Ingress controller
Expand Down Expand Up @@ -283,7 +284,7 @@ func (ic *GenericController) syncIngress(key interface{}) error {
PassthroughBackends: passUpstreams,
}

if !ic.forceReload && ic.runningConfig != nil && ic.runningConfig.Equal(&pcfg) {
if !ic.isForceReload() && ic.runningConfig != nil && ic.runningConfig.Equal(&pcfg) {
glog.V(3).Infof("skipping backend reload (no changes detected)")
return nil
}
Expand All @@ -302,7 +303,7 @@ func (ic *GenericController) syncIngress(key interface{}) error {
setSSLExpireTime(servers)

ic.runningConfig = &pcfg
ic.forceReload = false
ic.setForceReload(false)

return nil
}
Expand Down Expand Up @@ -1185,7 +1186,7 @@ func (ic GenericController) Stop() error {
}

// Start starts the Ingress controller.
func (ic GenericController) Start() {
func (ic *GenericController) Start() {
glog.Infof("starting Ingress controller")

go ic.ingController.Run(ic.stopCh)
Expand Down Expand Up @@ -1224,21 +1225,41 @@ func (ic GenericController) Start() {

createDefaultSSLCertificate()

ic.setInitialSyncDone()

go ic.syncQueue.Run(time.Second, ic.stopCh)

if ic.syncStatus != nil {
go ic.syncStatus.Run(ic.stopCh)
}

ic.initialSyncDone = true

time.Sleep(5 * time.Second)
// force initial sync
ic.syncQueue.Enqueue(&extensions.Ingress{})

<-ic.stopCh
}

func (ic *GenericController) isForceReload() bool {
return atomic.LoadInt32(&ic.forceReload) != 0
}

func (ic *GenericController) setForceReload(shouldReload bool) {
if shouldReload {
atomic.StoreInt32(&ic.forceReload, 1)
} else {
atomic.StoreInt32(&ic.forceReload, 0)
}
}

func (ic *GenericController) isInitialSyncDone() bool {
return atomic.LoadInt32(&ic.initialSyncDone) != 0
}

func (ic *GenericController) setInitialSyncDone() {
atomic.StoreInt32(&ic.initialSyncDone, 1)
}

func createDefaultSSLCertificate() {
defCert, defKey := ssl.GetFakeSSLCert()
c, err := ssl.AddOrUpdateCertAndKey(fakeCertificate, defCert, defKey, []byte{})
Expand Down
6 changes: 3 additions & 3 deletions core/pkg/ingress/controller/listers.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (ic *GenericController) createListers(disableNodeLister bool) {
}
ic.recorder.Eventf(addIng, apiv1.EventTypeNormal, "CREATE", fmt.Sprintf("Ingress %s/%s", addIng.Namespace, addIng.Name))

if ic.initialSyncDone {
if ic.isInitialSyncDone() {
ic.syncQueue.Enqueue(obj)
}
},
Expand Down Expand Up @@ -142,7 +142,7 @@ func (ic *GenericController) createListers(disableNodeLister bool) {
if mapKey == ic.cfg.ConfigMapName {
glog.V(2).Infof("adding configmap %v to backend", mapKey)
ic.cfg.Backend.SetConfig(upCmap)
ic.forceReload = true
ic.setForceReload(true)
}
},
UpdateFunc: func(old, cur interface{}) {
Expand All @@ -152,7 +152,7 @@ func (ic *GenericController) createListers(disableNodeLister bool) {
if mapKey == ic.cfg.ConfigMapName {
glog.V(2).Infof("updating configmap backend (%v)", mapKey)
ic.cfg.Backend.SetConfig(upCmap)
ic.forceReload = true
ic.setForceReload(true)
}
// updates to configuration configmaps can trigger an update
if mapKey == ic.cfg.ConfigMapName || mapKey == ic.cfg.TCPConfigMapName || mapKey == ic.cfg.UDPConfigMapName {
Expand Down