@@ -20,15 +20,15 @@ import (
20
20
"fmt"
21
21
"time"
22
22
23
- "k8s.io/klog"
24
-
25
23
apierrors "k8s.io/apimachinery/pkg/api/errors"
24
+ "k8s.io/apimachinery/pkg/labels"
26
25
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
27
26
"k8s.io/apimachinery/pkg/util/wait"
28
27
"k8s.io/client-go/tools/cache"
29
28
"k8s.io/client-go/util/workqueue"
29
+ "k8s.io/klog"
30
30
31
- "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1"
31
+ v1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1"
32
32
informers "k8s.io/kube-aggregator/pkg/client/informers/externalversions/apiregistration/v1"
33
33
listers "k8s.io/kube-aggregator/pkg/client/listers/apiregistration/v1"
34
34
"k8s.io/kube-aggregator/pkg/controllers"
@@ -87,7 +87,7 @@ func (c *APIServiceRegistrationController) sync(key string) error {
87
87
}
88
88
89
89
// 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 {} ) {
91
91
defer utilruntime .HandleCrash ()
92
92
defer c .queue .ShutDown ()
93
93
@@ -98,6 +98,28 @@ func (c *APIServiceRegistrationController) Run(stopCh <-chan struct{}) {
98
98
return
99
99
}
100
100
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
+
101
123
// only start one worker thread since its a slow moving API and the aggregation server adding bits
102
124
// aren't threadsafe
103
125
go wait .Until (c .runWorker , time .Second , stopCh )
0 commit comments