Skip to content

Commit

Permalink
Quick fix: wait for cache to sync after crds are created.
Browse files Browse the repository at this point in the history
  • Loading branch information
AMecea committed May 29, 2018
1 parent 830c23c commit 09e6110
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,12 @@ publish: images
###############
CHART_TEMPLATE_PATH := deploy/
CRDS := mysqlclusters.mysql.presslabs.org mysqlbackups.mysql.presslabs.org
GROUP_NAME := mysql.presslabs.org

CRD_GEN_FILES := $(addprefix $(CHART_TEMPLATE_PATH),$(addsuffix .yaml,$(CRDS)))

$(CRD_GEN_FILES):
bin/gen-crds-yaml_$(GOOS)_$(GOARCH) --crd $(basename $(notdir $@)) >> $(@:.mysql.presslabs.org.yaml=.yaml)
bin/gen-crds-yaml_$(GOOS)_$(GOARCH) --crd $(basename $(notdir $@)) > $(@:.$(GROUP_NAME).yaml=.yaml)

.PHONY: gen-crds gen-crds-verify gen-crds-clean
gen-crds: gen-crds-clean $(CRD_GEN_FILES)
Expand All @@ -124,10 +125,10 @@ gen-crds-verify: SHELL := /bin/bash
gen-crds-verify: $(addsuffix -verify,$(CRD_GEN_FILES))
@echo "Verifying generated CRDs"

$(addsuffix -verify,$(CRD_GEN_FILES)):
$(addsuffix -verify,$(CRD_GEN_FILES)): bin/gen-crds-yaml_$(GOOS)_$(GOARCH)
$(eval FILE := $(subst -verify,,$@))
$(eval CRD := $(basename $(notdir $@)))
diff -Naupr $(FILE) <(bin/gen-crds-yaml_$(GOOS)_$(GOARCH) --crd $(CRD))
diff -Naupr $(FILE:.$(GROUP_NAME).yaml=.yaml) <(bin/gen-crds-yaml_$(GOOS)_$(GOARCH) --crd $(CRD))

gen-crds-clean:
rm -f $(CRD_GEN_FILES)
Expand Down
8 changes: 4 additions & 4 deletions pkg/controller/backupscontroller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,6 @@ func New(ctx *controllerpkg.Context) *Controller {
func (c *Controller) Start(workers int, stopCh <-chan struct{}) error {
glog.Info("Starting controller ...")

if !cache.WaitForCacheSync(stopCh, c.syncedFuncs...) {
return fmt.Errorf("error waiting for informer cache to sync")
}

if c.InstallCRDs {
if err := kube.InstallCRD(c.CRDClient, api.ResourceMysqlBackupCRD); err != nil {
glog.Fatalf(err.Error())
Expand All @@ -138,6 +134,10 @@ func (c *Controller) Start(workers int, stopCh <-chan struct{}) error {
c.SharedInformerFactory.Start(stopCh)
c.KubeSharedInformerFactory.Start(stopCh)

if !cache.WaitForCacheSync(stopCh, c.syncedFuncs...) {
return fmt.Errorf("error waiting for informer cache to sync")
}

for i := 0; i < workers; i++ {
c.workerWg.Add(1)
go wait.Until(func() { c.work(stopCh) }, workerPeriodTime, stopCh)
Expand Down
10 changes: 6 additions & 4 deletions pkg/controller/clustercontroller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,15 @@ func New(ctx *controllerpkg.Context) *Controller {
func (c *Controller) Start(workers int, stopCh <-chan struct{}) error {
glog.Info("Starting controller ...")

if !cache.WaitForCacheSync(stopCh, c.syncedFuncs...) {
return fmt.Errorf("error waiting for informer cache to sync")
}

if c.InstallCRDs {
glog.V(3).Info("Installing mysql crd...")
if err := kube.InstallCRD(c.CRDClient, api.ResourceMysqlClusterCRD); err != nil {
glog.Fatalf(err.Error())
return fmt.Errorf("fail to create crd: %s", err)
}
}

glog.V(3).Info("Wait for mysql crd...")
if err := kube.WaitForCRD(c.CRDClient, api.ResourceMysqlClusterCRD); err != nil {
return fmt.Errorf("crd does not exists: %s", err)
}
Expand All @@ -146,6 +144,10 @@ func (c *Controller) Start(workers int, stopCh <-chan struct{}) error {
c.SharedInformerFactory.Start(stopCh)
c.KubeSharedInformerFactory.Start(stopCh)

if !cache.WaitForCacheSync(stopCh, c.syncedFuncs...) {
return fmt.Errorf("error waiting for informer cache to sync")
}

for i := 0; i < workers; i++ {
c.workerWg.Add(1)
go wait.Until(func() { c.workerController(stopCh) }, workerPeriodTime, stopCh)
Expand Down

0 comments on commit 09e6110

Please sign in to comment.