Skip to content

Commit

Permalink
Bump golangci-lint version and fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
giorio94 committed Dec 2, 2021
1 parent 7031c24 commit b941774
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Check linting
uses: golangci/golangci-lint-action@v2
with:
version: v1.41.1
version: v1.43.0
working-directory: operators
args: --timeout=600s

Expand Down
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,8 @@ issues:
- stylecheck
# Excluding, as many packages are currently affected by this
text: "ST1003: should not use underscores in package names"

# Exclude the following linters from running on tests files.
- path: _test\.go
linters:
- gosec
5 changes: 2 additions & 3 deletions operators/pkg/bastion-controller/bastion_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package bastion_controller

import (
"context"
"io/ioutil"
"os"
"strings"

Expand Down Expand Up @@ -63,7 +62,7 @@ func (r *BastionReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct

if _, err := os.Stat(r.AuthorizedKeysPath); err == nil {
// if the file exists, read the whole file in a []byte
data, err := ioutil.ReadFile(r.AuthorizedKeysPath)
data, err := os.ReadFile(r.AuthorizedKeysPath)
if err != nil {
klog.Errorf("unable to read the file authorized_keys: %v", err)
return ctrl.Result{}, err
Expand All @@ -88,7 +87,7 @@ func (r *BastionReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
defer closeFile(f)

if len(keys) > 0 {
_, err = f.Write([]byte(strings.Join(keys, string("\n"))))
_, err = f.WriteString(strings.Join(keys, string("\n")))
if err != nil {
klog.Errorf("unable to write to authorized_keys: %v", err)
return ctrl.Result{}, nil
Expand Down
3 changes: 1 addition & 2 deletions operators/pkg/bastion-controller/bastion_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package bastion_controller
import (
"bytes"
"context"
"io/ioutil"
"os"
"time"

Expand Down Expand Up @@ -54,7 +53,7 @@ var _ = Describe("Bastion controller - creating two tenants", func() {
// this function checks if the keys are properly placed in the file.
checkFile := func() (bool, error) {

data, err := ioutil.ReadFile(testFile)
data, err := os.ReadFile(testFile)
if err != nil {
return false, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (r *InstanceSnapshotReconciler) Reconcile(ctx context.Context, req ctrl.Req
}
// Since we don't have to retry, validation failed
// Add the event and stop reconciliation since the request is not valid.
r.EventsRecorder.Event(isnap, "Warning", "ValidationError", fmt.Sprintf("%s", err1))
r.EventsRecorder.Event(isnap, "Warning", "ValidationError", err1.Error())
return ctrl.Result{}, nil
}
// Job successfully created
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (r *InstanceSnapshotReconciler) CreateSnapshottingJobDefinition(ctx context
}

var backoff int32 = 2
imagetag := fmt.Sprint(time.Now().Format("20060102t150405"))
imagetag := time.Now().Format("20060102t150405")
// Volume name does not accept dots, replace them with dashes
volumename := strings.ReplaceAll(isnap.Spec.Instance.Name, ".", "-")
imagedir := utils.ParseDockerDirectory(instance.Spec.Tenant.Name)
Expand Down
2 changes: 1 addition & 1 deletion operators/pkg/tenantwh/mutating.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func MakeTenantLabeler(c client.Client, webhookBypassGroups []string, opSelector
}

// Handle on TenantLabeler adds operator selector labels to new tenants and prevents possible changes - this method is used by controller runtime.
func (tl *TenantLabeler) Handle(ctx context.Context, req admission.Request) admission.Response { //nolint:gocritic,hugeParam // the signature of this method is imposed by controller runtime.
func (tl *TenantLabeler) Handle(ctx context.Context, req admission.Request) admission.Response { //nolint:gocritic // the signature of this method is imposed by controller runtime.
log := ctrl.LoggerFrom(ctx).WithName("labeler").WithValues("username", req.UserInfo.Username, "tenant", req.Name)
ctx = ctrl.LoggerInto(ctx, log)

Expand Down
2 changes: 1 addition & 1 deletion operators/pkg/tenantwh/validating.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func MakeTenantValidator(c client.Client, webhookBypassGroups []string) *webhook

// Handle admits a tenant if user is editing its own tenant or a user is adding/removing workspaces
// they own to/from another user - this method is used by controller runtime.
func (tv *TenantValidator) Handle(ctx context.Context, req admission.Request) admission.Response { //nolint:gocritic,hugeParam // the signature of this method is imposed by controller runtime.
func (tv *TenantValidator) Handle(ctx context.Context, req admission.Request) admission.Response { //nolint:gocritic // the signature of this method is imposed by controller runtime.
log := ctrl.LoggerFrom(ctx).WithName("validator").WithValues("username", req.UserInfo.Username, "tenant", req.Name)

log.V(utils.LogDebugLevel).Info("processing admission request", "groups", strings.Join(req.UserInfo.Groups, ","))
Expand Down

0 comments on commit b941774

Please sign in to comment.