Skip to content

Commit

Permalink
Merge pull request volcano-sh#144 from SrinivasChilveri/version-changes
Browse files Browse the repository at this point in the history
version related changes
  • Loading branch information
volcano-sh-bot committed May 8, 2019
2 parents 7a91eb9 + fb3da5e commit a0bcf38
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ REL_OSARCH=linux/amd64
REPO_PATH=volcano.sh/volcano
IMAGE_PREFIX=volcanosh/vk
TAG=latest
RELEASE_VER=v0.1
GitSHA=`git rev-parse HEAD`
Date=`date "+%Y-%m-%d %H:%M:%S"`
LD_FLAGS=" \
Expand Down Expand Up @@ -31,9 +32,9 @@ vkctl: init

image_bins:
go get github.com/mitchellh/gox
CGO_ENABLED=0 gox -osarch=${REL_OSARCH} -output ${BIN_DIR}/${REL_OSARCH}/vkctl ./cmd/cli
CGO_ENABLED=0 gox -osarch=${REL_OSARCH} -ldflags ${LD_FLAGS} -output ${BIN_DIR}/${REL_OSARCH}/vkctl ./cmd/cli
for name in controllers scheduler admission; do\
CGO_ENABLED=0 gox -osarch=${REL_OSARCH} -output ${BIN_DIR}/${REL_OSARCH}/vk-$$name ./cmd/$$name; \
CGO_ENABLED=0 gox -osarch=${REL_OSARCH} -ldflags ${LD_FLAGS} -output ${BIN_DIR}/${REL_OSARCH}/vk-$$name ./cmd/$$name; \
done

images: image_bins
Expand Down
2 changes: 2 additions & 0 deletions cmd/admission/app/configure/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type Config struct {
MutateWebhookName string
ValidateWebhookConfigName string
ValidateWebhookName string
PrintVersion bool
}

func NewConfig() *Config {
Expand All @@ -64,6 +65,7 @@ func (c *Config) AddFlags() {
"Name of the mutatingwebhookconfiguration resource in Kubernetes.")
flag.StringVar(&c.ValidateWebhookName, "validate-webhook-name", "validatejob.volcano.sh",
"Name of the webhook entry in the webhook config.")
flag.BoolVar(&c.PrintVersion, "version", false, "Show version and quit")
}

func (c *Config) CheckPortOrDie() error {
Expand Down
5 changes: 5 additions & 0 deletions cmd/admission/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"volcano.sh/volcano/cmd/admission/app"
appConf "volcano.sh/volcano/cmd/admission/app/configure"
admissioncontroller "volcano.sh/volcano/pkg/admission"
"volcano.sh/volcano/pkg/version"
)

func serveJobs(w http.ResponseWriter, r *http.Request) {
Expand All @@ -41,6 +42,10 @@ func main() {
config.AddFlags()
flag.Parse()

if config.PrintVersion {
version.PrintVersionAndExit()
}

http.HandleFunc(admissioncontroller.AdmitJobPath, serveJobs)
http.HandleFunc(admissioncontroller.MutateJobPath, serveMutateJobs)

Expand Down
18 changes: 18 additions & 0 deletions cmd/cli/vkctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/spf13/pflag"

"k8s.io/apimachinery/pkg/util/wait"
"volcano.sh/volcano/pkg/version"
)

var logFlushFreq = pflag.Duration("log-flush-frequency", 5*time.Second, "Maximum number of seconds between log flushes")
Expand All @@ -41,6 +42,7 @@ func main() {

rootCmd.AddCommand(buildJobCmd())
rootCmd.AddCommand(buildQueueCmd())
rootCmd.AddCommand(versionCommand())

if err := rootCmd.Execute(); err != nil {
fmt.Printf("Failed to execute command: %v", err)
Expand All @@ -59,3 +61,19 @@ func checkError(cmd *cobra.Command, err error) {
fmt.Printf("%s: %v\n", msg, err)
}
}

var versionExample = `vkctl version`

func versionCommand() *cobra.Command {

var command = &cobra.Command{
Use: "version",
Short: "Print the version information",
Long: "Print the version information",
Example: versionExample,
Run: func(cmd *cobra.Command, args []string) {
version.PrintVersionAndExit()
},
}
return command
}
2 changes: 2 additions & 0 deletions cmd/controllers/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type ServerOption struct {
LockObjectNamespace string
KubeAPIBurst int
KubeAPIQPS float32
PrintVersion bool
}

// NewServerOption creates a new CMServer with a default config.
Expand All @@ -52,6 +53,7 @@ func (s *ServerOption) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&s.LockObjectNamespace, "lock-object-namespace", s.LockObjectNamespace, "Define the namespace of the lock object.")
fs.Float32Var(&s.KubeAPIQPS, "kube-api-qps", defaultQPS, "QPS to use while talking with kubernetes apiserver")
fs.IntVar(&s.KubeAPIBurst, "kube-api-burst", defaultBurst, "Burst to use while talking with kubernetes apiserver")
fs.BoolVar(&s.PrintVersion, "version", false, "Show version and quit")
}

func (s *ServerOption) CheckOptionOrDie() error {
Expand Down
5 changes: 5 additions & 0 deletions cmd/controllers/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

"volcano.sh/volcano/cmd/controllers/app"
"volcano.sh/volcano/cmd/controllers/app/options"
"volcano.sh/volcano/pkg/version"
)

var logFlushFreq = pflag.Duration("log-flush-frequency", 5*time.Second, "Maximum number of seconds between log flushes")
Expand All @@ -37,6 +38,10 @@ func main() {
s.AddFlags(pflag.CommandLine)

flag.InitFlags()

if s.PrintVersion {
version.PrintVersionAndExit()
}
if err := s.CheckOptionOrDie(); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
Expand Down
53 changes: 53 additions & 0 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
Copyright 2019 The Volcano Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package version

import (
"fmt"
"os"
"runtime"
)

var (
// Version shows the version of volcano.
Version = "Not provided."
// GitSHA shoows the git commit id of volcano.
GitSHA = "Not provided."
// Built shows the built time of the binary.
Built = "Not provided."
apiVersion = "v1alpha1"
)

// PrintVersionAndExit prints versions from the array returned by Info() and exit
func PrintVersionAndExit() {
for _, i := range Info(apiVersion) {
fmt.Printf("%v\n", i)
}
os.Exit(0)
}

// Info returns an array of various service versions
func Info(apiVersion string) []string {
return []string{
fmt.Sprintf("API Version: %s", apiVersion),
fmt.Sprintf("Version: %s", Version),
fmt.Sprintf("Git SHA: %s", GitSHA),
fmt.Sprintf("Built At: %s", Built),
fmt.Sprintf("Go Version: %s", runtime.Version()),
fmt.Sprintf("Go OS/Arch: %s/%s", runtime.GOOS, runtime.GOARCH),
}
}

0 comments on commit a0bcf38

Please sign in to comment.