Skip to content

Commit

Permalink
fix: linter checks
Browse files Browse the repository at this point in the history
Linter fixes.

Signed-off-by: Serge Logvinov <serge.logvinov@sinextra.dev>
  • Loading branch information
sergelogvinov committed Dec 22, 2024
1 parent 9fb1d83 commit 006d804
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 44 deletions.
22 changes: 11 additions & 11 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ run:
# include test files or not, default is true
tests: true

# which files to skip: they will be analyzed, but issues from them
# won't be reported. Default value is empty list, but there is
# no need to include all autogenerated files, we confidently recognize
# autogenerated files. If it's not please let us know.
exclude-files:
- charts/
- docs/

# list of build tags, all linters use it. Default is empty list.
build-tags:
- integration
Expand Down Expand Up @@ -72,7 +64,7 @@ linters-settings:
lll:
# max line length, lines longer will be reported. Default is 120.
# '\t' is counted as 1 character by default, and can be changed with the tab-width option
line-length: 200
line-length: 400
# tab width in spaces. Default to 1.
tab-width: 1
unparam:
Expand Down Expand Up @@ -116,6 +108,9 @@ linters-settings:
linters:
enable-all: true
disable:
- wsl
- nlreturn

- depguard
- errorlint
- exhaustruct
Expand Down Expand Up @@ -168,14 +163,19 @@ issues:
- package comment should be of the form "Package services ..." # revive
- ^ST1000 # ST1000: at least one file in a package should have a package comment (stylecheck)

exclude-rules:

# Independently from option `exclude` we use default exclude patterns,
# it can be disabled by this option. To list all
# excluded by default patterns execute `golangci-lint run --help`.
# Default value for this option is true.
exclude-use-default: false

# Which dirs to exclude: issues from them won't be reported.
# Can use regexp here: `generated.*`, regexp is applied on full path,
# including the path prefix if one is set.
exclude-dirs:
# copied from kubernetes repo
- pkg/csi

# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
max-issues-per-linter: 0

Expand Down
15 changes: 8 additions & 7 deletions cmd/csi-provisioner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ import (
"strings"
"time"

"github.com/kubernetes-csi/csi-lib-utils/leaderelection"
flag "github.com/spf13/pflag"
controller "sigs.k8s.io/sig-storage-lib-external-provisioner/v10/controller"

"github.com/sergelogvinov/hybrid-csi-plugin/pkg/provisioner"

flag "github.com/spf13/pflag"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/klog/v2"

"github.com/kubernetes-csi/csi-lib-utils/leaderelection"
controller "sigs.k8s.io/sig-storage-lib-external-provisioner/v10/controller"
)

var (
Expand All @@ -58,10 +58,11 @@ var (
)

const (
// DriverName is the name of the driver
DriverName = "csi.hybrid.sinextra.dev"

ResyncPeriodOfCsiNodeInformer = 1 * time.Hour
ResyncPeriodOfReferenceGrantInformer = 1 * time.Hour
// ResyncPeriodOfCsiNodeInformer is the resync period of the informer for the CSINode objects
ResyncPeriodOfCsiNodeInformer = 1 * time.Hour
)

func main() {
Expand Down Expand Up @@ -164,7 +165,7 @@ func main() {
} else {
// this lock name pattern is also copied from sigs.k8s.io/sig-storage-lib-external-provisioner/controller
// to preserve backwards compatibility
lockName := strings.Replace(DriverName, "/", "-", -1)
lockName := strings.ReplaceAll(DriverName, "/", "-")

// create a new clientset for leader election
leClientset, err := kubernetes.NewForConfig(coreConfig)
Expand Down
8 changes: 2 additions & 6 deletions pkg/csi/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package csi

import (
"context"
"sync"

"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/kubernetes-csi/csi-lib-utils/protosanitizer"
Expand All @@ -41,9 +40,6 @@ var controllerCaps = []csi.ControllerServiceCapability_RPC_Type{
// ControllerService is the controller service for the CSI driver
type ControllerService struct {
Kclient clientkubernetes.Interface

volumeLocks sync.Mutex

csi.UnimplementedControllerServer
}

Expand Down Expand Up @@ -89,14 +85,14 @@ func (d *ControllerService) ControllerGetCapabilities(_ context.Context, _ *csi.
}

// ControllerPublishVolume publish a volume
func (d *ControllerService) ControllerPublishVolume(ctx context.Context, request *csi.ControllerPublishVolumeRequest) (*csi.ControllerPublishVolumeResponse, error) {
func (d *ControllerService) ControllerPublishVolume(_ context.Context, request *csi.ControllerPublishVolumeRequest) (*csi.ControllerPublishVolumeResponse, error) {
klog.V(4).InfoS("ControllerPublishVolume: called", "args", protosanitizer.StripSecrets(request))

return nil, status.Error(codes.Unimplemented, "")
}

// ControllerUnpublishVolume unpublish a volume
func (d *ControllerService) ControllerUnpublishVolume(ctx context.Context, request *csi.ControllerUnpublishVolumeRequest) (*csi.ControllerUnpublishVolumeResponse, error) {
func (d *ControllerService) ControllerUnpublishVolume(_ context.Context, request *csi.ControllerUnpublishVolumeRequest) (*csi.ControllerUnpublishVolumeResponse, error) {
klog.V(4).InfoS("ControllerUnpublishVolume: called", "args", protosanitizer.StripSecrets(request))

return nil, status.Error(codes.Unimplemented, "")
Expand Down
4 changes: 0 additions & 4 deletions pkg/csi/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package csi
import (
"context"
"fmt"
"sync"

"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/kubernetes-csi/csi-lib-utils/protosanitizer"
Expand Down Expand Up @@ -55,9 +54,6 @@ var volumeCaps = []csi.VolumeCapability_AccessMode{
type NodeService struct {
nodeID string
kclient kubernetes.Interface

volumeLocks sync.Mutex

csi.UnimplementedNodeServer
}

Expand Down
38 changes: 22 additions & 16 deletions pkg/provisioner/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// Package provisioner contains the Hybrid CSI driver implementation
package provisioner

import (
Expand All @@ -22,8 +23,7 @@ import (
"fmt"
"time"

corelisters "k8s.io/client-go/listers/core/v1"
storagelistersv1 "k8s.io/client-go/listers/storage/v1"
controller "sigs.k8s.io/sig-storage-lib-external-provisioner/v10/controller"

corev1 "k8s.io/api/core/v1"
storagev1 "k8s.io/api/storage/v1"
Expand All @@ -33,15 +33,12 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/kubernetes"
corelisters "k8s.io/client-go/listers/core/v1"
storagelistersv1 "k8s.io/client-go/listers/storage/v1"
"k8s.io/component-helpers/storage/volume"
"k8s.io/klog/v2"

controller "sigs.k8s.io/sig-storage-lib-external-provisioner/v10/controller"
)

const annBetaStorageProvisioner = "volume.beta.kubernetes.io/storage-provisioner"
const annStorageProvisioner = "volume.kubernetes.io/storage-provisioner"

const (
// DriverName is the name of the CSI driver
DriverName = "csi.hybrid.sinextra.dev"
Expand All @@ -50,10 +47,14 @@ const (

defaultCreateProvisionedPVRetryCount = 5
defaultCreateProvisionedPVInterval = 10 * time.Second

annBetaStorageProvisioner = "volume.beta.kubernetes.io/storage-provisioner"
annStorageProvisioner = "volume.kubernetes.io/storage-provisioner"
)

// HybridProvisioner is a hybrid provisioner
type HybridProvisioner struct {
ctx context.Context
ctx context.Context // nolint: containedctx
client kubernetes.Interface

backoff wait.Backoff
Expand All @@ -64,6 +65,7 @@ type HybridProvisioner struct {
claimLister corelisters.PersistentVolumeClaimLister
}

// NewProvisioner creates a new hybrid provisioner
func NewProvisioner(
ctx context.Context,
client kubernetes.Interface,
Expand Down Expand Up @@ -91,6 +93,14 @@ func NewProvisioner(
return p
}

// Provision creates a volume i.e. the storage asset and returns a PV object
// for the volume. The provisioner can return an error (e.g. timeout) and state
// ProvisioningInBackground to tell the controller that provisioning may be in
// progress after Provision() finishes. The controller will call Provision()
// again with the same parameters, assuming that the provisioner continues
// provisioning the volume. The provisioner must return either final error (with
// ProvisioningFinished) or success eventually, otherwise the controller will try
// forever (unless FailedProvisionThreshold is set).
func (p *HybridProvisioner) Provision(ctx context.Context, opts controller.ProvisionOptions) (*corev1.PersistentVolume, controller.ProvisioningState, error) {
klog.V(4).InfoS("Provision: called", "PV", opts.PVName, "node", klog.KObj(opts.SelectedNode), "storageClass", klog.KObj(opts.StorageClass))

Expand All @@ -116,6 +126,8 @@ func (p *HybridProvisioner) Provision(ctx context.Context, opts controller.Provi
return pv, controller.ProvisioningFinished, nil
}

// Delete removes the storage asset that was created by Provision backing the
// given PV. Does not delete the PV object itself.
func (p *HybridProvisioner) Delete(_ context.Context, pv *corev1.PersistentVolume) (err error) {
klog.V(4).InfoS("Delete: called", "pv", pv.Name)

Expand Down Expand Up @@ -266,7 +278,7 @@ func (p *HybridProvisioner) createPV(ctx context.Context, opts controller.Provis
}

func (p *HybridProvisioner) bondPVC(ctx context.Context, opts controller.ProvisionOptions, pvName string, storageClass *storagev1.StorageClass) error {
patchPVC := corev1.PersistentVolumeClaim{
patch, _ := json.Marshal(&corev1.PersistentVolumeClaim{ // nolint: errcheck,errchkjson
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
annStorageProvisioner: storageClass.Provisioner,
Expand All @@ -278,9 +290,8 @@ func (p *HybridProvisioner) bondPVC(ctx context.Context, opts controller.Provisi
Spec: corev1.PersistentVolumeClaimSpec{
VolumeName: pvName,
},
}
})

patch, _ := json.Marshal(&patchPVC)
if _, err := p.client.CoreV1().PersistentVolumeClaims(opts.PVC.Namespace).Patch(ctx, opts.PVC.Name, types.MergePatchType, patch, metav1.PatchOptions{}); err != nil {
return fmt.Errorf("failed to patch PersistentVolumeClaims: %v", err)
}
Expand All @@ -294,8 +305,3 @@ func (p *HybridProvisioner) bondPVC(ctx context.Context, opts controller.Provisi

return nil
}

func bytesToQuantity(bytes int64) resource.Quantity {
quantity := resource.NewQuantity(bytes, resource.BinarySI)
return *quantity
}

0 comments on commit 006d804

Please sign in to comment.