Skip to content

Commit

Permalink
[Feature]Add subcommand --version (ray-project#166)
Browse files Browse the repository at this point in the history
* add subcommand --version

* fix

* lint

Co-authored-by: wuhua.ck <[email protected]>
  • Loading branch information
chenk008 and wuhua.ck committed Mar 8, 2022
1 parent faebcc8 commit fd72e71
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
10 changes: 9 additions & 1 deletion ray-operator/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
BUILD_TIME := $(shell date "+%F %T")
COMMIT_SHA1 := $(shell git rev-parse HEAD )

# Image URL to use all building/pushing image targets
IMG ?= controller:latest
Expand Down Expand Up @@ -58,7 +60,13 @@ test: manifests generate fmt vet ## Run tests.
##@ Build

build: generate fmt vet ## Build manager binary.
go build -o bin/manager main.go
go build \
-ldflags \
" \
-X 'main._buildTime_=${BUILD_TIME}' \
-X 'main._commitId_=${COMMIT_SHA1}' \
" \
-o bin/manager main.go

run: manifests generate fmt vet ## Run a controller from your host.
go run ./main.go
Expand Down
16 changes: 14 additions & 2 deletions ray-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"flag"
"fmt"
"os"

"sigs.k8s.io/controller-runtime/pkg/healthz"
Expand All @@ -19,8 +20,11 @@ import (
)

var (
scheme = runtime.NewScheme()
setupLog = ctrl.Log.WithName("setup")
_version_ = "0.2"
_buildTime_ = ""
_commitId_ = ""
scheme = runtime.NewScheme()
setupLog = ctrl.Log.WithName("setup")
)

func init() {
Expand All @@ -30,11 +34,13 @@ func init() {
}

func main() {
var version bool
var metricsAddr string
var enableLeaderElection bool
var probeAddr string
var reconcileConcurrency int
var watchNamespace string
flag.BoolVar(&version, "version", false, "Show the version information.")
flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.BoolVar(&enableLeaderElection, "enable-leader-election", true,
Expand All @@ -50,6 +56,12 @@ func main() {
}
opts.BindFlags(flag.CommandLine)
flag.Parse()
if version {
fmt.Printf("Version:\t%s\n", _version_)
fmt.Printf("Commit ID:\t%s\n", _commitId_)
fmt.Printf("Build time:\t%s\n", _buildTime_)
os.Exit(0)
}

ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))

Expand Down

0 comments on commit fd72e71

Please sign in to comment.