Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]Add subcommand --version #166

Merged
merged 4 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 \
Jeffwan marked this conversation as resolved.
Show resolved Hide resolved
-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
20 changes: 16 additions & 4 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,14 +34,16 @@ 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", false,
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8082", "The address the probe endpoint binds to.")
flag.BoolVar(&enableLeaderElection, "enable-leader-election", true,
"Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager.")
flag.IntVar(&reconcileConcurrency, "reconcile-concurrency", 1, "max concurrency for reconciling")
flag.StringVar(
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