diff --git a/changelogs/unreleased/6162-blackpiglet b/changelogs/unreleased/6162-blackpiglet new file mode 100644 index 0000000000..2f4ad1c8e8 --- /dev/null +++ b/changelogs/unreleased/6162-blackpiglet @@ -0,0 +1 @@ +Fix usestdlibvars and whitespace linters issues. \ No newline at end of file diff --git a/golangci.yaml b/golangci.yaml index 4422a3a3c3..5b4bfbd646 100644 --- a/golangci.yaml +++ b/golangci.yaml @@ -300,6 +300,8 @@ linters: - typecheck - unparam - unused + - usestdlibvars + - whitespace fast: false diff --git a/hack/release-tools/chk_version.go b/hack/release-tools/chk_version.go index be9f69baca..9f87bff258 100644 --- a/hack/release-tools/chk_version.go +++ b/hack/release-tools/chk_version.go @@ -35,7 +35,6 @@ var release_regex *regexp.Regexp = regexp.MustCompile(`^v(?P[[:digit:]]+) // Calling it with --verify will verify whether or not the VELERO_VERSION environment variable is a valid version string, without parsing for its components. // Calling it without --verify will try to parse the version into its component pieces. func main() { - velero_version := os.Getenv("VELERO_VERSION") submatches := reSubMatchMap(release_regex, velero_version) diff --git a/internal/delete/delete_item_action_handler.go b/internal/delete/delete_item_action_handler.go index bdcf511b24..f91127d7d8 100644 --- a/internal/delete/delete_item_action_handler.go +++ b/internal/delete/delete_item_action_handler.go @@ -121,7 +121,6 @@ func InvokeDeleteActions(ctx *Context) error { // Since we want to keep looping even on errors, log them instead of just returning. if err != nil { itemLog.WithError(err).Error("plugin error") - } } } diff --git a/internal/hook/item_hook_handler.go b/internal/hook/item_hook_handler.go index 50ab84b2d3..fc97541140 100644 --- a/internal/hook/item_hook_handler.go +++ b/internal/hook/item_hook_handler.go @@ -283,7 +283,6 @@ func (h *NoOpItemHookHandler) HandleHooks( resourceHooks []ResourceHook, phase hookPhase, ) error { - return nil } diff --git a/internal/resourcepolicies/volume_resources.go b/internal/resourcepolicies/volume_resources.go index 5c60d88e73..51bb914f0e 100644 --- a/internal/resourcepolicies/volume_resources.go +++ b/internal/resourcepolicies/volume_resources.go @@ -121,7 +121,6 @@ func (c *nfsCondition) match(v *structuredVolume) bool { return false } return true - } type csiCondition struct { diff --git a/internal/resourcepolicies/volume_resources_validator.go b/internal/resourcepolicies/volume_resources_validator.go index a6597a3f9a..7b4d0b815d 100644 --- a/internal/resourcepolicies/volume_resources_validator.go +++ b/internal/resourcepolicies/volume_resources_validator.go @@ -39,7 +39,6 @@ func (c *capacityCondition) validate() error { return nil } return errors.Errorf("illegal values for capacity %v", c.capacity) - } func (s *storageClassCondition) validate() error { diff --git a/pkg/backup/backup.go b/pkg/backup/backup.go index 1e2dce2a67..c7492c0c43 100644 --- a/pkg/backup/backup.go +++ b/pkg/backup/backup.go @@ -528,7 +528,6 @@ func (kb *kubernetesBackupper) FinalizeBackup(log logrus.FieldLogger, outBackupFile io.Writer, backupItemActionResolver framework.BackupItemActionResolverV2, asyncBIAOperations []*itemoperation.BackupOperation) error { - gzw := gzip.NewWriter(outBackupFile) defer gzw.Close() tw := tar.NewWriter(gzw) @@ -623,7 +622,6 @@ func (kb *kubernetesBackupper) FinalizeBackup(log logrus.FieldLogger, updateFiles[itemFile.FilePath] = itemFile } } - }() // updated total is computed as "how many items we've backed up so far, plus @@ -694,7 +692,6 @@ func buildFinalTarball(tr *tar.Reader, tw *tar.Writer, updateFiles map[string]Fi } } return nil - } type tarWriter interface { diff --git a/pkg/backup/item_backupper.go b/pkg/backup/item_backupper.go index 1dec2b3c21..2739ebba85 100644 --- a/pkg/backup/item_backupper.go +++ b/pkg/backup/item_backupper.go @@ -150,7 +150,6 @@ func (ib *itemBackupper) backupItemInternal(logger logrus.FieldLogger, obj runti log.Info("Excluding item because resource is excluded") return false, itemFiles, nil } - } if metadata.GetDeletionTimestamp() != nil { diff --git a/pkg/backup/item_collector.go b/pkg/backup/item_collector.go index a320311fef..08ee44fb1b 100644 --- a/pkg/backup/item_collector.go +++ b/pkg/backup/item_collector.go @@ -62,7 +62,6 @@ type kubernetesResource struct { // getItemsFromResourceIdentifiers converts ResourceIdentifiers to // kubernetesResources func (r *itemCollector) getItemsFromResourceIdentifiers(resourceIDs []velero.ResourceIdentifier) []*kubernetesResource { - grResourceIDsMap := make(map[schema.GroupResource][]velero.ResourceIdentifier) for _, resourceID := range resourceIDs { grResourceIDsMap[resourceID.GroupResource] = append(grResourceIDsMap[resourceID.GroupResource], resourceID) diff --git a/pkg/backup/remap_crd_version_action.go b/pkg/backup/remap_crd_version_action.go index d54f018ca5..e1e6583ebe 100644 --- a/pkg/backup/remap_crd_version_action.go +++ b/pkg/backup/remap_crd_version_action.go @@ -82,7 +82,6 @@ CheckVersion: break CheckVersion } } - } } if !supportv1b1 { @@ -142,7 +141,6 @@ func fetchV1beta1CRD(name string, betaCRDClient apiextv1beta1client.CustomResour item := &unstructured.Unstructured{Object: m} return item, nil - } // hasPreserveUnknownFields determines whether or not a CRD is set to preserve unknown fields or not. diff --git a/pkg/client/config.go b/pkg/client/config.go index 2302ca9c91..7546a0ac4c 100644 --- a/pkg/client/config.go +++ b/pkg/client/config.go @@ -130,7 +130,6 @@ func (c VeleroConfig) Colorized() bool { } return colorized - } func (c VeleroConfig) CACertFile() string { diff --git a/pkg/cmd/cli/backup/describe.go b/pkg/cmd/cli/backup/describe.go index 29f034354c..e47ddab11e 100644 --- a/pkg/cmd/cli/backup/describe.go +++ b/pkg/cmd/cli/backup/describe.go @@ -121,7 +121,6 @@ func NewDescribeCommand(f client.Factory, use string) *cobra.Command { fmt.Printf("\n\n%s", s) } } - } cmd.CheckError(err) }, diff --git a/pkg/cmd/cli/backup/download.go b/pkg/cmd/cli/backup/download.go index 464be25790..dec0864e02 100644 --- a/pkg/cmd/cli/backup/download.go +++ b/pkg/cmd/cli/backup/download.go @@ -81,7 +81,6 @@ func (o *DownloadOptions) BindFlags(flags *pflag.FlagSet) { flags.DurationVar(&o.Timeout, "timeout", o.Timeout, "Maximum time to wait to process download request.") flags.BoolVar(&o.InsecureSkipTLSVerify, "insecure-skip-tls-verify", o.InsecureSkipTLSVerify, "If true, the object store's TLS certificate will not be checked for validity. This is insecure and susceptible to man-in-the-middle attacks. Not recommended for production.") flags.StringVar(&o.caCertFile, "cacert", o.caCertFile, "Path to a certificate bundle to use when verifying TLS connections.") - } func (o *DownloadOptions) Validate(c *cobra.Command, args []string, f client.Factory) error { diff --git a/pkg/cmd/cli/install/install.go b/pkg/cmd/cli/install/install.go index 722473b4f8..886dbb71ac 100644 --- a/pkg/cmd/cli/install/install.go +++ b/pkg/cmd/cli/install/install.go @@ -355,7 +355,6 @@ func (o *InstallOptions) Validate(c *cobra.Command, args []string, f client.Fact } if o.NoDefaultBackupLocation { - if o.BucketName != "" { return errors.New("Cannot use both --bucket and --no-default-backup-location at the same time") } @@ -375,7 +374,6 @@ func (o *InstallOptions) Validate(c *cobra.Command, args []string, f client.Fact if o.BucketName == "" { return errors.New("--bucket is required") } - } if o.UseVolumeSnapshots { diff --git a/pkg/cmd/cli/restore/delete.go b/pkg/cmd/cli/restore/delete.go index a634c9e408..42479ced28 100644 --- a/pkg/cmd/cli/restore/delete.go +++ b/pkg/cmd/cli/restore/delete.go @@ -57,7 +57,6 @@ func NewDeleteCommand(f client.Factory, use string) *cobra.Command { cmd.CheckError(o.Complete(f, args)) cmd.CheckError(o.Validate(c, f, args)) cmd.CheckError(Run(o)) - }, } o.BindFlags(c.Flags()) diff --git a/pkg/cmd/util/downloadrequest/downloadrequest.go b/pkg/cmd/util/downloadrequest/downloadrequest.go index 1b973d118e..716815c9db 100644 --- a/pkg/cmd/util/downloadrequest/downloadrequest.go +++ b/pkg/cmd/util/downloadrequest/downloadrequest.go @@ -123,7 +123,7 @@ func Stream(ctx context.Context, kbClient kbclient.Client, namespace, name strin ExpectContinueTimeout: defaultTransport.ExpectContinueTimeout, } - httpReq, err := http.NewRequest("GET", created.Status.DownloadURL, nil) + httpReq, err := http.NewRequest(http.MethodGet, created.Status.DownloadURL, nil) if err != nil { return err } diff --git a/pkg/cmd/util/output/backup_structured_describer.go b/pkg/cmd/util/output/backup_structured_describer.go index 3ffc967d50..b12a9b3135 100644 --- a/pkg/cmd/util/output/backup_structured_describer.go +++ b/pkg/cmd/util/output/backup_structured_describer.go @@ -242,7 +242,6 @@ func DescribeBackupStatusInSF(ctx context.Context, kbClient kbclient.Client, d * } if status.CompletionTimestamp == nil || status.CompletionTimestamp.Time.IsZero() { backupStatusInfo["completed"] = "" - } else { backupStatusInfo["completed"] = status.CompletionTimestamp.Time.String() } @@ -258,7 +257,6 @@ func DescribeBackupStatusInSF(ctx context.Context, kbClient kbclient.Client, d * if backup.Status.Phase == velerov1api.BackupPhaseInProgress { backupStatusInfo["estimatedTotalItemsToBeBackedUp"] = backup.Status.Progress.TotalItems backupStatusInfo["itemsBackedUpSoFar"] = backup.Status.Progress.ItemsBackedUp - } else { backupStatusInfo["totalItemsToBeBackedUp"] = backup.Status.Progress.TotalItems backupStatusInfo["itemsBackedUp"] = backup.Status.Progress.ItemsBackedUp @@ -298,7 +296,6 @@ func DescribeBackupStatusInSF(ctx context.Context, kbClient kbclient.Client, d * backupStatusInfo["veleroNativeSnapshotsDetail"] = snapshotDetails return } - } func describeBackupResourceListInSF(ctx context.Context, kbClient kbclient.Client, backupStatusInfo map[string]interface{}, backup *velerov1api.Backup, insecureSkipTLSVerify bool, caCertPath string) { @@ -340,7 +337,6 @@ func describeSnapshotInSF(pvName, snapshotID, volumeType, volumeAZ string, iops snapshotInfo["availabilityZone"] = volumeAZ snapshotInfo["IOPS"] = iopsString snapshotDetails[pvName] = snapshotInfo - } // DescribeDeleteBackupRequestsInSF describes delete backup requests in structured format. @@ -457,7 +453,6 @@ func DescribeVSCInSF(details bool, vsc snapshotv1api.VolumeSnapshotContent, vscD if vsc.Status.RestoreSize != nil { content["snapshotSize(bytes)"] = *vsc.Status.RestoreSize - } if vsc.Status.ReadyToUse != nil { diff --git a/pkg/controller/backup_controller.go b/pkg/controller/backup_controller.go index f66c8f92e7..cd628aefcc 100644 --- a/pkg/controller/backup_controller.go +++ b/pkg/controller/backup_controller.go @@ -118,7 +118,6 @@ func NewBackupReconciler( credentialStore credentials.FileStore, maxConcurrentK8SConnections int, ) *backupReconciler { - b := &backupReconciler{ ctx: ctx, discoveryHelper: discoveryHelper, diff --git a/pkg/controller/backup_operations_controller.go b/pkg/controller/backup_operations_controller.go index 96ba1c3124..bd68131ccb 100644 --- a/pkg/controller/backup_operations_controller.go +++ b/pkg/controller/backup_operations_controller.go @@ -215,7 +215,6 @@ func (c *backupOperationsReconciler) updateBackupAndOperationsJSON( operations *itemoperationmap.OperationsForBackup, changes bool, completionChanges bool) error { - backupScheduleName := backup.GetLabels()[velerov1api.ScheduleNameLabel] if len(operations.ErrsSinceUpdate) > 0 { @@ -229,7 +228,6 @@ func (c *backupOperationsReconciler) updateBackupAndOperationsJSON( backup.Status.Phase == velerov1api.BackupPhasePartiallyFailed || backup.Status.Phase == velerov1api.BackupPhaseFinalizing || backup.Status.Phase == velerov1api.BackupPhaseFinalizingPartiallyFailed) { - c.itemOperationsMap.DeleteOperationsForBackup(backup.Name) } else if changes { c.itemOperationsMap.PutOperationsForBackup(operations, backup.Name) diff --git a/pkg/controller/backup_sync_controller.go b/pkg/controller/backup_sync_controller.go index 4edc03e554..7e8b8a8e94 100644 --- a/pkg/controller/backup_sync_controller.go +++ b/pkg/controller/backup_sync_controller.go @@ -152,7 +152,6 @@ func (b *backupSyncReconciler) Reconcile(ctx context.Context, req ctrl.Request) backup.Status.Phase == velerov1api.BackupPhaseWaitingForPluginOperationsPartiallyFailed || backup.Status.Phase == velerov1api.BackupPhaseFinalizing || backup.Status.Phase == velerov1api.BackupPhaseFinalizingPartiallyFailed { - if backup.Status.Expiration == nil || backup.Status.Expiration.After(time.Now()) { log.Debugf("Skipping non-expired incomplete backup %v", backup.Name) continue diff --git a/pkg/controller/download_request_controller.go b/pkg/controller/download_request_controller.go index 94b49dd04c..479c6d4079 100644 --- a/pkg/controller/download_request_controller.go +++ b/pkg/controller/download_request_controller.go @@ -104,7 +104,6 @@ func (r *downloadRequestReconciler) Reconcile(ctx context.Context, req ctrl.Requ if downloadRequest.Status != (velerov1api.DownloadRequestStatus{}) && downloadRequest.Status.Expiration != nil { if downloadRequest.Status.Expiration.Time.Before(r.clock.Now()) { - // Delete any request that is expired, regardless of the phase: it is not // worth proceeding and trying/retrying to find it. log.Debug("DownloadRequest has expired - deleting") @@ -113,9 +112,7 @@ func (r *downloadRequestReconciler) Reconcile(ctx context.Context, req ctrl.Requ return ctrl.Result{}, errors.WithStack(err) } return ctrl.Result{Requeue: false}, nil - } else if downloadRequest.Status.Phase == velerov1api.DownloadRequestPhaseProcessed { - // Requeue the request if is not yet expired and has already been processed before, // since it might still be in use by the logs streaming and shouldn't // be deleted until after its expiration. @@ -127,7 +124,6 @@ func (r *downloadRequestReconciler) Reconcile(ctx context.Context, req ctrl.Requ // Process a brand new request. backupName := downloadRequest.Spec.Target.Name if downloadRequest.Status.Phase == "" || downloadRequest.Status.Phase == velerov1api.DownloadRequestPhaseNew { - // Update the expiration. downloadRequest.Status.Expiration = &metav1.Time{Time: r.clock.Now().Add(persistence.DownloadURLTTL)} diff --git a/pkg/controller/restore_operations_controller.go b/pkg/controller/restore_operations_controller.go index fe51286ac2..1677d97c9a 100644 --- a/pkg/controller/restore_operations_controller.go +++ b/pkg/controller/restore_operations_controller.go @@ -216,7 +216,6 @@ func (r *restoreOperationsReconciler) updateRestoreAndOperationsJSON( operations *itemoperationmap.OperationsForRestore, changes bool, completionChanges bool) error { - if len(operations.ErrsSinceUpdate) > 0 { // FIXME: download/upload results } @@ -225,7 +224,6 @@ func (r *restoreOperationsReconciler) updateRestoreAndOperationsJSON( // remove local operations list if complete if removeIfComplete && (restore.Status.Phase == velerov1api.RestorePhaseCompleted || restore.Status.Phase == velerov1api.RestorePhasePartiallyFailed) { - r.itemOperationsMap.DeleteOperationsForRestore(restore.Name) } else if changes { r.itemOperationsMap.PutOperationsForRestore(operations, restore.Name) diff --git a/pkg/install/daemonset.go b/pkg/install/daemonset.go index fa8acb9c90..b139f81242 100644 --- a/pkg/install/daemonset.go +++ b/pkg/install/daemonset.go @@ -40,7 +40,6 @@ func DaemonSet(namespace string, opts ...podTemplateOption) *appsv1.DaemonSet { imageParts := strings.Split(c.image, ":") if len(imageParts) == 2 && imageParts[1] != "latest" { pullPolicy = corev1.PullIfNotPresent - } daemonSetArgs := []string{ diff --git a/pkg/install/deployment.go b/pkg/install/deployment.go index 11740c5f54..22e2e5a4dd 100644 --- a/pkg/install/deployment.go +++ b/pkg/install/deployment.go @@ -156,7 +156,6 @@ func Deployment(namespace string, opts ...podTemplateOption) *appsv1.Deployment imageParts := strings.Split(c.image, ":") if len(imageParts) == 2 && imageParts[1] != "latest" { pullPolicy = corev1.PullIfNotPresent - } args := []string{"server"} @@ -308,7 +307,6 @@ func Deployment(namespace string, opts ...podTemplateOption) *appsv1.Deployment container := *builder.ForPluginContainer(image, pullPolicy).Result() deployment.Spec.Template.Spec.InitContainers = append(deployment.Spec.Template.Spec.InitContainers, container) } - } return deployment diff --git a/pkg/itemoperationmap/backup_operation_map.go b/pkg/itemoperationmap/backup_operation_map.go index 0fb369f33b..f818733e93 100644 --- a/pkg/itemoperationmap/backup_operation_map.go +++ b/pkg/itemoperationmap/backup_operation_map.go @@ -84,7 +84,6 @@ func (m *BackupItemOperationsMap) UploadProgressAndPutOperationsForBackup( backupStore persistence.BackupStore, operations *OperationsForBackup, backupName string) error { - m.opsLock.Lock() defer m.opsLock.Unlock() diff --git a/pkg/itemoperationmap/restore_operation_map.go b/pkg/itemoperationmap/restore_operation_map.go index 596f9e5d33..7435607493 100644 --- a/pkg/itemoperationmap/restore_operation_map.go +++ b/pkg/itemoperationmap/restore_operation_map.go @@ -84,7 +84,6 @@ func (m *RestoreItemOperationsMap) UploadProgressAndPutOperationsForRestore( backupStore persistence.BackupStore, operations *OperationsForRestore, restoreName string) error { - m.opsLock.Lock() defer m.opsLock.Unlock() diff --git a/pkg/persistence/object_store.go b/pkg/persistence/object_store.go index 2021edde33..d0fd9c1f16 100644 --- a/pkg/persistence/object_store.go +++ b/pkg/persistence/object_store.go @@ -429,7 +429,6 @@ func (s *objectBackupStore) GetCSIVolumeSnapshotClasses(name string) ([]*snapsho return nil, err } return csiVSClasses, nil - } func (s *objectBackupStore) GetCSIVolumeSnapshots(name string) ([]*snapshotv1api.VolumeSnapshot, error) { diff --git a/pkg/plugin/framework/object_store.go b/pkg/plugin/framework/object_store.go index ddf7414218..ad246ede8e 100644 --- a/pkg/plugin/framework/object_store.go +++ b/pkg/plugin/framework/object_store.go @@ -36,7 +36,6 @@ type ObjectStorePlugin struct { // GRPCClient returns an ObjectStore gRPC client. func (p *ObjectStorePlugin) GRPCClient(_ context.Context, _ *plugin.GRPCBroker, clientConn *grpc.ClientConn) (interface{}, error) { return common.NewClientDispenser(p.ClientLogger, clientConn, newObjectStoreGRPCClient), nil - } // GRPCServer registers an ObjectStore gRPC server. diff --git a/pkg/restore/change_image_name_action.go b/pkg/restore/change_image_name_action.go index 755ceddedb..f6f1834f35 100644 --- a/pkg/restore/change_image_name_action.go +++ b/pkg/restore/change_image_name_action.go @@ -102,7 +102,6 @@ func (a *ChangeImageNameAction) Execute(input *velero.RestoreItemActionExecuteIn return nil, errors.Errorf("object was of unexpected type %T", input.Item) } if obj.GetKind() == "Pod" { - err = a.replaceImageName(obj, config, "spec", "containers") if err != nil { a.logger.Infof("replace image name meet error: %v", err) @@ -114,7 +113,6 @@ func (a *ChangeImageNameAction) Execute(input *velero.RestoreItemActionExecuteIn a.logger.Infof("replace image name meet error: %v", err) return nil, errors.Wrap(err, "error getting item's spec.containers") } - } else if obj.GetKind() == "CronJob" { //handle containers err = a.replaceImageName(obj, config, "spec", "jobTemplate", "spec", "template", "spec", "containers") @@ -128,7 +126,6 @@ func (a *ChangeImageNameAction) Execute(input *velero.RestoreItemActionExecuteIn a.logger.Infof("replace image name meet error: %v", err) return nil, errors.Wrap(err, "error getting item's spec.containers") } - } else { //handle containers err = a.replaceImageName(obj, config, "spec", "template", "spec", "containers") @@ -148,7 +145,6 @@ func (a *ChangeImageNameAction) Execute(input *velero.RestoreItemActionExecuteIn } func (a *ChangeImageNameAction) replaceImageName(obj *unstructured.Unstructured, config *corev1.ConfigMap, filed ...string) error { - log := a.logger.WithFields(map[string]interface{}{ "kind": obj.GetKind(), "namespace": obj.GetNamespace(), diff --git a/pkg/restore/merge_service_account.go b/pkg/restore/merge_service_account.go index dd210f10f0..a5eddb3b42 100644 --- a/pkg/restore/merge_service_account.go +++ b/pkg/restore/merge_service_account.go @@ -33,7 +33,6 @@ func mergeServiceAccounts(fromCluster, fromBackup *unstructured.Unstructured) (* desired := new(corev1api.ServiceAccount) if err := runtime.DefaultUnstructuredConverter.FromUnstructured(fromCluster.UnstructuredContent(), desired); err != nil { return nil, errors.Wrap(err, "unable to convert from-cluster service account from unstructured to serviceaccount") - } backupSA := new(corev1api.ServiceAccount) diff --git a/pkg/restore/restore.go b/pkg/restore/restore.go index e163c2e9a9..afeb26cbba 100644 --- a/pkg/restore/restore.go +++ b/pkg/restore/restore.go @@ -1283,7 +1283,6 @@ func (ctx *restoreContext) restoreItem(obj *unstructured.Unstructured, groupReso } else if !available { errs.Add(namespace, fmt.Errorf("Additional items for %s are not ready to use.", resourceID)) } - } // This comes after running item actions because we have built-in actions that restore diff --git a/pkg/restore/service_action.go b/pkg/restore/service_action.go index 68daf5404f..724763c595 100644 --- a/pkg/restore/service_action.go +++ b/pkg/restore/service_action.go @@ -130,7 +130,6 @@ func deleteNodePorts(service *corev1api.Service) error { } else { explicitNodePorts.Insert(portName.(string)) } - } } } diff --git a/pkg/test/tar_writer.go b/pkg/test/tar_writer.go index 94cf6c8142..8b6ecf7f3b 100644 --- a/pkg/test/tar_writer.go +++ b/pkg/test/tar_writer.go @@ -53,7 +53,6 @@ func (tw *TarWriter) AddItems(groupResource string, items ...metav1.Object) *Tar tw.t.Helper() for _, obj := range items { - var path string if obj.GetNamespace() == "" { path = fmt.Sprintf("resources/%s/cluster/%s.json", groupResource, obj.GetName())