Plugins: Pass cancellable context during API server creation (#86545)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package apiserver
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
@@ -54,8 +55,14 @@ func newCommandStartExampleAPIServer(o *APIServerOptions, stopCh <-chan struct{}
|
||||
// TODO: Fix so that TracingOptions.ApplyTo happens before or during loadAPIGroupBuilders.
|
||||
tracer := newLateInitializedTracingService()
|
||||
|
||||
ctx, cancel := context.WithCancel(c.Context())
|
||||
go func() {
|
||||
<-stopCh
|
||||
cancel()
|
||||
}()
|
||||
|
||||
// Load each group from the args
|
||||
if err := o.loadAPIGroupBuilders(tracer, apis); err != nil {
|
||||
if err := o.loadAPIGroupBuilders(ctx, tracer, apis); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package apiserver
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
@@ -50,10 +51,10 @@ func newAPIServerOptions(out, errOut io.Writer) *APIServerOptions {
|
||||
}
|
||||
}
|
||||
|
||||
func (o *APIServerOptions) loadAPIGroupBuilders(tracer tracing.Tracer, apis []schema.GroupVersion) error {
|
||||
func (o *APIServerOptions) loadAPIGroupBuilders(ctx context.Context, tracer tracing.Tracer, apis []schema.GroupVersion) error {
|
||||
o.builders = []builder.APIGroupBuilder{}
|
||||
for _, gv := range apis {
|
||||
api, err := o.factory.MakeAPIServer(tracer, gv)
|
||||
api, err := o.factory.MakeAPIServer(ctx, tracer, gv)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user