Skip to content

Commit

Permalink
Resolve linter issues.
Browse files Browse the repository at this point in the history
Signed-off-by: Xun Jiang <jxun@vmware.com>
  • Loading branch information
Xun Jiang committed Nov 28, 2023
1 parent bdc63c5 commit d19cce7
Show file tree
Hide file tree
Showing 16 changed files with 25 additions and 18 deletions.
2 changes: 1 addition & 1 deletion hack/build-image/Dockerfile
Expand Up @@ -56,7 +56,7 @@ RUN wget --quiet https://github.com/goreleaser/goreleaser/releases/download/v1.1
chmod +x /usr/bin/goreleaser

# get golangci-lint
RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.51.0
RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.54.2

# install kubectl
RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
Expand Down
2 changes: 1 addition & 1 deletion pkg/archive/extractor.go
Expand Up @@ -84,7 +84,7 @@ func (e *Extractor) readBackup(tarRdr *tar.Reader) (string, error) {
return "", err
}

target := filepath.Join(dir, header.Name) //nolint:gosec
target := filepath.Join(dir, header.Name) //nolint:gosec // Internal usage. No need to check.

switch header.Typeflag {
case tar.TypeDir:
Expand Down
2 changes: 1 addition & 1 deletion pkg/builder/server_status_request_builder.go
Expand Up @@ -29,7 +29,7 @@ type ServerStatusRequestBuilder struct {
object *velerov1api.ServerStatusRequest
}

// ForServerStatusRequest is the constructor for for a ServerStatusRequestBuilder.
// ForServerStatusRequest is the constructor for a ServerStatusRequestBuilder.
func ForServerStatusRequest(ns, name, resourceVersion string) *ServerStatusRequestBuilder {
return &ServerStatusRequestBuilder{
object: &velerov1api.ServerStatusRequest{
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/cli/nodeagent/server.go
Expand Up @@ -523,7 +523,7 @@ func (s *nodeAgentServer) getDataPathConcurrentNum(defaultNum int) int {
concurrentNum := math.MaxInt32

for _, rule := range configs.DataPathConcurrency.PerNodeConfig {
selector, err := metav1.LabelSelectorAsSelector(&rule.NodeSelector)
selector, err := metav1.LabelSelectorAsSelector(&(rule.NodeSelector))
if err != nil {
s.logger.WithError(err).Warnf("Failed to parse rule with label selector %s, skip it", rule.NodeSelector.String())
continue
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/server/server.go
Expand Up @@ -248,7 +248,7 @@ type server struct {
discoveryHelper velerodiscovery.Helper
dynamicClient dynamic.Interface
// controller-runtime client. the difference from the controller-manager's client
// is that the the controller-manager's client is limited to list namespaced-scoped
// is that the controller-manager's client is limited to list namespaced-scoped
// resources in the namespace where Velero is installed, or the cluster-scoped
// resources. The crClient doesn't have the limitation.
crClient ctrlclient.Client
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/util/downloadrequest/downloadrequest.go
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, //nolint:gosec
InsecureSkipVerify: insecureSkipTLSVerify, //nolint:gosec // This parameter is useful for some scenarios.
RootCAs: caPool,
},
IdleConnTimeout: timeout,
Expand Down
7 changes: 6 additions & 1 deletion pkg/cmd/util/output/describe.go
Expand Up @@ -164,6 +164,11 @@ func (d *StructuredDescriber) JSONEncode() string {
encoder := json.NewEncoder(byteBuffer)
encoder.SetEscapeHTML(false)
encoder.SetIndent("", " ")
encoder.Encode(d.output)

err := encoder.Encode(d.output)
if err != nil {
fmt.Printf("fail to encode %s", err.Error())
return ""
}

Check warning on line 172 in pkg/cmd/util/output/describe.go

View check run for this annotation

Codecov / codecov/patch

pkg/cmd/util/output/describe.go#L170-L172

Added lines #L170 - L172 were not covered by tests
return byteBuffer.String()
}
2 changes: 1 addition & 1 deletion pkg/controller/backup_controller.go
Expand Up @@ -1080,7 +1080,7 @@ func generateVolumeInfoForCSIVolumeSnapshot(backup *pkgbackup.Request, csiVolume
SnapshotDataMoved: false,
PreserveLocalSnapshot: true,
OperationID: operation.Spec.OperationID,
StartTimestamp: &volumeSnapshot.CreationTimestamp,
StartTimestamp: &(volumeSnapshot.CreationTimestamp),
CSISnapshotInfo: volume.CSISnapshotInfo{
VSCName: *volumeSnapshot.Status.BoundVolumeSnapshotContentName,
Size: size,
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/pod_volume_restore_controller.go
Expand Up @@ -303,7 +303,7 @@ func (c *PodVolumeRestoreReconciler) OnDataPathCompleted(ctx context.Context, na
// Write a done file with name=<restore-uid> into the just-created .velero dir
// within the volume. The velero init container on the pod is waiting
// for this file to exist in each restored volume before completing.
if err := os.WriteFile(filepath.Join(volumePath, ".velero", string(restoreUID)), nil, 0644); err != nil { //nolint:gosec
if err := os.WriteFile(filepath.Join(volumePath, ".velero", string(restoreUID)), nil, 0644); err != nil { //nolint:gosec // Internal usage. No need to check.

Check warning on line 306 in pkg/controller/pod_volume_restore_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/pod_volume_restore_controller.go#L306

Added line #L306 was not covered by tests
_, _ = c.errorOut(ctx, &pvr, err, "error writing done file", log)
return
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/datamover/dataupload_delete_action.go
Expand Up @@ -63,7 +63,9 @@ func genConfigmap(bak *velerov1.Backup, du velerov2alpha1.DataUpload) *corev1api
return nil
}

Check warning on line 64 in pkg/datamover/dataupload_delete_action.go

View check run for this annotation

Codecov / codecov/patch

pkg/datamover/dataupload_delete_action.go#L61-L64

Added lines #L61 - L64 were not covered by tests
data := make(map[string]string)
json.Unmarshal(b, &data)
if err := json.Unmarshal(b, &data); err != nil {
return &corev1api.ConfigMap{}
}

Check warning on line 68 in pkg/datamover/dataupload_delete_action.go

View check run for this annotation

Codecov / codecov/patch

pkg/datamover/dataupload_delete_action.go#L66-L68

Added lines #L66 - L68 were not covered by tests
return &corev1api.ConfigMap{
TypeMeta: metav1.TypeMeta{
APIVersion: corev1api.SchemeGroupVersion.String(),
Expand Down
2 changes: 1 addition & 1 deletion pkg/metrics/metrics.go
Expand Up @@ -69,7 +69,7 @@ const (
// data mover metrics
DataUploadSuccessTotal = "data_upload_success_total"
DataUploadFailureTotal = "data_upload_failure_total"
DataUploadCancelTotal = "data_upload_cancel_total"
DataUploadCancelTotal = "data_upload_cancel_total" //nolint:gosec // Not a hard code secret.
DataDownloadSuccessTotal = "data_download_success_total"
DataDownloadFailureTotal = "data_download_failure_total"
DataDownloadCancelTotal = "data_download_cancel_total"
Expand Down
2 changes: 1 addition & 1 deletion pkg/repository/config/aws.go
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

//nolint:gosec
//nolint:gosec // Internal usage. No need to check.
package config

import (
Expand Down
2 changes: 1 addition & 1 deletion pkg/repository/config/gcp.go
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

//nolint:gosec
//nolint:gosec // Internal usage. No need to check.
package config

import "os"
Expand Down
2 changes: 1 addition & 1 deletion pkg/repository/keys/keys.go
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

//nolint:gosec
//nolint:gosec // Internal call. No need to check.
package keys

import (
Expand Down
6 changes: 3 additions & 3 deletions pkg/restore/restore.go
Expand Up @@ -1883,7 +1883,7 @@ func shouldRenamePV(ctx *restoreContext, obj *unstructured.Unstructured, client
// remapClaimRefNS remaps a PersistentVolume's claimRef.Namespace based on a
// restore's NamespaceMappings, if necessary. Returns true if the namespace was
// remapped, false if it was not required.
func remapClaimRefNS(ctx *restoreContext, obj *unstructured.Unstructured) (bool, error) { //nolint:unparam
func remapClaimRefNS(ctx *restoreContext, obj *unstructured.Unstructured) (bool, error) { //nolint:unparam // ignore the result 0 (bool) is never used warning.
if len(ctx.restore.Spec.NamespaceMapping) == 0 {
ctx.log.Debug("Persistent volume does not need to have the claimRef.namespace remapped because restore is not remapping any namespaces")
return false, nil
Expand Down Expand Up @@ -2310,7 +2310,7 @@ func (ctx *restoreContext) getOrderedResourceCollection(
// getSelectedRestoreableItems applies Kubernetes selectors on individual items
// of each resource type to create a list of items which will be actually
// restored.
func (ctx *restoreContext) getSelectedRestoreableItems(resource, targetNamespace, originalNamespace string, items []string) (restoreableResource, results.Result, results.Result) {
func (ctx *restoreContext) getSelectedRestoreableItems(resource, targetNamespace, originalNamespace string, items []string) (restoreableResource, results.Result, results.Result) { //nolint:unparam // Ignore the warnings is always nil warning.
warnings, errs := results.Result{}, results.Result{}

restorable := restoreableResource{
Expand Down Expand Up @@ -2411,7 +2411,7 @@ func removeRestoreLabels(obj metav1.Object) {
}

// updates the backup/restore labels
func (ctx *restoreContext) updateBackupRestoreLabels(fromCluster, fromClusterWithLabels *unstructured.Unstructured, namespace string, resourceClient client.Dynamic) (warnings, errs results.Result) {
func (ctx *restoreContext) updateBackupRestoreLabels(fromCluster, fromClusterWithLabels *unstructured.Unstructured, namespace string, resourceClient client.Dynamic) (warnings, errs results.Result) { //nolint:unparam // Ignore the warnings is nil warning.
patchBytes, err := generatePatch(fromCluster, fromClusterWithLabels)
if err != nil {
ctx.log.Errorf("error generating patch for %s %s: %v", fromCluster.GroupVersionKind().Kind, kube.NamespaceAndName(fromCluster), err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/uploader/kopia/progress.go
Expand Up @@ -33,7 +33,7 @@ type Throttle struct {

func (t *Throttle) ShouldOutput() bool {
nextOutputTimeUnixNano := atomic.LoadInt64(&t.throttle)
if nowNano := time.Now().UnixNano(); nowNano > nextOutputTimeUnixNano { //nolint:forbidigo
if nowNano := time.Now().UnixNano(); nowNano > nextOutputTimeUnixNano {
if atomic.CompareAndSwapInt64(&t.throttle, nextOutputTimeUnixNano, nowNano+t.interval.Nanoseconds()) {
return true
}
Expand Down

0 comments on commit d19cce7

Please sign in to comment.