From 3f8bd3b2a65c36b63e798ce7a3a4139b73017430 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Fri, 12 Jul 2019 15:48:00 +0530 Subject: [PATCH] Update driver version during build time update driver version and add git commit to the image. This will help us to identify what latest git commit image contains. Signed-off-by: Madhu Rajanna --- Makefile | 12 +++++++++++- cmd/cephcsi.go | 1 + pkg/cephfs/driver.go | 5 +---- pkg/cephfs/mountcache.go | 4 ++-- pkg/rbd/rbd.go | 5 +---- pkg/util/util.go | 8 ++++++++ 6 files changed, 24 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 89eff2d11..955286386 100644 --- a/Makefile +++ b/Makefile @@ -21,6 +21,16 @@ CSI_IMAGE_VERSION=$(if $(ENV_CSI_IMAGE_VERSION),$(ENV_CSI_IMAGE_VERSION),canary) $(info cephcsi image settings: $(CSI_IMAGE_NAME) version $(CSI_IMAGE_VERSION)) +GIT_COMMIT=$(shell git rev-list -1 HEAD) + +GO_PROJECT=github.com/ceph/ceph-csi + +# go build flags +LDFLAGS ?= +LDFLAGS += -X $(GO_PROJECT)/pkg/util.GitCommit=$(GIT_COMMIT) +# CSI_IMAGE_VERSION will be considered as the driver version +LDFLAGS += -X $(GO_PROJECT)/pkg/util.DriverVersion=$(CSI_IMAGE_VERSION) + all: cephcsi test: go-test static-check @@ -38,7 +48,7 @@ func-test: .PHONY: cephcsi cephcsi: if [ ! -d ./vendor ]; then dep ensure -vendor-only; fi - CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static"' -o _output/cephcsi ./cmd/ + CGO_ENABLED=0 GOOS=linux go build -a -ldflags '$(LDFLAGS) -extldflags "-static"' -o _output/cephcsi ./cmd/ image-cephcsi: cephcsi cp _output/cephcsi deploy/cephcsi/image/cephcsi diff --git a/cmd/cephcsi.go b/cmd/cephcsi.go index 665b106d7..ef8ec4654 100644 --- a/cmd/cephcsi.go +++ b/cmd/cephcsi.go @@ -93,6 +93,7 @@ func getDriverName() string { } func main() { + klog.Infof("Driver version: %s and Git version: %s", util.DriverVersion, util.GitCommit) var cp util.CachePersister driverType := getType() diff --git a/pkg/cephfs/driver.go b/pkg/cephfs/driver.go index 2b08cb0dd..a21c40bd1 100644 --- a/pkg/cephfs/driver.go +++ b/pkg/cephfs/driver.go @@ -26,8 +26,6 @@ import ( ) const ( - // version of ceph driver - version = "1.0.0" // volIDVersion is the version number of volume ID encoding scheme volIDVersion uint16 = 1 @@ -94,7 +92,6 @@ func NewNodeServer(d *csicommon.CSIDriver) *NodeServer { // Run start a non-blocking grpc controller,node and identityserver for // ceph CSI driver which can serve multiple parallel requests func (fs *Driver) Run(driverName, nodeID, endpoint, volumeMounter, mountCacheDir, instanceID string, cachePersister util.CachePersister) { - klog.Infof("Driver: %v version: %v", driverName, version) // Configuration @@ -144,7 +141,7 @@ func (fs *Driver) Run(driverName, nodeID, endpoint, volumeMounter, mountCacheDir } // Initialize default library driver - fs.cd = csicommon.NewCSIDriver(driverName, version, nodeID) + fs.cd = csicommon.NewCSIDriver(driverName, util.DriverVersion, nodeID) if fs.cd == nil { klog.Fatalln("failed to initialize CSI driver") } diff --git a/pkg/cephfs/mountcache.go b/pkg/cephfs/mountcache.go index 962ccd12e..eafcbe2fd 100644 --- a/pkg/cephfs/mountcache.go +++ b/pkg/cephfs/mountcache.go @@ -39,7 +39,7 @@ func initVolumeMountCache(driverName, mountCacheDir string) { volumeMountCache.nodeCacheStore.BasePath = mountCacheDir volumeMountCache.nodeCacheStore.CacheDir = driverName - klog.Infof("mount-cache: name: %s, version: %s, mountCacheDir: %s", driverName, version, mountCacheDir) + klog.Infof("mount-cache: name: %s, version: %s, mountCacheDir: %s", driverName, util.DriverVersion, mountCacheDir) } func remountCachedVolumes() error { @@ -228,7 +228,7 @@ func (mc *volumeMountCacheMap) nodeStageVolume(volID, stagingTargetPath, mounter klog.Warningf("mount-cache: node stage volume ignore last cache entry for volume %s", volID) } - me = volumeMountCacheEntry{DriverVersion: version} + me = volumeMountCacheEntry{DriverVersion: util.DriverVersion} me.VolumeID = volID me.Secrets = encodeCredentials(secrets) diff --git a/pkg/rbd/rbd.go b/pkg/rbd/rbd.go index a33dc0c8d..e50bdb118 100644 --- a/pkg/rbd/rbd.go +++ b/pkg/rbd/rbd.go @@ -46,7 +46,6 @@ type Driver struct { } var ( - version = "1.0.0" // PluginFolder defines the location of ceph plugin PluginFolder = "/var/lib/kubelet/plugins/" @@ -102,8 +101,6 @@ func NewNodeServer(d *csicommon.CSIDriver, containerized bool) (*NodeServer, err func (r *Driver) Run(driverName, nodeID, endpoint, instanceID string, containerized bool, cachePersister util.CachePersister) { var err error - klog.Infof("Driver: %v version: %v", driverName, version) - // Create ceph.conf for use with CLI commands if err = util.WriteCephConfig(); err != nil { klog.Fatalf("failed to write ceph configuration file (%v)", err) @@ -123,7 +120,7 @@ func (r *Driver) Run(driverName, nodeID, endpoint, instanceID string, containeri snapJournal.SetCSIDirectorySuffix(CSIInstanceID) // Initialize default library driver - r.cd = csicommon.NewCSIDriver(driverName, version, nodeID) + r.cd = csicommon.NewCSIDriver(driverName, util.DriverVersion, nodeID) if r.cd == nil { klog.Fatalln("Failed to initialize CSI Driver.") } diff --git a/pkg/util/util.go b/pkg/util/util.go index 22eb2f8ba..a53a5c4fe 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -39,6 +39,14 @@ func RoundUpToMiB(size int64) int64 { return roundUpSize(requestBytes, MiB) } +// variables which will be set during the build time +var ( + // GitCommit tell the latest git commit image is built from + GitCommit string + // DriverVersion which will be driver version + DriverVersion string +) + func roundUpSize(volumeSizeBytes, allocationUnitBytes int64) int64 { roundedUp := volumeSizeBytes / allocationUnitBytes if volumeSizeBytes%allocationUnitBytes > 0 {