Skip to content

Commit

Permalink
chore: define common alias for k8s packages
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu MOREL <[email protected]>
  • Loading branch information
mmorel-35 committed Feb 26, 2025
1 parent a45c9f2 commit f1fff75
Show file tree
Hide file tree
Showing 138 changed files with 1,914 additions and 1,901 deletions.
16 changes: 16 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,22 @@ linters-settings:
disable:
- shadow
disable-all: false
importas:
alias:
- alias: appsv1api
pkg: k8s.io/api/apps/v1
- alias: corev1api
pkg: k8s.io/api/core/v1
- alias: rbacv1
pkg: k8s.io/api/rbac/v1
- alias: apierrors
pkg: k8s.io/apimachinery/pkg/api/errors
- alias: apiextv1
pkg: k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1
- alias: metav1
pkg: k8s.io/apimachinery/pkg/apis/meta/v1
- alias: storagev1api
pkg: k8s.io/api/storage/v1
lll:
# max line length, lines longer will be reported. Default is 120.
# '\t' is counted as 1 character by default, and can be changed with the tab-width option
Expand Down
8 changes: 4 additions & 4 deletions internal/credentials/file_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"testing"

"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
corev1api "k8s.io/api/core/v1"

"github.com/vmware-tanzu/velero/pkg/builder"
velerotest "github.com/vmware-tanzu/velero/pkg/test"
Expand All @@ -32,8 +32,8 @@ func TestNamespacedFileStore(t *testing.T) {
name string
namespace string
fsRoot string
secrets []*corev1.Secret
secretSelector *corev1.SecretKeySelector
secrets []*corev1api.Secret
secretSelector *corev1api.SecretKeySelector
wantErr string
expectedPath string
expectedContents string
Expand All @@ -48,7 +48,7 @@ func TestNamespacedFileStore(t *testing.T) {
namespace: "ns1",
fsRoot: "/tmp/credentials",
secretSelector: builder.ForSecretKeySelector("credential", "key2").Result(),
secrets: []*corev1.Secret{
secrets: []*corev1api.Secret{
builder.ForSecret("ns1", "credential").Data(map[string][]byte{
"key1": []byte("ns1-secretdata1"),
"key2": []byte("ns1-secretdata2"),
Expand Down
8 changes: 4 additions & 4 deletions internal/credentials/mocks/FileStore.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions internal/credentials/mocks/SecretStore.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions internal/hook/wait_exec_hook_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"time"

"github.com/sirupsen/logrus"
v1 "k8s.io/api/core/v1"
corev1api "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/tools/cache"
Expand All @@ -37,7 +37,7 @@ type WaitExecHookHandler interface {
HandleHooks(
ctx context.Context,
log logrus.FieldLogger,
pod *v1.Pod,
pod *corev1api.Pod,
byContainer map[string][]PodExecRestoreHook,
multiHookTracker *MultiHookTracker,
restoreName string,
Expand Down Expand Up @@ -73,7 +73,7 @@ var _ WaitExecHookHandler = &DefaultWaitExecHookHandler{}
func (e *DefaultWaitExecHookHandler) HandleHooks(
ctx context.Context,
log logrus.FieldLogger,
pod *v1.Pod,
pod *corev1api.Pod,
byContainer map[string][]PodExecRestoreHook,
multiHookTracker *MultiHookTracker,
restoreName string,
Expand Down Expand Up @@ -117,7 +117,7 @@ func (e *DefaultWaitExecHookHandler) HandleHooks(
// When a container is observed running and its hooks are executed, the container is deleted
// from the byContainer map. When the map is empty the watch is ended.
handler := func(newObj any) {
newPod, ok := newObj.(*v1.Pod)
newPod, ok := newObj.(*corev1api.Pod)
if !ok {
return
}
Expand All @@ -128,7 +128,7 @@ func (e *DefaultWaitExecHookHandler) HandleHooks(
},
)

if newPod.Status.Phase == v1.PodSucceeded || newPod.Status.Phase == v1.PodFailed {
if newPod.Status.Phase == corev1api.PodSucceeded || newPod.Status.Phase == corev1api.PodFailed {
err := fmt.Errorf("pod entered phase %s before some post-restore exec hooks ran", newPod.Status.Phase)
podLog.Warning(err)
cancel()
Expand Down Expand Up @@ -265,7 +265,7 @@ func (e *DefaultWaitExecHookHandler) HandleHooks(
return errors
}

func podHasContainer(pod *v1.Pod, containerName string) bool {
func podHasContainer(pod *corev1api.Pod, containerName string) bool {
if pod == nil {
return false
}
Expand All @@ -278,7 +278,7 @@ func podHasContainer(pod *v1.Pod, containerName string) bool {
return false
}

func isContainerUp(pod *v1.Pod, containerName string, hooks []PodExecRestoreHook) bool {
func isContainerUp(pod *corev1api.Pod, containerName string, hooks []PodExecRestoreHook) bool {
if pod == nil {
return false
}
Expand Down
Loading

0 comments on commit f1fff75

Please sign in to comment.