Skip to content

Commit

Permalink
address all gosimple fixes (#428)
Browse files Browse the repository at this point in the history
* address all gosimple fixes

* remove nolints

* Update api-export-rule-get-iter.go

* oops
  • Loading branch information
based64god committed Oct 23, 2020
1 parent 4c0959c commit b4a3b4d
Show file tree
Hide file tree
Showing 56 changed files with 130 additions and 171 deletions.
10 changes: 5 additions & 5 deletions cli/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -1632,7 +1632,7 @@ func waitForTridentPod() (*v1.Pod, error) {
if pod.Status.Phase != "" {
errMessages = append(errMessages, fmt.Sprintf("Pod status is %s.", pod.Status.Phase))
if pod.Status.Message != "" {
errMessages = append(errMessages, fmt.Sprintf("%s", pod.Status.Message))
errMessages = append(errMessages, pod.Status.Message)
}
}
errMessages = append(errMessages,
Expand Down Expand Up @@ -1661,7 +1661,7 @@ func waitForRESTInterface() error {
cliCommand := []string{"tridentctl", "version", "-o", "json"}
versionJSON, err := client.Exec(TridentPodName, tridentconfig.ContainerTrident, cliCommand)
if err != nil {
if versionJSON != nil && len(versionJSON) > 0 {
if len(versionJSON) > 0 {
err = fmt.Errorf("%v; %s", err, strings.TrimSpace(string(versionJSON)))
}
return err
Expand Down Expand Up @@ -2153,7 +2153,7 @@ func waitForPodToStart(label, purpose string) (*v1.Pod, error) {
if pod.Status.Phase != "" {
errMessages = append(errMessages, fmt.Sprintf("Pod status is %s.", pod.Status.Phase))
if pod.Status.Message != "" {
errMessages = append(errMessages, fmt.Sprintf("%s", pod.Status.Message))
errMessages = append(errMessages, pod.Status.Message)
}
}
errMessages = append(errMessages,
Expand Down Expand Up @@ -2214,7 +2214,7 @@ func waitForPodToFinish(label, purpose string) (*v1.Pod, error) {
if pod.Status.Phase != "" {
errMessages = append(errMessages, fmt.Sprintf("Pod status is %s.", pod.Status.Phase))
if pod.Status.Message != "" {
errMessages = append(errMessages, fmt.Sprintf("%s", pod.Status.Message))
errMessages = append(errMessages, pod.Status.Message)
}
}
errMessages = append(errMessages,
Expand Down Expand Up @@ -2290,7 +2290,7 @@ func waitForContainerToFinish(podLabel, containerName, purpose string, timeout t
if pod.Status.Phase != "" {
errMessages = append(errMessages, fmt.Sprintf("Pod status is %s.", pod.Status.Phase))
if pod.Status.Message != "" {
errMessages = append(errMessages, fmt.Sprintf("%s", pod.Status.Message))
errMessages = append(errMessages, pod.Status.Message)
}
}
errMessages = append(errMessages,
Expand Down
4 changes: 2 additions & 2 deletions cli/cmd/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ func getNodeLogs(logName, nodeName string) error {
}

nodeLogName := "trident-node-" + nodeName
if prev == true {
if prev {
nodeLogName = nodeLogName + "-previous"
}
// Build command to get K8S logs
Expand Down Expand Up @@ -393,7 +393,7 @@ func getAllNodeLogs(logName string) error {

for node, pod := range tridentNodeNames {
nodeLogName := "trident-node-" + node
if prev == true {
if prev {
nodeLogName = nodeLogName + "-previous"
}
// Build command to get K8S logs
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/obliviate_alpha_snapshot_crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func deleteAlphaSnapshotCRDs() error {
}
}

if alpha == false {
if !alpha {
log.WithFields(logFields).Info("CRD is not alpha")
continue
}
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func getVersionFromTunnel() (rest.GetVersionResponse, error) {
command := []string{"version", "-o", "json"}
versionJSON, err := TunnelCommandRaw(command)
if err != nil {
if versionJSON != nil && len(versionJSON) > 0 {
if len(versionJSON) > 0 {
err = fmt.Errorf("%v; %s", err, string(versionJSON))
}
return rest.GetVersionResponse{}, err
Expand Down
2 changes: 1 addition & 1 deletion cli/k8s_client/k8s_cli_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1922,7 +1922,7 @@ func (c *KubectlClient) RemoveTridentUserFromOpenShiftSCC(user, scc string) erro
func (c *KubectlClient) GetOpenShiftSCCByName(user, scc string) (bool, bool, []byte, error) {
var SCCExist, SCCUserExist bool
sccUser := fmt.Sprintf("system:serviceaccount:%s:%s", c.namespace, user)
sccName := fmt.Sprintf("\"name\": \"trident\"")
sccName := `"name": "trident"`

if c.flavor != FlavorOpenShift {
return SCCExist, SCCUserExist, nil, errors.New("the current client context is not OpenShift")
Expand Down
14 changes: 6 additions & 8 deletions core/orchestrator_core.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,7 @@ func (o *TridentOrchestrator) bootstrapVolumes(ctx context.Context) error {
// TODO: If the API evolves, check the Version field here.
var backend *storage.Backend
var ok bool
var vol *storage.Volume
vol = storage.NewVolume(v.Config, v.BackendUUID, v.Pool, v.Orphaned)
vol := storage.NewVolume(v.Config, v.BackendUUID, v.Pool, v.Orphaned)
o.volumes[vol.Config.Name] = vol

if backend, ok = o.backends[v.BackendUUID]; !ok {
Expand Down Expand Up @@ -338,8 +337,7 @@ func (o *TridentOrchestrator) bootstrapSnapshots(ctx context.Context) error {
}
for _, s := range snapshots {
// TODO: If the API evolves, check the Version field here.
var snapshot *storage.Snapshot
snapshot = storage.NewSnapshot(s.Config, s.Created, s.SizeBytes, s.State)
snapshot := storage.NewSnapshot(s.Config, s.Created, s.SizeBytes, s.State)
o.snapshots[snapshot.ID()] = snapshot
volume, ok := o.volumes[s.Config.VolumeName]
if !ok {
Expand Down Expand Up @@ -1158,7 +1156,7 @@ func (o *TridentOrchestrator) updateBackendByBackendUUID(
updatePersistentStore := false
volumeExists := backend.Driver.Get(ctx, vol.Config.InternalName) == nil
if !volumeExists {
if vol.Orphaned == false {
if !vol.Orphaned {
vol.Orphaned = true
updatePersistentStore = true
Logc(ctx).WithFields(log.Fields{
Expand All @@ -1168,7 +1166,7 @@ func (o *TridentOrchestrator) updateBackendByBackendUUID(
}).Warn("Backend update resulted in an orphaned volume.")
}
} else {
if vol.Orphaned == true {
if vol.Orphaned {
vol.Orphaned = false
updatePersistentStore = true
Logc(ctx).WithFields(log.Fields{
Expand Down Expand Up @@ -1429,7 +1427,7 @@ func (o *TridentOrchestrator) deleteBackendByBackendUUID(ctx context.Context, ba

backend.Online = false // TODO eventually remove
backend.State = storage.Deleting
storageClasses := make(map[string]*storageclass.StorageClass, 0)
storageClasses := make(map[string]*storageclass.StorageClass)
for _, storagePool := range backend.Storage {
for _, scName := range storagePool.StorageClasses {
storageClasses[scName] = o.storageClasses[scName]
Expand Down Expand Up @@ -1534,7 +1532,7 @@ func (o *TridentOrchestrator) addVolumeInitial(
Logc(ctx).WithField("volume", volumeConfig.Name).Debugf("Looking through %d storage pools.", len(pools))

errorMessages := make([]string, 0)
ineligibleBackends := make(map[string]struct{}, 0)
ineligibleBackends := make(map[string]struct{})

// The pool lists are already shuffled, so just try them in order.
// The loop terminates when creation on all matching pools has failed.
Expand Down
11 changes: 3 additions & 8 deletions core/orchestrator_core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func cleanup(t *testing.T, o *TridentOrchestrator) {

func diffConfig(expected, got interface{}, fieldToSkip string) []string {

diffs := make([]string, 0, 0)
diffs := make([]string, 0)
expectedStruct := reflect.Indirect(reflect.ValueOf(expected))
gotStruct := reflect.Indirect(reflect.ValueOf(got))

Expand Down Expand Up @@ -295,9 +295,7 @@ func validateStorageClass(
t.Errorf("%s: Storage class not found in backend.", name)
}
remaining := make([]*tu.PoolMatch, len(expected))
for i, match := range expected {
remaining[i] = match
}
copy(remaining, expected)
for _, protocol := range []config.Protocol{config.File, config.Block} {
for _, pool := range sc.GetStoragePoolsForProtocol(ctx(), protocol) {
nameFound := false
Expand Down Expand Up @@ -2686,10 +2684,7 @@ func unorderedNodeSlicesEqual(x, y []*utils.Node) bool {
delete(diff, _y)
}
}
if len(diff) == 0 {
return true
}
return false
return len(diff) == 0
}

func TestDeleteNode(t *testing.T) {
Expand Down
14 changes: 7 additions & 7 deletions frontend/crd/crd_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ type TestingCache struct {

func NewTestingCache() *TestingCache {
result := &TestingCache{
backendCache: make(map[string]*tridentv1.TridentBackend, 0),
nodeCache: make(map[string]*tridentv1.TridentNode, 0),
storageClassCache: make(map[string]*tridentv1.TridentStorageClass, 0),
transactionCache: make(map[string]*tridentv1.TridentTransaction, 0),
versionCache: make(map[string]*tridentv1.TridentVersion, 0),
volumeCache: make(map[string]*tridentv1.TridentVolume, 0),
snapshotCache: make(map[string]*tridentv1.TridentSnapshot, 0),
backendCache: make(map[string]*tridentv1.TridentBackend),
nodeCache: make(map[string]*tridentv1.TridentNode),
storageClassCache: make(map[string]*tridentv1.TridentStorageClass),
transactionCache: make(map[string]*tridentv1.TridentTransaction),
versionCache: make(map[string]*tridentv1.TridentVersion),
volumeCache: make(map[string]*tridentv1.TridentVolume),
snapshotCache: make(map[string]*tridentv1.TridentSnapshot),
}
return result
}
Expand Down
5 changes: 1 addition & 4 deletions frontend/kubernetes/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,6 @@ func (p *Plugin) processBoundClaim(ctx context.Context, claim *v1.PersistentVolu
return
}
// The names match, so the PVC is successfully bound to the provisioned PV.
return
}

// processLostClaim cleans up Trident-created PVs.
Expand All @@ -580,7 +579,6 @@ func (p *Plugin) processLostClaim(claim *v1.PersistentVolumeClaim) {
p.mutex.Lock()
delete(p.pendingClaimMatchMap, volName)
p.mutex.Unlock()
return
}

// processDeletedClaim cleans up Trident-created PVs.
Expand Down Expand Up @@ -1101,7 +1099,7 @@ func (p *Plugin) createVolumeAndPV(
storageClass := GetPersistentVolumeClaimClass(claim)
annotations := p.processStorageClassAnnotations(claim, storageClass)

size, _ := claim.Spec.Resources.Requests[v1.ResourceStorage]
size := claim.Spec.Resources.Requests[v1.ResourceStorage]
accessModes := claim.Spec.AccessModes
volumeMode := claim.Spec.VolumeMode
volConfig := getVolumeConfig(accessModes, volumeMode, uniqueName, size, annotations)
Expand Down Expand Up @@ -1304,7 +1302,6 @@ func (p *Plugin) processDeletedVolume(ctx context.Context, pv *v1.PersistentVolu
"volume": pv.Name,
}).Infof("Kubernetes frontend %s", message)
}
return
}

// processUpdatedVolume processes updated Trident-created PVs.
Expand Down
2 changes: 1 addition & 1 deletion frontend/kubernetes/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
// with the binder.
func canPVMatchWithPVC(ctx context.Context, pv *v1.PersistentVolume, claim *v1.PersistentVolumeClaim) bool {

claimSize, _ := claim.Spec.Resources.Requests[v1.ResourceStorage]
claimSize := claim.Spec.Resources.Requests[v1.ResourceStorage]
claimAccessModes := claim.Spec.AccessModes
volumeAccessModes := pv.Spec.AccessModes
volumeSize, ok := pv.Spec.Capacity[v1.ResourceStorage]
Expand Down
12 changes: 6 additions & 6 deletions frontend/rest/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ func ListBackends(w http.ResponseWriter, r *http.Request) {
if err != nil {
Logc(r.Context()).Errorf("ListBackends: %v", err)
response.Error = err.Error()
} else if backends != nil && len(backends) > 0 {
} else if len(backends) > 0 {
backendNames = make([]string, 0, len(backends))
for _, backend := range backends {
backendNames = append(backendNames, backend.Name)
Expand Down Expand Up @@ -584,7 +584,7 @@ func ListVolumes(w http.ResponseWriter, r *http.Request) {
volumes, err := orchestrator.ListVolumes(r.Context())
if err != nil {
response.Error = err.Error()
} else if volumes != nil && len(volumes) > 0 {
} else if len(volumes) > 0 {
volumeNames = make([]string, 0, len(volumes))
for _, volume := range volumes {
volumeNames = append(volumeNames, volume.Config.Name)
Expand Down Expand Up @@ -829,7 +829,7 @@ func ListStorageClasses(w http.ResponseWriter, r *http.Request) {
storageClasses, err := orchestrator.ListStorageClasses(r.Context())
if err != nil {
response.Error = err.Error()
} else if storageClasses != nil && len(storageClasses) > 0 {
} else if len(storageClasses) > 0 {
storageClassNames = make([]string, 0, len(storageClasses))
for _, sc := range storageClasses {
storageClassNames = append(storageClassNames, sc.GetName())
Expand Down Expand Up @@ -991,7 +991,7 @@ func ListNodes(w http.ResponseWriter, r *http.Request) {
nodes, err := orchestrator.ListNodes(r.Context())
if err != nil {
response.Error = err.Error()
} else if nodes != nil && len(nodes) > 0 {
} else if len(nodes) > 0 {
nodeNames = make([]string, 0, len(nodes))
for _, node := range nodes {
nodeNames = append(nodeNames, node.Name)
Expand Down Expand Up @@ -1044,7 +1044,7 @@ func ListSnapshots(w http.ResponseWriter, r *http.Request) {
snapshots, err := orchestrator.ListSnapshots(r.Context())
if err != nil {
response.Error = err.Error()
} else if snapshots != nil && len(snapshots) > 0 {
} else if len(snapshots) > 0 {
snapshotIDs = make([]string, 0, len(snapshots))
for _, snapshot := range snapshots {
snapshotIDs = append(snapshotIDs, snapshot.ID())
Expand All @@ -1064,7 +1064,7 @@ func ListSnapshotsForVolume(w http.ResponseWriter, r *http.Request) {
snapshots, err := orchestrator.ListSnapshotsForVolume(r.Context(), volumeName)
if err != nil {
response.Error = err.Error()
} else if snapshots != nil && len(snapshots) > 0 {
} else if len(snapshots) > 0 {
snapshotIDs = make([]string, 0, len(snapshots))
for _, snapshot := range snapshots {
snapshotIDs = append(snapshotIDs, snapshot.ID())
Expand Down
10 changes: 5 additions & 5 deletions k8s_client/k8s_client_fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ func NewFakeKubeClientBasic(config *rest.Config, namespace string) (Interface, e
Minor: "8",
GitVersion: "v1.8.0",
},
Deployments: make(map[string]*appsv1.Deployment, 0),
PVCs: make(map[string]*v1.PersistentVolumeClaim, 0),
failMatrix: make(map[string]bool, 0),
Deployments: make(map[string]*appsv1.Deployment),
PVCs: make(map[string]*v1.PersistentVolumeClaim),
failMatrix: make(map[string]bool),
}, nil
}

Expand All @@ -42,8 +42,8 @@ func NewFakeKubeClient(failMatrix map[string]bool, versionMajor, versionMinor st
Minor: versionMinor,
GitVersion: "v" + versionMajor + "." + versionMinor + ".0",
},
Deployments: make(map[string]*appsv1.Deployment, 0),
PVCs: make(map[string]*v1.PersistentVolumeClaim, 0),
Deployments: make(map[string]*appsv1.Deployment),
PVCs: make(map[string]*v1.PersistentVolumeClaim),
failMatrix: failMatrix,
}
}
Expand Down
9 changes: 1 addition & 8 deletions logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,10 @@ func NewFileHook(logName, logFormat string) (*FileHook, error) {
switch runtime.GOOS {
case utils.Linux:
logFileLocation = LogRoot + "/" + logName + ".log"
break
case utils.Darwin:
logFileLocation = LogRoot + "/" + logName + ".log"
break
case utils.Windows:
logFileLocation = logName + ".log"
break
}

return &FileHook{logFileLocation, formatter, &sync.Mutex{}}, nil
Expand Down Expand Up @@ -272,11 +269,7 @@ func (hook *FileHook) logfileNeedsRotation() bool {
size := fileInfo.Size()
logFile.Close()

if size >= LogRotationThreshold {
return true
}

return false
return size >= LogRotationThreshold
}

// maybeDoLogfileRotation prevents descending into doLogfileRotation on every call as the inner
Expand Down
4 changes: 2 additions & 2 deletions operator/controllers/provisioner/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ func (c *Controller) removeTridentctlBasedInstallation(tridentCR *netappv1.Tride
}

// Uninstall succeeded, so re-run the reconcile loop
eventMessage := fmt.Sprintf("tridentctl-based CSI Trident installation removed.")
eventMessage := "tridentctl-based CSI Trident installation removed."

log.Info(eventMessage)
c.eventRecorder.Event(tridentCR, corev1.EventTypeNormal, string(AppStatusInstalling), eventMessage)
Expand Down Expand Up @@ -977,7 +977,7 @@ func (c *Controller) reconcileTridentNotPresent() error {
// 2. Prefer a CR in the same namespace as the Operator
var tridentCR *netappv1.TridentProvisioner
for _, cr := range tridentCRs {
if cr.Spec.Uninstall != true {
if !cr.Spec.Uninstall {
tridentCR = &cr
if cr.Namespace == c.Namespace {
break
Expand Down
Loading

0 comments on commit b4a3b4d

Please sign in to comment.