sample-apiserver admission wait for informer sync before serving

This commit is contained in:
xuzhonghu 2018-05-10 19:30:56 +08:00
parent e63f25902c
commit ec30ad48b8
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
})