Skip to content

Commit

Permalink
chore(deps): handle code analysis warnings (GoUnusedParameter)
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeyberezansky committed Sep 27, 2024
1 parent 7325dae commit 28837a9
Show file tree
Hide file tree
Showing 16 changed files with 78 additions and 105 deletions.
2 changes: 1 addition & 1 deletion docs/NFS.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ This is done by setting the `pluginConfig.mountProtocol.allowNfsFailback` parame
The parameter `pluginConfig.mountProtocol.useNfs` enforces the use of NFS transport even if Weka client is installed on the node,
and recommended to be set to `true` ONLY for testing.

Follow the [Helm installation instructions](./charts/csi-wekafsplugin/README.md) to install the Weka CSI Plugin.
Follow the [Helm installation instructions](../charts/csi-wekafsplugin/README.md) to install the Weka CSI Plugin.
Most of the installation steps are the same as for the native WekaFS driver, however, additional parameters should be set in the `values.yaml` file,
or passed as command line arguments to the `helm install` command.

Expand Down
2 changes: 1 addition & 1 deletion docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ pvc-ee54de25-14f3-4024-98d0-12225e4b8215 4Gi RWX Delete
<REPLACE spec.resources.requests.storage value with 4Gi>
```

1. Check that configuration was applied
2. Check that configuration was applied
```shell script
$ kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
Expand Down
1 change: 1 addition & 0 deletions pkg/wekafs/apiclient/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ func (fs *FileSystem) GetType() string {
return "filesystem"
}

//goland:noinspection GoUnusedParameter
func (fs *FileSystem) GetBasePath(a *ApiClient) string {
return "fileSystems"
}
Expand Down
1 change: 1 addition & 0 deletions pkg/wekafs/apiclient/interfacegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func (i *InterfaceGroup) GetType() string {
return "interfaceGroup"
}

//goland:noinspection GoUnusedParameter
func (i *InterfaceGroup) GetBasePath(client *ApiClient) string {
return "interfaceGroups"
}
Expand Down
15 changes: 4 additions & 11 deletions pkg/wekafs/apiclient/nfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func (n NfsVersionString) AsWeka() NfsVersionString {

type NfsAuthType string

//goland:noinspection GoUnusedConst
const (
NfsPermissionTypeReadWrite NfsPermissionType = "RW"
NfsPermissionTypeReadOnly NfsPermissionType = "RO"
Expand Down Expand Up @@ -76,13 +77,14 @@ func (n *NfsPermission) GetType() string {
return "nfsPermission"
}

//goland:noinspection GoUnusedParameter
func (n *NfsPermission) GetBasePath(a *ApiClient) string {
return "nfs/permissions"
}

func (n *NfsPermission) GetApiUrl(a *ApiClient) string {
url, err := urlutil.URLJoin(n.GetBasePath(a), n.Uid.String())
if err != nil {
if err == nil {
return url
}
return ""
Expand All @@ -106,16 +108,6 @@ func (n *NfsPermission) IsEligibleForCsi() bool {
n.SquashMode == NfsPermissionSquashModeNone
}

func (a *ApiClient) GetNfsPermissions(ctx context.Context, fsUid uuid.UUID, permissions *[]NfsPermission) error {
n := &NfsPermission{}

err := a.Get(ctx, n.GetBasePath(a), nil, permissions)
if err != nil {
return err
}
return nil
}

func (a *ApiClient) FindNfsPermissionsByFilter(ctx context.Context, query *NfsPermission, resultSet *[]NfsPermission) error {
op := "FindNfsPermissionsByFilter"
ctx, span := otel.Tracer(TracerName).Start(ctx, op)
Expand Down Expand Up @@ -333,6 +325,7 @@ func (g *NfsClientGroup) GetType() string {
return "clientGroup"
}

//goland:noinspection GoUnusedParameter
func (g *NfsClientGroup) GetBasePath(a *ApiClient) string {
return "nfs/clientGroups"
}
Expand Down
35 changes: 23 additions & 12 deletions pkg/wekafs/apiclient/nfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ var fsName string
var client *ApiClient

func TestMain(m *testing.M) {
flag.StringVar(&endpoint, "api-endpoint", "vm125-1726039130891528-0.lan:14000", "API endpoint for tests")
flag.StringVar(&endpoint, "api-endpoint", "localhost:14000", "API endpoint for tests")
flag.StringVar(&creds.Username, "api-username", "admin", "API username for tests")
flag.StringVar(&creds.Password, "api-password", "AAbb1234", "API password for tests")
flag.StringVar(&creds.Password, "api-password", "Qwerty1@", "API password for tests")
flag.StringVar(&creds.Organization, "api-org", "Root", "API org for tests")
flag.StringVar(&creds.HttpScheme, "api-scheme", "https", "API scheme for tests")
flag.StringVar(&fsName, "fs-name", "default", "Filesystem name for tests")
Expand Down Expand Up @@ -81,16 +81,27 @@ func GetApiClientForTest(t *testing.T) *ApiClient {
// assert.NoError(t, err)
// assert.NotNil(t, result)
//}
//
//func TestGetNfsPermissionsByFilesystemName(t *testing.T) {
// apiClient := GetApiClientForTest(t)
//
//
// var permissions []NfsPermission
// err := apiClient.GetNfsPermissionsByFilesystemName(context.Background(), "fs1", &permissions)
// assert.NoError(t, err)
// assert.NotEmpty(t, permissions)
//}

func TestFindNfsPermissionsByFilesystemName(t *testing.T) {
apiClient := GetApiClientForTest(t)

var permissions []NfsPermission
err := apiClient.FindNfsPermissionsByFilesystem(context.Background(), "snapvolFilesystem", &permissions)
assert.NoError(t, err)
assert.NotEmpty(t, permissions)
if len(permissions) > 0 {
for _, p := range permissions {
r := &NfsPermissionDeleteRequest{Uid: p.Uid}
err := apiClient.DeleteNfsPermission(context.Background(), r)
assert.NoError(t, err)
}
}
err = apiClient.FindNfsPermissionsByFilesystem(context.Background(), "snapvolFilesystem", &permissions)
assert.NoError(t, err)
assert.Empty(t, permissions)

}

//
//func TestGetNfsPermissionByUid(t *testing.T) {
// apiClient := GetApiClientForTest(t)
Expand Down
19 changes: 11 additions & 8 deletions pkg/wekafs/apiclient/quota.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ import (
type QuotaType string
type QuotaStatus string

const QuotaTypeHard QuotaType = "HARD"
const QuotaTypeSoft QuotaType = "SOFT"
const QuotaTypeDefault = QuotaTypeHard
const QuotaStatusActive = "ACTIVE"
const QuotaStatusPending = "ADDING"
const QuotaStatusError = "ERROR"
const QuotaStatusDeleting = "DELETING"
const MaxQuotaSize uint64 = 9223372036854775807
//goland:noinspection GoUnusedConst
const (
QuotaTypeHard QuotaType = "HARD"
QuotaTypeSoft QuotaType = "SOFT"
QuotaTypeDefault = QuotaTypeHard
QuotaStatusActive = "ACTIVE"
QuotaStatusPending = "ADDING"
QuotaStatusError = "ERROR"
QuotaStatusDeleting = "DELETING"
MaxQuotaSize uint64 = 9223372036854775807
)

type Quota struct {
FilesystemUid uuid.UUID `json:"-"`
Expand Down
1 change: 1 addition & 0 deletions pkg/wekafs/apiclient/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ func (snap *Snapshot) GetType() string {
return "snapshot"
}

//goland:noinspection GoUnusedParameter
func (snap *Snapshot) GetBasePath(a *ApiClient) string {
return "snapshots"
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/wekafs/apiclient/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func GetNodeIpAddressByRouting(targetHost string) (string, error) {
if err != nil {
return "", err
}
defer conn.Close()
defer func() { _ = conn.Close() }()

// Set a deadline for the connection
err = conn.SetDeadline(time.Now().Add(1 * time.Second))
Expand Down
4 changes: 4 additions & 0 deletions pkg/wekafs/identityserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type identityServer struct {
config *DriverConfig
}

//goland:noinspection GoExportedFuncWithUnexportedType
func NewIdentityServer(name, version string, config *DriverConfig) *identityServer {
return &identityServer{
name: name,
Expand All @@ -44,6 +45,7 @@ func NewIdentityServer(name, version string, config *DriverConfig) *identityServ
}
}

//goland:noinspection GoUnusedParameter
func (ids *identityServer) GetPluginInfo(ctx context.Context, req *csi.GetPluginInfoRequest) (*csi.GetPluginInfoResponse, error) {
op := "GetPluginInfo"
result := "SUCCESS"
Expand Down Expand Up @@ -78,6 +80,7 @@ func (ids *identityServer) getConfig() *DriverConfig {
return ids.config
}

//goland:noinspection GoUnusedParameter
func (ids *identityServer) Probe(ctx context.Context, req *csi.ProbeRequest) (*csi.ProbeResponse, error) {
logger := log.Ctx(ctx)
isReady := ids.getConfig().isInDevMode() || isWekaInstalled()
Expand All @@ -96,6 +99,7 @@ func (ids *identityServer) Probe(ctx context.Context, req *csi.ProbeRequest) (*c
}, nil
}

//goland:noinspection GoUnusedParameter
func (ids *identityServer) GetPluginCapabilities(ctx context.Context, req *csi.GetPluginCapabilitiesRequest) (*csi.GetPluginCapabilitiesResponse, error) {
op := "GetPluginCapabilities"
result := "SUCCESS"
Expand Down
2 changes: 1 addition & 1 deletion pkg/wekafs/nfsmount.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (m *nfsMount) doMount(ctx context.Context, apiClient *apiclient.ApiClient,
}

if apiClient.EnsureNfsPermissions(ctx, nodeIP, m.fsName, apiclient.NfsVersionV4, m.clientGroupName) != nil {
logger.Error().Msg("Failed to ensure NFS permissions")
logger.Error().Err(err).Msg("Failed to ensure NFS permissions")
return errors.New("failed to ensure NFS permissions")
}

Expand Down
86 changes: 18 additions & 68 deletions pkg/wekafs/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,16 @@ func (ns *NodeServer) NodeGetVolumeStats(ctx context.Context, req *csi.NodeGetVo
volumePath := req.GetVolumePath()

// Validate request fields
if volumeID == "" || volumePath == "" {
return nil, status.Error(codes.InvalidArgument, "Volume ID and path must be provided")
if volumeID == "" {
return nil, status.Error(codes.InvalidArgument, "Volume ID must be provided")
}
if volumePath == "" {
return nil, status.Error(codes.InvalidArgument, "Volume path must be provided")
}
if req.GetStagingTargetPath() != "" {
if !PathExists(req.GetStagingTargetPath()) {
return nil, status.Error(codes.NotFound, "Staging area path not found")
}
}

// Check if the volume path exists
Expand Down Expand Up @@ -185,7 +193,6 @@ func NewNodeServer(nodeId string, maxVolumesPerNode int64, api *ApiStore, mounte
csi.NodeServiceCapability_RPC_SINGLE_NODE_MULTI_WRITER,
csi.NodeServiceCapability_RPC_GET_VOLUME_STATS,
csi.NodeServiceCapability_RPC_VOLUME_CONDITION,
//csi.NodeServiceCapability_RPC_EXPAND_VOLUME,
},
),
nodeID: nodeId,
Expand Down Expand Up @@ -454,6 +461,10 @@ func (ns *NodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpu
} else {
msg := fmt.Sprintf("Directory %s exists, but not a weka mount, assuming already unpublished", targetPath)
logger.Warn().Msg(msg)
if err := os.Remove(targetPath); err != nil {
result = "FAILURE"
return NodeUnpublishVolumeError(ctx, codes.Internal, err.Error())
}
result = "SUCCESS_WITH_WARNING"
return &csi.NodeUnpublishVolumeResponse{}, nil
}
Expand All @@ -475,75 +486,14 @@ func (ns *NodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpu
return &csi.NodeUnpublishVolumeResponse{}, nil
}

func NodeStageVolumeError(ctx context.Context, errorCode codes.Code, errorMessage string) (*csi.NodeStageVolumeResponse, error) {
err := status.Error(errorCode, strings.ToLower(errorMessage))
log.Ctx(ctx).Err(err).CallerSkipFrame(1).Msg("Error staging volume")
return &csi.NodeStageVolumeResponse{}, err
}

//goland:noinspection GoUnusedParameter
func (ns *NodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRequest) (*csi.NodeStageVolumeResponse, error) {
op := "NodeStageVolume"
ctx, span := otel.Tracer(TracerName).Start(ctx, op, trace.WithNewRoot())
defer span.End()
ctx = log.With().Str("trace_id", span.SpanContext().TraceID().String()).Str("span_id", span.SpanContext().SpanID().String()).Str("op", op).Logger().WithContext(ctx)

volumeId := req.GetVolumeId()
logger := log.Ctx(ctx)
result := "FAILURE"
logger.Info().Str("volume_id", volumeId).Msg(">>>> Received request")
defer func() {
level := zerolog.InfoLevel
if result != "SUCCESS" {
level = zerolog.ErrorLevel
}
logger.WithLevel(level).Str("result", result).Msg("<<<< Completed processing request")
}()

// Check arguments
if len(req.GetStagingTargetPath()) == 0 {
return NodeStageVolumeError(ctx, codes.InvalidArgument, "Target path missing in request")
}

if req.GetVolumeCapability() == nil {
return NodeStageVolumeError(ctx, codes.InvalidArgument, "Error occured, volume Capability missing in request")
}

if req.GetVolumeCapability().GetBlock() != nil {
return NodeStageVolumeError(ctx, codes.InvalidArgument, "Block accessType is unsupported")
}
result = "SUCCESS"
return &csi.NodeStageVolumeResponse{}, nil
}

func NodeUnstageVolumeError(ctx context.Context, errorCode codes.Code, errorMessage string) (*csi.NodeUnstageVolumeResponse, error) {
err := status.Error(errorCode, strings.ToLower(errorMessage))
log.Ctx(ctx).Err(err).CallerSkipFrame(1).Msg("Error unstaging volume")
return &csi.NodeUnstageVolumeResponse{}, err
return nil, status.Error(codes.Unimplemented, "NodeStageVolume is not supported")
}

//goland:noinspection GoUnusedParameter
func (ns *NodeServer) NodeUnstageVolume(ctx context.Context, req *csi.NodeUnstageVolumeRequest) (*csi.NodeUnstageVolumeResponse, error) {
op := "NodeUnstageVolume"
result := "FAILURE"
volumeId := req.GetVolumeId()
ctx, span := otel.Tracer(TracerName).Start(ctx, op, trace.WithNewRoot())
defer span.End()
ctx = log.With().Str("trace_id", span.SpanContext().TraceID().String()).Str("span_id", span.SpanContext().SpanID().String()).Str("op", op).Logger().WithContext(ctx)

logger := log.Ctx(ctx)
logger.Info().Str("volume_id", volumeId).Msg(">>>> Received request")
defer func() {
level := zerolog.InfoLevel
if result != "SUCCESS" {
level = zerolog.ErrorLevel
}
logger.WithLevel(level).Str("result", result).Msg("<<<< Completed processing request")
}()

if len(req.GetStagingTargetPath()) == 0 {
return NodeUnstageVolumeError(ctx, codes.InvalidArgument, "Target path missing in request")
}
result = "SUCCESS"
return &csi.NodeUnstageVolumeResponse{}, nil
return nil, status.Error(codes.Unimplemented, "NodeUnstageVolume is not supported")
}

//goland:noinspection GoUnusedParameter
Expand Down
1 change: 1 addition & 0 deletions pkg/wekafs/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const (
xattrVolumeName = "user.weka_k8s_volname"
)

//goland:noinspection GoExportedFuncWithUnexportedType
func NewNonBlockingGRPCServer(mode CsiPluginMode) *nonBlockingGRPCServer {
return &nonBlockingGRPCServer{
csiMmode: mode,
Expand Down
1 change: 1 addition & 0 deletions pkg/wekafs/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ func fileExists(filename string) bool {
return false
}

//goland:noinspection GoUnusedParameter
func PathIsWekaMount(ctx context.Context, path string) bool {
file, err := os.Open("/proc/mounts")
if err != nil {
Expand Down
Loading

0 comments on commit 28837a9

Please sign in to comment.