|
|
|
|
@ -15,6 +15,7 @@ import ( |
|
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/apiserver/builder" |
|
|
|
|
grafanaAPIServer "github.com/grafana/grafana/pkg/services/apiserver" |
|
|
|
|
grafanaAPIServerOptions "github.com/grafana/grafana/pkg/services/apiserver/options" |
|
|
|
|
"github.com/grafana/grafana/pkg/services/apiserver/standalone" |
|
|
|
|
"github.com/grafana/grafana/pkg/services/apiserver/utils" |
|
|
|
|
"github.com/grafana/grafana/pkg/setting" |
|
|
|
|
@ -29,6 +30,7 @@ const ( |
|
|
|
|
type APIServerOptions struct { |
|
|
|
|
factory standalone.APIServerFactory |
|
|
|
|
builders []builder.APIGroupBuilder |
|
|
|
|
ExtraOptions *grafanaAPIServerOptions.ExtraOptions |
|
|
|
|
RecommendedOptions *options.RecommendedOptions |
|
|
|
|
AlternateDNS []string |
|
|
|
|
|
|
|
|
|
@ -40,6 +42,11 @@ func newAPIServerOptions(out, errOut io.Writer) *APIServerOptions { |
|
|
|
|
return &APIServerOptions{ |
|
|
|
|
StdOut: out, |
|
|
|
|
StdErr: errOut, |
|
|
|
|
RecommendedOptions: options.NewRecommendedOptions( |
|
|
|
|
defaultEtcdPathPrefix, |
|
|
|
|
grafanaAPIServer.Codecs.LegacyCodec(), // the codec is passed to etcd and not used
|
|
|
|
|
), |
|
|
|
|
ExtraOptions: grafanaAPIServerOptions.NewExtraOptions(), |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -148,6 +155,12 @@ func (o *APIServerOptions) Config() (*genericapiserver.RecommendedConfig, error) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if o.ExtraOptions != nil { |
|
|
|
|
if err := o.ExtraOptions.ApplyTo(serverConfig); err != nil { |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
serverConfig.DisabledPostStartHooks = serverConfig.DisabledPostStartHooks.Insert("generic-apiserver-start-informers") |
|
|
|
|
serverConfig.DisabledPostStartHooks = serverConfig.DisabledPostStartHooks.Insert("priority-and-fairness-config-consumer") |
|
|
|
|
|
|
|
|
|
@ -165,12 +178,15 @@ func (o *APIServerOptions) Config() (*genericapiserver.RecommendedConfig, error) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Validate validates APIServerOptions
|
|
|
|
|
// NOTE: we don't call validate on the top level recommended options as it doesn't like skipping etcd-servers
|
|
|
|
|
// the function is left here for troubleshooting any other config issues
|
|
|
|
|
func (o *APIServerOptions) Validate(args []string) error { |
|
|
|
|
errors := []error{} |
|
|
|
|
errors = append(errors, o.RecommendedOptions.Validate()...) |
|
|
|
|
errors = append(errors, o.factory.GetOptions().ValidateOptions()...) |
|
|
|
|
func (o *APIServerOptions) Validate() error { |
|
|
|
|
errors := make([]error, 0) |
|
|
|
|
// NOTE: we don't call validate on the top level recommended options as it doesn't like skipping etcd-servers
|
|
|
|
|
// the function is left here for troubleshooting any other config issues
|
|
|
|
|
// errors = append(errors, o.RecommendedOptions.Validate()...)
|
|
|
|
|
if factoryOptions := o.factory.GetOptions(); factoryOptions != nil { |
|
|
|
|
errors = append(errors, factoryOptions.ValidateOptions()...) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return utilerrors.NewAggregate(errors) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -183,7 +199,7 @@ func (o *APIServerOptions) RunAPIServer(config *genericapiserver.RecommendedConf |
|
|
|
|
delegationTarget := genericapiserver.NewEmptyDelegate() |
|
|
|
|
completedConfig := config.Complete() |
|
|
|
|
|
|
|
|
|
server, err := completedConfig.New("example-apiserver", delegationTarget) |
|
|
|
|
server, err := completedConfig.New("standalone-apiserver", delegationTarget) |
|
|
|
|
if err != nil { |
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
|
@ -195,11 +211,13 @@ func (o *APIServerOptions) RunAPIServer(config *genericapiserver.RecommendedConf |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// write the local config to disk
|
|
|
|
|
if err = clientcmd.WriteToFile( |
|
|
|
|
utils.FormatKubeConfig(server.LoopbackClientConfig), |
|
|
|
|
path.Join(dataPath, "apiserver.kubeconfig"), |
|
|
|
|
); err != nil { |
|
|
|
|
return err |
|
|
|
|
if o.ExtraOptions.DevMode { |
|
|
|
|
if err = clientcmd.WriteToFile( |
|
|
|
|
utils.FormatKubeConfig(server.LoopbackClientConfig), |
|
|
|
|
path.Join(dataPath, "apiserver.kubeconfig"), |
|
|
|
|
); err != nil { |
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return server.PrepareRun().Run(stopCh) |
|
|
|
|
|