Skip to content

Commit

Permalink
fix lint errors
Browse files Browse the repository at this point in the history
Signed-off-by: Lyndon-Li <[email protected]>
  • Loading branch information
Lyndon-Li committed Oct 18, 2022
1 parent df5436b commit f17e59d
Show file tree
Hide file tree
Showing 32 changed files with 94 additions and 81 deletions.
2 changes: 1 addition & 1 deletion pkg/archive/extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (e *Extractor) readBackup(tarRdr *tar.Reader) (string, error) {
return "", err
}

target := filepath.Join(dir, header.Name)
target := filepath.Join(dir, header.Name) //nolint:gosec

switch header.Typeflag {
case tar.TypeDir:
Expand Down
4 changes: 2 additions & 2 deletions pkg/backup/item_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func sortResourcesByOrder(log logrus.FieldLogger, items []*kubernetesResource, o
}

// getOrderedResourcesForType gets order of resourceType from orderResources.
func getOrderedResourcesForType(log logrus.FieldLogger, orderedResources map[string]string, resourceType string) []string {
func getOrderedResourcesForType(orderedResources map[string]string, resourceType string) []string {
if orderedResources == nil {
return nil
}
Expand All @@ -175,7 +175,7 @@ func (r *itemCollector) getResourceItems(log logrus.FieldLogger, gv schema.Group
clusterScoped = !resource.Namespaced
)

orders := getOrderedResourcesForType(log, r.backupRequest.Backup.Spec.OrderedResources, resource.Name)
orders := getOrderedResourcesForType(r.backupRequest.Backup.Spec.OrderedResources, resource.Name)
// Getting the preferred group version of this resource
preferredGVR, _, err := r.discoveryHelper.ResourceFor(gr.WithVersion(""))
if err != nil {
Expand Down
10 changes: 7 additions & 3 deletions pkg/cmd/cli/backup/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ func NewCreateOptions() *CreateOptions {
}
}

const (
strTrue = "true"
)

func (o *CreateOptions) BindFlags(flags *pflag.FlagSet) {
flags.DurationVar(&o.TTL, "ttl", o.TTL, "How long before the backup can be garbage collected.")
flags.Var(&o.IncludeNamespaces, "include-namespaces", "Namespaces to include in the backup (use '*' for all namespaces).")
Expand All @@ -127,13 +131,13 @@ func (o *CreateOptions) BindFlags(flags *pflag.FlagSet) {
f := flags.VarPF(&o.SnapshotVolumes, "snapshot-volumes", "", "Take snapshots of PersistentVolumes as part of the backup. If the parameter is not set, it is treated as setting to 'true'.")
// this allows the user to just specify "--snapshot-volumes" as shorthand for "--snapshot-volumes=true"
// like a normal bool flag
f.NoOptDefVal = "true"
f.NoOptDefVal = strTrue

f = flags.VarPF(&o.IncludeClusterResources, "include-cluster-resources", "", "Include cluster-scoped resources in the backup")
f.NoOptDefVal = "true"
f.NoOptDefVal = strTrue

f = flags.VarPF(&o.DefaultVolumesToFsBackup, "default-volumes-to-fs-backup", "", "Use pod volume file system backup by default for volumes")
f.NoOptDefVal = "true"
f.NoOptDefVal = strTrue
}

// BindWait binds the wait flag separately so it is not called by other create
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/cli/backup/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func NewDescribeCommand(f client.Factory, use string) *cobra.Command {
}
}

s := output.DescribeBackup(context.Background(), kbClient, &backup, deleteRequestList.Items, podVolumeBackupList.Items, vscList.Items, details, veleroClient, insecureSkipTLSVerify, caCertFile)
s := output.DescribeBackup(context.Background(), kbClient, &backup, deleteRequestList.Items, podVolumeBackupList.Items, vscList.Items, details, veleroClient, insecureSkipTLSVerify, caCertFile) //nolint
if first {
first = false
fmt.Print(s)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/cli/backuplocation/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func (o *CreateOptions) Run(c *cobra.Command, f client.Factory) error {
for _, location := range locations.Items {
if location.Spec.Default {
location.Spec.Default = false
if err := kbClient.Update(context.Background(), &location, &kbclient.UpdateOptions{}); err != nil {
if err := kbClient.Update(context.Background(), &location, &kbclient.UpdateOptions{}); err != nil { //nolint
return errors.WithStack(err)
}
break
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/cli/backuplocation/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func Run(f client.Factory, o *cli.DeleteOptions) error {

// Create a backup-location deletion request for each
for _, location := range locations.Items {
if err := kbClient.Delete(context.Background(), &location, &kbclient.DeleteOptions{}); err != nil {
if err := kbClient.Delete(context.Background(), &location, &kbclient.DeleteOptions{}); err != nil { //nolint
errs = append(errs, errors.WithStack(err))
continue
}
Expand Down Expand Up @@ -163,7 +163,7 @@ func findAssociatedBackupRepos(client kbclient.Client, bslName, ns string) (vele
func deleteBackups(client kbclient.Client, backups velerov1api.BackupList) []error {
var errs []error
for _, backup := range backups.Items {
if err := client.Delete(context.Background(), &backup, &kbclient.DeleteOptions{}); err != nil {
if err := client.Delete(context.Background(), &backup, &kbclient.DeleteOptions{}); err != nil { //nolint
errs = append(errs, errors.WithStack(fmt.Errorf("delete backup %q associated with deleted BSL: %w", backup.Name, err)))
continue
}
Expand All @@ -175,7 +175,7 @@ func deleteBackups(client kbclient.Client, backups velerov1api.BackupList) []err
func deleteBackupRepos(client kbclient.Client, repos velerov1api.BackupRepositoryList) []error {
var errs []error
for _, repo := range repos.Items {
if err := client.Delete(context.Background(), &repo, &kbclient.DeleteOptions{}); err != nil {
if err := client.Delete(context.Background(), &repo, &kbclient.DeleteOptions{}); err != nil { //nolint
errs = append(errs, errors.WithStack(fmt.Errorf("delete backup repository %q associated with deleted BSL: %w", repo.Name, err)))
continue
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/cli/backuplocation/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (o *SetOptions) Run(c *cobra.Command, f client.Factory) error {
break
}
location.Spec.Default = false
if err := kbClient.Update(context.Background(), &location, &kbclient.UpdateOptions{}); err != nil {
if err := kbClient.Update(context.Background(), &location, &kbclient.UpdateOptions{}); err != nil { //nolint
return errors.WithStack(err)
}
break
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/cli/nodeagent/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func (s *nodeAgentServer) markInProgressPVBsFailed(client ctrlclient.Client) {
pvb.Status.Phase = velerov1api.PodVolumeBackupPhaseFailed
pvb.Status.Message = fmt.Sprintf("get a podvolumebackup with status %q during the server starting, mark it as %q", velerov1api.PodVolumeBackupPhaseInProgress, pvb.Status.Phase)
pvb.Status.CompletionTimestamp = &metav1.Time{Time: time.Now()}
if err := client.Patch(s.ctx, &pvb, ctrlclient.MergeFrom(original)); err != nil {
if err := client.Patch(s.ctx, &pvb, ctrlclient.MergeFrom(original)); err != nil { //nolint
s.logger.WithError(errors.WithStack(err)).Errorf("failed to patch podvolumebackup %q", pvb.GetName())
continue
}
Expand Down Expand Up @@ -345,7 +345,7 @@ func (s *nodeAgentServer) markInProgressPVRsFailed(client ctrlclient.Client) {
pvr.Status.Phase = velerov1api.PodVolumeRestorePhaseFailed
pvr.Status.Message = fmt.Sprintf("get a podvolumerestore with status %q during the server starting, mark it as %q", velerov1api.PodVolumeRestorePhaseInProgress, pvr.Status.Phase)
pvr.Status.CompletionTimestamp = &metav1.Time{Time: time.Now()}
if err := client.Patch(s.ctx, &pvr, ctrlclient.MergeFrom(original)); err != nil {
if err := client.Patch(s.ctx, &pvr, ctrlclient.MergeFrom(original)); err != nil { //nolint
s.logger.WithError(errors.WithStack(err)).Errorf("failed to patch podvolumerestore %q", pvr.GetName())
continue
}
Expand Down
12 changes: 8 additions & 4 deletions pkg/cmd/cli/restore/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ func NewCreateOptions() *CreateOptions {
}
}

const (
strTrue = "true"
)

func (o *CreateOptions) BindFlags(flags *pflag.FlagSet) {
flags.StringVar(&o.BackupName, "from-backup", "", "Backup to restore from")
flags.StringVar(&o.ScheduleName, "from-schedule", "", "Schedule to restore from")
Expand All @@ -123,18 +127,18 @@ func (o *CreateOptions) BindFlags(flags *pflag.FlagSet) {
f := flags.VarPF(&o.RestoreVolumes, "restore-volumes", "", "Whether to restore volumes from snapshots.")
// this allows the user to just specify "--restore-volumes" as shorthand for "--restore-volumes=true"
// like a normal bool flag
f.NoOptDefVal = "true"
f.NoOptDefVal = strTrue

f = flags.VarPF(&o.PreserveNodePorts, "preserve-nodeports", "", "Whether to preserve nodeports of Services when restoring.")
// this allows the user to just specify "--preserve-nodeports" as shorthand for "--preserve-nodeports=true"
// like a normal bool flag
f.NoOptDefVal = "true"
f.NoOptDefVal = strTrue

f = flags.VarPF(&o.IncludeClusterResources, "include-cluster-resources", "", "Include cluster-scoped resources in the restore.")
f.NoOptDefVal = "true"
f.NoOptDefVal = strTrue

f = flags.VarPF(&o.AllowPartiallyFailed, "allow-partially-failed", "", "If using --from-schedule, whether to consider PartiallyFailed backups when looking for the most recent one. This flag has no effect if not using --from-schedule.")
f.NoOptDefVal = "true"
f.NoOptDefVal = strTrue

flags.BoolVarP(&o.Wait, "wait", "w", o.Wait, "Wait for the operation to complete.")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/cli/restore/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func NewDescribeCommand(f client.Factory, use string) *cobra.Command {
fmt.Fprintf(os.Stderr, "error getting PodVolumeRestores for restore %s: %v\n", restore.Name, err)
}

s := output.DescribeRestore(context.Background(), kbClient, &restore, podvolumeRestoreList.Items, details, veleroClient, insecureSkipTLSVerify, caCertFile)
s := output.DescribeRestore(context.Background(), kbClient, &restore, podvolumeRestoreList.Items, details, veleroClient, insecureSkipTLSVerify, caCertFile) //nolint
if first {
first = false
fmt.Print(s)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/cli/schedule/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func NewDescribeCommand(f client.Factory, use string) *cobra.Command {

first := true
for _, schedule := range schedules.Items {
s := output.DescribeSchedule(&schedule)
s := output.DescribeSchedule(&schedule) //nolint
if first {
first = false
fmt.Print(s)
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ func markInProgressBackupsFailed(ctx context.Context, client ctrlclient.Client,
updated.Status.Phase = velerov1api.BackupPhaseFailed
updated.Status.FailureReason = fmt.Sprintf("get a backup with status %q during the server starting, mark it as %q", velerov1api.BackupPhaseInProgress, updated.Status.Phase)
updated.Status.CompletionTimestamp = &metav1.Time{Time: time.Now()}
if err := client.Patch(ctx, updated, ctrlclient.MergeFrom(&backup)); err != nil {
if err := client.Patch(ctx, updated, ctrlclient.MergeFrom(&backup)); err != nil { //nolint
log.WithError(errors.WithStack(err)).Errorf("failed to patch backup %q", backup.GetName())
continue
}
Expand All @@ -971,7 +971,7 @@ func markInProgressRestoresFailed(ctx context.Context, client ctrlclient.Client,
updated.Status.Phase = velerov1api.RestorePhaseFailed
updated.Status.FailureReason = fmt.Sprintf("get a restore with status %q during the server starting, mark it as %q", velerov1api.RestorePhaseInProgress, updated.Status.Phase)
updated.Status.CompletionTimestamp = &metav1.Time{Time: time.Now()}
if err := client.Patch(ctx, updated, ctrlclient.MergeFrom(&restore)); err != nil {
if err := client.Patch(ctx, updated, ctrlclient.MergeFrom(&restore)); err != nil { //nolint
log.WithError(errors.WithStack(err)).Errorf("failed to patch restore %q", restore.GetName())
continue
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/util/downloadrequest/downloadrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func Stream(ctx context.Context, kbClient kbclient.Client, namespace, name strin
httpClient := new(http.Client)
httpClient.Transport = &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: insecureSkipTLSVerify,
InsecureSkipVerify: insecureSkipTLSVerify, //nolint:gosec
RootCAs: caPool,
},
IdleConnTimeout: timeout,
Expand Down
14 changes: 7 additions & 7 deletions pkg/cmd/util/output/backup_describer.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func DescribeBackupSpec(d *Describer, spec velerov1api.BackupSpec) {
}
d.Printf("\tIncluded:\t%s\n", s)
if len(spec.ExcludedNamespaces) == 0 {
s = "<none>"
s = emptyDisplay
} else {
s = strings.Join(spec.ExcludedNamespaces, ", ")
}
Expand All @@ -140,7 +140,7 @@ func DescribeBackupSpec(d *Describer, spec velerov1api.BackupSpec) {
}
d.Printf("\tIncluded:\t%s\n", s)
if len(spec.ExcludedResources) == 0 {
s = "<none>"
s = emptyDisplay
} else {
s = strings.Join(spec.ExcludedResources, ", ")
}
Expand All @@ -149,7 +149,7 @@ func DescribeBackupSpec(d *Describer, spec velerov1api.BackupSpec) {
d.Printf("\tCluster-scoped:\t%s\n", BoolPointerString(spec.IncludeClusterResources, "excluded", "included", "auto"))

d.Println()
s = "<none>"
s = emptyDisplay
if spec.LabelSelector != nil {
s = metav1.FormatLabelSelector(spec.LabelSelector)
}
Expand All @@ -169,7 +169,7 @@ func DescribeBackupSpec(d *Describer, spec velerov1api.BackupSpec) {

d.Println()
if len(spec.Hooks.Resources) == 0 {
d.Printf("Hooks:\t<none>\n")
d.Printf("Hooks:\t" + emptyDisplay + "\n")
} else {
d.Printf("Hooks:\n")
d.Printf("\tResources:\n")
Expand All @@ -184,7 +184,7 @@ func DescribeBackupSpec(d *Describer, spec velerov1api.BackupSpec) {
}
d.Printf("\t\t\t\tIncluded:\t%s\n", s)
if len(spec.ExcludedNamespaces) == 0 {
s = "<none>"
s = emptyDisplay
} else {
s = strings.Join(spec.ExcludedNamespaces, ", ")
}
Expand All @@ -199,14 +199,14 @@ func DescribeBackupSpec(d *Describer, spec velerov1api.BackupSpec) {
}
d.Printf("\t\t\t\tIncluded:\t%s\n", s)
if len(spec.ExcludedResources) == 0 {
s = "<none>"
s = emptyDisplay
} else {
s = strings.Join(spec.ExcludedResources, ", ")
}
d.Printf("\t\t\t\tExcluded:\t%s\n", s)

d.Println()
s = "<none>"
s = emptyDisplay
if backupResourceHookSpec.LabelSelector != nil {
s = metav1.FormatLabelSelector(backupResourceHookSpec.LabelSelector)
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/cmd/util/output/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ import (
"github.com/vmware-tanzu/velero/pkg/util/encode"
)

const downloadRequestTimeout = 30 * time.Second
const (
const downloadRequestTimeout = 30 * time.Second
emptyDisplay = "<none>"
)

// BindFlags defines a set of output-specific flags within the provided
// FlagSet.
Expand Down
8 changes: 4 additions & 4 deletions pkg/cmd/util/output/restore_describer.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func DescribeRestore(ctx context.Context, kbClient kbclient.Client, restore *vel
}
d.Printf("\tIncluded:\t%s\n", s)
if len(restore.Spec.ExcludedNamespaces) == 0 {
s = "<none>"
s = emptyDisplay
} else {
s = strings.Join(restore.Spec.ExcludedNamespaces, ", ")
}
Expand All @@ -122,7 +122,7 @@ func DescribeRestore(ctx context.Context, kbClient kbclient.Client, restore *vel
}
d.Printf("\tIncluded:\t%s\n", s)
if len(restore.Spec.ExcludedResources) == 0 {
s = "<none>"
s = emptyDisplay
} else {
s = strings.Join(restore.Spec.ExcludedResources, ", ")
}
Expand All @@ -134,7 +134,7 @@ func DescribeRestore(ctx context.Context, kbClient kbclient.Client, restore *vel
d.DescribeMap("Namespace mappings", restore.Spec.NamespaceMapping)

d.Println()
s = "<none>"
s = emptyDisplay
if restore.Spec.LabelSelector != nil {
s = metav1.FormatLabelSelector(restore.Spec.LabelSelector)
}
Expand All @@ -149,7 +149,7 @@ func DescribeRestore(ctx context.Context, kbClient kbclient.Client, restore *vel
}

d.Println()
s = "<none>"
s = emptyDisplay
if restore.Spec.ExistingResourcePolicy != "" {
s = string(restore.Spec.ExistingResourcePolicy)
}
Expand Down
7 changes: 3 additions & 4 deletions pkg/controller/backup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ func (c *backupController) runBackup(backup *pkgbackup.Request) error {
}

// Delete the VolumeSnapshots created in the backup, when CSI feature is enabled.
c.deleteVolumeSnapshot(volumeSnapshots, volumeSnapshotContents, *backup, backupLog)
c.deleteVolumeSnapshot(volumeSnapshots, volumeSnapshotContents, backupLog)

}

Expand Down Expand Up @@ -751,7 +751,7 @@ func (c *backupController) runBackup(backup *pkgbackup.Request) error {
return err
}

if errs := persistBackup(backup, backupFile, logFile, backupStore, c.logger.WithField(Backup, kubeutil.NamespaceAndName(backup)), volumeSnapshots, volumeSnapshotContents, volumeSnapshotClasses); len(errs) > 0 {
if errs := persistBackup(backup, backupFile, logFile, backupStore, volumeSnapshots, volumeSnapshotContents, volumeSnapshotClasses); len(errs) > 0 {
fatalErrs = append(fatalErrs, errs...)
}

Expand Down Expand Up @@ -795,7 +795,6 @@ func recordBackupMetrics(log logrus.FieldLogger, backup *velerov1api.Backup, bac
func persistBackup(backup *pkgbackup.Request,
backupContents, backupLog *os.File,
backupStore persistence.BackupStore,
log logrus.FieldLogger,
csiVolumeSnapshots []snapshotv1api.VolumeSnapshot,
csiVolumeSnapshotContents []snapshotv1api.VolumeSnapshotContent,
csiVolumesnapshotClasses []snapshotv1api.VolumeSnapshotClass,
Expand Down Expand Up @@ -945,7 +944,7 @@ func (c *backupController) checkVolumeSnapshotReadyToUse(ctx context.Context, vo
// change DeletionPolicy to Retain before deleting VS, then change DeletionPolicy back to Delete.
func (c *backupController) deleteVolumeSnapshot(volumeSnapshots []snapshotv1api.VolumeSnapshot,
volumeSnapshotContents []snapshotv1api.VolumeSnapshotContent,
backup pkgbackup.Request, logger logrus.FieldLogger) {
logger logrus.FieldLogger) {
var wg sync.WaitGroup
vscMap := make(map[string]snapshotv1api.VolumeSnapshotContent)
for _, vsc := range volumeSnapshotContents {
Expand Down
8 changes: 4 additions & 4 deletions pkg/controller/backup_deletion_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func (r *backupDeletionReconciler) Reconcile(ctx context.Context, req ctrl.Reque
if restore.Spec.BackupName != backup.Name {
continue
}
restoreLog := log.WithField("restore", kube.NamespaceAndName(&restore))
restoreLog := log.WithField("restore", kube.NamespaceAndName(&restore)) //nolint

restoreLog.Info("Deleting restore log/results from backup storage")
if err := backupStore.DeleteRestore(restore.Name); err != nil {
Expand All @@ -339,8 +339,8 @@ func (r *backupDeletionReconciler) Reconcile(ctx context.Context, req ctrl.Reque
}

restoreLog.Info("Deleting restore referencing backup")
if err := r.Delete(ctx, &restore); err != nil {
errs = append(errs, errors.Wrapf(err, "error deleting restore %s", kube.NamespaceAndName(&restore)).Error())
if err := r.Delete(ctx, &restore); err != nil { //nolint
errs = append(errs, errors.Wrapf(err, "error deleting restore %s", kube.NamespaceAndName(&restore)).Error()) //nolint
}
}
}
Expand Down Expand Up @@ -427,7 +427,7 @@ func (r *backupDeletionReconciler) deleteExistingDeletionRequests(ctx context.Co
if dbr.Name == req.Name {
continue
}
if err := r.Delete(ctx, &dbr); err != nil {
if err := r.Delete(ctx, &dbr); err != nil { //nolint
errs = append(errs, errors.WithStack(err))
} else {
log.Infof("deletion request '%s' removed.", dbr.Name)
Expand Down
Loading

0 comments on commit f17e59d

Please sign in to comment.