K8s: Move standalone apiserver CLI to enterprise (#93799)

This commit is contained in:
Ryan McKinley
2024-09-27 09:04:35 +03:00
committed by GitHub
parent e672796632
commit 87c81825b7
24 changed files with 63 additions and 924 deletions
+3 -2
View File
@@ -5,10 +5,11 @@ import (
"time"
"github.com/grafana/grafana/pkg/extensions"
"github.com/grafana/grafana/pkg/services/apiserver/standalone"
"github.com/grafana/grafana/pkg/setting"
)
func getBuildstamp(opts ServerOptions) int64 {
func getBuildstamp(opts standalone.BuildInfo) int64 {
buildstampInt64, err := strconv.ParseInt(opts.BuildStamp, 10, 64)
if err != nil || buildstampInt64 == 0 {
buildstampInt64 = time.Now().Unix()
@@ -16,7 +17,7 @@ func getBuildstamp(opts ServerOptions) int64 {
return buildstampInt64
}
func SetBuildInfo(opts ServerOptions) {
func SetBuildInfo(opts standalone.BuildInfo) {
setting.BuildVersion = opts.Version
setting.BuildCommit = opts.Commit
setting.EnterpriseBuildCommit = opts.EnterpriseCommit
+5 -14
View File
@@ -21,38 +21,29 @@ import (
"github.com/grafana/grafana/pkg/infra/metrics"
"github.com/grafana/grafana/pkg/infra/process"
"github.com/grafana/grafana/pkg/server"
"github.com/grafana/grafana/pkg/services/apiserver/standalone"
"github.com/grafana/grafana/pkg/setting"
)
type ServerOptions struct {
Version string
Commit string
EnterpriseCommit string
BuildBranch string
BuildStamp string
Context *cli.Context
}
func ServerCommand(version, commit, enterpriseCommit, buildBranch, buildstamp string) *cli.Command {
return &cli.Command{
Name: "server",
Usage: "run the grafana server",
Flags: commonFlags,
Action: func(context *cli.Context) error {
return RunServer(ServerOptions{
return RunServer(standalone.BuildInfo{
Version: version,
Commit: commit,
EnterpriseCommit: enterpriseCommit,
BuildBranch: buildBranch,
BuildStamp: buildstamp,
Context: context,
})
}, context)
},
Subcommands: []*cli.Command{TargetCommand(version, commit, buildBranch, buildstamp)},
}
}
func RunServer(opts ServerOptions) error {
func RunServer(opts standalone.BuildInfo, cli *cli.Context) error {
if Version || VerboseVersion {
if opts.EnterpriseCommit != gcli.DefaultCommitValue && opts.EnterpriseCommit != "" {
fmt.Printf("Version %s (commit: %s, branch: %s, enterprise-commit: %s)\n", opts.Version, opts.Commit, opts.BuildBranch, opts.EnterpriseCommit)
@@ -106,7 +97,7 @@ func RunServer(opts ServerOptions) error {
Config: ConfigFile,
HomePath: HomePath,
// tailing arguments have precedence over the options string
Args: append(configOptions, opts.Context.Args().Slice()...),
Args: append(configOptions, cli.Args().Slice()...),
})
if err != nil {
return err
+5 -5
View File
@@ -13,6 +13,7 @@ import (
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/infra/metrics"
"github.com/grafana/grafana/pkg/server"
"github.com/grafana/grafana/pkg/services/apiserver/standalone"
"github.com/grafana/grafana/pkg/setting"
)
@@ -22,18 +23,17 @@ func TargetCommand(version, commit, buildBranch, buildstamp string) *cli.Command
Usage: "target specific grafana dskit services",
Flags: commonFlags,
Action: func(context *cli.Context) error {
return RunTargetServer(ServerOptions{
return RunTargetServer(standalone.BuildInfo{
Version: version,
Commit: commit,
BuildBranch: buildBranch,
BuildStamp: buildstamp,
Context: context,
})
}, context)
},
}
}
func RunTargetServer(opts ServerOptions) error {
func RunTargetServer(opts standalone.BuildInfo, cli *cli.Context) error {
if Version || VerboseVersion {
fmt.Printf("Version %s (commit: %s, branch: %s)\n", opts.Version, opts.Commit, opts.BuildBranch)
if VerboseVersion {
@@ -83,7 +83,7 @@ func RunTargetServer(opts ServerOptions) error {
Config: ConfigFile,
HomePath: HomePath,
// tailing arguments have precedence over the options string
Args: append(configOptions, opts.Context.Args().Slice()...),
Args: append(configOptions, cli.Args().Slice()...),
})
if err != nil {
return err