K8s/Testdata: Expose testdata in standalone apiserver (#80248)

This commit is contained in:
Ryan McKinley
2024-01-10 17:45:23 +02:00
committed by GitHub
parent 42f1059bc9
commit 6be6724433
9 changed files with 93 additions and 24 deletions
+6 -7
View File
@@ -4,18 +4,17 @@ import (
"os"
"path"
"github.com/spf13/cobra"
genericapiserver "k8s.io/apiserver/pkg/server"
"k8s.io/apiserver/pkg/server/options"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/component-base/cli"
"k8s.io/klog/v2"
aggregatorscheme "k8s.io/kube-aggregator/pkg/apiserver/scheme"
"github.com/grafana/grafana/pkg/aggregator"
grafanaapiserver "github.com/grafana/grafana/pkg/services/grafana-apiserver"
"github.com/grafana/grafana/pkg/services/grafana-apiserver/utils"
"github.com/spf13/cobra"
genericapiserver "k8s.io/apiserver/pkg/server"
"k8s.io/apiserver/pkg/server/options"
"k8s.io/component-base/cli"
aggregatorscheme "k8s.io/kube-aggregator/pkg/apiserver/scheme"
)
const (
@@ -34,7 +33,7 @@ func newCommandStartExampleAPIServer(o *APIServerOptions, stopCh <-chan struct{}
Example: "grafana apiserver example.grafana.app",
RunE: func(c *cobra.Command, args []string) error {
// Load each group from the args
if err := o.LoadAPIGroupBuilders(args[1:]); err != nil {
if err := o.loadAPIGroupBuilders(args[1:]); err != nil {
return err
}
+8 -1
View File
@@ -12,6 +12,7 @@ import (
"k8s.io/client-go/tools/clientcmd"
netutils "k8s.io/utils/net"
"github.com/grafana/grafana/pkg/registry/apis/datasource"
"github.com/grafana/grafana/pkg/registry/apis/example"
grafanaAPIServer "github.com/grafana/grafana/pkg/services/grafana-apiserver"
"github.com/grafana/grafana/pkg/services/grafana-apiserver/utils"
@@ -39,13 +40,19 @@ func newAPIServerOptions(out, errOut io.Writer) *APIServerOptions {
}
}
func (o *APIServerOptions) LoadAPIGroupBuilders(args []string) error {
func (o *APIServerOptions) loadAPIGroupBuilders(args []string) error {
o.builders = []grafanaAPIServer.APIGroupBuilder{}
for _, g := range args {
switch g {
// No dependencies for testing
case "example.grafana.app":
o.builders = append(o.builders, example.NewTestingAPIBuilder())
case "testdata.datasource.grafana.app":
ds, err := datasource.NewStandaloneDatasource(g)
if err != nil {
return err
}
o.builders = append(o.builders, ds)
default:
return fmt.Errorf("unknown group: %s", g)
}