Skip to content

Commit

Permalink
fix(discovery): fix bug that discovery may be blocked when start (#4440
Browse files Browse the repository at this point in the history
…) (#4442)
  • Loading branch information
ti-srebot authored Feb 23, 2022
1 parent 58fba3f commit 7b170c3
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions cmd/discovery/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"github.com/pingcap/tidb-operator/pkg/pdapi"
"github.com/pingcap/tidb-operator/pkg/version"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/informers"
kubeinformers "k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
Expand Down Expand Up @@ -91,24 +90,25 @@ func main() {
tcTls = true
}
// informers
options := []informers.SharedInformerOption{
informers.WithNamespace(os.Getenv("MY_POD_NAMESPACE")),
options := []kubeinformers.SharedInformerOption{
kubeinformers.WithNamespace(os.Getenv("MY_POD_NAMESPACE")),
}

kubeInformerFactory := kubeinformers.NewSharedInformerFactoryWithOptions(kubeCli, 30*time.Minute, options...)
secretInformer := kubeInformerFactory.Core().V1().Secrets()
secretInformer := kubeInformerFactory.Core().V1().Secrets().Informer()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go kubeInformerFactory.Start(ctx.Done())
kubeInformerFactory.Start(ctx.Done())

// waiting for the shared informer's store has synced.
cache.WaitForCacheSync(ctx.Done(), secretInformer.Informer().HasSynced)
cache.WaitForCacheSync(ctx.Done(), secretInformer.HasSynced)

go wait.Forever(func() {
addr := fmt.Sprintf("0.0.0.0:%d", port)
klog.Infof("starting TiDB Discovery server, listening on %s", addr)
discoveryServer := server.NewServer(pdapi.NewDefaultPDControl(secretInformer.Lister()), dmapi.NewDefaultMasterControl(secretInformer.Lister()), cli, kubeCli)
lister := kubeInformerFactory.Core().V1().Secrets().Lister()
discoveryServer := server.NewServer(pdapi.NewDefaultPDControl(lister), dmapi.NewDefaultMasterControl(lister), cli, kubeCli)
discoveryServer.ListenAndServe(addr)
}, 5*time.Second)
go wait.Forever(func() {
Expand Down

0 comments on commit 7b170c3

Please sign in to comment.