Skip to content

Commit b14a84b

Browse files
committed
Add version support to daemon, gateway, and pilotctl
All three client binaries now accept version injection via ldflags (-X main.version=vX.Y.Z). Daemon and gateway expose -version flag, pilotctl exposes 'version' subcommand (used by install.sh for update detection). Also adds pilotctl member-tags subcommand.
1 parent 0250455 commit b14a84b

3 files changed

Lines changed: 121 additions & 0 deletions

File tree

cmd/daemon/main.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"flag"
5+
"fmt"
56
"log"
67
"log/slog"
78
"os"
@@ -15,6 +16,8 @@ import (
1516
"github.com/TeoSlayer/pilotprotocol/pkg/logging"
1617
)
1718

19+
var version = "dev"
20+
1821
func main() {
1922
configPath := flag.String("config", "", "path to config file (JSON)")
2023
registryAddr := flag.String("registry", "34.71.57.205:9000", "registry server address")
@@ -43,10 +46,16 @@ func main() {
4346
webhookURL := flag.String("webhook", "", "HTTP(S) endpoint for event notifications (empty = disabled)")
4447
adminToken := flag.String("admin-token", "", "admin token for network operations")
4548
networks := flag.String("networks", "", "comma-separated network IDs to auto-join at startup")
49+
showVersion := flag.Bool("version", false, "print version and exit")
4650
logLevel := flag.String("log-level", "info", "log level (debug, info, warn, error)")
4751
logFormat := flag.String("log-format", "text", "log format (text, json)")
4852
flag.Parse()
4953

54+
if *showVersion {
55+
fmt.Println(version)
56+
os.Exit(0)
57+
}
58+
5059
if *configPath != "" {
5160
cfg, err := config.Load(*configPath)
5261
if err != nil {

cmd/gateway/main.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,23 @@ import (
1818
"github.com/TeoSlayer/pilotprotocol/pkg/protocol"
1919
)
2020

21+
var version = "dev"
22+
2123
func main() {
2224
configPath := flag.String("config", "", "path to config file (JSON)")
2325
socketPath := flag.String("socket", "/tmp/pilot.sock", "daemon socket path")
2426
subnet := flag.String("subnet", "10.4.0.0/16", "local IP subnet for mappings")
2527
portsStr := flag.String("ports", "", "comma-separated ports to proxy (default: 80,443,1000,1001,1002,7,8080,8443)")
28+
showVersion := flag.Bool("version", false, "print version and exit")
2629
logLevel := flag.String("log-level", "info", "log level (debug, info, warn, error)")
2730
logFormat := flag.String("log-format", "text", "log format (text, json)")
2831
flag.Parse()
2932

33+
if *showVersion {
34+
fmt.Println(version)
35+
os.Exit(0)
36+
}
37+
3038
if *configPath != "" {
3139
cfg, err := config.Load(*configPath)
3240
if err != nil {

cmd/pilotctl/main.go

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import (
3030
"github.com/TeoSlayer/pilotprotocol/pkg/tasksubmit"
3131
)
3232

33+
var version = "dev"
34+
3335
// Global flags
3436
var jsonOutput bool
3537

@@ -439,6 +441,9 @@ Environment:
439441
PILOT_REGISTRY Registry address (default: 34.71.57.205:9000)
440442
PILOT_SOCKET Daemon socket path (default: /tmp/pilot.sock)
441443
444+
Version:
445+
pilotctl version
446+
442447
Config file: ~/.pilot/config.json
443448
`)
444449
os.Exit(2)
@@ -465,6 +470,10 @@ func main() {
465470
cmdArgs := args[1:]
466471

467472
switch cmd {
473+
case "version":
474+
fmt.Println(version)
475+
return
476+
468477
// Bootstrap
469478
case "init":
470479
cmdInit(cmdArgs)
@@ -676,6 +685,23 @@ func main() {
676685
"unknown managed subcommand: %s", cmdArgs[0])
677686
}
678687

688+
case "member-tags":
689+
if len(cmdArgs) < 1 {
690+
fatalHint("invalid_argument",
691+
"available: set, get",
692+
"usage: pilotctl member-tags <subcommand>")
693+
}
694+
switch cmdArgs[0] {
695+
case "set":
696+
cmdMemberTagsSet(cmdArgs[1:])
697+
case "get":
698+
cmdMemberTagsGet(cmdArgs[1:])
699+
default:
700+
fatalHint("invalid_argument",
701+
"available: set, get",
702+
"unknown member-tags subcommand: %s", cmdArgs[0])
703+
}
704+
679705
case "policy":
680706
if len(cmdArgs) < 1 {
681707
fatalHint("invalid_argument",
@@ -5444,3 +5470,81 @@ func directiveTypeName(dt policy.DirectiveType) string {
54445470
return "unknown"
54455471
}
54465472
}
5473+
5474+
func cmdMemberTagsSet(args []string) {
5475+
flags, _ := parseFlags(args)
5476+
netID := parseUint16(flagString(flags, "net", "0"), "net")
5477+
nodeID := flagString(flags, "node", "0")
5478+
tagsStr := flagString(flags, "tags", "")
5479+
5480+
if netID == 0 || nodeID == "0" || tagsStr == "" {
5481+
fatalCode("invalid_argument", "usage: pilotctl member-tags set --net <id> --node <id> --tags tag1,tag2")
5482+
}
5483+
5484+
nid, err := strconv.ParseUint(nodeID, 10, 32)
5485+
if err != nil {
5486+
fatalCode("invalid_argument", "invalid node ID: %s", nodeID)
5487+
}
5488+
5489+
tags := strings.Split(tagsStr, ",")
5490+
5491+
d := connectDriver()
5492+
defer d.Close()
5493+
5494+
result, err := d.MemberTagsSet(netID, uint32(nid), tags)
5495+
if err != nil {
5496+
fatalCode("connection_failed", "member-tags set: %v", err)
5497+
}
5498+
5499+
if jsonOutput {
5500+
output(result)
5501+
return
5502+
}
5503+
fmt.Printf("Member tags set for node %d in network %d: %s\n", uint32(nid), netID, strings.Join(tags, ", "))
5504+
}
5505+
5506+
func cmdMemberTagsGet(args []string) {
5507+
flags, _ := parseFlags(args)
5508+
netID := parseUint16(flagString(flags, "net", "0"), "net")
5509+
nodeID := flagString(flags, "node", "0")
5510+
5511+
if netID == 0 {
5512+
fatalCode("invalid_argument", "usage: pilotctl member-tags get --net <id> [--node <id>]")
5513+
}
5514+
5515+
nid, err := strconv.ParseUint(nodeID, 10, 32)
5516+
if err != nil {
5517+
fatalCode("invalid_argument", "invalid node ID: %s", nodeID)
5518+
}
5519+
5520+
d := connectDriver()
5521+
defer d.Close()
5522+
5523+
result, err := d.MemberTagsGet(netID, uint32(nid))
5524+
if err != nil {
5525+
fatalCode("connection_failed", "member-tags get: %v", err)
5526+
}
5527+
5528+
if jsonOutput {
5529+
output(result)
5530+
return
5531+
}
5532+
5533+
if uint32(nid) != 0 {
5534+
if tags, ok := result["tags"].([]interface{}); ok {
5535+
tagStrs := make([]string, len(tags))
5536+
for i, t := range tags {
5537+
tagStrs[i] = fmt.Sprint(t)
5538+
}
5539+
fmt.Printf("Node %d in network %d: %s\n", uint32(nid), netID, strings.Join(tagStrs, ", "))
5540+
} else {
5541+
fmt.Printf("Node %d in network %d: (no tags)\n", uint32(nid), netID)
5542+
}
5543+
} else {
5544+
if members, ok := result["members"].(map[string]interface{}); ok {
5545+
for mid, tags := range members {
5546+
fmt.Printf(" node %s: %v\n", mid, tags)
5547+
}
5548+
}
5549+
}
5550+
}

0 commit comments

Comments
 (0)