Duplicates
no check
Summary π‘
Add the command-line parameter --version to output the version information of the operator. By passing the build version number, build time, and git commit short sha during the build process using ldflat, the version information can be obtained.
It is also necessary to pay extra attention that when building with Docker, the content in the Dockerfile also needs to be adjusted. During the build process, dynamic information can be passed to the Dockerfile through build-arg.
Examples π
Here is show zookeeper-operator to build operator manager:
make build
/Users/kevin/workspace/git/github/zncdatadev/zookeeper-operator/bin/controller-gen rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
/Users/kevin/workspace/git/github/zncdatadev/zookeeper-operator/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
go fmt ./...
go vet ./...
go build -ldflags "-X github.com/zncdatadev/zookeeper-operator/internal/util/version.BuildVersion=0.0.0-dev -X github.com/zncdatadev/zookeeper-operator/internal/util/version.GitCommit=3970ad0a16165373292be91b554795fb1807287e -X github.com/zncdatadev/zookeeper-operator/internal/util/version.BuildTime=2025-11-30T07:16:53Z" -o bin/manager cmd/main.go
To run manager show version
./bin/manager --version
{"AppName":"zookeeper-operator","AppVersion":"0.0.0-dev","BuildTime":"2025-11-30T07:16:53Z","GitCommit":"3970ad0a16165373292be91b554795fb1807287e","GoVersion":"go1.25.3","Compiler":"gc","Platform":"darwin/arm64"}
Motivation π¦
When using the operator, you can use --version to display the current version information, which is helpful for troubleshooting when errors occur.
Duplicates
no check
Summary π‘
Add the command-line parameter
--versionto output the version information of the operator. By passing the build version number, build time, and git commit short sha during the build process usingldflat, the version information can be obtained.It is also necessary to pay extra attention that when building with Docker, the content in the Dockerfile also needs to be adjusted. During the build process, dynamic information can be passed to the Dockerfile through
build-arg.Examples π
Here is show zookeeper-operator to build operator manager:
To run manager show version
./bin/manager --version {"AppName":"zookeeper-operator","AppVersion":"0.0.0-dev","BuildTime":"2025-11-30T07:16:53Z","GitCommit":"3970ad0a16165373292be91b554795fb1807287e","GoVersion":"go1.25.3","Compiler":"gc","Platform":"darwin/arm64"}Motivation π¦
When using the operator, you can use
--versionto display the current version information, which is helpful for troubleshooting when errors occur.