Skip to content

Commit

Permalink
K8s: Move standalone apiserver CLI to enterprise (grafana#93799)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryantxu authored Sep 27, 2024
1 parent e672796 commit 87c8182
Show file tree
Hide file tree
Showing 24 changed files with 62 additions and 923 deletions.
1 change: 0 additions & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
/pkg/apis/query @grafana/grafana-datasources-core-services
/pkg/bus/ @grafana/grafana-search-and-storage
/pkg/cmd/ @grafana/grafana-backend-group
/pkg/cmd/grafana/apiserver @grafana/grafana-app-platform-squad
/pkg/components/apikeygen/ @grafana/identity-squad
/pkg/components/satokengen/ @grafana/identity-squad
/pkg/components/dashdiffs/ @grafana/grafana-app-platform-squad
Expand Down
5 changes: 3 additions & 2 deletions pkg/cmd/grafana-server/commands/buildinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@ 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()
}
return buildstampInt64
}

func SetBuildInfo(opts ServerOptions) {
func SetBuildInfo(opts standalone.BuildInfo) {
setting.BuildVersion = opts.Version
setting.BuildCommit = opts.Commit
setting.EnterpriseBuildCommit = opts.EnterpriseCommit
Expand Down
19 changes: 5 additions & 14 deletions pkg/cmd/grafana-server/commands/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions pkg/cmd/grafana-server/commands/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
60 changes: 0 additions & 60 deletions pkg/cmd/grafana/apiserver/apiserver.md

This file was deleted.

157 changes: 0 additions & 157 deletions pkg/cmd/grafana/apiserver/cmd.go

This file was deleted.

15 changes: 0 additions & 15 deletions pkg/cmd/grafana/apiserver/deploy/aggregator-test/apiservice.yaml

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 87c8182

Please sign in to comment.