Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: apply gofumpt in pkg packages #8613

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
@@ -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
2 changes: 1 addition & 1 deletion pkg/archive/extractor_test.go
Original file line number Diff line number Diff line change
@@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@reasonerjt @Lyndon-Li thoughts on using this notation for octal?

require.NoError(t, err)

_, err = ext.UnzipAndExtractBackup(file.(io.Reader))
4 changes: 2 additions & 2 deletions pkg/archive/parser_test.go
Original file line number Diff line number Diff line change
@@ -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)
@@ -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)
5 changes: 3 additions & 2 deletions pkg/backup/backup.go
Original file line number Diff line number Diff line change
@@ -221,7 +221,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)
@@ -891,7 +892,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 {
15 changes: 11 additions & 4 deletions pkg/backup/backup_test.go
Original file line number Diff line number Diff line change
@@ -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(
@@ -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{
@@ -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{
@@ -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 {
2 changes: 1 addition & 1 deletion pkg/backup/item_backupper.go
Original file line number Diff line number Diff line change
@@ -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}
3 changes: 1 addition & 2 deletions pkg/backup/item_collector.go
Original file line number Diff line number Diff line change
@@ -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)
@@ -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
2 changes: 1 addition & 1 deletion pkg/backup/pv_skip_tracker_test.go
Original file line number Diff line number Diff line change
@@ -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 ")

6 changes: 2 additions & 4 deletions pkg/builder/testcr_builder.go
Original file line number Diff line number Diff line change
@@ -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
@@ -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)
}
1 change: 1 addition & 0 deletions pkg/client/config_test.go
Original file line number Diff line number Diff line change
@@ -47,6 +47,7 @@ func removeConfigfileName() error {
}
return nil
}

func TestConfigOperations(t *testing.T) {
preHomeEnv := ""
prevEnv := os.Environ()
4 changes: 2 additions & 2 deletions pkg/client/dynamic.go
Original file line number Diff line number Diff line change
@@ -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
}
3 changes: 0 additions & 3 deletions pkg/client/factory.go
Original file line number Diff line number Diff line change
@@ -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)
}
@@ -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
}
@@ -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
}
12 changes: 6 additions & 6 deletions pkg/cmd/cli/backup/create_test.go
Original file line number Diff line number Diff line change
@@ -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)
@@ -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()
2 changes: 1 addition & 1 deletion pkg/cmd/cli/backup/download.go
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 0 additions & 1 deletion pkg/cmd/cli/backup/download_test.go
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion pkg/cmd/cli/backuplocation/delete_test.go
Original file line number Diff line number Diff line change
@@ -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)
1 change: 0 additions & 1 deletion pkg/cmd/cli/backuplocation/get_test.go
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion pkg/cmd/cli/backuplocation/set_test.go
Original file line number Diff line number Diff line change
@@ -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
12 changes: 8 additions & 4 deletions pkg/cmd/cli/datamover/backup.go
Original file line number Diff line number Diff line change
@@ -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)
@@ -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(
1 change: 0 additions & 1 deletion pkg/cmd/cli/datamover/backup_test.go
Original file line number Diff line number Diff line change
@@ -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) {
6 changes: 4 additions & 2 deletions pkg/cmd/cli/datamover/data_mover.go
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion pkg/cmd/cli/datamover/data_mover_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
4 changes: 1 addition & 3 deletions pkg/cmd/cli/nodeagent/server.go
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions pkg/cmd/cli/restore/create_test.go
Original file line number Diff line number Diff line change
@@ -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)

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

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