Skip to content

Commit 3d125f5

Browse files
committed
chore: apply gofumpt in pkg packages
Signed-off-by: Matthieu MOREL <[email protected]>
1 parent f56698e commit 3d125f5

File tree

128 files changed

+580
-482
lines changed

Some content is hidden

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

128 files changed

+580
-482
lines changed

pkg/apis/velero/v1/server_status_request_types.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ type ServerStatusRequest struct {
4545
}
4646

4747
// ServerStatusRequestSpec is the specification for a ServerStatusRequest.
48-
type ServerStatusRequestSpec struct {
49-
}
48+
type ServerStatusRequestSpec struct{}
5049

5150
// ServerStatusRequestPhase represents the lifecycle phase of a ServerStatusRequest.
5251
// +kubebuilder:validation:Enum=New;Processed

pkg/archive/extractor_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func TestUnzipAndExtractBackup(t *testing.T) {
7272
}
7373
require.NoError(t, err)
7474

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

7878
_, err = ext.UnzipAndExtractBackup(file.(io.Reader))

pkg/archive/parser_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func TestParse(t *testing.T) {
9999
}
100100

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

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

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

218218
if !strings.HasSuffix(file, "/") {
219219
res, err := p.fs.Create(file)

pkg/backup/backup.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ type VolumeSnapshotterGetter interface {
221221
// back up individual resources that don't prevent the backup from continuing to be processed) are logged
222222
// to the backup log.
223223
func (kb *kubernetesBackupper) Backup(log logrus.FieldLogger, backupRequest *Request, backupFile io.Writer,
224-
actions []biav2.BackupItemAction, itemBlockActions []ibav1.ItemBlockAction, volumeSnapshotterGetter VolumeSnapshotterGetter) error {
224+
actions []biav2.BackupItemAction, itemBlockActions []ibav1.ItemBlockAction, volumeSnapshotterGetter VolumeSnapshotterGetter,
225+
) error {
225226
backupItemActions := framework.NewBackupItemActionResolverV2(actions)
226227
itemBlockActionResolver := framework.NewItemBlockActionResolver(itemBlockActions)
227228
return kb.BackupWithResolvers(log, backupRequest, backupFile, backupItemActions, itemBlockActionResolver, volumeSnapshotterGetter)
@@ -891,7 +892,7 @@ func (kb *kubernetesBackupper) writeBackupVersion(tw *tar.Writer) error {
891892
Name: versionFile,
892893
Size: int64(len(versionString)),
893894
Typeflag: tar.TypeReg,
894-
Mode: 0755,
895+
Mode: 0o755,
895896
ModTime: time.Now(),
896897
}
897898
if err := tw.WriteHeader(hdr); err != nil {

pkg/backup/backup_test.go

+11-4
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,12 @@ func TestBackupOldResourceFiltering(t *testing.T) {
352352
{
353353
name: "OrLabelSelector only backs up matching resources",
354354
backup: defaultBackup().
355-
OrLabelSelector([]*metav1.LabelSelector{{MatchLabels: map[string]string{"a1": "b1"}}, {MatchLabels: map[string]string{"a2": "b2"}},
356-
{MatchLabels: map[string]string{"a3": "b3"}}, {MatchLabels: map[string]string{"a4": "b4"}}}).
355+
OrLabelSelector([]*metav1.LabelSelector{
356+
{MatchLabels: map[string]string{"a1": "b1"}},
357+
{MatchLabels: map[string]string{"a2": "b2"}},
358+
{MatchLabels: map[string]string{"a3": "b3"}},
359+
{MatchLabels: map[string]string{"a4": "b4"}},
360+
}).
357361
Result(),
358362
apiResources: []*test.APIResource{
359363
test.Pods(
@@ -3300,7 +3304,8 @@ func TestBackupWithAsyncOperations(t *testing.T) {
33003304
ResourceIdentifier: velero.ResourceIdentifier{
33013305
GroupResource: kuberesource.Pods,
33023306
Namespace: "ns-1",
3303-
Name: "pod-1"},
3307+
Name: "pod-1",
3308+
},
33043309
OperationID: "pod-1-1",
33053310
},
33063311
Status: itemoperation.OperationStatus{
@@ -3331,7 +3336,8 @@ func TestBackupWithAsyncOperations(t *testing.T) {
33313336
ResourceIdentifier: velero.ResourceIdentifier{
33323337
GroupResource: kuberesource.Pods,
33333338
Namespace: "ns-1",
3334-
Name: "pod-2"},
3339+
Name: "pod-2",
3340+
},
33353341
OperationID: "pod-2-1",
33363342
},
33373343
Status: itemoperation.OperationStatus{
@@ -3986,6 +3992,7 @@ func (b *fakePodVolumeBackupper) GetPodVolumeBackup(namespace, name string) (*ve
39863992
}
39873993
return nil, nil
39883994
}
3995+
39893996
func (b *fakePodVolumeBackupper) ListPodVolumeBackupsByPod(podNamespace, podName string) ([]*velerov1.PodVolumeBackup, error) {
39903997
var pvbs []*velerov1.PodVolumeBackup
39913998
for _, pvb := range b.pvbs {

pkg/backup/item_backupper.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ func getFileForArchive(namespace, name, groupResource, versionPath string, itemB
319319
Name: filePath,
320320
Size: int64(len(itemBytes)),
321321
Typeflag: tar.TypeReg,
322-
Mode: 0755,
322+
Mode: 0o755,
323323
ModTime: time.Now(),
324324
}
325325
return FileForArchive{FilePath: filePath, Header: hdr, FileBytes: itemBytes}

pkg/backup/item_collector.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ func sortResourcesByOrder(
312312
fullname = item.name
313313
}
314314
if _, ok := itemMap[fullname]; !ok {
315-
//This item has been inserted in the result
315+
// This item has been inserted in the result
316316
continue
317317
}
318318
sortedItems = append(sortedItems, item)
@@ -672,7 +672,6 @@ func (r *itemCollector) processPagerClientCalls(
672672
listPager.PageSize = int64(r.pageSize)
673673
// Add each item to temporary slice
674674
list, paginated, err := listPager.List(context.Background(), metav1.ListOptions{LabelSelector: label})
675-
676675
if err != nil {
677676
r.log.WithError(errors.WithStack(err)).Error("Error listing resources")
678677
return list, err

pkg/backup/pv_skip_tracker_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func TestSummary(t *testing.T) {
6161

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

pkg/builder/testcr_builder.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ type TestCR struct {
7070
Status TestCRStatus `json:"status,omitempty"`
7171
}
7272

73-
type TestCRSpec struct {
74-
}
73+
type TestCRSpec struct{}
7574

76-
type TestCRStatus struct {
77-
}
75+
type TestCRStatus struct{}

pkg/client/config.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ func SaveConfig(config VeleroConfig) error {
7272

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

79-
configFile, err := os.OpenFile(fileName, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0600)
79+
configFile, err := os.OpenFile(fileName, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o600)
8080
if err != nil {
8181
return errors.WithStack(err)
8282
}

pkg/client/config_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func removeConfigfileName() error {
4747
}
4848
return nil
4949
}
50+
5051
func TestConfigOperations(t *testing.T) {
5152
preHomeEnv := ""
5253
prevEnv := os.Environ()

pkg/client/dynamic.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,14 @@ type Getter interface {
8585

8686
// Patcher patches an object.
8787
type Patcher interface {
88-
//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.
88+
// 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.
8989

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

9393
// Deletor deletes an object.
9494
type Deletor interface {
95-
//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.
95+
// 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.
9696

9797
Delete(name string, opts metav1.DeleteOptions) error
9898
}

pkg/client/factory.go

-3
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ func (f *factory) KubeClient() (kubernetes.Interface, error) {
122122
return nil, err
123123
}
124124
kubeClient, err := kubernetes.NewForConfig(clientConfig)
125-
126125
if err != nil {
127126
return nil, errors.WithStack(err)
128127
}
@@ -169,7 +168,6 @@ func (f *factory) KubebuilderClient() (kbclient.Client, error) {
169168
kubebuilderClient, err := kbclient.New(clientConfig, kbclient.Options{
170169
Scheme: scheme,
171170
})
172-
173171
if err != nil {
174172
return nil, err
175173
}
@@ -205,7 +203,6 @@ func (f *factory) KubebuilderWatchClient() (kbclient.WithWatch, error) {
205203
kubebuilderWatchClient, err := kbclient.NewWithWatch(clientConfig, kbclient.Options{
206204
Scheme: scheme,
207205
})
208-
209206
if err != nil {
210207
return nil, err
211208
}

pkg/cmd/cli/backup/create_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -224,27 +224,27 @@ func TestCreateCommand(t *testing.T) {
224224
flags.Parse([]string{"--resource-policies-configmap", resPoliciesConfigmap})
225225
flags.Parse([]string{"--data-mover", dataMover})
226226
flags.Parse([]string{"--parallel-files-upload", strconv.Itoa(parallelFilesUpload)})
227-
//flags.Parse([]string{"--wait"})
227+
// flags.Parse([]string{"--wait"})
228228

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

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

234-
//Complete
234+
// Complete
235235
e := o.Complete(args, f)
236236
require.NoError(t, e)
237237

238-
//Validate
238+
// Validate
239239
e = o.Validate(cmd, args, f)
240240
require.ErrorContains(t, e, "include-resources, exclude-resources and include-cluster-resources are old filter parameters")
241241
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")
242242

243-
//cmd
243+
// cmd
244244
e = o.Run(cmd, f)
245245
require.NoError(t, e)
246246

247-
//Execute
247+
// Execute
248248
cmd.SetArgs([]string{"bk-name-exe"})
249249
e = cmd.Execute()
250250
require.NoError(t, e)
@@ -274,7 +274,7 @@ func TestCreateCommand(t *testing.T) {
274274
require.Equal(t, resPoliciesConfigmap, o.ResPoliciesConfigmap)
275275
require.Equal(t, dataMover, o.DataMover)
276276
require.Equal(t, parallelFilesUpload, o.ParallelFilesUpload)
277-
//assert.Equal(t, true, o.Wait)
277+
// assert.Equal(t, true, o.Wait)
278278

279279
// verify oldAndNewFilterParametersUsedTogether
280280
mix := o.oldAndNewFilterParametersUsedTogether()

pkg/cmd/cli/backup/download.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func (o *DownloadOptions) Run(c *cobra.Command, f client.Factory) error {
118118
kbClient, err := f.KubebuilderClient()
119119
cmd.CheckError(err)
120120

121-
backupDest, err := os.OpenFile(o.Output, o.writeOptions, 0600)
121+
backupDest, err := os.OpenFile(o.Output, o.writeOptions, 0o600)
122122
if err != nil {
123123
return err
124124
}

pkg/cmd/cli/backup/download_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ func TestNewDownloadCommand(t *testing.T) {
9595
cmd := exec.Command(os.Args[0], []string{"-test.run=TestNewDownloadCommand"}...)
9696
cmd.Env = append(os.Environ(), fmt.Sprintf("%s=1", cmdtest.CaptureFlag))
9797
_, stderr, err := veleroexec.RunCommand(cmd)
98-
9998
if err != nil {
10099
require.Contains(t, stderr, "download request download url timeout")
101100
return

pkg/cmd/cli/backuplocation/delete_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ func TestNewDeleteCommand(t *testing.T) {
7575
}
7676
t.Fatalf("process ran with err %v, want backups by get()", err)
7777
}
78+
7879
func TestDeleteFunctions(t *testing.T) {
79-
//t.Run("create the other create command with fromSchedule option for Run() other branches", func(t *testing.T) {
80+
// t.Run("create the other create command with fromSchedule option for Run() other branches", func(t *testing.T) {
8081
// create a factory
8182
f := &factorymocks.Factory{}
8283
kbclient := velerotest.NewFakeControllerRuntimeClient(t)

pkg/cmd/cli/backuplocation/get_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ func TestNewGetCommand(t *testing.T) {
5353
cmd := exec.Command(os.Args[0], []string{"-test.run=TestNewGetCommand"}...)
5454
cmd.Env = append(os.Environ(), fmt.Sprintf("%s=1", cmdtest.CaptureFlag))
5555
_, stderr, err := veleroexec.RunCommand(cmd)
56-
5756
if err != nil {
5857
assert.Contains(t, stderr, fmt.Sprintf("backupstoragelocations.velero.io \"%s\" not found", bkList[0]))
5958
return

pkg/cmd/cli/backuplocation/set_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ func TestSetCommand_Execute(t *testing.T) {
101101
cmd := exec.Command(os.Args[0], []string{"-test.run=TestSetCommand_Execute"}...)
102102
cmd.Env = append(os.Environ(), fmt.Sprintf("%s=1", cmdtest.CaptureFlag))
103103
_, stderr, err := veleroexec.RunCommand(cmd)
104-
105104
if err != nil {
106105
assert.Contains(t, stderr, "backupstoragelocations.velero.io \"bsl-1\" not found")
107106
return

pkg/cmd/cli/datamover/backup.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,10 @@ func newdataMoverBackup(logger logrus.FieldLogger, factory client.Factory, confi
213213
return s, nil
214214
}
215215

216-
var funcExitWithMessage = exitWithMessage
217-
var funcCreateDataPathService = (*dataMoverBackup).createDataPathService
216+
var (
217+
funcExitWithMessage = exitWithMessage
218+
funcCreateDataPathService = (*dataMoverBackup).createDataPathService
219+
)
218220

219221
func (s *dataMoverBackup) run() {
220222
signals.CancelOnShutdown(s.cancelFunc, s.logger)
@@ -268,8 +270,10 @@ func (s *dataMoverBackup) runDataPath() {
268270
funcExitWithMessage(s.logger, true, result)
269271
}
270272

271-
var funcNewCredentialFileStore = credentials.NewNamespacedFileStore
272-
var funcNewCredentialSecretStore = credentials.NewNamespacedSecretStore
273+
var (
274+
funcNewCredentialFileStore = credentials.NewNamespacedFileStore
275+
funcNewCredentialSecretStore = credentials.NewNamespacedSecretStore
276+
)
273277

274278
func (s *dataMoverBackup) createDataPathService() (dataPathService, error) {
275279
credentialFileStore, err := funcNewCredentialFileStore(

pkg/cmd/cli/datamover/backup_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ func (fr *fakeRunHelper) RunCancelableDataPath(_ context.Context) (string, error
6161
}
6262

6363
func (fr *fakeRunHelper) Shutdown() {
64-
6564
}
6665

6766
func (fr *fakeRunHelper) ExitWithMessage(logger logrus.FieldLogger, succeed bool, message string, a ...any) {

pkg/cmd/cli/datamover/data_mover.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ type dataPathService interface {
4646
Shutdown()
4747
}
4848

49-
var funcExit = os.Exit
50-
var funcCreateFile = os.Create
49+
var (
50+
funcExit = os.Exit
51+
funcCreateFile = os.Create
52+
)
5153

5254
func exitWithMessage(logger logrus.FieldLogger, succeed bool, message string, a ...any) {
5355
exitCode := 0

pkg/cmd/cli/datamover/data_mover_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (em *exitWithMessageMock) CreateFile(name string) (*os.File, error) {
4545
}
4646

4747
if em.writeFail {
48-
return os.OpenFile(em.filePath, os.O_CREATE|os.O_RDONLY, 0500)
48+
return os.OpenFile(em.filePath, os.O_CREATE|os.O_RDONLY, 0o500)
4949
} else {
5050
return os.Create(em.filePath)
5151
}

pkg/cmd/cli/nodeagent/server.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ import (
6767
cacheutil "k8s.io/client-go/tools/cache"
6868
)
6969

70-
var (
71-
scheme = runtime.NewScheme()
72-
)
70+
var scheme = runtime.NewScheme()
7371

7472
const (
7573
// the port where prometheus metrics are exposed

pkg/cmd/cli/restore/create_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,15 @@ func TestCreateCommand(t *testing.T) {
109109
f.On("Namespace").Return(mock.Anything)
110110
f.On("KubebuilderWatchClient").Return(client, nil)
111111

112-
//Complete
112+
// Complete
113113
e := o.Complete(args, f)
114114
require.NoError(t, e)
115115

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

120-
//cmd
120+
// cmd
121121
e = o.Run(cmd, f)
122122
require.NoError(t, e)
123123

pkg/cmd/server/plugin/plugin.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,8 @@ func newChangeImageNameRestoreItemAction(f client.Factory) plugincommon.HandlerI
348348
), nil
349349
}
350350
}
351-
func newRoleBindingItemAction(logger logrus.FieldLogger) (any, error) {
351+
352+
func newRoleBindingItemAction(logger logrus.FieldLogger) (interface{}, error) {
352353
return ria.NewRoleBindingAction(logger), nil
353354
}
354355

0 commit comments

Comments
 (0)