Skip to content

Commit 77f6ec6

Browse files
committed
chore: define common alias for k8s packages
Signed-off-by: Matthieu MOREL <[email protected]>
1 parent 0bf2252 commit 77f6ec6

File tree

139 files changed

+1934
-1922
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+1934
-1922
lines changed

.golangci.yaml

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ output:
5252

5353
# all available settings of specific linters
5454
linters-settings:
55+
depguard:
56+
list-type: blacklist # Velero.io word list : ignore
57+
include-go-root: false
58+
packages:
59+
- github.com/sirupsen/logrus
60+
packages-with-error-message:
61+
# specify an error message to output when a denylisted package is used
62+
- github.com/sirupsen/logrus: "logging is allowed only by logutils.Log"
5563
dogsled:
5664
# checks assignments with too many blank identifiers; default is 2
5765
max-blank-identifiers: 2
@@ -86,9 +94,6 @@ linters-settings:
8694
gocognit:
8795
# minimal code complexity to report, 30 by default (but we recommend 10-20)
8896
min-complexity: 10
89-
nestif:
90-
# minimal complexity of if statements to report, 5 by default
91-
min-complexity: 4
9297
goconst:
9398
# minimal length of string constant, 3 by default
9499
min-len: 3
@@ -180,14 +185,22 @@ linters-settings:
180185
disable:
181186
- shadow
182187
disable-all: false
183-
depguard:
184-
list-type: blacklist # Velero.io word list : ignore
185-
include-go-root: false
186-
packages:
187-
- github.com/sirupsen/logrus
188-
packages-with-error-message:
189-
# specify an error message to output when a denylisted package is used
190-
- github.com/sirupsen/logrus: "logging is allowed only by logutils.Log"
188+
importas:
189+
alias:
190+
- alias: appsv1api
191+
pkg: k8s.io/api/apps/v1
192+
- alias: corev1api
193+
pkg: k8s.io/api/core/v1
194+
- alias: rbacv1
195+
pkg: k8s.io/api/rbac/v1
196+
- alias: apierrors
197+
pkg: k8s.io/apimachinery/pkg/api/errors
198+
- alias: apiextv1
199+
pkg: k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1
200+
- alias: metav1
201+
pkg: k8s.io/apimachinery/pkg/apis/meta/v1
202+
- alias: storagev1api
203+
pkg: k8s.io/api/storage/v1
191204
lll:
192205
# max line length, lines longer will be reported. Default is 120.
193206
# '\t' is counted as 1 character by default, and can be changed with the tab-width option
@@ -207,15 +220,9 @@ linters-settings:
207220
nakedret:
208221
# make an issue if func has more lines of code than this setting and it has naked returns; default is 30
209222
max-func-lines: 30
210-
prealloc:
211-
# XXX: we don't recommend using this linter before doing performance profiling.
212-
# For most programs usage of prealloc will be a premature optimization.
213-
214-
# Report preallocation suggestions only on simple loops that have no returns/breaks/continues/gotos in them.
215-
# True by default.
216-
simple: true
217-
range-loops: true # Report preallocation suggestions on range loops, true by default
218-
for-loops: false # Report preallocation suggestions on for loops, false by default
223+
nestif:
224+
# minimal complexity of if statements to report, 5 by default
225+
min-complexity: 4
219226
nolintlint:
220227
# Enable to ensure that nolint directives are all used. Default is true.
221228
allow-unused: false
@@ -233,6 +240,15 @@ linters-settings:
233240
errorf: false
234241
int-conversion: true
235242
fiximports: true
243+
prealloc:
244+
# XXX: we don't recommend using this linter before doing performance profiling.
245+
# For most programs usage of prealloc will be a premature optimization.
246+
247+
# Report preallocation suggestions only on simple loops that have no returns/breaks/continues/gotos in them.
248+
# True by default.
249+
simple: true
250+
range-loops: true # Report preallocation suggestions on range loops, true by default
251+
for-loops: false # Report preallocation suggestions on for loops, false by default
236252
revive:
237253
rules:
238254
- name: blank-imports
@@ -280,7 +296,6 @@ linters-settings:
280296
- name: var-declaration
281297
- name: var-naming
282298
disabled: true
283-
284299
rowserrcheck:
285300
packages:
286301
- github.com/jmoiron/sqlx

internal/credentials/file_store_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"testing"
2222

2323
"github.com/stretchr/testify/require"
24-
corev1 "k8s.io/api/core/v1"
24+
corev1api "k8s.io/api/core/v1"
2525

2626
"github.com/vmware-tanzu/velero/pkg/builder"
2727
velerotest "github.com/vmware-tanzu/velero/pkg/test"
@@ -32,8 +32,8 @@ func TestNamespacedFileStore(t *testing.T) {
3232
name string
3333
namespace string
3434
fsRoot string
35-
secrets []*corev1.Secret
36-
secretSelector *corev1.SecretKeySelector
35+
secrets []*corev1api.Secret
36+
secretSelector *corev1api.SecretKeySelector
3737
wantErr string
3838
expectedPath string
3939
expectedContents string
@@ -48,7 +48,7 @@ func TestNamespacedFileStore(t *testing.T) {
4848
namespace: "ns1",
4949
fsRoot: "/tmp/credentials",
5050
secretSelector: builder.ForSecretKeySelector("credential", "key2").Result(),
51-
secrets: []*corev1.Secret{
51+
secrets: []*corev1api.Secret{
5252
builder.ForSecret("ns1", "credential").Data(map[string][]byte{
5353
"key1": []byte("ns1-secretdata1"),
5454
"key2": []byte("ns1-secretdata2"),

internal/credentials/mocks/FileStore.go

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/credentials/mocks/SecretStore.go

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/hook/wait_exec_hook_handler.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"time"
2323

2424
"github.com/sirupsen/logrus"
25-
v1 "k8s.io/api/core/v1"
25+
corev1api "k8s.io/api/core/v1"
2626
"k8s.io/apimachinery/pkg/fields"
2727
"k8s.io/apimachinery/pkg/runtime"
2828
"k8s.io/client-go/tools/cache"
@@ -37,7 +37,7 @@ type WaitExecHookHandler interface {
3737
HandleHooks(
3838
ctx context.Context,
3939
log logrus.FieldLogger,
40-
pod *v1.Pod,
40+
pod *corev1api.Pod,
4141
byContainer map[string][]PodExecRestoreHook,
4242
multiHookTracker *MultiHookTracker,
4343
restoreName string,
@@ -73,7 +73,7 @@ var _ WaitExecHookHandler = &DefaultWaitExecHookHandler{}
7373
func (e *DefaultWaitExecHookHandler) HandleHooks(
7474
ctx context.Context,
7575
log logrus.FieldLogger,
76-
pod *v1.Pod,
76+
pod *corev1api.Pod,
7777
byContainer map[string][]PodExecRestoreHook,
7878
multiHookTracker *MultiHookTracker,
7979
restoreName string,
@@ -117,7 +117,7 @@ func (e *DefaultWaitExecHookHandler) HandleHooks(
117117
// When a container is observed running and its hooks are executed, the container is deleted
118118
// from the byContainer map. When the map is empty the watch is ended.
119119
handler := func(newObj any) {
120-
newPod, ok := newObj.(*v1.Pod)
120+
newPod, ok := newObj.(*corev1api.Pod)
121121
if !ok {
122122
return
123123
}
@@ -128,7 +128,7 @@ func (e *DefaultWaitExecHookHandler) HandleHooks(
128128
},
129129
)
130130

131-
if newPod.Status.Phase == v1.PodSucceeded || newPod.Status.Phase == v1.PodFailed {
131+
if newPod.Status.Phase == corev1api.PodSucceeded || newPod.Status.Phase == corev1api.PodFailed {
132132
err := fmt.Errorf("pod entered phase %s before some post-restore exec hooks ran", newPod.Status.Phase)
133133
podLog.Warning(err)
134134
cancel()
@@ -260,7 +260,7 @@ func (e *DefaultWaitExecHookHandler) HandleHooks(
260260
return errors
261261
}
262262

263-
func podHasContainer(pod *v1.Pod, containerName string) bool {
263+
func podHasContainer(pod *corev1api.Pod, containerName string) bool {
264264
if pod == nil {
265265
return false
266266
}
@@ -273,7 +273,7 @@ func podHasContainer(pod *v1.Pod, containerName string) bool {
273273
return false
274274
}
275275

276-
func isContainerUp(pod *v1.Pod, containerName string, hooks []PodExecRestoreHook) bool {
276+
func isContainerUp(pod *corev1api.Pod, containerName string, hooks []PodExecRestoreHook) bool {
277277
if pod == nil {
278278
return false
279279
}

0 commit comments

Comments
 (0)