Enable stylecheck linter and resolve found issues.

Signed-off-by: Xun Jiang <blackpiglet@gmail.com>
This commit is contained in:
Xun Jiang
2023-04-25 14:37:02 +08:00
parent 980106dc39
commit bbc1e2e151
40 changed files with 215 additions and 227 deletions
+1 -1
View File
@@ -61,7 +61,7 @@ func NewDescribeCommand(f client.Factory, use string) *cobra.Command {
cmd.CheckError(err)
if outputFormat != "plaintext" && outputFormat != "json" {
cmd.CheckError(fmt.Errorf("Invalid output format '%s'. Valid value are 'plaintext, json'", outputFormat))
cmd.CheckError(fmt.Errorf("invalid output format '%s'. valid value are 'plaintext, json'", outputFormat))
}
var backups *velerov1api.BackupList
+1 -1
View File
@@ -58,7 +58,7 @@ func (o *DeleteOptions) Complete(f client.Factory, args []string) error {
// Validate validates the fields of the DeleteOptions struct.
func (o *DeleteOptions) Validate(c *cobra.Command, f client.Factory, args []string) error {
if o.Client == nil {
return errors.New("Velero client is not set; unable to proceed")
return errors.New("velero client is not set; unable to proceed")
}
return o.SelectOptions.Validate()
+1 -2
View File
@@ -23,7 +23,6 @@ import (
"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/fake"
@@ -51,7 +50,7 @@ func Test_validatePodVolumesHostPath(t *testing.T) {
name: "no error when pod volumes are present and there are mirror pods",
pods: []*corev1.Pod{
builder.ForPod("foo", "bar").ObjectMeta(builder.WithUID("foo")).Result(),
builder.ForPod("zoo", "raz").ObjectMeta(builder.WithUID("zoo"), builder.WithAnnotations(v1.MirrorPodAnnotationKey, "baz")).Result(),
builder.ForPod("zoo", "raz").ObjectMeta(builder.WithUID("zoo"), builder.WithAnnotations(corev1.MirrorPodAnnotationKey, "baz")).Result(),
},
dirs: []string{"foo", "baz"},
wantErr: false,
+1 -2
View File
@@ -22,7 +22,6 @@ import (
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/util/wait"
"sigs.k8s.io/controller-runtime/pkg/client"
kbclient "sigs.k8s.io/controller-runtime/pkg/client"
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
@@ -48,7 +47,7 @@ func (g *DefaultServerStatusGetter) GetServerStatus(kbClient kbclient.Client) (*
ctx, cancel := context.WithCancel(g.Context)
defer cancel()
key := client.ObjectKey{Name: created.Name, Namespace: g.Namespace}
key := kbclient.ObjectKey{Name: created.Name, Namespace: g.Namespace}
checkFunc := func() {
updated := &velerov1api.ServerStatusRequest{}
if err := kbClient.Get(ctx, key, updated); err != nil {
@@ -60,11 +60,11 @@ func Stream(ctx context.Context, kbClient kbclient.Client, namespace, name strin
key := kbclient.ObjectKey{Name: created.Name, Namespace: namespace}
timeStreamFirstCheck := time.Now()
downloadUrlTimeout := false
downloadURLTimeout := false
checkFunc := func() {
// if timeout has been reached, cancel request
if time.Now().After(timeStreamFirstCheck.Add(timeout)) {
downloadUrlTimeout = true
downloadURLTimeout = true
cancel()
}
updated := &velerov1api.DownloadRequest{}
@@ -85,7 +85,7 @@ func Stream(ctx context.Context, kbClient kbclient.Client, namespace, name strin
}
wait.Until(checkFunc, 25*time.Millisecond, ctx.Done())
if downloadUrlTimeout {
if downloadURLTimeout {
return ErrDownloadRequestDownloadURLTimeout
}
+3 -3
View File
@@ -149,7 +149,7 @@ func NewStructuredDescriber(format string) *StructuredDescriber {
func DescribeInSF(fn func(d *StructuredDescriber), format string) string {
d := NewStructuredDescriber(format)
fn(d)
return d.JsonEncode()
return d.JSONEncode()
}
// Describe adds all types of argument to d.output.
@@ -167,8 +167,8 @@ func (d *StructuredDescriber) DescribeMetadata(metadata metav1.ObjectMeta) {
d.Describe("metadata", metadataInfo)
}
// JsonEncode encodes d.output to json
func (d *StructuredDescriber) JsonEncode() string {
// JSONEncode encodes d.output to json
func (d *StructuredDescriber) JSONEncode() string {
byteBuffer := &bytes.Buffer{}
encoder := json.NewEncoder(byteBuffer)
encoder.SetEscapeHTML(false)