Skip to content

Commit 4ce7f85

Browse files
committed
chore: cleanup code
chore: cleanup code chore: cleanup code chore: cleanup code
1 parent 9ffefe3 commit 4ce7f85

File tree

10 files changed

+22
-21
lines changed

10 files changed

+22
-21
lines changed

cmd/kube-scheduler/app/options/configfile.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ func LoadConfigFromFile(logger klog.Logger, file string) (*config.KubeSchedulerC
3636
return nil, err
3737
}
3838

39-
return loadConfig(logger, data)
39+
return loadConfig(data)
4040
}
4141

42-
func loadConfig(logger klog.Logger, data []byte) (*config.KubeSchedulerConfiguration, error) {
42+
func loadConfig(data []byte) (*config.KubeSchedulerConfiguration, error) {
4343
// The UniversalDecoder runs defaulting and returns the internal type by default.
4444
obj, gvk, err := scheme.Codecs.UniversalDecoder().Decode(data, nil, nil)
4545
if err != nil {

cmd/kube-scheduler/app/options/configfile_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package options
1818

1919
import (
2020
"context"
21+
"errors"
2122
"fmt"
2223
"os"
2324
"path/filepath"
@@ -103,13 +104,13 @@ func TestLoadConfigFromFile(t *testing.T) {
103104
{
104105
name: "Scheduler config with decode error",
105106
path: decodeErrConfigFile,
106-
expectedErr: fmt.Errorf(apiVersionMissing),
107+
expectedErr: errors.New(apiVersionMissing),
107108
expectedConfig: nil,
108109
},
109110
{
110111
name: "Scheduler config version too old",
111112
path: versionTooOldConfigFile,
112-
expectedErr: fmt.Errorf(apiVersionTooOld),
113+
expectedErr: errors.New(apiVersionTooOld),
113114
expectedConfig: nil,
114115
},
115116
}

cmd/kubeadm/app/apis/kubeadm/v1beta3/defaults.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ func SetDefaults_FileDiscovery(obj *FileDiscovery) {
175175
// layer, but set to a random value later at runtime if not set before.
176176
func SetDefaults_BootstrapTokens(obj *InitConfiguration) {
177177

178-
if obj.BootstrapTokens == nil || len(obj.BootstrapTokens) == 0 {
178+
if len(obj.BootstrapTokens) == 0 {
179179
obj.BootstrapTokens = []bootstraptokenv1.BootstrapToken{{}}
180180
}
181181

cmd/kubeadm/app/apis/kubeadm/v1beta4/defaults.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func SetDefaults_FileDiscovery(obj *FileDiscovery) {
183183
// layer, but set to a random value later at runtime if not set before.
184184
func SetDefaults_BootstrapTokens(obj *InitConfiguration) {
185185

186-
if obj.BootstrapTokens == nil || len(obj.BootstrapTokens) == 0 {
186+
if len(obj.BootstrapTokens) == 0 {
187187
obj.BootstrapTokens = []bootstraptokenv1.BootstrapToken{{}}
188188
}
189189

cmd/kubeadm/app/cmd/completion_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func TestNewCmdCompletion(t *testing.T) {
2929
var out bytes.Buffer
3030
shells := GetSupportedShells()
3131
if len(shells) == 0 {
32-
t.Errorf(shellsError)
32+
t.Error(shellsError)
3333
}
3434
// test newCmdCompletion with a valid shell.
3535
// use a dummy parent command as newCmdCompletion needs it.
@@ -72,7 +72,7 @@ func TestRunCompletion(t *testing.T) {
7272
// test all supported shells
7373
shells := GetSupportedShells()
7474
if len(shells) == 0 {
75-
t.Errorf(shellsError)
75+
t.Error(shellsError)
7676
}
7777
for _, shell := range shells {
7878
test := TestCase{

cmd/kubeadm/app/cmd/upgrade/diff.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,9 @@ func runDiff(fs *pflag.FlagSet, flags *diffFlags, args []string, fetchInitConfig
184184
Context: cmdutil.ValueFromFlagsOrConfig(fs, "context-lines", upgradeCfg.Diff.DiffContextLines, flags.contextLines).(int),
185185
}
186186

187-
difflib.WriteUnifiedDiff(flags.out, diff)
187+
if err = difflib.WriteUnifiedDiff(flags.out, diff); err != nil {
188+
return errors.Wrap(err, "error writing unified diff")
189+
}
188190
}
189191
return nil
190192
}

cmd/kubeadm/app/cmd/upgrade/node.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func newCmdNode(out io.Writer) *cobra.Command {
106106
// sets the data builder function, that will be used by the runner
107107
// both when running the entire workflow or single phases
108108
nodeRunner.SetDataInitializer(func(cmd *cobra.Command, args []string) (workflow.RunData, error) {
109-
data, err := newNodeData(cmd, args, nodeOptions, out)
109+
data, err := newNodeData(cmd, nodeOptions, out)
110110
if err != nil {
111111
return nil, err
112112
}
@@ -145,7 +145,7 @@ func addUpgradeNodeFlags(flagSet *flag.FlagSet, nodeOptions *nodeOptions) {
145145
// newNodeData returns a new nodeData struct to be used for the execution of the kubeadm upgrade node workflow.
146146
// This func takes care of validating nodeOptions passed to the command, and then it converts
147147
// options into the internal InitConfiguration type that is used as input all the phases in the kubeadm upgrade node workflow
148-
func newNodeData(cmd *cobra.Command, args []string, nodeOptions *nodeOptions, out io.Writer) (*nodeData, error) {
148+
func newNodeData(cmd *cobra.Command, nodeOptions *nodeOptions, out io.Writer) (*nodeData, error) {
149149
// Checks if a node is a control-plane node by looking up the kube-apiserver manifest file
150150
isControlPlaneNode := true
151151
filepath := constants.GetStaticPodFilepath(constants.KubeAPIServer, constants.GetStaticPodDirectory())

cmd/prune-junit-xml/prunexml_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func TestPruneXML(t *testing.T) {
6363
writer := bufio.NewWriter(&output)
6464
_ = streamXML(writer, suites)
6565
_ = writer.Flush()
66-
assert.Equal(t, outputXML, string(output.Bytes()), "xml was not pruned correctly")
66+
assert.Equal(t, outputXML, output.String(), "xml was not pruned correctly")
6767
}
6868

6969
func TestPruneTESTS(t *testing.T) {
@@ -114,5 +114,5 @@ func TestPruneTESTS(t *testing.T) {
114114
writer := bufio.NewWriter(&output)
115115
_ = streamXML(writer, suites)
116116
_ = writer.Flush()
117-
assert.Equal(t, outputXML, string(output.Bytes()), "tests in xml was not pruned correctly")
117+
assert.Equal(t, outputXML, output.String(), "tests in xml was not pruned correctly")
118118
}

cmd/yamlfmt/yamlfmt_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ package main
1919
import (
2020
"bufio"
2121
"bytes"
22-
"github.com/stretchr/testify/assert"
2322
"testing"
23+
24+
"github.com/stretchr/testify/assert"
2425
)
2526

2627
func TestFetchYaml(t *testing.T) {
@@ -48,5 +49,5 @@ labels:
4849
writer := bufio.NewWriter(&output)
4950
_ = streamYaml(writer, &indent, node)
5051
_ = writer.Flush()
51-
assert.Equal(t, outputYaml, string(output.Bytes()), "yaml was not formatted correctly")
52+
assert.Equal(t, outputYaml, output.String(), "yaml was not formatted correctly")
5253
}

staging/src/k8s.io/code-generator/cmd/go-to-protobuf/protobuf/generator.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,7 @@ func isOptionalAlias(t *types.Type) bool {
145145
if t.Underlying == nil || (t.Underlying.Kind != types.Map && t.Underlying.Kind != types.Slice) {
146146
return false
147147
}
148-
if extractBoolTagOrDie("protobuf.nullable", t.CommentLines) == false {
149-
return false
150-
}
151-
return true
148+
return extractBoolTagOrDie("protobuf.nullable", t.CommentLines)
152149
}
153150

154151
func (g *genProtoIDL) Imports(c *generator.Context) (imports []string) {
@@ -187,7 +184,7 @@ func (g *genProtoIDL) GenerateType(c *generator.Context, t *types.Type, w io.Wri
187184
case types.Struct:
188185
return b.doStruct(sw)
189186
default:
190-
return b.unknown(sw)
187+
return b.unknown()
191188
}
192189
}
193190

@@ -262,7 +259,7 @@ type bodyGen struct {
262259
t *types.Type
263260
}
264261

265-
func (b bodyGen) unknown(sw *generator.SnippetWriter) error {
262+
func (b bodyGen) unknown() error {
266263
return fmt.Errorf("not sure how to generate: %#v", b.t)
267264
}
268265

0 commit comments

Comments
 (0)