Skip to content

Commit

Permalink
Fix the failure of starting fluid-csi (fluid-cloudnative#238)
Browse files Browse the repository at this point in the history
* fix bug, edit dockerfile and add version log

* fix bug, edit dockerfile and add version log

* edit makefile

* edit the location of 'v' in version info and remove return of print

Co-authored-by: 仇伶玮 <qiulingwei@gitlab.com>
  • Loading branch information
yangyuliufeng and 仇伶玮 authored Oct 18, 2020
1 parent 524bcf7 commit f251410
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 24 deletions.
3 changes: 2 additions & 1 deletion Dockerfile.csi
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ COPY . .

# Build
# RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o csi main.go
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=off go build -a -o /go/bin/fluid-csi cmd/csi/*.go
#RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=off go build -a -o /go/bin/fluid-csi cmd/csi/*.go
RUN make csi-build

# RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=off go build -gcflags="-N -l" -a -o /go/bin/fluid-csi cmd/csi/*.go

Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ endif

CURRENT_DIR=$(shell pwd)
VERSION=v0.4.0
BUILD_DATE=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
BUILD_DATE=$(shell date -u +'%Y-%m-%d-%H:%M:%S')
GIT_COMMIT=$(shell git rev-parse HEAD)
GIT_TAG=$(shell if [ -z "`git status --porcelain`" ]; then git describe --exact-match --tags HEAD 2>/dev/null; fi)
GIT_TREE_STATE=$(shell if [ -z "`git status --porcelain`" ]; then echo "clean" ; else echo "dirty"; fi)
Expand Down Expand Up @@ -54,6 +54,10 @@ manager: generate fmt vet
csi: generate fmt vet
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=off go build -o bin/csi -ldflags '${LDFLAGS}' cmd/csi/main.go

# Build CSI binary in dockerfile
csi-build:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=off go build -o /go/bin/fluid-csi -ldflags '${LDFLAGS}' cmd/csi/main.go

# Debug against the configured Kubernetes cluster in ~/.kube/config, add debug
debug: generate fmt vet manifests
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=off dlv debug --headless --listen ":12345" --log --api-version=2 cmd/controller/main.go
Expand Down
23 changes: 4 additions & 19 deletions cmd/csi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var (
)

var cmd = &cobra.Command{
Use: "csi",
Use: "fluid-csi",
Short: "CSI based fluid driver for Fuse",
}

Expand All @@ -47,23 +47,8 @@ var startCmd = &cobra.Command{
var versionCmd = &cobra.Command{
Use: "version",
Short: "print version information",
Long: "print version information",
Run: func(cmd *cobra.Command, args []string) {
v := fluid.GetVersion()

if short {
fmt.Printf("version: %s\n", v)
return
}
fmt.Printf(" BuildDate: %s\n", v.BuildDate)
fmt.Printf(" GitCommit: %s\n", v.GitCommit)
fmt.Printf(" GitTreeState: %s\n", v.GitTreeState)
if v.GitTag != "" {
fmt.Printf(" GitTag: %s\n", v.GitTag)
}
fmt.Printf(" GoVersion: %s\n", v.GoVersion)
fmt.Printf(" Compiler: %s\n", v.Compiler)
fmt.Printf(" Platform: %s\n", v.Platform)
fluid.PrintVersion(short)
},
}

Expand All @@ -78,7 +63,7 @@ func init() {
errorAndExit(err)
}

startCmd.Flags().StringVarP(&nodeID, "endpoint","","", "CSI endpoint")
startCmd.Flags().StringVarP(&endpoint, "endpoint","","", "CSI endpoint")
if err := startCmd.MarkFlagRequired("endpoint"); err != nil {
errorAndExit(err)
}
Expand All @@ -102,7 +87,7 @@ func main() {

func handle() {
// startReaper()

fluid.LogVersion()
d := csi.NewDriver(nodeID, endpoint)
d.Run()
}
Expand Down
2 changes: 1 addition & 1 deletion csi/shell/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ set -xe
rm -f /var/lib/kubelet/csi-plugins/fuse.csi.fluid.io/csi.sock
mkdir -p /var/lib/kubelet/csi-plugins/fuse.csi.fluid.io

fluid-csi $@
fluid-csi start $@
37 changes: 35 additions & 2 deletions version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fluid

import "runtime"
import "fmt"
import "github.com/golang/glog"

type Version struct {
Version string
Expand All @@ -22,7 +23,7 @@ var (
)


func GetVersion() Version {
func getVersion() Version {
var versionStr string
if gitCommit != "" && gitTag != "" && gitTreeState == "clean" {
// if we have a clean tree state and the current commit is tagged,
Expand All @@ -31,7 +32,7 @@ func GetVersion() Version {
} else {
// otherwise formulate a queryversion string based on as much metadata
// information we have available.
versionStr = "v" + version
versionStr = version
if len(gitCommit) >= 7 {
versionStr += "+" + gitCommit[0:7]
if gitTreeState != "clean" {
Expand All @@ -51,4 +52,36 @@ func GetVersion() Version {
Compiler: runtime.Compiler,
Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH),
}
}

// Print version info directly by command
func PrintVersion(short bool){
v := getVersion()
if short {
fmt.Printf("version: %s\n", v.Version)
return
}
fmt.Printf(" BuildDate: %s\n", v.BuildDate)
fmt.Printf(" GitCommit: %s\n", v.GitCommit)
fmt.Printf(" GitTreeState: %s\n", v.GitTreeState)
if v.GitTag != "" {
fmt.Printf(" GitTag: %s\n", v.GitTag)
}
fmt.Printf(" GoVersion: %s\n", v.GoVersion)
fmt.Printf(" Compiler: %s\n", v.Compiler)
fmt.Printf(" Platform: %s\n", v.Platform)
}

// Print version info in log when start
func LogVersion(){
v := getVersion()
glog.Infof("BuildDate: %s\n", v.BuildDate)
glog.Infof("GitCommit: %s\n", v.GitCommit)
glog.Infof("GitTreeState: %s\n", v.GitTreeState)
if v.GitTag != "" {
glog.Infof("GitTag: %s\n", v.GitTag)
}
glog.Infof("GoVersion: %s\n", v.GoVersion)
glog.Infof("Compiler: %s\n", v.Compiler)
glog.Infof("Platform: %s\n", v.Platform)
}

0 comments on commit f251410

Please sign in to comment.