mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Merge pull request #1121 from filbranden/rawversion2
Add support for -version=raw
This commit is contained in:
commit
8ad98db773
@ -30,7 +30,7 @@ import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/master"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
verflag "github.com/GoogleCloudPlatform/kubernetes/pkg/version/flag"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/version/verflag"
|
||||
"github.com/golang/glog"
|
||||
)
|
||||
|
||||
|
@ -27,7 +27,7 @@ import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/controller"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
verflag "github.com/GoogleCloudPlatform/kubernetes/pkg/version/flag"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/version/verflag"
|
||||
"github.com/golang/glog"
|
||||
)
|
||||
|
||||
|
@ -34,7 +34,7 @@ import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/version"
|
||||
verflag "github.com/GoogleCloudPlatform/kubernetes/pkg/version/flag"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/version/verflag"
|
||||
"github.com/golang/glog"
|
||||
)
|
||||
|
||||
|
@ -36,7 +36,7 @@ import (
|
||||
kconfig "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/config"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
verflag "github.com/GoogleCloudPlatform/kubernetes/pkg/version/flag"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/version/verflag"
|
||||
"github.com/coreos/go-etcd/etcd"
|
||||
"github.com/fsouza/go-dockerclient"
|
||||
"github.com/golang/glog"
|
||||
|
@ -24,7 +24,7 @@ import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/proxy"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/proxy/config"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
verflag "github.com/GoogleCloudPlatform/kubernetes/pkg/version/flag"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/version/verflag"
|
||||
"github.com/coreos/go-etcd/etcd"
|
||||
"github.com/golang/glog"
|
||||
)
|
||||
|
@ -1,39 +0,0 @@
|
||||
/*
|
||||
Copyright 2014 Google Inc. All rights reserved.
|
||||
|
||||
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 flag defines utility functions to handle command line flags related to version of Kubernetes.
|
||||
package flag
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/version"
|
||||
)
|
||||
|
||||
var (
|
||||
versionFlag = flag.Bool("version", false, "Print version information and quit")
|
||||
)
|
||||
|
||||
// PrintAndExitIfRequested will check if the -version flag was passed
|
||||
// and, if so, print the version and exit.
|
||||
func PrintAndExitIfRequested() {
|
||||
if *versionFlag {
|
||||
fmt.Printf("Kubernetes %s\n", version.Get())
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
94
pkg/version/verflag/verflag.go
Normal file
94
pkg/version/verflag/verflag.go
Normal file
@ -0,0 +1,94 @@
|
||||
/*
|
||||
Copyright 2014 Google Inc. All rights reserved.
|
||||
|
||||
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 verflag defines utility functions to handle command line flags
|
||||
// related to version of Kubernetes.
|
||||
package verflag
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/version"
|
||||
)
|
||||
|
||||
type versionValue int
|
||||
|
||||
const (
|
||||
VersionFalse versionValue = 0
|
||||
VersionTrue versionValue = 1
|
||||
VersionRaw versionValue = 2
|
||||
)
|
||||
|
||||
const strRawVersion string = "raw"
|
||||
|
||||
func (v *versionValue) IsBoolFlag() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (v *versionValue) Get() interface{} {
|
||||
return versionValue(*v)
|
||||
}
|
||||
|
||||
func (v *versionValue) Set(s string) error {
|
||||
if s == strRawVersion {
|
||||
*v = VersionRaw
|
||||
return nil
|
||||
}
|
||||
boolVal, err := strconv.ParseBool(s)
|
||||
if boolVal {
|
||||
*v = VersionTrue
|
||||
} else {
|
||||
*v = VersionFalse
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (v *versionValue) String() string {
|
||||
if *v == VersionRaw {
|
||||
return strRawVersion
|
||||
}
|
||||
return fmt.Sprintf("%v", bool(*v == VersionTrue))
|
||||
}
|
||||
|
||||
func VersionVar(p *versionValue, name string, value versionValue, usage string) {
|
||||
*p = value
|
||||
flag.Var(p, name, usage)
|
||||
}
|
||||
|
||||
func Version(name string, value versionValue, usage string) *versionValue {
|
||||
p := new(versionValue)
|
||||
VersionVar(p, name, value, usage)
|
||||
return p
|
||||
}
|
||||
|
||||
var (
|
||||
versionFlag = Version("version", VersionFalse, "Print version information and quit")
|
||||
)
|
||||
|
||||
// PrintAndExitIfRequested will check if the -version flag was passed
|
||||
// and, if so, print the version and exit.
|
||||
func PrintAndExitIfRequested() {
|
||||
if *versionFlag == VersionRaw {
|
||||
fmt.Printf("%#v\n", version.Get())
|
||||
os.Exit(0)
|
||||
} else if *versionFlag == VersionTrue {
|
||||
fmt.Printf("Kubernetes %s\n", version.Get())
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
@ -21,7 +21,7 @@ import (
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
verflag "github.com/GoogleCloudPlatform/kubernetes/pkg/version/flag"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/version/verflag"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler/factory"
|
||||
"github.com/golang/glog"
|
||||
|
Loading…
Reference in New Issue
Block a user