Skip to content

Commit

Permalink
Enable staticcheck linter. Disable check for folder /pkg and /test by…
Browse files Browse the repository at this point in the history
… now.

Signed-off-by: Xun Jiang <blackpiglet@gmail.com>
  • Loading branch information
Xun Jiang committed Jan 20, 2023
1 parent 71b459d commit c64a952
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 32 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/pr-staticcheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Run staticcheck on Pull Request
on: [pull_request]
jobs:
ci:
name: "Run staticcheck linter"
runs-on: ubuntu-latest
steps:
- name: Check out the code
uses: actions/checkout@v2

- name: Run staticcheck
uses: dominikh/staticcheck-action@v1.3.0
with:
version: "2022.1.3"
1 change: 1 addition & 0 deletions changelogs/unreleased/5788-blackpiglet
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Enable staticcheck linter.
20 changes: 9 additions & 11 deletions cmd/velero-restore-helper/velero-restore-helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,16 @@ func main() {
defer ticker.Stop()

for {
select {
case <-ticker.C:
if done() {
fmt.Println("All restic restores are done")
err := removeFolder()
if err != nil {
fmt.Println(err)
} else {
fmt.Println("Done cleanup .velero folder")
}
return
<-ticker.C
if done() {
fmt.Println("All restic restores are done")
err := removeFolder()
if err != nil {
fmt.Println(err)
} else {
fmt.Println("Done cleanup .velero folder")
}
return
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion hack/release-tools/chk_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
// minor
// patch
// prerelease (this will be alpha/beta/rc followed by a ".", followed by 1 or more digits (alpha.5)
var release_regex *regexp.Regexp = regexp.MustCompile("^v(?P<major>[[:digit:]]+)\\.(?P<minor>[[:digit:]]+)\\.(?P<patch>[[:digit:]]+)(-{1}(?P<prerelease>(alpha|beta|rc)\\.[[:digit:]]+))*")
var release_regex *regexp.Regexp = regexp.MustCompile(`^v(?P<major>[[:digit:]]+)\.(?P<minor>[[:digit:]]+)\.(?P<patch>[[:digit:]]+)(-{1}(?P<prerelease>(alpha|beta|rc)\.[[:digit:]]+))*`)

// This small program exists because checking the VELERO_VERSION rules in bash is difficult, and difficult to test for correctness.
// Calling it with --verify will verify whether or not the VELERO_VERSION environment variable is a valid version string, without parsing for its components.
Expand Down
10 changes: 0 additions & 10 deletions internal/hook/item_hook_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"time"

"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
Expand All @@ -40,15 +39,6 @@ import (
"github.com/vmware-tanzu/velero/pkg/util/collections"
)

type mockItemHookHandler struct {
mock.Mock
}

func (h *mockItemHookHandler) HandleHooks(log logrus.FieldLogger, groupResource schema.GroupResource, obj runtime.Unstructured, resourceHooks []ResourceHook, phase hookPhase) error {
args := h.Called(log, groupResource, obj, resourceHooks, phase)
return args.Error(0)
}

func TestHandleHooksSkips(t *testing.T) {
tests := []struct {
name string
Expand Down
8 changes: 4 additions & 4 deletions internal/hook/wait_exec_hook_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (e *DefaultWaitExecHookHandler) HandleHooks(
)

if newPod.Status.Phase == v1.PodSucceeded || newPod.Status.Phase == v1.PodFailed {
err := fmt.Errorf("Pod entered phase %s before some post-restore exec hooks ran", newPod.Status.Phase)
err := fmt.Errorf("pod entered phase %s before some post-restore exec hooks ran", newPod.Status.Phase)
podLog.Warning(err)
cancel()
return
Expand Down Expand Up @@ -155,7 +155,7 @@ func (e *DefaultWaitExecHookHandler) HandleHooks(
)
// Check the individual hook's wait timeout is not expired
if hook.Hook.WaitTimeout.Duration != 0 && time.Since(waitStart) > hook.Hook.WaitTimeout.Duration {
err := fmt.Errorf("Hook %s in container %s expired before executing", hook.HookName, hook.Hook.Container)
err := fmt.Errorf("hook %s in container %s expired before executing", hook.HookName, hook.Hook.Container)
hookLog.Error(err)
if hook.Hook.OnError == velerov1api.HookErrorModeFail {
errors = append(errors, err)
Expand Down Expand Up @@ -194,7 +194,7 @@ func (e *DefaultWaitExecHookHandler) HandleHooks(
handler(newObj)
},
DeleteFunc: func(obj interface{}) {
err := fmt.Errorf("Pod %s deleted before all hooks were executed", kube.NamespaceAndName(pod))
err := fmt.Errorf("pod %s deleted before all hooks were executed", kube.NamespaceAndName(pod))
log.Error(err)
cancel()
},
Expand All @@ -212,7 +212,7 @@ func (e *DefaultWaitExecHookHandler) HandleHooks(
if hook.executed {
continue
}
err := fmt.Errorf("Hook %s in container %s in pod %s not executed: %v", hook.HookName, hook.Hook.Container, kube.NamespaceAndName(pod), ctx.Err())
err := fmt.Errorf("hook %s in container %s in pod %s not executed: %v", hook.HookName, hook.Hook.Container, kube.NamespaceAndName(pod), ctx.Err())
hookLog := log.WithFields(
logrus.Fields{
"hookSource": hook.HookSource,
Expand Down
4 changes: 2 additions & 2 deletions internal/hook/wait_exec_hook_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ func TestWaitExecHandleHooks(t *testing.T) {
},
}).
Result(),
expectedErrors: []error{errors.New("Hook my-hook-1 in container container1 in pod default/my-pod not executed: context deadline exceeded")},
expectedErrors: []error{errors.New("hook my-hook-1 in container container1 in pod default/my-pod not executed: context deadline exceeded")},
byContainer: map[string][]PodExecRestoreHook{
"container1": {
{
Expand Down Expand Up @@ -496,7 +496,7 @@ func TestWaitExecHandleHooks(t *testing.T) {
},
}).
Result(),
expectedErrors: []error{errors.New("Hook my-hook-1 in container container1 in pod default/my-pod not executed: context deadline exceeded")},
expectedErrors: []error{errors.New("hook my-hook-1 in container container1 in pod default/my-pod not executed: context deadline exceeded")},
byContainer: map[string][]PodExecRestoreHook{
"container1": {
{
Expand Down
5 changes: 1 addition & 4 deletions internal/storage/storagelocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,7 @@ func IsReadyToValidate(bslValidationFrequency *metav1.Duration, lastValidationTi

// We want to validate BSL only if the set validation frequency/ interval has elapsed.
nextValidation := lastValidation.Add(validationFrequency) // next validation time: last validation time + validation frequency
if time.Now().UTC().Before(nextValidation) { // ready only when NOW is equal to or after the next validation time
return false
}
return true
return !time.Now().UTC().Before(nextValidation) // ready only when NOW is equal to or after the next validation time
}

// ListBackupStorageLocations verifies if there are any backup storage locations.
Expand Down
1 change: 1 addition & 0 deletions pkg/staticcheck.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
checks = []
1 change: 1 addition & 0 deletions test/staticcheck.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
checks = []

0 comments on commit c64a952

Please sign in to comment.