美文网首页
etcd学习笔记1

etcd学习笔记1

作者: 酱油王0901 | 来源:发表于2020-05-31 19:27 被阅读0次

今天看etcd代码时发现打印版本信息的代码,追踪发现其中的GitSHA是通过编译传进来的值。

 26 var (
 27     // MinClusterVersion is the min cluster version this etcd binary is compatible with.
 28     MinClusterVersion = "3.0.0"
 29     Version           = "3.5.0-pre"
 30     APIVersion        = "unknown"
 31
 32     // Git SHA Value will be set during build
 33     GitSHA = "Not provided (use ./build instead of go build)"
 34 )

执行结果如下所示:

(ENV) 🍺 /Users/xsky/go/src/github.com/etcd-io/etcd ☞ git:(test) ✗ ./bin/etcd --version
etcd Version: 3.5.0-pre
Git SHA: 9b6c3e337
Go Version: go1.14.3
Go OS/Arch: darwin/amd64

在编译时使用参数-ldflags -X importpath.name=value

-X importpath.name=value
Set the value of the string variable in importpath named name to value.
This is only effective if the variable is declared in the source code either uninitialized
or initialized to a constant string expression. -X will not work if the initializer makes
a function call or refers to other variables.
Note that before Go 1.5 this option took two separate arguments.

使用如下:

  7 GIT_SHA=$(git rev-parse --short HEAD || echo "GitNotFound")
  8 if [[ -n "$FAILPOINTS" ]]; then
  9     GIT_SHA="$GIT_SHA"-FAILPOINTS
 10 fi
 11
 12 # Set GO_LDFLAGS="-s" for building without symbols for debugging.
 13 GO_LDFLAGS="$GO_LDFLAGS -X ${REPO_PATH}/version.GitSHA=${GIT_SHA}"
.....
 78     for tool in ${tools_path}
 79     do
 80         echo "Building" "'${tool}'"...
 81         # shellcheck disable=SC2086
 82         CGO_ENABLED=0 go build ${GO_BUILD_FLAGS} \
 83           -installsuffix cgo \
 84           -ldflags "${GO_LDFLAGS}" \
 85           -o "${out}/${tool}" "${REPO_PATH}/${tool}" || return
 86     done

顺便发现一个小bug:https://github.com/etcd-io/etcd/issues/11958

References

相关文章

  • etcd学习笔记1

    今天看etcd代码时发现打印版本信息的代码,追踪发现其中的GitSHA是通过编译传进来的值。 执行结果如下所示: ...

  • etcd-raft 库源码阅读【WIP】

    Etcd 源码阅读 本文是 etcd-raft 库源码的阅读笔记。希望通过阅读 etcd-raft 库的源码,学习...

  • etcd笔记1

    etcd 是一个分布式键值对存储,设计用来可靠而快速的保存关键数据并提供访问。通过分布式锁,leader选举和写屏...

  • etcd学习笔记

    本文作者:陈进坚个人博客:https://jian1098.github.ioCSDN博客:https://blo...

  • 从零开始学习etcd的使用

    etcd做注册服务使用 类似java生态的zookeeper,最近在学学习 1、下载etcd包 2、使用记录

  • kubernetes部署教程

    1. etcd配置 /usr/lib/systemd/system/etcd.service /opt/etcd/...

  • etcd学习笔记4(草稿)

    ClientV3发送Put请求时,其携带的key,value数据被封装成一个Op,然后转化为一个pb.PutReq...

  • etcd学习笔记3 (草稿)

    Raft协议主要分为三个模块:Leader election、Log replication和Safety。Raf...

  • etcd学习笔记2(草稿)

    etcd初始化流程 etcd启动时首先会调用startEtcdOrProxyV2, 这个方法里首先会进行confi...

  • etcd学习笔记(三): Propose

    我们已经在raft-example看过了对Propose的简单处理了,但是真正的etcd对Propose的处理更加...

网友评论

      本文标题:etcd学习笔记1

      本文链接:https://www.haomeiwen.com/subject/fylrzhtx.html