Skip to content

Commit

Permalink
fix golint (#1035)
Browse files Browse the repository at this point in the history
* fix golint
* fix dev minor

Signed-off-by: zwwhdls <[email protected]>
  • Loading branch information
zwwhdls authored Jul 15, 2024
1 parent 337603e commit 8171f0b
Show file tree
Hide file tree
Showing 24 changed files with 142 additions and 169 deletions.
11 changes: 8 additions & 3 deletions cmd/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ import (
"k8s.io/klog"
ctrl "sigs.k8s.io/controller-runtime"

"github.com/prometheus/client_golang/prometheus/promhttp"

"github.com/juicedata/juicefs-csi-driver/cmd/app"
"github.com/juicedata/juicefs-csi-driver/pkg/config"
"github.com/juicedata/juicefs-csi-driver/pkg/driver"
k8s "github.com/juicedata/juicefs-csi-driver/pkg/k8sclient"
"github.com/juicedata/juicefs-csi-driver/pkg/util"
"github.com/prometheus/client_golang/prometheus/promhttp"
)

var (
Expand Down Expand Up @@ -133,7 +134,9 @@ func controllerRun() {
go func() {
port := 6060
for {
http.ListenAndServe(fmt.Sprintf("localhost:%d", port), nil)
if err := http.ListenAndServe(fmt.Sprintf("localhost:%d", port), nil); err != nil {
klog.Errorf("failed to start pprof server: %v", err)
}
port++
}
}()
Expand All @@ -153,7 +156,9 @@ func controllerRun() {
Addr: fmt.Sprintf(":%d", config.WebPort),
Handler: mux,
}
server.ListenAndServe()
if err := server.ListenAndServe(); err != nil {
klog.Errorf("failed to start metrics server: %v", err)
}
}()

// enable mount manager in csi controller
Expand Down
11 changes: 8 additions & 3 deletions cmd/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ import (
"k8s.io/klog"
ctrl "sigs.k8s.io/controller-runtime"

"github.com/prometheus/client_golang/prometheus/promhttp"

"github.com/juicedata/juicefs-csi-driver/cmd/app"
"github.com/juicedata/juicefs-csi-driver/pkg/config"
"github.com/juicedata/juicefs-csi-driver/pkg/controller"
"github.com/juicedata/juicefs-csi-driver/pkg/driver"
k8s "github.com/juicedata/juicefs-csi-driver/pkg/k8sclient"
"github.com/juicedata/juicefs-csi-driver/pkg/util"
"github.com/prometheus/client_golang/prometheus/promhttp"
)

func parseNodeConfig() {
Expand Down Expand Up @@ -135,7 +136,9 @@ func nodeRun() {
go func() {
port := 6060
for {
http.ListenAndServe(fmt.Sprintf("localhost:%d", port), nil)
if err := http.ListenAndServe(fmt.Sprintf("localhost:%d", port), nil); err != nil {
klog.Errorf("failed to start pprof server: %v", err)
}
port++
}
}()
Expand All @@ -155,7 +158,9 @@ func nodeRun() {
Addr: fmt.Sprintf(":%d", config.WebPort),
Handler: mux,
}
server.ListenAndServe()
if err := server.ListenAndServe(); err != nil {
klog.Errorf("failed to start metrics server: %v", err)
}
}()

// enable pod manager in csi node
Expand Down
4 changes: 2 additions & 2 deletions hack/verify-golint
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ set -euo pipefail

if ! which golangci-lint > /dev/null; then
echo "Cannot find golangci-lint. Installing golangci-lint..."
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.21.0
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.59.1
export PATH="$(go env GOPATH)/bin:$PATH"
fi

golangci-lint run --deadline=10m
golangci-lint run

echo "Congratulations! All Go source files have been linted."
13 changes: 8 additions & 5 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ type MountPodPatch struct {
func (mpp *MountPodPatch) deepCopy() MountPodPatch {
var copy MountPodPatch
data, _ := json.Marshal(mpp)
json.Unmarshal(data, &copy)
_ = json.Unmarshal(data, &copy)
return copy
}

Expand Down Expand Up @@ -279,7 +279,7 @@ func (c *Config) GenMountPodPatch(setting JfsSetting) MountPodPatch {
strData = strings.ReplaceAll(strData, "${VOLUME_ID}", setting.VolumeId)
strData = strings.ReplaceAll(strData, "${VOLUME_NAME}", setting.Name)
strData = strings.ReplaceAll(strData, "${SUB_PATH}", setting.SubPath)
json.Unmarshal([]byte(strData), patch)
_ = json.Unmarshal([]byte(strData), patch)
klog.V(6).Infof("volume %s using patch: %+v", setting.VolumeId, patch)
return *patch
}
Expand Down Expand Up @@ -349,9 +349,9 @@ func StartConfigReloader(configPath string) error {
}
// k8s configmaps uses symlinks, we need this workaround to detect the real file change
if event.Op == fsnotify.Remove {
watcher.Remove(event.Name)
_ = watcher.Remove(event.Name)
// add a new watcher pointing to the new symlink/file
watcher.Add(configPath)
_ = watcher.Add(configPath)
}

klog.Infof("config file %s updated, reload config", configPath)
Expand All @@ -374,7 +374,10 @@ func StartConfigReloader(configPath string) error {
ticker := time.NewTicker(5 * time.Minute)
defer ticker.Stop()
for range ticker.C {
LoadConfig(configPath)
err = LoadConfig(configPath)
if err != nil {
klog.Error(err)
}
}
}()

Expand Down
14 changes: 7 additions & 7 deletions pkg/controller/mountinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func TestMountInfo(t *testing.T) {
defer patch1.Reset()

mit := newMountInfoTable()
mit.parse()
_ = mit.parse()
mi := mit.resolveTarget(target)

So(mi, ShouldNotBeNil)
Expand Down Expand Up @@ -117,7 +117,7 @@ func TestMountInfo(t *testing.T) {
})
Convey("test invalid base target", func() {
mit := newMountInfoTable()
mit.parse()
_ = mit.parse()
mi := mit.resolveTarget("/invalid-target-path")
So(mi, ShouldBeNil)
})
Expand All @@ -129,7 +129,7 @@ func TestMountInfo(t *testing.T) {
defer patch1.Reset()

mit := newMountInfoTable()
mit.parse()
_ = mit.parse()
mi := mit.resolveTarget(target)

So(mi, ShouldNotBeNil)
Expand All @@ -150,7 +150,7 @@ func TestMountInfo(t *testing.T) {
defer patch1.Reset()

mit := newMountInfoTable()
mit.parse()
_ = mit.parse()
mi := mit.resolveTarget("/poddir/uid-1/volumes/kubernetes.io~csi/pvn-not-exist/mount")

So(mi, ShouldNotBeNil)
Expand All @@ -166,7 +166,7 @@ func TestMountInfo(t *testing.T) {
defer patch1.Reset()

mit := newMountInfoTable()
mit.parse()
_ = mit.parse()
mi := mit.resolveTarget(target)

So(mi, ShouldNotBeNil)
Expand All @@ -182,7 +182,7 @@ func TestMountInfo(t *testing.T) {
defer patch1.Reset()

mit := newMountInfoTable()
mit.parse()
_ = mit.parse()
mi := mit.resolveTarget(target)

So(mi, ShouldNotBeNil)
Expand All @@ -198,7 +198,7 @@ func TestMountInfo(t *testing.T) {
mmit.addBaseTarget("/sub-x", podUID, pv)

mit := newMountInfoTable()
mit.parse()
_ = mit.parse()
mi := mit.resolveTarget(target)

So(mi, ShouldNotBeNil)
Expand Down
29 changes: 17 additions & 12 deletions pkg/controller/pod_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"fmt"
"os"
"runtime"
"strings"
"syscall"
"time"
Expand Down Expand Up @@ -509,9 +510,11 @@ func (p *PodDriver) podReadyHandler(ctx context.Context, pod *corev1.Pod) error
if e != nil {
return e
}
var dev uint64
if st, ok := finfo.Sys().(*syscall.Stat_t); ok {
if st.Ino == 1 {
resource.MountPointDevMinorTable.Store(mntPath, util.DevMinor(st.Dev))
dev = uint64(st.Dev)
util.DevMinorTableStore(mntPath, dev)
}
}
return e
Expand Down Expand Up @@ -611,7 +614,7 @@ func (p *PodDriver) umountTarget(target string, count int) {
klog.V(5).Infof("umount target %d times", count)
for i := 0; i < count; i++ {
// ignore error
p.Unmount(target)
_ = p.Unmount(target)
}
}

Expand Down Expand Up @@ -644,10 +647,6 @@ func (p *PodDriver) umountTargetUntilRemain(ctx context.Context, basemi *mountIt
}

util.UmountPath(subCtx, target)
select {
case <-subCtx.Done():
return fmt.Errorf("umountTargetWithRemain timeout")
}
}
}

Expand Down Expand Up @@ -741,7 +740,11 @@ func (p *PodDriver) checkMountPodStuck(pod *corev1.Pod) {
return
}
mountPoint, _, _ := util.GetMountPathOfPod(*pod)
defer resource.MountPointDevMinorTable.Delete(mountPoint)
defer func() {
if runtime.GOOS == "linux" {
util.DevMinorTableDelete(mountPoint)
}
}()

timeout := 1 * time.Minute
if pod.Spec.TerminationGracePeriodSeconds != nil {
Expand All @@ -757,12 +760,14 @@ func (p *PodDriver) checkMountPodStuck(pod *corev1.Pod) {
select {
case <-ctx.Done():
klog.V(5).Infof("pod %s/%s may be stuck in terminating state, create a job to abort fuse connection", pod.Namespace, pod.Name)
if devMinor, ok := resource.MountPointDevMinorTable.Load(mountPoint); ok {
if err := p.doAbortFuse(pod, devMinor.(uint32)); err != nil {
klog.Errorf("abort fuse connection error: %v", err)
if runtime.GOOS == "linux" {
if devMinor, ok := util.DevMinorTableLoad(mountPoint); ok {
if err := p.doAbortFuse(pod, uint32(devMinor)); err != nil {
klog.Errorf("abort fuse connection error: %v", err)
}
} else {
klog.Errorf("can't find devMinor of mountPoint %s", mountPoint)
}
} else {
klog.Errorf("can't find devMinor of mountPoint %s", mountPoint)
}
return
default:
Expand Down
10 changes: 5 additions & 5 deletions pkg/controller/pod_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,7 @@ func copyPod(oldPod *corev1.Pod) *corev1.Pod {
newPod.Spec = oldPod.Spec
newPod.Spec.Containers = make([]corev1.Container, 0)
if oldPod.Spec.Containers != nil && len(oldPod.Spec.Containers) != 0 {
for _, v := range oldPod.Spec.Containers {
newPod.Spec.Containers = append(newPod.Spec.Containers, v)
}
newPod.Spec.Containers = append(newPod.Spec.Containers, oldPod.Spec.Containers...)
}
newPod.Status = oldPod.Status
return &newPod
Expand Down Expand Up @@ -958,7 +956,9 @@ func TestPodDriver_podErrorHandler(t *testing.T) {
})
defer patch1.Reset()
_, err := d.Client.CreatePod(context.TODO(), errorPod1)
defer d.Client.DeletePod(context.TODO(), errorPod1)
defer func() {
_ = d.Client.DeletePod(context.TODO(), errorPod1)
}()
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -989,7 +989,7 @@ func TestPodDriver_podErrorHandler(t *testing.T) {
errPod := copyPod(resourceErrPod)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
d.Client.CreatePod(ctx, errPod)
_, _ = d.Client.CreatePod(ctx, errPod)
err := d.podErrorHandler(ctx, errPod)
So(err, ShouldBeNil)
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func doReconcile(ks *k8sclient.K8sClient, kc *k8sclient.KubeletClient) {
})
}
backOff.GC()
g.Wait()
_ = g.Wait()
finish:
cancel()
time.Sleep(time.Duration(config.ReconcilerInterval) * time.Second)
Expand Down
5 changes: 2 additions & 3 deletions pkg/dashboard/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ func newLogPipe(ctx context.Context, conn *websocket.Conn, stream io.ReadCloser)
return
}
if string(temp) == "ping" {
websocket.Message.Send(l.conn, "pong")
_ = websocket.Message.Send(l.conn, "pong")
}
}
}
Expand All @@ -728,8 +728,7 @@ func newLogPipe(ctx context.Context, conn *websocket.Conn, stream io.ReadCloser)
}

func (l *LogPipe) Write(p []byte) (int, error) {
websocket.Message.Send(l.conn, string(p))
return len(p), nil
return len(p), websocket.Message.Send(l.conn, string(p))
}

func (l *LogPipe) Read(p []byte) (int, error) {
Expand Down
9 changes: 1 addition & 8 deletions pkg/driver/identity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"google.golang.org/grpc"

"github.com/juicedata/juicefs-csi-driver/pkg/config"
"github.com/juicedata/juicefs-csi-driver/pkg/juicefs"
)

func TestDriver_GetPluginInfo(t *testing.T) {
Expand Down Expand Up @@ -81,24 +80,18 @@ func TestDriver_GetPluginInfo(t *testing.T) {
}

func TestGetPluginCapabilities(t *testing.T) {
type fields struct {
juicefs juicefs.Interface
vols map[string]int64
}
type args struct {
ctx context.Context
req *csi.GetPluginCapabilitiesRequest
}
tests := []struct {
name string
fields fields
args args
want *csi.GetPluginCapabilitiesResponse
wantErr bool
}{
{
name: "test",
fields: fields{},
name: "test",
args: args{
req: &csi.GetPluginCapabilitiesRequest{},
},
Expand Down
7 changes: 5 additions & 2 deletions pkg/driver/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ import (
"k8s.io/klog"
provisioncontroller "sigs.k8s.io/sig-storage-lib-external-provisioner/v6/controller"

"github.com/prometheus/client_golang/prometheus"

"github.com/juicedata/juicefs-csi-driver/pkg/config"
"github.com/juicedata/juicefs-csi-driver/pkg/juicefs"
k8s "github.com/juicedata/juicefs-csi-driver/pkg/k8sclient"
"github.com/juicedata/juicefs-csi-driver/pkg/util/resource"
"github.com/prometheus/client_golang/prometheus"
)

type provisionerService struct {
Expand Down Expand Up @@ -247,7 +248,9 @@ func (j *provisionerService) Delete(ctx context.Context, volume *corev1.Persiste
}
if shouldRemoveFinalizer {
klog.V(6).Infof("Provisioner: Remove Finalizer on %s/%s", secretNamespace, secretName)
resource.RemoveSecretFinalizer(ctx, j.K8sClient, secret, config.Finalizer)
if err = resource.RemoveSecretFinalizer(ctx, j.K8sClient, secret, config.Finalizer); err != nil {
return err
}
}
}
return nil
Expand Down
Loading

0 comments on commit 8171f0b

Please sign in to comment.