Skip to content

Commit

Permalink
fix linting issue
Browse files Browse the repository at this point in the history
  • Loading branch information
xuluna committed Feb 26, 2024
1 parent 4e57cb5 commit cf620f6
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 26 deletions.
19 changes: 9 additions & 10 deletions controllers/dellcsivolumegroupsnapshot_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,12 @@ func (r *DellCsiVolumeGroupSnapshotReconciler) Reconcile(ctx context.Context, re
var volIDPvcNameMap map[string]string
var volErr error
if vg.Spec.PvcList != nil {
srcVolIDs, volIDPvcNameMap, volErr = r.getSourceVolIdsFromPvcName(ctx, vg.Spec.PvcList, ns)
srcVolIDs, volIDPvcNameMap, volErr = r.getSourceVolIDsFromPvcName(ctx, vg.Spec.PvcList, ns)
} else if vg.Spec.PvcLabel != "" {
srcVolIDs, volIDPvcNameMap, volErr = r.getSourceVolIdsFromLabel(ctx, vg.Spec.PvcLabel, ns)
srcVolIDs, volIDPvcNameMap, volErr = r.getSourceVolIDsFromLabel(ctx, vg.Spec.PvcLabel, ns)
} else {
// snapshot pvcs under given namespace
srcVolIDs, volIDPvcNameMap, volErr = r.getSourceVolIdsFromNs(ctx, ns)
srcVolIDs, volIDPvcNameMap, volErr = r.getSourceVolIDsFromNs(ctx, ns)
}

if volErr != nil {
Expand Down Expand Up @@ -419,7 +419,7 @@ func (r *DellCsiVolumeGroupSnapshotReconciler) bindContentToSnapshot(
contentName string,
vgNamespace string,
vgName string,
failedMap map[string]string,
_ map[string]string,
) error {
vs := new(s1.VolumeSnapshot)
nameSpacedName := t1.NamespacedName{
Expand Down Expand Up @@ -764,7 +764,7 @@ func (r *DellCsiVolumeGroupSnapshotReconciler) checkExistingVolSnapshot(
}

// get a list of source volume Ids, a map from these Ids to corresponding pvc names based on the given pvc label
func (r *DellCsiVolumeGroupSnapshotReconciler) getSourceVolIdsFromLabel(ctx context.Context,
func (r *DellCsiVolumeGroupSnapshotReconciler) getSourceVolIDsFromLabel(ctx context.Context,
label string, ns string,
) ([]string, map[string]string, error) {
pvclabel := label
Expand Down Expand Up @@ -793,7 +793,7 @@ func (r *DellCsiVolumeGroupSnapshotReconciler) getSourceVolIdsFromLabel(ctx cont
}

// get a list of source volume Ids, a map from these Ids to corresponding pvc names based on a list of pvc names
func (r *DellCsiVolumeGroupSnapshotReconciler) getSourceVolIdsFromPvcName(ctx context.Context, pvcNames []string, ns string) ([]string, map[string]string, error) {
func (r *DellCsiVolumeGroupSnapshotReconciler) getSourceVolIDsFromPvcName(ctx context.Context, pvcNames []string, ns string) ([]string, map[string]string, error) {
duplicateMap := make(map[string]bool)
pvcList := make([]v1.PersistentVolumeClaim, 0)
for _, pvcName := range pvcNames {
Expand All @@ -802,9 +802,8 @@ func (r *DellCsiVolumeGroupSnapshotReconciler) getSourceVolIdsFromPvcName(ctx co
if present {
log.Info("VG Snapshotter vg finds duplicate PVC names ", "pvc name", pvcName)
continue
} else {
duplicateMap[pvcName] = true
}
duplicateMap[pvcName] = true

// find pvc for the given pvc Name
pvc := &v1.PersistentVolumeClaim{}
Expand All @@ -823,7 +822,7 @@ func (r *DellCsiVolumeGroupSnapshotReconciler) getSourceVolIdsFromPvcName(ctx co
return r.mapVolIDToPvcName(ctx, pvcList)
}

func (r *DellCsiVolumeGroupSnapshotReconciler) getSourceVolIdsFromNs(ctx context.Context, ns string) ([]string, map[string]string, error) {
func (r *DellCsiVolumeGroupSnapshotReconciler) getSourceVolIDsFromNs(ctx context.Context, ns string) ([]string, map[string]string, error) {
pvcList := &v1.PersistentVolumeClaimList{}
log.Info("VG Snapshotter find matching pvc", "namespace", ns)

Expand Down Expand Up @@ -1013,7 +1012,7 @@ func (r *DellCsiVolumeGroupSnapshotReconciler) ignoreUpdatePredicate() predicate
}
}

func (r *DellCsiVolumeGroupSnapshotReconciler) handleSnapUpdate(oldObj interface{}, obj interface{}) {
func (r *DellCsiVolumeGroupSnapshotReconciler) handleSnapUpdate(_ interface{}, obj interface{}) {
nsnapshot, _ := obj.(*s1.VolumeSnapshot)

// vgs-helm-test-1-pvol1
Expand Down
5 changes: 3 additions & 2 deletions controllers/dellcsivolumegroupsnapshot_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ func (suite *VGSControllerTestSuite) createReconcilerAndReq(localVgName string)
return
}

func (suite *VGSControllerTestSuite) runFakeVGManagerSetup(localVgName, expectedErr string) {
func (suite *VGSControllerTestSuite) runFakeVGManagerSetup(_, expectedErr string) {
vgReconcile, req := suite.createReconcilerAndReq(vgName)

mgr, _ := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Expand Down Expand Up @@ -675,6 +675,7 @@ func (suite *VGSControllerTestSuite) deleteVGForReUse(localVgName string, induce
vc := &s1.VolumeSnapshotContent{}
for _, c := range vcList.Items {
fmt.Printf("fake client found content ReadyToUse %#v \n", c)
c := c
vc = &c
}
*vc.Spec.Source.SnapshotHandle = "badid"
Expand Down Expand Up @@ -705,7 +706,7 @@ func (suite *VGSControllerTestSuite) deleteVGForReUse(localVgName string, induce
suite.makeFakeVG(ctx, label, "reuse-vg-snap", suite.mockUtils.Specs.Namespace, "Retain", nil)
}

func (suite *VGSControllerTestSuite) runFakeVGManager(localVgName, namespace, expectedErr string) {
func (suite *VGSControllerTestSuite) runFakeVGManager(localVgName, _, expectedErr string) {
vgReconcile, req := suite.createReconcilerAndReq(localVgName)

// invoke controller Reconcile to test. typically k8s would call this when resource is changed
Expand Down
4 changes: 2 additions & 2 deletions pkg/csiclient/csiclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func New(conn *grpc.ClientConn, log logr.Logger, timeout time.Duration) *VolumeG
}

// CreateVolumeGroupSnapshot grpc call to driver
func (v *VolumeGroupSnapshotClient) CreateVolumeGroupSnapshot(vgName string, volIds []string,
func (v *VolumeGroupSnapshotClient) CreateVolumeGroupSnapshot(vgName string, volIDs []string,
params map[string]string,
) (*vgsext.CreateVolumeGroupSnapshotResponse, error) {
ctx, cancel := context.WithTimeout(context.Background(), v.timeout)
Expand All @@ -58,7 +58,7 @@ func (v *VolumeGroupSnapshotClient) CreateVolumeGroupSnapshot(vgName string, vol
client := vgsext.NewVolumeGroupSnapshotClient(v.conn)

req := &vgsext.CreateVolumeGroupSnapshotRequest{
SourceVolumeIDs: volIds,
SourceVolumeIDs: volIDs,
Name: vgName,
Parameters: params,
}
Expand Down
4 changes: 2 additions & 2 deletions test/mock-server/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ type MockVolumeGroupSnapshotServer struct{}
var MockServer *grpc.Server

// ProbeController grpc call to get driver information
func (vgs *MockVolumeGroupSnapshotServer) ProbeController(ctx context.Context, in *csiext.ProbeControllerRequest) (*csiext.ProbeControllerResponse, error) {
func (vgs *MockVolumeGroupSnapshotServer) ProbeController(_ context.Context, in *csiext.ProbeControllerRequest) (*csiext.ProbeControllerResponse, error) {
out := &csiext.ProbeControllerResponse{}
err := FindStub("VolumeGroupSnapshot", "ProbeController", in, out)
return out, err
}

// CreateVolumeGroupSnapshot creete vgs
func (vgs *MockVolumeGroupSnapshotServer) CreateVolumeGroupSnapshot(ctx context.Context, in *vgsext.CreateVolumeGroupSnapshotRequest) (*vgsext.CreateVolumeGroupSnapshotResponse, error) {
func (vgs *MockVolumeGroupSnapshotServer) CreateVolumeGroupSnapshot(_ context.Context, in *vgsext.CreateVolumeGroupSnapshotRequest) (*vgsext.CreateVolumeGroupSnapshotResponse, error) {
out := &vgsext.CreateVolumeGroupSnapshotResponse{}
err := FindStub("VolumeGroupSnapshot", "CreateVolumeGroupSnapshot", in, out)
return out, err
Expand Down
14 changes: 11 additions & 3 deletions test/mock-server/stub/stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"log"
"net/http"
"strings"
"time"

"github.com/go-chi/chi"
)
Expand Down Expand Up @@ -56,6 +57,8 @@ const (
DefaultAddress = "localhost"
// DefaultPort for test
DefaultPort = "4771"
// DefaultTimeout for test
TimeOut = 10 * time.Minute
)

// RunStubServer test server
Expand All @@ -79,7 +82,12 @@ func RunStubServer(opt Options) {

fmt.Println("Serving stub admin on http://" + addr)
go func() {
err := http.ListenAndServe(addr, r)
server := &http.Server{
Addr: addr,
ReadHeaderTimeout: TimeOut,
Handler: r,
}
err := server.ListenAndServe()
log.Println(err)
}()
}
Expand Down Expand Up @@ -124,7 +132,7 @@ func handleAddStub(w http.ResponseWriter, r *http.Request) {
}
}

func handleListStub(w http.ResponseWriter, r *http.Request) {
func handleListStub(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Content-Type", "application/json")
err := json.NewEncoder(w).Encode(allStub())
if err != nil {
Expand Down Expand Up @@ -196,7 +204,7 @@ func handleFindStub(w http.ResponseWriter, r *http.Request) {
}
}

func handleClearStub(w http.ResponseWriter, r *http.Request) {
func handleClearStub(w http.ResponseWriter, _ *http.Request) {
clearStorage()
_, err := w.Write([]byte("OK"))
if err != nil {
Expand Down
14 changes: 7 additions & 7 deletions test/shared/fake-client/fake-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func NewFakeClient(initialObjects []runtime.Object, errorInjector ErrorInjector)
}

// Get fake object
func (f Client) Get(ctx context.Context, key client.ObjectKey, obj client.Object) error {
func (f Client) Get(_ context.Context, key client.ObjectKey, obj client.Object) error {
if f.ErrorInjector != nil {
if err := f.ErrorInjector.ShouldFail("Get", obj); err != nil {
return err
Expand Down Expand Up @@ -131,7 +131,7 @@ func (f Client) Get(ctx context.Context, key client.ObjectKey, obj client.Object
}

// List fake objects
func (f Client) List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error {
func (f Client) List(_ context.Context, list client.ObjectList, opts ...client.ListOption) error {
if f.ErrorInjector != nil {
if err := f.ErrorInjector.ShouldFail("List", list); err != nil {
return err
Expand Down Expand Up @@ -228,7 +228,7 @@ func (f *Client) listPersistentVolume(list *core_v1.PersistentVolumeList) error
}

// Create fake object
func (f Client) Create(ctx context.Context, obj client.Object, opts ...client.CreateOption) error {
func (f Client) Create(_ context.Context, obj client.Object, _ ...client.CreateOption) error {
if f.ErrorInjector != nil {
if err := f.ErrorInjector.ShouldFail("Create", obj); err != nil {
return err
Expand Down Expand Up @@ -315,7 +315,7 @@ func (f Client) Delete(ctx context.Context, obj client.Object, opts ...client.De
}

// SetDeletionTimeStamp set deletion timestamp so that reconcile can go into deletion part of code
func (f Client) SetDeletionTimeStamp(ctx context.Context, obj client.Object) error {
func (f Client) SetDeletionTimeStamp(_ context.Context, obj client.Object) error {
k, err := getKey(obj)
if err != nil {
return err
Expand All @@ -331,7 +331,7 @@ func (f Client) SetDeletionTimeStamp(ctx context.Context, obj client.Object) err
}

// Update fake object
func (f Client) Update(ctx context.Context, obj client.Object, opts ...client.UpdateOption) error {
func (f Client) Update(_ context.Context, obj client.Object, _ ...client.UpdateOption) error {
if f.ErrorInjector != nil {
if err := f.ErrorInjector.ShouldFail("Update", obj); err != nil {
return err
Expand All @@ -358,12 +358,12 @@ func (f Client) Update(ctx context.Context, obj client.Object, opts ...client.Up
}

// Patch fake object
func (f Client) Patch(ctx context.Context, obj client.Object, patch client.Patch, opts ...client.PatchOption) error {
func (f Client) Patch(_ context.Context, _ client.Object, _ client.Patch, _ ...client.PatchOption) error {
panic("implement me")
}

// DeleteAllOf delete all objects
func (f Client) DeleteAllOf(ctx context.Context, obj client.Object, opts ...client.DeleteAllOfOption) error {
func (f Client) DeleteAllOf(_ context.Context, _ client.Object, _ ...client.DeleteAllOfOption) error {
panic("implement me")
}

Expand Down

0 comments on commit cf620f6

Please sign in to comment.