mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 06:27:05 +00:00
Merge pull request #1063 from filbranden/versioning_fixes2
Grab complete version information from git
This commit is contained in:
commit
b1ebfd4824
@ -32,7 +32,7 @@ cd "${KUBE_REPO_ROOT}"
|
|||||||
kube::setup_go_environment
|
kube::setup_go_environment
|
||||||
|
|
||||||
# Fetch the version.
|
# Fetch the version.
|
||||||
version=$(gitcommit)
|
version_ldflags=$(kube::version_ldflags)
|
||||||
|
|
||||||
if [[ $# == 0 ]]; then
|
if [[ $# == 0 ]]; then
|
||||||
# Update $@ with the default list of targets to build.
|
# Update $@ with the default list of targets to build.
|
||||||
@ -48,4 +48,4 @@ done
|
|||||||
# our cluster deploy. If we add more command line options to our standard build
|
# our cluster deploy. If we add more command line options to our standard build
|
||||||
# we'll want to duplicate them there. As we move to distributing pre- built
|
# we'll want to duplicate them there. As we move to distributing pre- built
|
||||||
# binaries we can eliminate this duplication.
|
# binaries we can eliminate this duplication.
|
||||||
go install -ldflags "-X github.com/GoogleCloudPlatform/kubernetes/pkg/version.gitCommit '${version}'" "${binaries[@]}"
|
go install -ldflags "${version_ldflags}" "${binaries[@]}"
|
||||||
|
@ -17,27 +17,43 @@
|
|||||||
# This script sets up a go workspace locally and builds all go components.
|
# This script sets up a go workspace locally and builds all go components.
|
||||||
# You can 'source' this file if you want to set up GOPATH in your local shell.
|
# You can 'source' this file if you want to set up GOPATH in your local shell.
|
||||||
|
|
||||||
# gitcommit prints the current Git commit information
|
# --- Helper Functions ---
|
||||||
function gitcommit() {
|
|
||||||
set -o errexit
|
|
||||||
set -o nounset
|
|
||||||
set -o pipefail
|
|
||||||
|
|
||||||
topdir=$(dirname "$0")/..
|
# Function kube::version_ldflags() prints the value that needs to be passed to
|
||||||
cd "${topdir}"
|
# the -ldflags parameter of go build in order to set the Kubernetes based on the
|
||||||
|
# git tree status.
|
||||||
|
kube::version_ldflags() {
|
||||||
|
(
|
||||||
|
# Run this in a subshell to prevent settings/variables from leaking.
|
||||||
|
set -o errexit
|
||||||
|
set -o nounset
|
||||||
|
set -o pipefail
|
||||||
|
|
||||||
# TODO: when we start making tags, switch to git describe?
|
unset CDPATH
|
||||||
if git_commit=$(git rev-parse --short "HEAD^{commit}" 2>/dev/null); then
|
|
||||||
# Check if the tree is dirty.
|
cd "${KUBE_REPO_ROOT}"
|
||||||
if ! dirty_tree=$(git status --porcelain) || [[ -n "${dirty_tree}" ]]; then
|
|
||||||
echo "${git_commit}-dirty"
|
declare -a ldflags=()
|
||||||
else
|
if git_commit=$(git rev-parse "HEAD^{commit}" 2>/dev/null); then
|
||||||
echo "${git_commit}"
|
ldflags+=(-X "${KUBE_GO_PACKAGE}/pkg/version.gitCommit" "${git_commit}")
|
||||||
|
|
||||||
|
# Check if the tree is dirty.
|
||||||
|
if git_status=$(git status --porcelain) && [[ -z "${git_status}" ]]; then
|
||||||
|
git_tree_state="clean"
|
||||||
|
else
|
||||||
|
git_tree_state="dirty"
|
||||||
|
fi
|
||||||
|
ldflags+=(-X "${KUBE_GO_PACKAGE}/pkg/version.gitTreeState" "${git_tree_state}")
|
||||||
|
|
||||||
|
# Use git describe to find the version based on annotated tags.
|
||||||
|
if git_version=$(git describe --abbrev=14 "${git_commit}^{commit}" 2>/dev/null); then
|
||||||
|
ldflags+=(-X "${KUBE_GO_PACKAGE}/pkg/version.gitVersion" "${git_version}")
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
|
||||||
echo "(none)"
|
# The -ldflags parameter takes a single string, so join the output.
|
||||||
fi
|
echo "${ldflags[*]}"
|
||||||
return 0
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
# kube::setup_go_environment will check that `go` and `godep` commands are
|
# kube::setup_go_environment will check that `go` and `godep` commands are
|
||||||
|
@ -26,6 +26,8 @@ INSTANCE_PREFIX=$1
|
|||||||
|
|
||||||
KUBE_DIR=$SCRIPT_DIR/..
|
KUBE_DIR=$SCRIPT_DIR/..
|
||||||
|
|
||||||
|
. "${KUBE_DIR}/hack/config-go.sh"
|
||||||
|
|
||||||
# Next build the release tar. This gets copied on to the master and installed
|
# Next build the release tar. This gets copied on to the master and installed
|
||||||
# from there. It includes the go source for the necessary servers along with
|
# from there. It includes the go source for the necessary servers along with
|
||||||
# the salt configs.
|
# the salt configs.
|
||||||
@ -41,15 +43,11 @@ cp -r $KUBE_DIR/cluster/saltbase $MASTER_RELEASE_DIR/src/saltbase
|
|||||||
|
|
||||||
# Capture the same version we are using to build the client tools and pass that
|
# Capture the same version we are using to build the client tools and pass that
|
||||||
# on.
|
# on.
|
||||||
version=$(
|
version_ldflags=$(kube::version_ldflags)
|
||||||
unset IFS
|
|
||||||
source $KUBE_DIR/hack/config-go.sh
|
|
||||||
gitcommit
|
|
||||||
)
|
|
||||||
|
|
||||||
cat << EOF > $MASTER_RELEASE_DIR/src/saltbase/pillar/common.sls
|
cat << EOF > $MASTER_RELEASE_DIR/src/saltbase/pillar/common.sls
|
||||||
instance_prefix: $INSTANCE_PREFIX-minion
|
instance_prefix: $INSTANCE_PREFIX-minion
|
||||||
go_opt: -ldflags "-X github.com/GoogleCloudPlatform/kubernetes/pkg/version.gitCommit '$version'"
|
go_opt: -ldflags '${version_ldflags}'
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
function find_go_files() {
|
function find_go_files() {
|
||||||
|
Loading…
Reference in New Issue
Block a user