From 639b13f6ddb668209bb01c4c8b336791789ed11b Mon Sep 17 00:00:00 2001 From: hlts2 Date: Wed, 6 Nov 2024 15:57:27 +0900 Subject: [PATCH] feat: add capability to be able to set current driver version in the binary Signed-off-by: hlts2 --- Dockerfile | 2 +- main.go | 11 +++++++++++ pkg/driver/driver.go | 7 ++----- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 19284a0..afd5d25 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,7 +17,7 @@ RUN go mod verify RUN find . # Build the binary. -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s -X github.com/civo/civo-csi/driver.CSIVersion=${VERSION}" -o /app/civo-csi +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s -X github.com/civo/civo-csi/pkg/driver.Version=${VERSION}" -o /app/civo-csi ############################ diff --git a/main.go b/main.go index 512b8ea..f85b062 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "context" + "flag" "os" "os/signal" "strings" @@ -13,10 +14,20 @@ import ( "github.com/rs/zerolog/log" ) +var ( + versionInfo = flag.Bool("version", false, "Print the driver version") +) + func main() { zerolog.TimeFieldFormat = zerolog.TimeFormatUnix log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr}) + flag.Parse() + if *versionInfo { + log.Info().Str("version", driver.Version).Msg("CSI driver") + return + } + apiURL := strings.TrimSpace(os.Getenv("CIVO_API_URL")) apiKey := strings.TrimSpace(os.Getenv("CIVO_API_KEY")) region := strings.TrimSpace(os.Getenv("CIVO_REGION")) diff --git a/pkg/driver/driver.go b/pkg/driver/driver.go index 30815ca..54adaf4 100644 --- a/pkg/driver/driver.go +++ b/pkg/driver/driver.go @@ -17,14 +17,11 @@ import ( "google.golang.org/grpc" ) -// CSIVersion is the version of the csi to set in the User-Agent header -var CSIVersion = "dev" - // Name is the name of the driver const Name string = "Civo CSI Driver" -// Version is the current release of the driver -const Version string = "0.0.1" +// Version is the current version of the driver to set in the User-Agent header +var Version string = "0.0.1" // DefaultVolumeSizeGB is the default size in Gigabytes of an unspecified volume const DefaultVolumeSizeGB int = 10