Skip to content

Commit da897f2

Browse files
committed
Fix lints
1 parent e08f91f commit da897f2

File tree

3 files changed

+15
-18
lines changed

3 files changed

+15
-18
lines changed

.golangci.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ issues:
2323
- path: .*\.go
2424
linters:
2525
- unused
26+
# Temporary: skip endpoint security lint until we rewrite EFC cache logics.
27+
- path: pkg/dadi/.*\.go
28+
text: endpoint
29+
linters:
30+
- gosec
2631

2732
# Mode of the generated files analysis.
2833
#

pkg/bmcpfs/bmcpfs.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17+
// Package bmcpfs provides the BMCPFS (Block Mount CPFS) CSI driver implementation.
1718
package bmcpfs
1819

1920
import (
@@ -47,7 +48,8 @@ const (
4748

4849
volumeHandleDelimiter = "+"
4950

50-
NODEID_INDEX = "nodeid-index"
51+
// NodeIDIndex is the index name for node ID in the informer cache
52+
NodeIDIndex = "nodeid-index"
5153
)
5254

5355
// Driver represents the BMCPFS CSI driver

pkg/bmcpfs/controllerserver.go

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,12 @@ func newControllerServer(region string) (*controllerServer, error) {
116116
return nil, err
117117
}
118118
kubeclient := mustGetKubeClient()
119-
nodeInformer := informerv1.NewFilteredNodeInformer(kubeclient, 0, cache.Indexers{NODEID_INDEX: nodeIndexFunc}, func(options *metav1.ListOptions) {
119+
nodeInformer := informerv1.NewFilteredNodeInformer(kubeclient, 0, cache.Indexers{NodeIDIndex: nodeIndexFunc}, func(options *metav1.ListOptions) {
120120
options.FieldSelector = fields.OneTermEqualSelector("alibabacloud.com/lingjun-worker", "true").String()
121121
})
122-
nodeInformer.SetTransform(nodeTransformFunc)
122+
if err := nodeInformer.SetTransform(nodeTransformFunc); err != nil {
123+
return nil, fmt.Errorf("failed to set transform function: %w", err)
124+
}
123125
return &controllerServer{
124126
vscManager: internal.NewPrimaryVscManagerWithCache(efloClient),
125127
attachDetacher: internal.NewCPFSAttachDetacher(nasClient),
@@ -137,16 +139,6 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
137139
logger := klog.FromContext(ctx)
138140
logger.V(2).Info("starting")
139141

140-
// Handle static volume creation (existing fileset)
141-
csiVolume, err := staticFileSetCreate(req, cs.filsetManager)
142-
if err != nil {
143-
return nil, status.Errorf(codes.InvalidArgument, "create static volume failed: %v", err)
144-
}
145-
if csiVolume != nil {
146-
klog.Infof("CreateVolume: static volume create successful, pvName: %s, VolumeId: %s, volumeContext: %v", req.Name, csiVolume.VolumeId, csiVolume.VolumeContext)
147-
return &csi.CreateVolumeResponse{Volume: csiVolume}, nil
148-
}
149-
150142
// Validate parameters
151143
if err := validateFileSetParameters(req); err != nil {
152144
klog.Errorf("CreateVolume: error parameters from input: %v, with error: %v", req.Name, err)
@@ -366,22 +358,20 @@ func (cs *controllerServer) ControllerUnpublishVolume(ctx context.Context, req *
366358
if !nodeStatus.HasPrefixInUse(cpfsID) {
367359
err := cs.attachDetacher.Detach(ctx, cpfsID, vsc.VscID)
368360
if err != nil {
369-
return nil, status.Error(codes.Internal, err.Error())
361+
return nil, status.Errorf(codes.Internal, "detach error: %v", err.Error())
370362
}
371363
return &csi.ControllerUnpublishVolumeResponse{}, nil
372364
}
373-
// 分支2:inuse & attach 同时存在,跳过卸载,返回成功
374365
if nodeStatus.HasPrefixInUse(cpfsID) && nodeStatus.HasVolumeAttachment(cpfsID) {
375-
klog.Infof("volume is in use and attached, skip detach for cpfsID: %s at node: %s", cpfsID, lingjunInstanceID)
366+
klog.InfoS("volume is in use and attached, skip detach", "cpfsID", cpfsID, "lingjunID", lingjunInstanceID)
376367
return &csi.ControllerUnpublishVolumeResponse{}, nil
377368
}
378-
// 分支3:inuse 存在,除了当前的 cpfs+fileset 之外的 attach 不存在,双重检查后卸载
379369
if nodeStatus.HasPrefixInUse(cpfsID) && !nodeStatus.HasVolumeAttachment(cpfsID) {
380370
currentStatus, err := cs.getActualStateOfNodeVolumeAttached(nodeStatus.Name) // TODO: checkRemoteNodeStatusByNodeName
381371
if err == nil && !currentStatus.HasVolumeAttachmentExceptVolumeHandle(cpfsID, req.VolumeId) {
382372
err := cs.attachDetacher.Detach(ctx, cpfsID, vsc.VscID)
383373
if err != nil {
384-
return nil, status.Error(codes.Internal, err.Error())
374+
return nil, status.Errorf(codes.Internal, "detach error: %v", err.Error())
385375
}
386376
// TODO: patch event 到 node
387377
return &csi.ControllerUnpublishVolumeResponse{}, nil

0 commit comments

Comments
 (0)