mirror of
https://github.com/vmware-tanzu/velero.git
synced 2025-12-23 06:15:21 +00:00
Enable staticcheck linter. Disable check for folder /pkg and /test by now.
Signed-off-by: Xun Jiang <blackpiglet@gmail.com>
This commit is contained in:
6
.github/workflows/pr-ci-check.yml
vendored
6
.github/workflows/pr-ci-check.yml
vendored
@@ -4,6 +4,8 @@ jobs:
|
|||||||
build:
|
build:
|
||||||
name: Run CI
|
name: Run CI
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
steps:
|
steps:
|
||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v2
|
uses: actions/setup-go@v2
|
||||||
@@ -27,3 +29,7 @@ jobs:
|
|||||||
token: ${{ secrets.CODECOV_TOKEN }}
|
token: ${{ secrets.CODECOV_TOKEN }}
|
||||||
files: coverage.out
|
files: coverage.out
|
||||||
verbose: true
|
verbose: true
|
||||||
|
- name: Run staticcheck
|
||||||
|
uses: dominikh/staticcheck-action@v1.3.0
|
||||||
|
with:
|
||||||
|
version: "2022.1.3"
|
||||||
1
changelogs/unreleased/5788-blackpiglet
Normal file
1
changelogs/unreleased/5788-blackpiglet
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Enable staticcheck linter.
|
||||||
@@ -18,7 +18,6 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
@@ -34,18 +33,16 @@ func main() {
|
|||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
<-ticker.C
|
||||||
case <-ticker.C:
|
if done() {
|
||||||
if done() {
|
fmt.Println("All restic restores are done")
|
||||||
fmt.Println("All restic restores are done")
|
err := removeFolder()
|
||||||
err := removeFolder()
|
if err != nil {
|
||||||
if err != nil {
|
fmt.Println(err)
|
||||||
fmt.Println(err)
|
} else {
|
||||||
} else {
|
fmt.Println("Done cleanup .velero folder")
|
||||||
fmt.Println("Done cleanup .velero folder")
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -54,7 +51,7 @@ func main() {
|
|||||||
// within the .velero/ subdirectory whose name is equal to os.Args[1], or
|
// within the .velero/ subdirectory whose name is equal to os.Args[1], or
|
||||||
// false otherwise
|
// false otherwise
|
||||||
func done() bool {
|
func done() bool {
|
||||||
children, err := ioutil.ReadDir("/restores")
|
children, err := os.ReadDir("/restores")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "ERROR reading /restores directory: %s\n", err)
|
fmt.Fprintf(os.Stderr, "ERROR reading /restores directory: %s\n", err)
|
||||||
return false
|
return false
|
||||||
@@ -84,7 +81,7 @@ func done() bool {
|
|||||||
|
|
||||||
// remove .velero folder
|
// remove .velero folder
|
||||||
func removeFolder() error {
|
func removeFolder() error {
|
||||||
children, err := ioutil.ReadDir("/restores")
|
children, err := os.ReadDir("/restores")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ package crds
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"io/ioutil"
|
"io"
|
||||||
|
|
||||||
apiextinstall "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/install"
|
apiextinstall "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/install"
|
||||||
apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
|
apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
|
||||||
@@ -53,7 +53,7 @@ func crds() []*apiextv1.CustomResourceDefinition {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
bytes, err := ioutil.ReadAll(gzr)
|
bytes, err := io.ReadAll(gzr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import (
|
|||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"text/template"
|
"text/template"
|
||||||
@@ -41,7 +40,7 @@ package crds
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"io/ioutil"
|
"io"
|
||||||
|
|
||||||
apiextinstall "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/install"
|
apiextinstall "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/install"
|
||||||
apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
|
apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
|
||||||
@@ -65,7 +64,7 @@ func crds() []*apiextv1.CustomResourceDefinition {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
bytes, err := ioutil.ReadAll(gzr)
|
bytes, err := io.ReadAll(gzr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@@ -87,7 +86,7 @@ type templateData struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
headerBytes, err := ioutil.ReadFile(goHeaderFile)
|
headerBytes, err := os.ReadFile(goHeaderFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
@@ -97,7 +96,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// This is relative to config/crd/crds
|
// This is relative to config/crd/crds
|
||||||
manifests, err := ioutil.ReadDir("../bases")
|
manifests, err := os.ReadDir("../bases")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import (
|
|||||||
// minor
|
// minor
|
||||||
// patch
|
// patch
|
||||||
// prerelease (this will be alpha/beta/rc followed by a ".", followed by 1 or more digits (alpha.5)
|
// 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.
|
// 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.
|
// Calling it with --verify will verify whether or not the VELERO_VERSION environment variable is a valid version string, without parsing for its components.
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/mock"
|
"github.com/stretchr/testify/mock"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@@ -40,15 +39,6 @@ import (
|
|||||||
"github.com/vmware-tanzu/velero/pkg/util/collections"
|
"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) {
|
func TestHandleHooksSkips(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ func (e *DefaultWaitExecHookHandler) HandleHooks(
|
|||||||
)
|
)
|
||||||
|
|
||||||
if newPod.Status.Phase == v1.PodSucceeded || newPod.Status.Phase == v1.PodFailed {
|
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)
|
podLog.Warning(err)
|
||||||
cancel()
|
cancel()
|
||||||
return
|
return
|
||||||
@@ -155,7 +155,7 @@ func (e *DefaultWaitExecHookHandler) HandleHooks(
|
|||||||
)
|
)
|
||||||
// Check the individual hook's wait timeout is not expired
|
// Check the individual hook's wait timeout is not expired
|
||||||
if hook.Hook.WaitTimeout.Duration != 0 && time.Since(waitStart) > hook.Hook.WaitTimeout.Duration {
|
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)
|
hookLog.Error(err)
|
||||||
if hook.Hook.OnError == velerov1api.HookErrorModeFail {
|
if hook.Hook.OnError == velerov1api.HookErrorModeFail {
|
||||||
errors = append(errors, err)
|
errors = append(errors, err)
|
||||||
@@ -194,7 +194,7 @@ func (e *DefaultWaitExecHookHandler) HandleHooks(
|
|||||||
handler(newObj)
|
handler(newObj)
|
||||||
},
|
},
|
||||||
DeleteFunc: func(obj interface{}) {
|
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)
|
log.Error(err)
|
||||||
cancel()
|
cancel()
|
||||||
},
|
},
|
||||||
@@ -212,7 +212,7 @@ func (e *DefaultWaitExecHookHandler) HandleHooks(
|
|||||||
if hook.executed {
|
if hook.executed {
|
||||||
continue
|
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(
|
hookLog := log.WithFields(
|
||||||
logrus.Fields{
|
logrus.Fields{
|
||||||
"hookSource": hook.HookSource,
|
"hookSource": hook.HookSource,
|
||||||
|
|||||||
@@ -465,7 +465,7 @@ func TestWaitExecHandleHooks(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}).
|
}).
|
||||||
Result(),
|
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{
|
byContainer: map[string][]PodExecRestoreHook{
|
||||||
"container1": {
|
"container1": {
|
||||||
{
|
{
|
||||||
@@ -496,7 +496,7 @@ func TestWaitExecHandleHooks(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}).
|
}).
|
||||||
Result(),
|
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{
|
byContainer: map[string][]PodExecRestoreHook{
|
||||||
"container1": {
|
"container1": {
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -71,10 +71,7 @@ func IsReadyToValidate(bslValidationFrequency *metav1.Duration, lastValidationTi
|
|||||||
|
|
||||||
// We want to validate BSL only if the set validation frequency/ interval has elapsed.
|
// 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
|
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 !time.Now().UTC().Before(nextValidation) // ready only when NOW is equal to or after the next validation time
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListBackupStorageLocations verifies if there are any backup storage locations.
|
// ListBackupStorageLocations verifies if there are any backup storage locations.
|
||||||
|
|||||||
@@ -163,7 +163,7 @@ func TestListBackupStorageLocations(t *testing.T) {
|
|||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
g := NewWithT(t)
|
g := NewWithT(t)
|
||||||
|
|
||||||
client := fake.NewFakeClientWithScheme(scheme.Scheme, tt.backupLocations)
|
client := fake.NewClientBuilder().WithScheme(scheme.Scheme).WithRuntimeObjects(tt.backupLocations).Build()
|
||||||
if tt.expectError {
|
if tt.expectError {
|
||||||
_, err := ListBackupStorageLocations(context.Background(), client, "ns-1")
|
_, err := ListBackupStorageLocations(context.Background(), client, "ns-1")
|
||||||
g.Expect(err).NotTo(BeNil())
|
g.Expect(err).NotTo(BeNil())
|
||||||
|
|||||||
1
pkg/staticcheck.conf
Normal file
1
pkg/staticcheck.conf
Normal file
@@ -0,0 +1 @@
|
|||||||
|
checks = []
|
||||||
1
test/staticcheck.conf
Normal file
1
test/staticcheck.conf
Normal file
@@ -0,0 +1 @@
|
|||||||
|
checks = []
|
||||||
Reference in New Issue
Block a user