forked from github/multus-cni
Refine build-go.sh and update 'version' output
This commit is contained in:
parent
3cda380ad1
commit
99dd6678d5
@ -30,6 +30,7 @@ import (
|
||||
utilwait "k8s.io/apimachinery/pkg/util/wait"
|
||||
|
||||
"gopkg.in/k8snetworkplumbingwg/multus-cni.v3/pkg/logging"
|
||||
"gopkg.in/k8snetworkplumbingwg/multus-cni.v3/pkg/multus"
|
||||
srv "gopkg.in/k8snetworkplumbingwg/multus-cni.v3/pkg/server"
|
||||
"gopkg.in/k8snetworkplumbingwg/multus-cni.v3/pkg/server/config"
|
||||
"gopkg.in/k8snetworkplumbingwg/multus-cni.v3/pkg/types"
|
||||
@ -94,11 +95,17 @@ func main() {
|
||||
forceCNIVersion := flag.Bool("force-cni-version", false, "force to use given CNI version. only for kind-e2e testing") // this is only for kind-e2e
|
||||
readinessIndicator := flag.String(multusReadinessIndicatorFile, "", "Which file should be used as the readiness indicator. Used only with --multus-conf-file=auto.")
|
||||
overrideNetworkName := flag.Bool("override-network-name", false, "Used when we need overrides the name of the multus configuration with the name of the delegated primary CNI")
|
||||
version := flag.Bool("version", false, "Show version")
|
||||
|
||||
configFilePath := flag.String("config", types.DefaultMultusDaemonConfigFile, "Specify the path to the multus-daemon configuration")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
if *version {
|
||||
fmt.Printf("multus-daemon: %s\n", multus.PrintVersionString())
|
||||
os.Exit(4)
|
||||
}
|
||||
|
||||
if err := startMultusDaemon(*configFilePath); err != nil {
|
||||
logging.Panicf("failed start the multus thick-plugin listener: %v", err)
|
||||
os.Exit(3)
|
||||
|
@ -40,7 +40,7 @@ func main() {
|
||||
|
||||
flag.Parse()
|
||||
if versionOpt == true {
|
||||
fmt.Printf("%s\n", multus.PrintVersionString())
|
||||
fmt.Printf("multus-shim: %s\n", multus.PrintVersionString())
|
||||
return
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ func main() {
|
||||
flag.BoolVar(&versionOpt, "v", false, "Show application version")
|
||||
flag.Parse()
|
||||
if versionOpt == true {
|
||||
fmt.Printf("%s\n", multus.PrintVersionString())
|
||||
fmt.Printf("multus: %s\n", multus.PrintVersionString())
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -7,54 +7,55 @@ if [ ! -d ${DEST_DIR} ]; then
|
||||
mkdir ${DEST_DIR}
|
||||
fi
|
||||
|
||||
# Add version/commit/date into binary
|
||||
# In case of TravisCI, need to check error code of 'git describe'.
|
||||
if [ -z "$VERSION" ]; then
|
||||
# version information
|
||||
hasGit=true
|
||||
git version > /dev/null 2>&1 || hasGit=false
|
||||
GIT_SHA=""
|
||||
GIT_TREE_STATE=""
|
||||
GIT_TAG=""
|
||||
GIT_TAG_LAST=""
|
||||
RELEASE_STATUS=""
|
||||
if $hasGit; then
|
||||
set +e
|
||||
git describe --tags --abbrev=0 > /dev/null 2>&1
|
||||
if [ "$?" != "0" ]; then
|
||||
VERSION="master"
|
||||
else
|
||||
VERSION=$(git describe --tags --abbrev=0)
|
||||
fi
|
||||
GIT_SHA=$(git rev-parse --short HEAD)
|
||||
# Tree state is "dirty" if there are uncommitted changes, untracked files are ignored
|
||||
GIT_TREE_STATE=$(test -n "`git status --porcelain --untracked-files=no`" && echo "dirty" || echo "clean")
|
||||
# Empty string if we are not building a tag
|
||||
GIT_TAG=$(git describe --tags --abbrev=0 --exact-match 2>/dev/null || true)
|
||||
# Find most recent tag
|
||||
GIT_TAG_LAST=$(git describe --tags --abbrev=0 2>/dev/null || true)
|
||||
set -e
|
||||
fi
|
||||
|
||||
# VERSION override mechanism if needed
|
||||
VERSION=${VERSION:-}
|
||||
if [[ -n "${VERSION}" || -n "${GIT_TAG}" ]]; then
|
||||
RELEASE_STATUS=",released"
|
||||
fi
|
||||
|
||||
if [ -z "$VERSION" ]; then
|
||||
VERSION=$GIT_TAG_LAST
|
||||
fi
|
||||
# Add version/commit/date into binary
|
||||
DATE=$(date -u -d "@${SOURCE_DATE_EPOCH:-$(date +%s)}" --iso-8601=seconds)
|
||||
COMMIT=${COMMIT:-$(git rev-parse --verify HEAD)}
|
||||
LDFLAGS="-X gopkg.in/k8snetworkplumbingwg/multus-cni.v3/pkg/multus.version=${VERSION:-master} -X gopkg.in/k8snetworkplumbingwg/multus-cni.v3/pkg/multus.commit=${COMMIT} -X gopkg.in/k8snetworkplumbingwg/multus-cni.v3/pkg/multus.date=${DATE}"
|
||||
LDFLAGS="-X gopkg.in/k8snetworkplumbingwg/multus-cni.v3/pkg/multus.version=${VERSION} \
|
||||
-X gopkg.in/k8snetworkplumbingwg/multus-cni.v3/pkg/multus.commit=${COMMIT} \
|
||||
-X gopkg.in/k8snetworkplumbingwg/multus-cni.v3/pkg/multus.gitTreeState=${GIT_TREE_STATE} \
|
||||
-X gopkg.in/k8snetworkplumbingwg/multus-cni.v3/pkg/multus.releaseStatus=${RELEASE_STATUS} \
|
||||
-X gopkg.in/k8snetworkplumbingwg/multus-cni.v3/pkg/multus.date=${DATE}"
|
||||
export CGO_ENABLED=0
|
||||
|
||||
# this if... will be removed when gomodules goes default
|
||||
if [ "$GO111MODULE" == "off" ]; then
|
||||
echo "Building plugin without go module"
|
||||
echo "Warning: this will be deprecated in near future so please use go modules!"
|
||||
|
||||
ORG_PATH="gopkg.in/k8snetworkplumbingwg"
|
||||
REPO_PATH="${ORG_PATH}/multus-cni.v3"
|
||||
|
||||
if [ ! -h gopath/src/${REPO_PATH} ]; then
|
||||
mkdir -p gopath/src/${ORG_PATH}
|
||||
ln -s ../../../.. gopath/src/${REPO_PATH} || exit 255
|
||||
fi
|
||||
|
||||
export GO15VENDOREXPERIMENT=1
|
||||
export GOBIN=${PWD}/bin
|
||||
export GOPATH=${PWD}/gopath
|
||||
go build -o ${PWD}/bin/multus -tags no_openssl -ldflags "${LDFLAGS}" "$@" ${REPO_PATH}/cmd/multus
|
||||
go build -o ${PWD}/bin/multus-daemon -tags no_openssl -ldflags "${LDFLAGS}" "$@" ${REPO_PATH}/cmd/multus-daemon
|
||||
go build -o ${PWD}/bin/multus-shim -tags no_openssl -ldflags "${LDFLAGS}" "$@" ${REPO_PATH}/cmd/multus-shim
|
||||
else
|
||||
# build with go modules
|
||||
export GO111MODULE=on
|
||||
BUILD_ARGS=(-o ${DEST_DIR}/multus -tags no_openssl)
|
||||
if [ -n "$MODMODE" ]; then
|
||||
BUILD_ARGS+=(-mod "$MODMODE")
|
||||
fi
|
||||
|
||||
echo "Building plugins"
|
||||
go build ${BUILD_ARGS[*]} -ldflags "${LDFLAGS}" "$@" ./cmd/multus
|
||||
echo "Building multus controller"
|
||||
go build -o "${DEST_DIR}"/multus-daemon -ldflags "${LDFLAGS}" ./cmd/multus-daemon
|
||||
echo "Building multus shim"
|
||||
go build -o "${DEST_DIR}"/multus-shim -ldflags "${LDFLAGS}" ./cmd/multus-shim
|
||||
# build with go modules
|
||||
export GO111MODULE=on
|
||||
BUILD_ARGS=(-o ${DEST_DIR}/multus -tags no_openssl)
|
||||
if [ -n "$MODMODE" ]; then
|
||||
BUILD_ARGS+=(-mod "$MODMODE")
|
||||
fi
|
||||
|
||||
echo "Building multus"
|
||||
go build ${BUILD_ARGS[*]} -ldflags "${LDFLAGS}" "$@" ./cmd/multus
|
||||
echo "Building multus-daemon"
|
||||
go build -o "${DEST_DIR}"/multus-daemon -ldflags "${LDFLAGS}" ./cmd/multus-daemon
|
||||
echo "Building multus-shim"
|
||||
go build -o "${DEST_DIR}"/multus-shim -ldflags "${LDFLAGS}" ./cmd/multus-shim
|
||||
|
@ -51,9 +51,11 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
version = "master@git"
|
||||
commit = "unknown commit"
|
||||
date = "unknown date"
|
||||
version = "master@git"
|
||||
commit = "unknown commit"
|
||||
date = "unknown date"
|
||||
gitTreeState = ""
|
||||
releaseStatus = ""
|
||||
)
|
||||
|
||||
var (
|
||||
@ -63,8 +65,7 @@ var (
|
||||
|
||||
// PrintVersionString ...
|
||||
func PrintVersionString() string {
|
||||
return fmt.Sprintf("multus-cni version:%s, commit:%s, date:%s",
|
||||
version, commit, date)
|
||||
return fmt.Sprintf("version:%s(%s%s), commit:%s, date:%s", version, gitTreeState, releaseStatus, commit, date)
|
||||
}
|
||||
|
||||
func saveScratchNetConf(containerID, dataDir string, netconf []byte) error {
|
||||
|
Loading…
Reference in New Issue
Block a user