Skip to content

Commit 1a85614

Browse files
authored
Merge pull request kubernetes#89147 from sttts/sttts-aggregator-handler-sync
aggregator: wait for complete proxy handler
2 parents a480f07 + e77ef0e commit 1a85614

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

staging/src/k8s.io/kube-aggregator/pkg/apiserver/apiserver.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,13 @@ func (c completedConfig) NewWithDelegate(delegationTarget genericapiserver.Deleg
235235
return nil
236236
})
237237
s.GenericAPIServer.AddPostStartHookOrDie("apiservice-registration-controller", func(context genericapiserver.PostStartHookContext) error {
238-
go apiserviceRegistrationController.Run(context.StopCh)
238+
handlerSyncedCh := make(chan struct{})
239+
go apiserviceRegistrationController.Run(context.StopCh, handlerSyncedCh)
240+
select {
241+
case <-context.StopCh:
242+
case <-handlerSyncedCh:
243+
}
244+
239245
return nil
240246
})
241247
s.GenericAPIServer.AddPostStartHookOrDie("apiservice-status-available-controller", func(context genericapiserver.PostStartHookContext) error {

staging/src/k8s.io/kube-aggregator/pkg/apiserver/apiservice_controller.go

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ import (
2020
"fmt"
2121
"time"
2222

23-
"k8s.io/klog"
24-
2523
apierrors "k8s.io/apimachinery/pkg/api/errors"
24+
"k8s.io/apimachinery/pkg/labels"
2625
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
2726
"k8s.io/apimachinery/pkg/util/wait"
2827
"k8s.io/client-go/tools/cache"
2928
"k8s.io/client-go/util/workqueue"
29+
"k8s.io/klog"
3030

31-
"k8s.io/kube-aggregator/pkg/apis/apiregistration/v1"
31+
v1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1"
3232
informers "k8s.io/kube-aggregator/pkg/client/informers/externalversions/apiregistration/v1"
3333
listers "k8s.io/kube-aggregator/pkg/client/listers/apiregistration/v1"
3434
"k8s.io/kube-aggregator/pkg/controllers"
@@ -87,7 +87,7 @@ func (c *APIServiceRegistrationController) sync(key string) error {
8787
}
8888

8989
// Run starts APIServiceRegistrationController which will process all registration requests until stopCh is closed.
90-
func (c *APIServiceRegistrationController) Run(stopCh <-chan struct{}) {
90+
func (c *APIServiceRegistrationController) Run(stopCh <-chan struct{}, handlerSyncedCh chan<- struct{}) {
9191
defer utilruntime.HandleCrash()
9292
defer c.queue.ShutDown()
9393

@@ -98,6 +98,28 @@ func (c *APIServiceRegistrationController) Run(stopCh <-chan struct{}) {
9898
return
9999
}
100100

101+
/// initially sync all APIServices to make sure the proxy handler is complete
102+
if err := wait.PollImmediateUntil(time.Second, func() (bool, error) {
103+
services, err := c.apiServiceLister.List(labels.Everything())
104+
if err != nil {
105+
utilruntime.HandleError(fmt.Errorf("failed to initially list APIServices: %v", err))
106+
return false, nil
107+
}
108+
for _, s := range services {
109+
if err := c.apiHandlerManager.AddAPIService(s); err != nil {
110+
utilruntime.HandleError(fmt.Errorf("failed to initially sync APIService %s: %v", s.Name, err))
111+
return false, nil
112+
}
113+
}
114+
return true, nil
115+
}, stopCh); err == wait.ErrWaitTimeout {
116+
utilruntime.HandleError(fmt.Errorf("timed out waiting for proxy handler to initialize"))
117+
return
118+
} else if err != nil {
119+
panic(fmt.Errorf("unexpected error: %v", err))
120+
}
121+
close(handlerSyncedCh)
122+
101123
// only start one worker thread since its a slow moving API and the aggregation server adding bits
102124
// aren't threadsafe
103125
go wait.Until(c.runWorker, time.Second, stopCh)

0 commit comments

Comments
 (0)