Merge pull request #63667 from hzxuzhonghu/wait-informer-synced

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

sample-apiserver admission wait for informer sync before serving

**What this PR does / why we need it**:

sample-apiserver admission wait for informer sync before serving

**Release note**:

```release-note
NONE
```
This commit is contained in:
Kubernetes Submit Queue 2018-05-11 05:13:36 -07:00 committed by GitHub
commit 233b267392
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 0 deletions

View File

@ -53,6 +53,10 @@ func (d *DisallowFlunder) Admit(a admission.Attributes) error {
return nil
}
if !d.WaitForReady() {
return admission.NewForbidden(a, fmt.Errorf("not yet ready to handle request"))
}
metaAccessor, err := meta.Accessor(a.GetObject())
if err != nil {
return err
@ -82,6 +86,7 @@ func (d *DisallowFlunder) Admit(a admission.Attributes) error {
// The lister knows how to lists Fischers.
func (d *DisallowFlunder) SetInternalWardleInformerFactory(f informers.SharedInformerFactory) {
d.lister = f.Wardle().InternalVersion().Fischers().Lister()
d.SetReadyFunc(f.Wardle().InternalVersion().Fischers().Informer().HasSynced)
}
// ValidaValidateInitializationte checks whether the plugin was correctly initialized.

View File

@ -137,6 +137,7 @@ func (o WardleServerOptions) RunWardleServer(stopCh <-chan struct{}) error {
server.GenericAPIServer.AddPostStartHook("start-sample-server-informers", func(context genericapiserver.PostStartHookContext) error {
config.GenericConfig.SharedInformerFactory.Start(context.StopCh)
o.SharedInformerFactory.Start(context.StopCh)
return nil
})