Skip to content

Commit

Permalink
Fix linter errors (#453)
Browse files Browse the repository at this point in the history
  • Loading branch information
donatwork authored Feb 7, 2024
1 parent a467aa6 commit e0c3e90
Show file tree
Hide file tree
Showing 40 changed files with 200 additions and 343 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.53
version: v1.54.2
skip-cache: true
1 change: 0 additions & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
run:
timeout: 20m
issue-exit-code: 0 # we will change this later
tests: true
skip-dirs-use-default: true
modules-download-mode: readonly
Expand Down
8 changes: 4 additions & 4 deletions api/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const (
ReverseProxy ModuleType = "csireverseproxy"

// ReverseProxyServer - placeholder for constant csipowermax-reverseproxy
ReverseProxyServer ModuleType = "csipowermax-reverseproxy"
ReverseProxyServer ModuleType = "csipowermax-reverseproxy" // #nosec G101

// ApplicationMobility - placeholder for constant application-mobility
ApplicationMobility ModuleType = "application-mobility"
Expand Down Expand Up @@ -353,15 +353,15 @@ type ContainerTemplate struct {
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Application Mobility Object Store Secret"
ObjectStoreSecretName string `json:"objectStoreSecretName,omitempty" yaml:"objectStoreSecretName,omitempty"`

//UseSnapshot is to check whether volume snapshot is enabled under velero component
// UseSnapshot is to check whether volume snapshot is enabled under velero component
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="use-volume-snapshots for Application Mobilit- Velero"
UseSnapshot bool `json:"useVolumeSnapshot,omitempty" yaml:"useVolumeSnapshot,omitempty"`

//ComponentCred is to store the velero credential contents
// ComponentCred is to store the velero credential contents
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="ComponentCred for velero component"
ComponentCred []Credential `json:"credentials,omitempty" yaml:"credentials,omitempty"`

//DeployNodeAgent is to enable/disable node-agent services
// DeployNodeAgent is to enable/disable node-agent services
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Deploy node-agent for Application Mobility"
DeployNodeAgent bool `json:"deployNodeAgent,omitempty" yaml:"deployNodeAgent,omitempty"`
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/acc_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ func (suite *AccControllerTestSuite) runFakeAccManager(expectedErr string, recon
}

// call reconcile with different injection errors in k8s client
func (suite *AccControllerTestSuite) reconcileAccWithErrorInjection(reqName, expectedErr string) {
func (suite *AccControllerTestSuite) reconcileAccWithErrorInjection(_, expectedErr string) {
reconciler := suite.createAccReconciler()

// create would fail
Expand Down
36 changes: 12 additions & 24 deletions controllers/csm_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"encoding/json"
"fmt"
"strconv"
"sync"
"sync/atomic"
"time"

Expand Down Expand Up @@ -54,9 +55,7 @@ import (
corev1 "k8s.io/api/core/v1"
storagev1 "k8s.io/api/storage/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

//metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sync"
// metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// ContainerStorageModuleReconciler reconciles a ContainerStorageModule object
Expand Down Expand Up @@ -377,7 +376,7 @@ func (r *ContainerStorageModuleReconciler) handleDeploymentUpdate(oldObj interfa
ready := d.Status.ReadyReplicas
numberUnavailable := d.Status.UnavailableReplicas

//Replicas: 2 desired | 2 updated | 2 total | 2 available | 0 unavailable
// Replicas: 2 desired | 2 updated | 2 total | 2 available | 0 unavailable

log.Infow("deployment", "desired", desired)
log.Infow("deployment", "numberReady", ready)
Expand All @@ -393,7 +392,6 @@ func (r *ContainerStorageModuleReconciler) handleDeploymentUpdate(oldObj interfa

csm := new(csmv1.ContainerStorageModule)
err := r.Client.Get(ctx, namespacedName, csm)

if err != nil {
log.Error("deployment get csm", "error", err.Error())
}
Expand All @@ -414,7 +412,7 @@ func (r *ContainerStorageModuleReconciler) handleDeploymentUpdate(oldObj interfa
}
}

func (r *ContainerStorageModuleReconciler) handlePodsUpdate(oldObj interface{}, obj interface{}) {
func (r *ContainerStorageModuleReconciler) handlePodsUpdate(_ interface{}, obj interface{}) {
dMutex.Lock()
defer dMutex.Unlock()

Expand Down Expand Up @@ -454,7 +452,6 @@ func (r *ContainerStorageModuleReconciler) handlePodsUpdate(oldObj interface{},
} else {
r.EventRecorder.Eventf(csm, corev1.EventTypeNormal, csmv1.EventCompleted, "%s Driver pods running OK", stamp)
}

}

func (r *ContainerStorageModuleReconciler) handleDaemonsetUpdate(oldObj interface{}, obj interface{}) {
Expand Down Expand Up @@ -505,12 +502,10 @@ func (r *ContainerStorageModuleReconciler) handleDaemonsetUpdate(oldObj interfac
} else {
r.EventRecorder.Eventf(csm, corev1.EventTypeNormal, csmv1.EventCompleted, "Driver daemonset running OK")
}

}

// ContentWatch - watch updates on deployment and deamonset
func (r *ContainerStorageModuleReconciler) ContentWatch() error {

sharedInformerFactory := sinformer.NewSharedInformerFactory(r.K8sClient, time.Duration(time.Hour))

daemonsetInformer := sharedInformerFactory.Apps().V1().DaemonSets().Informer()
Expand Down Expand Up @@ -543,7 +538,6 @@ func (r *ContainerStorageModuleReconciler) ContentWatch() error {

// SetupWithManager sets up the controller with the Manager.
func (r *ContainerStorageModuleReconciler) SetupWithManager(mgr ctrl.Manager, limiter ratelimiter.RateLimiter, maxReconcilers int) error {

go r.ContentWatch()

return ctrl.NewControllerManagedBy(mgr).
Expand Down Expand Up @@ -639,7 +633,7 @@ func (r *ContainerStorageModuleReconciler) oldStandAloneModuleCleanup(ctx contex
}
}

//check if application mobility needs to be uninstalled
// check if application mobility needs to be uninstalled
oldApplicationmobilityEnabled, _ := utils.IsModuleEnabled(ctx, *oldCR, csmv1.ApplicationMobility)
newApplicationmobilityEnabled, _ := utils.IsModuleEnabled(ctx, *newCR, csmv1.ApplicationMobility)

Expand Down Expand Up @@ -695,7 +689,7 @@ func (r *ContainerStorageModuleReconciler) SyncCSM(ctx context.Context, cr csmv1
}
}

//Create/Update Reverseproxy Server
// Create/Update Reverseproxy Server
if reverseProxyEnabled, _ := utils.IsModuleEnabled(ctx, cr, csmv1.ReverseProxy); reverseProxyEnabled {
log.Infow("Trying Create/Update reverseproxy...")
if err := r.reconcileReverseProxy(ctx, false, operatorConfig, cr, ctrlClient); err != nil {
Expand Down Expand Up @@ -793,7 +787,6 @@ func (r *ContainerStorageModuleReconciler) SyncCSM(ctx context.Context, cr csmv1

controller.Rbac.ClusterRole = *clusterRole
}

}
}

Expand Down Expand Up @@ -1009,7 +1002,8 @@ func (r *ContainerStorageModuleReconciler) reconcileAppMobility(ctx context.Cont

func getDriverConfig(ctx context.Context,
cr csmv1.ContainerStorageModule,
operatorConfig utils.OperatorConfig) (*DriverConfig, error) {
operatorConfig utils.OperatorConfig,
) (*DriverConfig, error) {
var (
err error
driver *storagev1.CSIDriver
Expand All @@ -1019,7 +1013,7 @@ func getDriverConfig(ctx context.Context,
log = logger.GetLogger(ctx)
)

//if no driver is specified, return nil
// if no driver is specified, return nil
if cr.Spec.Driver.CSIDriverType == "" {
log.Infof("No driver specified in manifest")
return nil, nil
Expand Down Expand Up @@ -1059,7 +1053,6 @@ func getDriverConfig(ctx context.Context,
Node: node,
Controller: controller,
}, nil

}

// reconcileReverseProxy - deploy reverse proxy server
Expand Down Expand Up @@ -1223,7 +1216,6 @@ func (r *ContainerStorageModuleReconciler) removeModule(ctx context.Context, ins

// PreChecks - validate input values
func (r *ContainerStorageModuleReconciler) PreChecks(ctx context.Context, cr *csmv1.ContainerStorageModule, operatorConfig utils.OperatorConfig) error {

log := logger.GetLogger(ctx)
var am bool
// Check drivers
Expand Down Expand Up @@ -1288,11 +1280,9 @@ func (r *ContainerStorageModuleReconciler) PreChecks(ctx context.Context, cr *cs
if m.Name == cr.Name {
log.Infow("Owner reference is found and matches")
break
} else {
return fmt.Errorf("required Owner reference not found. Please re-install driver ")
}
return fmt.Errorf("required Owner reference not found. Please re-install driver ")
}

}
}

Expand Down Expand Up @@ -1327,7 +1317,7 @@ func (r *ContainerStorageModuleReconciler) PreChecks(ctx context.Context, cr *cs
return fmt.Errorf("failed observability validation: %v", err)
}
case csmv1.ApplicationMobility:
//ApplicationMobility precheck
// ApplicationMobility precheck
if err := modules.ApplicationMobilityPrecheck(ctx, operatorConfig, m, *cr, r); err != nil {
return fmt.Errorf("failed Appmobility validation: %v", err)
}
Expand All @@ -1338,7 +1328,6 @@ func (r *ContainerStorageModuleReconciler) PreChecks(ctx context.Context, cr *cs
default:
return fmt.Errorf("unsupported module type %s", m.Name)
}

}
}

Expand Down Expand Up @@ -1367,7 +1356,7 @@ func checkUpgrade(ctx context.Context, cr *csmv1.ContainerStorageModule, operato
log.Infow("proceeding with modification of driver install")
return true, nil
}
//if not equal, it is an upgrade/downgrade
// if not equal, it is an upgrade/downgrade
// get minimum required version for upgrade
minUpgradePath, err := drivers.GetUpgradeInfo(ctx, operatorConfig, driverType, oldVersion)
if err != nil {
Expand All @@ -1389,7 +1378,6 @@ func checkUpgrade(ctx context.Context, cr *csmv1.ContainerStorageModule, operato

// TODO: refactor this
func applyConfigVersionAnnotations(ctx context.Context, instance *csmv1.ContainerStorageModule) bool {

log := logger.GetLogger(ctx)

// If driver has not been initialized yet, we first annotate the driver with the config version annotation
Expand Down
Loading

0 comments on commit e0c3e90

Please sign in to comment.