mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-11 13:02:14 +00:00
chore: cleanup code
chore: cleanup code chore: cleanup code chore: cleanup code
This commit is contained in:
parent
9ffefe3da2
commit
4ce7f8547d
@ -36,10 +36,10 @@ func LoadConfigFromFile(logger klog.Logger, file string) (*config.KubeSchedulerC
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return loadConfig(logger, data)
|
return loadConfig(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadConfig(logger klog.Logger, data []byte) (*config.KubeSchedulerConfiguration, error) {
|
func loadConfig(data []byte) (*config.KubeSchedulerConfiguration, error) {
|
||||||
// The UniversalDecoder runs defaulting and returns the internal type by default.
|
// The UniversalDecoder runs defaulting and returns the internal type by default.
|
||||||
obj, gvk, err := scheme.Codecs.UniversalDecoder().Decode(data, nil, nil)
|
obj, gvk, err := scheme.Codecs.UniversalDecoder().Decode(data, nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -18,6 +18,7 @@ package options
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -103,13 +104,13 @@ func TestLoadConfigFromFile(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "Scheduler config with decode error",
|
name: "Scheduler config with decode error",
|
||||||
path: decodeErrConfigFile,
|
path: decodeErrConfigFile,
|
||||||
expectedErr: fmt.Errorf(apiVersionMissing),
|
expectedErr: errors.New(apiVersionMissing),
|
||||||
expectedConfig: nil,
|
expectedConfig: nil,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Scheduler config version too old",
|
name: "Scheduler config version too old",
|
||||||
path: versionTooOldConfigFile,
|
path: versionTooOldConfigFile,
|
||||||
expectedErr: fmt.Errorf(apiVersionTooOld),
|
expectedErr: errors.New(apiVersionTooOld),
|
||||||
expectedConfig: nil,
|
expectedConfig: nil,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -175,7 +175,7 @@ func SetDefaults_FileDiscovery(obj *FileDiscovery) {
|
|||||||
// layer, but set to a random value later at runtime if not set before.
|
// layer, but set to a random value later at runtime if not set before.
|
||||||
func SetDefaults_BootstrapTokens(obj *InitConfiguration) {
|
func SetDefaults_BootstrapTokens(obj *InitConfiguration) {
|
||||||
|
|
||||||
if obj.BootstrapTokens == nil || len(obj.BootstrapTokens) == 0 {
|
if len(obj.BootstrapTokens) == 0 {
|
||||||
obj.BootstrapTokens = []bootstraptokenv1.BootstrapToken{{}}
|
obj.BootstrapTokens = []bootstraptokenv1.BootstrapToken{{}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,7 +183,7 @@ func SetDefaults_FileDiscovery(obj *FileDiscovery) {
|
|||||||
// layer, but set to a random value later at runtime if not set before.
|
// layer, but set to a random value later at runtime if not set before.
|
||||||
func SetDefaults_BootstrapTokens(obj *InitConfiguration) {
|
func SetDefaults_BootstrapTokens(obj *InitConfiguration) {
|
||||||
|
|
||||||
if obj.BootstrapTokens == nil || len(obj.BootstrapTokens) == 0 {
|
if len(obj.BootstrapTokens) == 0 {
|
||||||
obj.BootstrapTokens = []bootstraptokenv1.BootstrapToken{{}}
|
obj.BootstrapTokens = []bootstraptokenv1.BootstrapToken{{}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ func TestNewCmdCompletion(t *testing.T) {
|
|||||||
var out bytes.Buffer
|
var out bytes.Buffer
|
||||||
shells := GetSupportedShells()
|
shells := GetSupportedShells()
|
||||||
if len(shells) == 0 {
|
if len(shells) == 0 {
|
||||||
t.Errorf(shellsError)
|
t.Error(shellsError)
|
||||||
}
|
}
|
||||||
// test newCmdCompletion with a valid shell.
|
// test newCmdCompletion with a valid shell.
|
||||||
// use a dummy parent command as newCmdCompletion needs it.
|
// use a dummy parent command as newCmdCompletion needs it.
|
||||||
@ -72,7 +72,7 @@ func TestRunCompletion(t *testing.T) {
|
|||||||
// test all supported shells
|
// test all supported shells
|
||||||
shells := GetSupportedShells()
|
shells := GetSupportedShells()
|
||||||
if len(shells) == 0 {
|
if len(shells) == 0 {
|
||||||
t.Errorf(shellsError)
|
t.Error(shellsError)
|
||||||
}
|
}
|
||||||
for _, shell := range shells {
|
for _, shell := range shells {
|
||||||
test := TestCase{
|
test := TestCase{
|
||||||
|
@ -184,7 +184,9 @@ func runDiff(fs *pflag.FlagSet, flags *diffFlags, args []string, fetchInitConfig
|
|||||||
Context: cmdutil.ValueFromFlagsOrConfig(fs, "context-lines", upgradeCfg.Diff.DiffContextLines, flags.contextLines).(int),
|
Context: cmdutil.ValueFromFlagsOrConfig(fs, "context-lines", upgradeCfg.Diff.DiffContextLines, flags.contextLines).(int),
|
||||||
}
|
}
|
||||||
|
|
||||||
difflib.WriteUnifiedDiff(flags.out, diff)
|
if err = difflib.WriteUnifiedDiff(flags.out, diff); err != nil {
|
||||||
|
return errors.Wrap(err, "error writing unified diff")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -106,7 +106,7 @@ func newCmdNode(out io.Writer) *cobra.Command {
|
|||||||
// sets the data builder function, that will be used by the runner
|
// sets the data builder function, that will be used by the runner
|
||||||
// both when running the entire workflow or single phases
|
// both when running the entire workflow or single phases
|
||||||
nodeRunner.SetDataInitializer(func(cmd *cobra.Command, args []string) (workflow.RunData, error) {
|
nodeRunner.SetDataInitializer(func(cmd *cobra.Command, args []string) (workflow.RunData, error) {
|
||||||
data, err := newNodeData(cmd, args, nodeOptions, out)
|
data, err := newNodeData(cmd, nodeOptions, out)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -145,7 +145,7 @@ func addUpgradeNodeFlags(flagSet *flag.FlagSet, nodeOptions *nodeOptions) {
|
|||||||
// newNodeData returns a new nodeData struct to be used for the execution of the kubeadm upgrade node workflow.
|
// newNodeData returns a new nodeData struct to be used for the execution of the kubeadm upgrade node workflow.
|
||||||
// This func takes care of validating nodeOptions passed to the command, and then it converts
|
// This func takes care of validating nodeOptions passed to the command, and then it converts
|
||||||
// options into the internal InitConfiguration type that is used as input all the phases in the kubeadm upgrade node workflow
|
// options into the internal InitConfiguration type that is used as input all the phases in the kubeadm upgrade node workflow
|
||||||
func newNodeData(cmd *cobra.Command, args []string, nodeOptions *nodeOptions, out io.Writer) (*nodeData, error) {
|
func newNodeData(cmd *cobra.Command, nodeOptions *nodeOptions, out io.Writer) (*nodeData, error) {
|
||||||
// Checks if a node is a control-plane node by looking up the kube-apiserver manifest file
|
// Checks if a node is a control-plane node by looking up the kube-apiserver manifest file
|
||||||
isControlPlaneNode := true
|
isControlPlaneNode := true
|
||||||
filepath := constants.GetStaticPodFilepath(constants.KubeAPIServer, constants.GetStaticPodDirectory())
|
filepath := constants.GetStaticPodFilepath(constants.KubeAPIServer, constants.GetStaticPodDirectory())
|
||||||
|
@ -63,7 +63,7 @@ func TestPruneXML(t *testing.T) {
|
|||||||
writer := bufio.NewWriter(&output)
|
writer := bufio.NewWriter(&output)
|
||||||
_ = streamXML(writer, suites)
|
_ = streamXML(writer, suites)
|
||||||
_ = writer.Flush()
|
_ = writer.Flush()
|
||||||
assert.Equal(t, outputXML, string(output.Bytes()), "xml was not pruned correctly")
|
assert.Equal(t, outputXML, output.String(), "xml was not pruned correctly")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPruneTESTS(t *testing.T) {
|
func TestPruneTESTS(t *testing.T) {
|
||||||
@ -114,5 +114,5 @@ func TestPruneTESTS(t *testing.T) {
|
|||||||
writer := bufio.NewWriter(&output)
|
writer := bufio.NewWriter(&output)
|
||||||
_ = streamXML(writer, suites)
|
_ = streamXML(writer, suites)
|
||||||
_ = writer.Flush()
|
_ = writer.Flush()
|
||||||
assert.Equal(t, outputXML, string(output.Bytes()), "tests in xml was not pruned correctly")
|
assert.Equal(t, outputXML, output.String(), "tests in xml was not pruned correctly")
|
||||||
}
|
}
|
||||||
|
@ -19,8 +19,9 @@ package main
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFetchYaml(t *testing.T) {
|
func TestFetchYaml(t *testing.T) {
|
||||||
@ -48,5 +49,5 @@ labels:
|
|||||||
writer := bufio.NewWriter(&output)
|
writer := bufio.NewWriter(&output)
|
||||||
_ = streamYaml(writer, &indent, node)
|
_ = streamYaml(writer, &indent, node)
|
||||||
_ = writer.Flush()
|
_ = writer.Flush()
|
||||||
assert.Equal(t, outputYaml, string(output.Bytes()), "yaml was not formatted correctly")
|
assert.Equal(t, outputYaml, output.String(), "yaml was not formatted correctly")
|
||||||
}
|
}
|
||||||
|
@ -145,10 +145,7 @@ func isOptionalAlias(t *types.Type) bool {
|
|||||||
if t.Underlying == nil || (t.Underlying.Kind != types.Map && t.Underlying.Kind != types.Slice) {
|
if t.Underlying == nil || (t.Underlying.Kind != types.Map && t.Underlying.Kind != types.Slice) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if extractBoolTagOrDie("protobuf.nullable", t.CommentLines) == false {
|
return extractBoolTagOrDie("protobuf.nullable", t.CommentLines)
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *genProtoIDL) Imports(c *generator.Context) (imports []string) {
|
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
|
|||||||
case types.Struct:
|
case types.Struct:
|
||||||
return b.doStruct(sw)
|
return b.doStruct(sw)
|
||||||
default:
|
default:
|
||||||
return b.unknown(sw)
|
return b.unknown()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,7 +259,7 @@ type bodyGen struct {
|
|||||||
t *types.Type
|
t *types.Type
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b bodyGen) unknown(sw *generator.SnippetWriter) error {
|
func (b bodyGen) unknown() error {
|
||||||
return fmt.Errorf("not sure how to generate: %#v", b.t)
|
return fmt.Errorf("not sure how to generate: %#v", b.t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user