mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Plugins: Pass cancellable context during API server creation (#86545)
This commit is contained in:
parent
aa825f5dee
commit
8a5c0cfdc0
@ -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
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ type APIServerFactory interface {
|
||||
GetEnabled(runtime []RuntimeConfig) ([]schema.GroupVersion, error)
|
||||
|
||||
// Make an API server for a given group+version
|
||||
MakeAPIServer(tracer tracing.Tracer, gv schema.GroupVersion) (builder.APIGroupBuilder, error)
|
||||
MakeAPIServer(ctx context.Context, tracer tracing.Tracer, gv schema.GroupVersion) (builder.APIGroupBuilder, error)
|
||||
}
|
||||
|
||||
// Zero dependency provider for testing
|
||||
@ -67,7 +67,7 @@ func (p *DummyAPIFactory) ApplyTo(config *genericapiserver.RecommendedConfig) er
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *DummyAPIFactory) MakeAPIServer(tracer tracing.Tracer, gv schema.GroupVersion) (builder.APIGroupBuilder, error) {
|
||||
func (p *DummyAPIFactory) MakeAPIServer(_ context.Context, tracer tracing.Tracer, gv schema.GroupVersion) (builder.APIGroupBuilder, error) {
|
||||
if gv.Version != "v0alpha1" {
|
||||
return nil, fmt.Errorf("only alpha supported now")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user