Skip to content

Commit

Permalink
chore: apply gofumpt in pkg 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 Jan 14, 2025
1 parent 2ef7711 commit 5152550
Show file tree
Hide file tree
Showing 128 changed files with 565 additions and 471 deletions.
3 changes: 1 addition & 2 deletions pkg/apis/velero/v1/server_status_request_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ type ServerStatusRequest struct {
}

// ServerStatusRequestSpec is the specification for a ServerStatusRequest.
type ServerStatusRequestSpec struct {
}
type ServerStatusRequestSpec struct{}

// ServerStatusRequestPhase represents the lifecycle phase of a ServerStatusRequest.
// +kubebuilder:validation:Enum=New;Processed
Expand Down
2 changes: 1 addition & 1 deletion pkg/archive/extractor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func TestUnzipAndExtractBackup(t *testing.T) {
}
require.NoError(t, err)

file, err := ext.fs.OpenFile(fileName, os.O_RDWR|os.O_CREATE, 0644)
file, err := ext.fs.OpenFile(fileName, os.O_RDWR|os.O_CREATE, 0o644)
require.NoError(t, err)

_, err = ext.UnzipAndExtractBackup(file.(io.Reader))
Expand Down
4 changes: 2 additions & 2 deletions pkg/archive/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func TestParse(t *testing.T) {
}

for _, file := range tc.files {
require.NoError(t, p.fs.MkdirAll(file, 0755))
require.NoError(t, p.fs.MkdirAll(file, 0o755))

if !strings.HasSuffix(file, "/") {
res, err := p.fs.Create(file)
Expand Down Expand Up @@ -213,7 +213,7 @@ func TestParseGroupVersions(t *testing.T) {
}

for _, file := range tc.files {
require.NoError(t, p.fs.MkdirAll(file, 0755))
require.NoError(t, p.fs.MkdirAll(file, 0o755))

if !strings.HasSuffix(file, "/") {
res, err := p.fs.Create(file)
Expand Down
5 changes: 3 additions & 2 deletions pkg/backup/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ type VolumeSnapshotterGetter interface {
// back up individual resources that don't prevent the backup from continuing to be processed) are logged
// to the backup log.
func (kb *kubernetesBackupper) Backup(log logrus.FieldLogger, backupRequest *Request, backupFile io.Writer,
actions []biav2.BackupItemAction, itemBlockActions []ibav1.ItemBlockAction, volumeSnapshotterGetter VolumeSnapshotterGetter) error {
actions []biav2.BackupItemAction, itemBlockActions []ibav1.ItemBlockAction, volumeSnapshotterGetter VolumeSnapshotterGetter,
) error {
backupItemActions := framework.NewBackupItemActionResolverV2(actions)
itemBlockActionResolver := framework.NewItemBlockActionResolver(itemBlockActions)
return kb.BackupWithResolvers(log, backupRequest, backupFile, backupItemActions, itemBlockActionResolver, volumeSnapshotterGetter)
Expand Down Expand Up @@ -889,7 +890,7 @@ func (kb *kubernetesBackupper) writeBackupVersion(tw *tar.Writer) error {
Name: versionFile,
Size: int64(len(versionString)),
Typeflag: tar.TypeReg,
Mode: 0755,
Mode: 0o755,
ModTime: time.Now(),
}
if err := tw.WriteHeader(hdr); err != nil {
Expand Down
15 changes: 11 additions & 4 deletions pkg/backup/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,12 @@ func TestBackupOldResourceFiltering(t *testing.T) {
{
name: "OrLabelSelector only backs up matching resources",
backup: defaultBackup().
OrLabelSelector([]*metav1.LabelSelector{{MatchLabels: map[string]string{"a1": "b1"}}, {MatchLabels: map[string]string{"a2": "b2"}},
{MatchLabels: map[string]string{"a3": "b3"}}, {MatchLabels: map[string]string{"a4": "b4"}}}).
OrLabelSelector([]*metav1.LabelSelector{
{MatchLabels: map[string]string{"a1": "b1"}},
{MatchLabels: map[string]string{"a2": "b2"}},
{MatchLabels: map[string]string{"a3": "b3"}},
{MatchLabels: map[string]string{"a4": "b4"}},
}).
Result(),
apiResources: []*test.APIResource{
test.Pods(
Expand Down Expand Up @@ -3300,7 +3304,8 @@ func TestBackupWithAsyncOperations(t *testing.T) {
ResourceIdentifier: velero.ResourceIdentifier{
GroupResource: kuberesource.Pods,
Namespace: "ns-1",
Name: "pod-1"},
Name: "pod-1",
},
OperationID: "pod-1-1",
},
Status: itemoperation.OperationStatus{
Expand Down Expand Up @@ -3331,7 +3336,8 @@ func TestBackupWithAsyncOperations(t *testing.T) {
ResourceIdentifier: velero.ResourceIdentifier{
GroupResource: kuberesource.Pods,
Namespace: "ns-1",
Name: "pod-2"},
Name: "pod-2",
},
OperationID: "pod-2-1",
},
Status: itemoperation.OperationStatus{
Expand Down Expand Up @@ -3986,6 +3992,7 @@ func (b *fakePodVolumeBackupper) GetPodVolumeBackup(namespace, name string) (*ve
}
return nil, nil
}

func (b *fakePodVolumeBackupper) ListPodVolumeBackupsByPod(podNamespace, podName string) ([]*velerov1.PodVolumeBackup, error) {
var pvbs []*velerov1.PodVolumeBackup
for _, pvb := range b.pvbs {
Expand Down
2 changes: 1 addition & 1 deletion pkg/backup/item_backupper.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ func getFileForArchive(namespace, name, groupResource, versionPath string, itemB
Name: filePath,
Size: int64(len(itemBytes)),
Typeflag: tar.TypeReg,
Mode: 0755,
Mode: 0o755,
ModTime: time.Now(),
}
return FileForArchive{FilePath: filePath, Header: hdr, FileBytes: itemBytes}
Expand Down
3 changes: 1 addition & 2 deletions pkg/backup/item_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ func sortResourcesByOrder(
fullname = item.name
}
if _, ok := itemMap[fullname]; !ok {
//This item has been inserted in the result
// This item has been inserted in the result
continue
}
sortedItems = append(sortedItems, item)
Expand Down Expand Up @@ -672,7 +672,6 @@ func (r *itemCollector) processPagerClientCalls(
listPager.PageSize = int64(r.pageSize)
// Add each item to temporary slice
list, paginated, err := listPager.List(context.Background(), metav1.ListOptions{LabelSelector: label})

if err != nil {
r.log.WithError(errors.WithStack(err)).Error("Error listing resources")
return list, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/backup/pv_skip_tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestSummary(t *testing.T) {

func TestSerializeSkipReasons(t *testing.T) {
tracker := NewSkipPVTracker()
//tracker.Track("pv5", "", "skipped due to policy")
// tracker.Track("pv5", "", "skipped due to policy")
tracker.Track("pv3", podVolumeApproach, "it's set to opt-out")
tracker.Track("pv3", csiSnapshotApproach, "not applicable for CSI ")

Expand Down
6 changes: 2 additions & 4 deletions pkg/builder/testcr_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ type TestCR struct {
Status TestCRStatus `json:"status,omitempty"`
}

type TestCRSpec struct {
}
type TestCRSpec struct{}

type TestCRStatus struct {
}
type TestCRStatus struct{}
4 changes: 2 additions & 2 deletions pkg/client/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ func SaveConfig(config VeleroConfig) error {

// Try to make the directory in case it doesn't exist
dir := filepath.Dir(fileName)
if err := os.MkdirAll(dir, 0700); err != nil {
if err := os.MkdirAll(dir, 0o700); err != nil {
return errors.WithStack(err)
}

configFile, err := os.OpenFile(fileName, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0600)
configFile, err := os.OpenFile(fileName, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o600)
if err != nil {
return errors.WithStack(err)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/client/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func removeConfigfileName() error {
}
return nil
}

func TestConfigOperations(t *testing.T) {
preHomeEnv := ""
prevEnv := os.Environ()
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/dynamic.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ type Getter interface {

// Patcher patches an object.
type Patcher interface {
//Patch patches the named object using the provided patch bytes, which are expected to be in JSON merge patch format. The patched object is returned.
// Patch patches the named object using the provided patch bytes, which are expected to be in JSON merge patch format. The patched object is returned.

Patch(name string, data []byte) (*unstructured.Unstructured, error)
}

// Deletor deletes an object.
type Deletor interface {
//Patch patches the named object using the provided patch bytes, which are expected to be in JSON merge patch format. The patched object is returned.
// Patch patches the named object using the provided patch bytes, which are expected to be in JSON merge patch format. The patched object is returned.

Delete(name string, opts metav1.DeleteOptions) error
}
Expand Down
3 changes: 0 additions & 3 deletions pkg/client/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ func (f *factory) KubeClient() (kubernetes.Interface, error) {
return nil, err
}
kubeClient, err := kubernetes.NewForConfig(clientConfig)

if err != nil {
return nil, errors.WithStack(err)
}
Expand Down Expand Up @@ -169,7 +168,6 @@ func (f *factory) KubebuilderClient() (kbclient.Client, error) {
kubebuilderClient, err := kbclient.New(clientConfig, kbclient.Options{
Scheme: scheme,
})

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -205,7 +203,6 @@ func (f *factory) KubebuilderWatchClient() (kbclient.WithWatch, error) {
kubebuilderWatchClient, err := kbclient.NewWithWatch(clientConfig, kbclient.Options{
Scheme: scheme,
})

if err != nil {
return nil, err
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/cmd/cli/backup/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,27 +224,27 @@ func TestCreateCommand(t *testing.T) {
flags.Parse([]string{"--resource-policies-configmap", resPoliciesConfigmap})
flags.Parse([]string{"--data-mover", dataMover})
flags.Parse([]string{"--parallel-files-upload", strconv.Itoa(parallelFilesUpload)})
//flags.Parse([]string{"--wait"})
// flags.Parse([]string{"--wait"})

client := velerotest.NewFakeControllerRuntimeClient(t).(kbclient.WithWatch)

f.On("Namespace").Return(mock.Anything)
f.On("KubebuilderWatchClient").Return(client, nil)

//Complete
// Complete
e := o.Complete(args, f)
require.NoError(t, e)

//Validate
// Validate
e = o.Validate(cmd, args, f)
require.ErrorContains(t, e, "include-resources, exclude-resources and include-cluster-resources are old filter parameters")
require.ErrorContains(t, e, "include-cluster-scoped-resources, exclude-cluster-scoped-resources, include-namespace-scoped-resources and exclude-namespace-scoped-resources are new filter parameters.\nThey cannot be used together")

//cmd
// cmd
e = o.Run(cmd, f)
require.NoError(t, e)

//Execute
// Execute
cmd.SetArgs([]string{"bk-name-exe"})
e = cmd.Execute()
require.NoError(t, e)
Expand Down Expand Up @@ -274,7 +274,7 @@ func TestCreateCommand(t *testing.T) {
require.Equal(t, resPoliciesConfigmap, o.ResPoliciesConfigmap)
require.Equal(t, dataMover, o.DataMover)
require.Equal(t, parallelFilesUpload, o.ParallelFilesUpload)
//assert.Equal(t, true, o.Wait)
// assert.Equal(t, true, o.Wait)

// verify oldAndNewFilterParametersUsedTogether
mix := o.oldAndNewFilterParametersUsedTogether()
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/cli/backup/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (o *DownloadOptions) Run(c *cobra.Command, f client.Factory) error {
kbClient, err := f.KubebuilderClient()
cmd.CheckError(err)

backupDest, err := os.OpenFile(o.Output, o.writeOptions, 0600)
backupDest, err := os.OpenFile(o.Output, o.writeOptions, 0o600)
if err != nil {
return err
}
Expand Down
1 change: 0 additions & 1 deletion pkg/cmd/cli/backup/download_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ func TestNewDownloadCommand(t *testing.T) {
cmd := exec.Command(os.Args[0], []string{"-test.run=TestNewDownloadCommand"}...)
cmd.Env = append(os.Environ(), fmt.Sprintf("%s=1", cmdtest.CaptureFlag))
_, stderr, err := veleroexec.RunCommand(cmd)

if err != nil {
require.Contains(t, stderr, "download request download url timeout")
return
Expand Down
3 changes: 2 additions & 1 deletion pkg/cmd/cli/backuplocation/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ func TestNewDeleteCommand(t *testing.T) {
}
t.Fatalf("process ran with err %v, want backups by get()", err)
}

func TestDeleteFunctions(t *testing.T) {
//t.Run("create the other create command with fromSchedule option for Run() other branches", func(t *testing.T) {
// t.Run("create the other create command with fromSchedule option for Run() other branches", func(t *testing.T) {
// create a factory
f := &factorymocks.Factory{}
kbclient := velerotest.NewFakeControllerRuntimeClient(t)
Expand Down
1 change: 0 additions & 1 deletion pkg/cmd/cli/backuplocation/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ func TestNewGetCommand(t *testing.T) {
cmd := exec.Command(os.Args[0], []string{"-test.run=TestNewGetCommand"}...)
cmd.Env = append(os.Environ(), fmt.Sprintf("%s=1", cmdtest.CaptureFlag))
_, stderr, err := veleroexec.RunCommand(cmd)

if err != nil {
assert.Contains(t, stderr, fmt.Sprintf("backupstoragelocations.velero.io \"%s\" not found", bkList[0]))
return
Expand Down
1 change: 0 additions & 1 deletion pkg/cmd/cli/backuplocation/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ func TestSetCommand_Execute(t *testing.T) {
cmd := exec.Command(os.Args[0], []string{"-test.run=TestSetCommand_Execute"}...)
cmd.Env = append(os.Environ(), fmt.Sprintf("%s=1", cmdtest.CaptureFlag))
_, stderr, err := veleroexec.RunCommand(cmd)

if err != nil {
assert.Contains(t, stderr, "backupstoragelocations.velero.io \"bsl-1\" not found")
return
Expand Down
12 changes: 8 additions & 4 deletions pkg/cmd/cli/datamover/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,10 @@ func newdataMoverBackup(logger logrus.FieldLogger, factory client.Factory, confi
return s, nil
}

var funcExitWithMessage = exitWithMessage
var funcCreateDataPathService = (*dataMoverBackup).createDataPathService
var (
funcExitWithMessage = exitWithMessage
funcCreateDataPathService = (*dataMoverBackup).createDataPathService
)

func (s *dataMoverBackup) run() {
signals.CancelOnShutdown(s.cancelFunc, s.logger)
Expand Down Expand Up @@ -268,8 +270,10 @@ func (s *dataMoverBackup) runDataPath() {
funcExitWithMessage(s.logger, true, result)
}

var funcNewCredentialFileStore = credentials.NewNamespacedFileStore
var funcNewCredentialSecretStore = credentials.NewNamespacedSecretStore
var (
funcNewCredentialFileStore = credentials.NewNamespacedFileStore
funcNewCredentialSecretStore = credentials.NewNamespacedSecretStore
)

func (s *dataMoverBackup) createDataPathService() (dataPathService, error) {
credentialFileStore, err := funcNewCredentialFileStore(
Expand Down
1 change: 0 additions & 1 deletion pkg/cmd/cli/datamover/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ func (fr *fakeRunHelper) RunCancelableDataPath(_ context.Context) (string, error
}

func (fr *fakeRunHelper) Shutdown() {

}

func (fr *fakeRunHelper) ExitWithMessage(logger logrus.FieldLogger, succeed bool, message string, a ...any) {
Expand Down
6 changes: 4 additions & 2 deletions pkg/cmd/cli/datamover/data_mover.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ type dataPathService interface {
Shutdown()
}

var funcExit = os.Exit
var funcCreateFile = os.Create
var (
funcExit = os.Exit
funcCreateFile = os.Create
)

func exitWithMessage(logger logrus.FieldLogger, succeed bool, message string, a ...any) {
exitCode := 0
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/cli/datamover/data_mover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (em *exitWithMessageMock) CreateFile(name string) (*os.File, error) {
}

if em.writeFail {
return os.OpenFile(em.filePath, os.O_CREATE|os.O_RDONLY, 0500)
return os.OpenFile(em.filePath, os.O_CREATE|os.O_RDONLY, 0o500)
} else {
return os.Create(em.filePath)
}
Expand Down
4 changes: 1 addition & 3 deletions pkg/cmd/cli/nodeagent/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ import (
cacheutil "k8s.io/client-go/tools/cache"
)

var (
scheme = runtime.NewScheme()
)
var scheme = runtime.NewScheme()

const (
// the port where prometheus metrics are exposed
Expand Down
1 change: 0 additions & 1 deletion pkg/cmd/cli/repomantenance/maintenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ func (o *Options) runRepoPrune(f velerocli.Factory, namespace string, logger log
BackupLocation: o.BackupStorageLocation,
RepositoryType: o.RepoType,
}, true)

if err != nil {
return errors.Wrap(err, "failed to get backup repository")
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/cli/restore/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ func TestCreateCommand(t *testing.T) {
f.On("Namespace").Return(mock.Anything)
f.On("KubebuilderWatchClient").Return(client, nil)

//Complete
// Complete
e := o.Complete(args, f)
require.NoError(t, e)

//Validate
// Validate
e = o.Validate(cmd, args, f)
require.ErrorContains(t, e, "either a backup or schedule must be specified, but not both")

//cmd
// cmd
e = o.Run(cmd, f)
require.NoError(t, e)

Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/server/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ func newChangeImageNameRestoreItemAction(f client.Factory) plugincommon.HandlerI
), nil
}
}

func newRoleBindingItemAction(logger logrus.FieldLogger) (interface{}, error) {
return ria.NewRoleBindingAction(logger), nil
}
Expand Down
Loading

0 comments on commit 5152550

Please sign in to comment.