Skip to content
This repository has been archived by the owner on May 25, 2023. It is now read-only.

Add version options for kube-batch #490

Merged
merged 1 commit into from
Dec 5, 2018
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
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
BIN_DIR=_output/bin
RELEASE_VER=v0.2
REPO_PATH=github.com/kubernetes-sigs/kube-batch
GitSHA=`git rev-parse HEAD`
Date=`date "+%Y-%m-%d %H:%M:%S"`

kube-batch: init
go build -o ${BIN_DIR}/kube-batch ./cmd/kube-batch/
go build -ldflags " \
-X '${REPO_PATH}/pkg/version.GitSHA=${GitSHA}' \
-X '${REPO_PATH}/pkg/version.Built=${Date}' \
-X '${REPO_PATH}/pkg/version.Version=${RELEASE_VER}'" \
-o _output/bin/kube-batch ./cmd/kube-batch

verify: generate-code
hack/verify-gofmt.sh
Expand Down
2 changes: 2 additions & 0 deletions cmd/kube-batch/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type ServerOption struct {
EnableLeaderElection bool
LockObjectNamespace string
DefaultQueue string
PrintVersion bool
}

var (
Expand Down Expand Up @@ -66,6 +67,7 @@ func (s *ServerOption) AddFlags(fs *pflag.FlagSet) {
"executing the main loop. Enable this when running replicated kube-batch for high availability")
fs.BoolVar(&s.NamespaceAsQueue, "enable-namespace-as-queue", true, "Make Namespace as Queue with weight one, "+
"but kube-batch will not handle Queue CRD anymore")
fs.BoolVar(&s.PrintVersion, "version", false, "Show version and quit")
fs.StringVar(&s.LockObjectNamespace, "lock-object-namespace", s.LockObjectNamespace, "Define the namespace of the lock object")
}

Expand Down
7 changes: 7 additions & 0 deletions cmd/kube-batch/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"github.com/golang/glog"
"github.com/kubernetes-sigs/kube-batch/cmd/kube-batch/app/options"
"github.com/kubernetes-sigs/kube-batch/pkg/scheduler"
"github.com/kubernetes-sigs/kube-batch/pkg/version"

"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/uuid"
clientset "k8s.io/client-go/kubernetes"
Expand All @@ -42,6 +44,7 @@ const (
leaseDuration = 15 * time.Second
renewDeadline = 10 * time.Second
retryPeriod = 5 * time.Second
apiVersion = "v1alpha1"
)

func buildConfig(master, kubeconfig string) (*rest.Config, error) {
Expand All @@ -52,6 +55,10 @@ func buildConfig(master, kubeconfig string) (*rest.Config, error) {
}

func Run(opt *options.ServerOption) error {
if opt.PrintVersion {
version.PrintVersionAndExit(apiVersion)
}

config, err := buildConfig(opt.Master, opt.Kubeconfig)
if err != nil {
return err
Expand Down
52 changes: 52 additions & 0 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
Copyright 2017 The Kubernetes 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 kube-batch.
Version = "Not provided."
// GitSHA shoows the git commit id of kube-batch.
GitSHA = "Not provided."
// Built shows the built time of the binary.
Built = "Not provided."
)

// PrintVersionAndExit prints versions from the array returned by Info() and exit
func PrintVersionAndExit(apiVersion string) {
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),
}
}