@@ -25,7 +25,6 @@ import (
25
25
"os"
26
26
"os/user"
27
27
"path/filepath"
28
- "reflect"
29
28
"time"
30
29
31
30
"go.opencensus.io/stats/view"
@@ -64,6 +63,7 @@ import (
64
63
// 2. Fallback to the KUBECONFIG environment variable.
65
64
// 3. Fallback to in-cluster config.
66
65
// 4. Fallback to the ~/.kube/config.
66
+ // Deprecated: use injection.GetRestConfig
67
67
func GetConfig (serverURL , kubeconfig string ) (* rest.Config , error ) {
68
68
if kubeconfig == "" {
69
69
kubeconfig = os .Getenv ("KUBECONFIG" )
@@ -128,40 +128,15 @@ func GetLeaderElectionConfig(ctx context.Context) (*leaderelection.Config, error
128
128
return leaderelection .NewConfigFromConfigMap (leaderElectionConfigMap )
129
129
}
130
130
131
- const (
132
- defaultStartInformerDelayTime = 5 * time .Second
133
- )
134
-
135
- type informerStartChanKey struct {}
136
- type informerStartTimeoutKey struct {}
137
-
138
- func WithInformerStart (ctx context.Context , start <- chan struct {}, timeout time.Duration ) context.Context {
139
- ctx = context .WithValue (ctx , informerStartChanKey {}, start )
140
- return context .WithValue (ctx , informerStartTimeoutKey {}, timeout )
141
- }
142
-
143
- func getInformerStartChanTimeout (ctx context.Context ) (<- chan struct {}, time.Duration ) {
144
- timeout := defaultStartInformerDelayTime
145
- tuntyped := ctx .Value (informerStartTimeoutKey {})
146
- if tuntyped != nil {
147
- timeout = tuntyped .(time.Duration )
148
- }
149
-
150
- untyped := ctx .Value (informerStartChanKey {})
151
- if untyped == nil || reflect .ValueOf (untyped ).IsNil () {
152
- return make (chan struct {}, 1 ), timeout
153
- }
154
- return untyped .(<- chan struct {}), timeout
155
- }
156
-
157
131
// EnableInjectionOrDie enables Knative Injection and starts the informers.
158
132
// Both Context and Config are optional.
133
+ // Deprecated: use injection.EnableInjectionOrDie
159
134
func EnableInjectionOrDie (ctx context.Context , cfg * rest.Config ) context.Context {
160
135
if ctx == nil {
161
136
ctx = signals .NewContext ()
162
137
}
163
138
if cfg == nil {
164
- cfg = ParseAndGetConfigOrDie ()
139
+ cfg = injection . ParseAndGetRestConfigOrDie ()
165
140
}
166
141
167
142
// Respect user provided settings, but if omitted customize the default behavior.
@@ -175,13 +150,7 @@ func EnableInjectionOrDie(ctx context.Context, cfg *rest.Config) context.Context
175
150
176
151
ctx , informers := injection .Default .SetupInformers (ctx , cfg )
177
152
178
- start , timeout := getInformerStartChanTimeout (ctx )
179
153
go func () {
180
- // Block until the timeout or we are told it is ok to start informers.
181
- select {
182
- case <- start :
183
- case <- time .After (timeout ):
184
- }
185
154
logging .FromContext (ctx ).Info ("Starting informers..." )
186
155
if err := controller .StartInformers (ctx .Done (), informers ... ); err != nil {
187
156
logging .FromContext (ctx ).Fatalw ("Failed to start informers" , zap .Error (err ))
@@ -192,8 +161,8 @@ func EnableInjectionOrDie(ctx context.Context, cfg *rest.Config) context.Context
192
161
}
193
162
194
163
// Main runs the generic main flow with a new context.
195
- // If any of the contructed controllers are AdmissionControllers or Conversion webhooks,
196
- // then a webhook is started to serve them.
164
+ // If any of the constructed controllers are AdmissionControllers or Conversion
165
+ // webhooks, then a webhook is started to serve them.
197
166
func Main (component string , ctors ... injection.ControllerConstructor ) {
198
167
// Set up signals so we handle the first shutdown signal gracefully.
199
168
MainWithContext (signals .NewContext (), component , ctors ... )
@@ -216,7 +185,7 @@ func MainWithContext(ctx context.Context, component string, ctors ...injection.C
216
185
"issue upstream!" )
217
186
218
187
// HACK: This parses flags, so the above should be set once this runs.
219
- cfg := ParseAndGetConfigOrDie ()
188
+ cfg := injection . ParseAndGetRestConfigOrDie ()
220
189
221
190
if * disableHighAvailability {
222
191
ctx = WithHADisabled (ctx )
@@ -256,8 +225,7 @@ func MainWithConfig(ctx context.Context, component string, cfg *rest.Config, cto
256
225
cfg .Burst = len (ctors ) * rest .DefaultBurst
257
226
}
258
227
259
- startCh := make (chan struct {}, 1 )
260
- ctx = EnableInjectionOrDie (WithInformerStart (ctx , startCh , defaultStartInformerDelayTime ), cfg )
228
+ ctx , startInformers := injection .EnableInjectionOrDie (ctx , cfg )
261
229
262
230
logger , atomicLevel := SetupLoggerOrDie (ctx , component )
263
231
defer flush (logger )
@@ -312,7 +280,7 @@ func MainWithConfig(ctx context.Context, component string, cfg *rest.Config, cto
312
280
}
313
281
314
282
// Start the injection clients and informers.
315
- startCh <- struct {}{}
283
+ startInformers ()
316
284
317
285
// Wait for webhook informers to sync.
318
286
if wh != nil {
@@ -339,6 +307,7 @@ func flush(logger *zap.SugaredLogger) {
339
307
340
308
// ParseAndGetConfigOrDie parses the rest config flags and creates a client or
341
309
// dies by calling log.Fatalf.
310
+ // Deprecated: use injeciton.ParseAndGetRestConfigOrDie
342
311
func ParseAndGetConfigOrDie () * rest.Config {
343
312
var (
344
313
serverURL = flag .String ("server" , "" ,
@@ -349,7 +318,7 @@ func ParseAndGetConfigOrDie() *rest.Config {
349
318
klog .InitFlags (flag .CommandLine )
350
319
flag .Parse ()
351
320
352
- cfg , err := GetConfig (* serverURL , * kubeconfig )
321
+ cfg , err := injection . GetRestConfig (* serverURL , * kubeconfig )
353
322
if err != nil {
354
323
log .Fatalf ("Error building kubeconfig: %v" , err )
355
324
}
0 commit comments