Merge pull request #714 from filbranden/version_fixes

Version fixes
pull/6/head
Daniel Smith 2014-07-30 19:08:21 -07:00
commit 6af0717205
9 changed files with 63 additions and 13 deletions

View File

@ -29,6 +29,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider"
"github.com/GoogleCloudPlatform/kubernetes/pkg/master"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/version"
"github.com/golang/glog"
)
@ -54,6 +55,8 @@ func main() {
util.InitLogs()
defer util.FlushLogs()
version.PrintAndExitIfRequested()
if len(machineList) == 0 {
glog.Fatal("No machines specified!")
}

View File

@ -28,6 +28,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/controller"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/version"
"github.com/coreos/go-etcd/etcd"
"github.com/golang/glog"
)
@ -46,6 +47,8 @@ func main() {
util.InitLogs()
defer util.FlushLogs()
version.PrintAndExitIfRequested()
if len(etcdServerList) == 0 || len(*master) == 0 {
glog.Fatal("usage: controller-manager -etcd_servers <servers> -master <master>")
}

View File

@ -37,7 +37,6 @@ import (
)
var (
versionFlag = flag.Bool("V", false, "Print the version number.")
serverVersion = flag.Bool("server_version", false, "Print the server's version number.")
preventSkew = flag.Bool("expect_version_match", false, "Fail if server's version doesn't match own version.")
httpServer = flag.String("h", "", "The host to connect to.")
@ -107,10 +106,7 @@ func main() {
util.InitLogs()
defer util.FlushLogs()
if *versionFlag {
fmt.Printf("Version: %#v\n", version.Get())
os.Exit(0)
}
version.PrintAndExitIfRequested()
secure := true
var masterServer string

View File

@ -35,6 +35,7 @@ import (
kconfig "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/config"
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/version"
"github.com/coreos/go-etcd/etcd"
"github.com/fsouza/go-dockerclient"
"github.com/golang/glog"
@ -95,6 +96,8 @@ func main() {
defer util.FlushLogs()
rand.Seed(time.Now().UTC().UnixNano())
version.PrintAndExitIfRequested()
etcd.SetLogger(util.NewLogger("etcd "))
dockerClient, err := docker.NewClient(getDockerEndpoint())

View File

@ -22,6 +22,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/proxy"
"github.com/GoogleCloudPlatform/kubernetes/pkg/proxy/config"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/version"
"github.com/coreos/go-etcd/etcd"
"github.com/golang/glog"
)
@ -40,6 +41,8 @@ func main() {
util.InitLogs()
defer util.FlushLogs()
version.PrintAndExitIfRequested()
// Set up logger for etcd client
etcd.SetLogger(util.NewLogger("etcd "))

View File

@ -82,7 +82,7 @@ wait_for_url "http://localhost:4001/version" "etcd: "
# Check kubecfg
out=$(${GO_OUT}/kubecfg -V)
out=$(${GO_OUT}/kubecfg -version)
echo kubecfg: $out
# Start kubelet

View File

@ -14,10 +14,28 @@
# See the License for the specific language governing permissions and
# limitations under the License.
set -o errexit
set -o nounset
set -o pipefail
topdir=$(dirname "$0")/..
cd "${topdir}"
# TODO: when we start making tags, switch to git describe?
desc=$(git rev-list --abbrev-commit --max-count=1 HEAD)
tab=$'\t'
script="22s/.*/${tab}commitFromGit = \`${desc}\`/"
infile="$(dirname $0)/../pkg/version/template.go"
outfile="$(dirname $0)/../pkg/version/autogenerated.go"
sed "${script}" "${infile}" > "${outfile}"
if git_commit=$(git rev-parse --short "HEAD^{commit}" 2>/dev/null); then
# Remove any invalid characters that might confuse "sed".
git_commit=${git_commit//[^a-f0-9]/}
# Check if the tree is dirty.
if ! dirty_tree=$(git status --porcelain) || [[ -n "${dirty_tree}" ]]; then
git_commit="${git_commit}-dirty"
fi
else
git_commit="(none)"
echo "WARNING: unable to find git commit, falling back to commitFromGit = \`${git_commit}\`" >&2
fi
# TODO: Instead of using an autogenerated file, we could pass this variable
# to the source through Go's -X ldflag.
sed "s/@@GIT_COMMIT@@/${git_commit}/g" \
pkg/version/template.go.tmpl >pkg/version/autogenerated.go

View File

@ -19,5 +19,5 @@ package version
// This file is the template for the machine-edited autogenerated.go.
// Do not modify this file without also modifying hack/version-gen.sh.
var (
placeholder interface{}
commitFromGit = `@@GIT_COMMIT@@`
)

View File

@ -16,6 +16,16 @@ limitations under the License.
package version
import (
"flag"
"fmt"
"os"
)
var (
versionFlag = flag.Bool("version", false, "Print version information and quit")
)
// Info contains versioning information.
// TODO: Add []string of api versions supported? It's still unclear
// how we'll want to distribute that information.
@ -34,3 +44,17 @@ func Get() Info {
GitCommit: commitFromGit,
}
}
// String returns info as a human-friendly version string.
func (info Info) String() string {
return fmt.Sprintf("version %s.%s, build %s", info.Major, info.Minor, info.GitCommit)
}
// 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", Get())
os.Exit(0)
}
}