Skip to content

[Feature]: Add version cmd flat to show operator versioninfo#235

Description

@whg517

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions