From 3e07ae4e6020fd5b05ba2779645a2437046244bd Mon Sep 17 00:00:00 2001 From: Meinhard Zhou Date: Sun, 13 Mar 2022 17:12:09 +0800 Subject: [PATCH] style&chore: modity Makefile and some code style 1. add .prow.sh 2. add a symlink in Makefile related to release-tools. 3. modify some code style to pass fmt test. Signed-off-by: Meinhard Zhou --- .gitignore | 1 + .prow.sh | 27 +++++++++++++++++++++++++++ Dockerfile | 4 ++-- Makefile | 16 ++++------------ pkg/nvmf/controllerserver.go | 2 +- pkg/nvmf/mounter.go | 14 +++++++------- pkg/nvmf/nvmf.go | 2 +- pkg/utils/utils.go | 2 -- 8 files changed, 43 insertions(+), 25 deletions(-) create mode 100755 .prow.sh diff --git a/.gitignore b/.gitignore index 9f11b75..0a95508 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .idea/ +.vscode/ \ No newline at end of file diff --git a/.prow.sh b/.prow.sh new file mode 100755 index 0000000..a2d6a36 --- /dev/null +++ b/.prow.sh @@ -0,0 +1,27 @@ +#! /bin/bash + +# Copyright 2022 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A Prow job can override these defaults, but this shouldn't be necessary. + +# disable e2e tests for now +CSI_PROW_E2E_REPO=none + +# Only these tests make sense for unit test +: ${CSI_PROW_TESTS:="unit"} + +. release-tools/prow.sh + +main diff --git a/Dockerfile b/Dockerfile index 4663c8a..1077d2d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ FROM debian:9.13 -COPY ./output/nvmfplugin . +COPY ./bin/nvmfplugin . -ENTRYPOINT ["./nvmfplugin"] \ No newline at end of file +ENTRYPOINT ["/nvmfplugin"] diff --git a/Makefile b/Makefile index a0f3494..dab6fa7 100644 --- a/Makefile +++ b/Makefile @@ -13,18 +13,10 @@ # limitations under the License. CMDS=nvmfplugin -REV=$(shell git describe --long --tags --match='v*' --dirty 2>/dev/null || git rev-list -n1 HEAD) - all: build -build-%: - mkdir -p output - CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-X main.version=$(REV) -extldflags "-static"' -o ./output/$* ./cmd/nvmfplugin/$*.go +include release-tools/build.make -container-%: build-% - docker build -t $*:latest -f Dockerfile --label revision=$(REV) . - -build: ${CMDS:%=build-%} -container: ${CMDS:%=container-%} -clean: - -rm -rf output/ +GOPATH ?= $(shell go env GOPATH) +GOBIN ?= $(GOPATH)/bin +export GOPATH GOBIN diff --git a/pkg/nvmf/controllerserver.go b/pkg/nvmf/controllerserver.go index 98b1399..269bb08 100644 --- a/pkg/nvmf/controllerserver.go +++ b/pkg/nvmf/controllerserver.go @@ -38,7 +38,7 @@ func NewControllerServer(d *driver) *ControllerServer { // You should realize your volume provider here, such as requesting the Cloud to create an NVMf block and // returning specific information to you func (c *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) (*csi.CreateVolumeResponse, error) { - return nil, status.Errorf(codes.Unimplemented,"CreateVolume should implement by yourself. ") + return nil, status.Errorf(codes.Unimplemented, "CreateVolume should implement by yourself. ") } func (c *ControllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeRequest) (*csi.DeleteVolumeResponse, error) { diff --git a/pkg/nvmf/mounter.go b/pkg/nvmf/mounter.go index e2d6005..f8d5383 100644 --- a/pkg/nvmf/mounter.go +++ b/pkg/nvmf/mounter.go @@ -44,14 +44,14 @@ func getNVMfDiskMounter(nvmfInfo *nvmfDiskInfo, req *csi.NodePublishVolumeReques mountOptions := req.GetVolumeCapability().GetMount().GetMountFlags() return &nvmfDiskMounter{ - nvmfDiskInfo : nvmfInfo, - readOnly: readOnly, - fsType: fsType, + nvmfDiskInfo: nvmfInfo, + readOnly: readOnly, + fsType: fsType, mountOptions: mountOptions, - mounter: &mount.SafeFormatAndMount{Interface: mount.New(""), Exec: exec.New()}, - exec: exec.New(), - targetPath: req.GetTargetPath(), - connector: getConnector(nvmfInfo), + mounter: &mount.SafeFormatAndMount{Interface: mount.New(""), Exec: exec.New()}, + exec: exec.New(), + targetPath: req.GetTargetPath(), + connector: getConnector(nvmfInfo), } } diff --git a/pkg/nvmf/nvmf.go b/pkg/nvmf/nvmf.go index 82b09d8..c696488 100644 --- a/pkg/nvmf/nvmf.go +++ b/pkg/nvmf/nvmf.go @@ -40,7 +40,7 @@ func AttachDisk(req *csi.NodePublishVolumeRequest, nm nvmfDiskMounter) (string, return "", fmt.Errorf("Heuristic determination of mount point failed:%v", err) } if !notMounted { - klog.Infof("AttachDisk: VolumeID: %s, Path: %s is already mounted, device: %s", req.VolumeId, nm.targetPath) + klog.Infof("AttachDisk: VolumeID: %s, Path: %s is already mounted, device: %s", req.VolumeId, nm.targetPath, nm.DeviceUUID) return "", nil } diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index cd30435..29a93d8 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -79,6 +79,4 @@ func ReadLinesFromFile(file *os.File) (lines []string, err error) { } } } - - return lines, nil }