Add version to controller info response

This change adds the GARM server version to the controller info response.

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
This commit is contained in:
Gabriel Adrian Samfira 2024-07-05 11:40:22 +00:00
parent dcee09281b
commit 42ae3c52d1
10 changed files with 43 additions and 16 deletions

View file

@ -145,7 +145,10 @@ func renderControllerInfoTable(info params.ControllerInfo) string {
if info.ControllerWebhookURL == "" {
info.ControllerWebhookURL = "N/A"
}
serverVersion := "v0.0.0-unknown"
if info.Version != "" {
serverVersion = info.Version
}
t.AppendHeader(header)
t.AppendRow(table.Row{"Controller ID", info.ControllerID})
if info.Hostname != "" {
@ -156,6 +159,7 @@ func renderControllerInfoTable(info params.ControllerInfo) string {
t.AppendRow(table.Row{"Webhook Base URL", info.WebhookURL})
t.AppendRow(table.Row{"Controller Webhook URL", info.ControllerWebhookURL})
t.AppendRow(table.Row{"Minimum Job Age Backoff", info.MinimumJobAgeBackoff})
t.AppendRow(table.Row{"Version", serverVersion})
return t.Render()
}

View file

@ -29,8 +29,6 @@ import (
"github.com/cloudbase/garm/params"
)
var Version string
var (
cfg *config.Config
mgr config.Manager

View file

@ -18,6 +18,9 @@ import (
"fmt"
"github.com/spf13/cobra"
apiClientControllerInfo "github.com/cloudbase/garm/client/controller_info"
"github.com/cloudbase/garm/util/appdefaults"
)
// runnerCmd represents the runner command
@ -26,7 +29,18 @@ var versionCmd = &cobra.Command{
SilenceUsage: true,
Short: "Print version and exit",
Run: func(_ *cobra.Command, _ []string) {
fmt.Println(Version)
serverVersion := "v0.0.0-unknown"
if !needsInit {
showInfo := apiClientControllerInfo.NewControllerInfoParams()
response, err := apiCli.ControllerInfo.ControllerInfo(showInfo, authToken)
if err == nil {
serverVersion = response.Payload.Version
}
}
fmt.Printf("garm-cli: %s\n", appdefaults.GetVersion())
fmt.Printf("garm server: %s\n", serverVersion)
},
}

View file

@ -55,8 +55,6 @@ var (
version = flag.Bool("version", false, "prints version")
)
var Version string
var signals = []os.Signal{
os.Interrupt,
syscall.SIGTERM,
@ -179,7 +177,7 @@ func maybeUpdateURLsFromConfig(cfg config.Config, store common.Store) error {
func main() {
flag.Parse()
if *version {
fmt.Println(Version)
fmt.Println(appdefaults.GetVersion())
return
}
ctx, stop := signal.NotifyContext(context.Background(), signals...)