Merge pull request #23660 from goltermann/vetclean

Automatic merge from submit-queue

Additional go vet fixes

Mostly:
- pass lock by value
- bad syntax for struct tag value
- example functions not formatted properly
This commit is contained in:
k8s-merge-robot
2016-04-12 06:22:16 -07:00
33 changed files with 136 additions and 118 deletions

View File

@@ -101,7 +101,7 @@ func InterpretWatchError(err error, resource unversioned.GroupResource, name str
switch {
case storage.IsInvalidError(err):
invalidError, _ := err.(storage.InvalidError)
return errors.NewInvalid(unversioned.GroupKind{resource.Group, resource.Resource}, name, invalidError.Errs)
return errors.NewInvalid(unversioned.GroupKind{Group: resource.Group, Kind: resource.Resource}, name, invalidError.Errs)
default:
return err
}

View File

@@ -52,7 +52,7 @@ func BeforeDelete(strategy RESTDeleteStrategy, ctx api.Context, obj runtime.Obje
}
// Checking the Preconditions here to fail early. They'll be enforced later on when we actually do the deletion, too.
if options.Preconditions != nil && options.Preconditions.UID != nil && *options.Preconditions.UID != objectMeta.UID {
return false, false, errors.NewConflict(unversioned.GroupResource{gvk.Group, gvk.Kind}, objectMeta.Name, fmt.Errorf("the UID in the precondition (%s) does not match the UID in record (%s). The object might have been deleted and then recreated", *options.Preconditions.UID, objectMeta.UID))
return false, false, errors.NewConflict(unversioned.GroupResource{Group: gvk.Group, Resource: gvk.Kind}, objectMeta.Name, fmt.Errorf("the UID in the precondition (%s) does not match the UID in record (%s). The object might have been deleted and then recreated", *options.Preconditions.UID, objectMeta.UID))
}
gracefulStrategy, ok := strategy.(RESTGracefulDeleteStrategy)
if !ok {

View File

@@ -33273,11 +33273,12 @@ func (x *NodeStatus) CodecEncodeSelf(e *codec1978.Encoder) {
yyq2[4] = len(x.Addresses) != 0
yyq2[5] = true
yyq2[6] = true
yyq2[7] = len(x.Images) != 0
var yynn2 int
if yyr2 || yy2arr2 {
r.EncodeArrayStart(8)
} else {
yynn2 = 1
yynn2 = 0
for _, b := range yyq2 {
if b {
yynn2++
@@ -33449,28 +33450,34 @@ func (x *NodeStatus) CodecEncodeSelf(e *codec1978.Encoder) {
}
if yyr2 || yy2arr2 {
z.EncSendContainerState(codecSelfer_containerArrayElem1234)
if x.Images == nil {
r.EncodeNil()
} else {
yym29 := z.EncBinary()
_ = yym29
if false {
if yyq2[7] {
if x.Images == nil {
r.EncodeNil()
} else {
h.encSliceContainerImage(([]ContainerImage)(x.Images), e)
yym29 := z.EncBinary()
_ = yym29
if false {
} else {
h.encSliceContainerImage(([]ContainerImage)(x.Images), e)
}
}
} else {
r.EncodeNil()
}
} else {
z.EncSendContainerState(codecSelfer_containerMapKey1234)
r.EncodeString(codecSelferC_UTF81234, string("images"))
z.EncSendContainerState(codecSelfer_containerMapValue1234)
if x.Images == nil {
r.EncodeNil()
} else {
yym30 := z.EncBinary()
_ = yym30
if false {
if yyq2[7] {
z.EncSendContainerState(codecSelfer_containerMapKey1234)
r.EncodeString(codecSelferC_UTF81234, string("images"))
z.EncSendContainerState(codecSelfer_containerMapValue1234)
if x.Images == nil {
r.EncodeNil()
} else {
h.encSliceContainerImage(([]ContainerImage)(x.Images), e)
yym30 := z.EncBinary()
_ = yym30
if false {
} else {
h.encSliceContainerImage(([]ContainerImage)(x.Images), e)
}
}
}
}

View File

@@ -1671,8 +1671,14 @@ type NodeSpec struct {
// DaemonEndpoint contains information about a single Daemon endpoint.
type DaemonEndpoint struct {
/*
The port tag was not properly in quotes in earlier releases, so it must be
uppercased for backwards compat (since it was falling back to var name of
'Port').
*/
// Port number of the given endpoint.
Port int `json:port`
Port int `json:"Port"`
}
// NodeDaemonEndpoints lists ports opened by daemons running on the Node.
@@ -1718,7 +1724,7 @@ type NodeStatus struct {
// Set of ids/uuids to uniquely identify the node.
NodeInfo NodeSystemInfo `json:"nodeInfo,omitempty"`
// List of container images on this node
Images []ContainerImage `json:"images",omitempty`
Images []ContainerImage `json:"images,omitempty"`
}
// Describe a container image

View File

@@ -33155,11 +33155,12 @@ func (x *NodeStatus) CodecEncodeSelf(e *codec1978.Encoder) {
yyq2[4] = len(x.Addresses) != 0
yyq2[5] = true
yyq2[6] = true
yyq2[7] = len(x.Images) != 0
var yynn2 int
if yyr2 || yy2arr2 {
r.EncodeArrayStart(8)
} else {
yynn2 = 1
yynn2 = 0
for _, b := range yyq2 {
if b {
yynn2++
@@ -33331,28 +33332,34 @@ func (x *NodeStatus) CodecEncodeSelf(e *codec1978.Encoder) {
}
if yyr2 || yy2arr2 {
z.EncSendContainerState(codecSelfer_containerArrayElem1234)
if x.Images == nil {
r.EncodeNil()
} else {
yym29 := z.EncBinary()
_ = yym29
if false {
if yyq2[7] {
if x.Images == nil {
r.EncodeNil()
} else {
h.encSliceContainerImage(([]ContainerImage)(x.Images), e)
yym29 := z.EncBinary()
_ = yym29
if false {
} else {
h.encSliceContainerImage(([]ContainerImage)(x.Images), e)
}
}
} else {
r.EncodeNil()
}
} else {
z.EncSendContainerState(codecSelfer_containerMapKey1234)
r.EncodeString(codecSelferC_UTF81234, string("images"))
z.EncSendContainerState(codecSelfer_containerMapValue1234)
if x.Images == nil {
r.EncodeNil()
} else {
yym30 := z.EncBinary()
_ = yym30
if false {
if yyq2[7] {
z.EncSendContainerState(codecSelfer_containerMapKey1234)
r.EncodeString(codecSelferC_UTF81234, string("images"))
z.EncSendContainerState(codecSelfer_containerMapValue1234)
if x.Images == nil {
r.EncodeNil()
} else {
h.encSliceContainerImage(([]ContainerImage)(x.Images), e)
yym30 := z.EncBinary()
_ = yym30
if false {
} else {
h.encSliceContainerImage(([]ContainerImage)(x.Images), e)
}
}
}
}

View File

@@ -2048,8 +2048,14 @@ type NodeSpec struct {
// DaemonEndpoint contains information about a single Daemon endpoint.
type DaemonEndpoint struct {
/*
The port tag was not properly in quotes in earlier releases, so it must be
uppercased for backwards compat (since it was falling back to var name of
'Port').
*/
// Port number of the given endpoint.
Port int32 `json:port`
Port int32 `json:"Port"`
}
// NodeDaemonEndpoints lists ports opened by daemons running on the Node.
@@ -2102,7 +2108,7 @@ type NodeStatus struct {
// More info: http://releases.k8s.io/HEAD/docs/admin/node.md#node-info
NodeInfo NodeSystemInfo `json:"nodeInfo,omitempty"`
// List of container images on this node
Images []ContainerImage `json:"images",omitempty`
Images []ContainerImage `json:"images,omitempty"`
}
// Describe a container image

View File

@@ -2048,7 +2048,7 @@ func (x *KubeletConfiguration) CodecEncodeSelf(e *codec1978.Encoder) {
}
} else {
z.EncSendContainerState(codecSelfer_containerMapKey1234)
r.EncodeString(codecSelferC_UTF81234, string("VolumeStatsAggPeriod"))
r.EncodeString(codecSelferC_UTF81234, string("volumeStatsAggPeriod"))
z.EncSendContainerState(codecSelfer_containerMapValue1234)
yy149 := &x.VolumeStatsAggPeriod
yym150 := z.EncBinary()
@@ -3190,7 +3190,7 @@ func (x *KubeletConfiguration) codecDecodeSelfFromMap(l int, d *codec1978.Decode
} else {
x.LowDiskSpaceThresholdMB = int(r.DecodeInt(codecSelferBitsize1234))
}
case "VolumeStatsAggPeriod":
case "volumeStatsAggPeriod":
if r.TryDecodeAsNil() {
x.VolumeStatsAggPeriod = pkg1_unversioned.Duration{}
} else {

View File

@@ -230,7 +230,7 @@ type KubeletConfiguration struct {
// be rejected.
LowDiskSpaceThresholdMB int `json:"lowDiskSpaceThresholdMB"`
// How frequently to calculate and cache volume disk usage for all pods
VolumeStatsAggPeriod unversioned.Duration `json:volumeStatsAggPeriod`
VolumeStatsAggPeriod unversioned.Duration `json:"volumeStatsAggPeriod"`
// networkPluginName is the name of the network plugin to be invoked for
// various events in kubelet/pod lifecycle
NetworkPluginName string `json:"networkPluginName"`

View File

@@ -206,7 +206,7 @@ func TestFlattenSuccess(t *testing.T) {
}
func ExampleMinifyAndShorten() {
func Example_minifyAndShorten() {
certFile, _ := ioutil.TempFile("", "")
defer os.Remove(certFile.Name())
keyFile, _ := ioutil.TempFile("", "")

View File

@@ -22,7 +22,7 @@ import (
"github.com/ghodss/yaml"
)
func ExampleEmptyConfig() {
func Example_emptyConfig() {
defaultConfig := NewConfig()
output, err := yaml.Marshal(defaultConfig)
@@ -39,7 +39,7 @@ func ExampleEmptyConfig() {
// users: {}
}
func ExampleOfOptionsConfig() {
func Example_ofOptionsConfig() {
defaultConfig := NewConfig()
defaultConfig.Preferences.Colors = true
defaultConfig.Clusters["alfa"] = &Cluster{

View File

@@ -376,7 +376,7 @@ func TestMigratingFileSourceMissingSkip(t *testing.T) {
}
}
func ExampleNoMergingOnExplicitPaths() {
func Example_noMergingOnExplicitPaths() {
commandLineFile, _ := ioutil.TempFile("", "")
defer os.Remove(commandLineFile.Name())
envVarFile, _ := ioutil.TempFile("", "")
@@ -423,7 +423,7 @@ func ExampleNoMergingOnExplicitPaths() {
// token: red-token
}
func ExampleMergingSomeWithConflict() {
func Example_mergingSomeWithConflict() {
commandLineFile, _ := ioutil.TempFile("", "")
defer os.Remove(commandLineFile.Name())
envVarFile, _ := ioutil.TempFile("", "")
@@ -476,7 +476,7 @@ func ExampleMergingSomeWithConflict() {
// token: yellow-token
}
func ExampleMergingEverythingNoConflicts() {
func Example_mergingEverythingNoConflicts() {
commandLineFile, _ := ioutil.TempFile("", "")
defer os.Remove(commandLineFile.Name())
envVarFile, _ := ioutil.TempFile("", "")

View File

@@ -97,8 +97,6 @@ func ObjectReaction(o ObjectRetriever, mapper meta.RESTMapper) ReactionFunc {
default:
return false, nil, fmt.Errorf("no reaction implemented for %s", action)
}
return true, nil, nil
}
}

View File

@@ -104,7 +104,7 @@ func newInformer(controller *HorizontalController, resyncPeriod time.Duration) (
func NewHorizontalController(evtNamespacer unversionedcore.EventsGetter, scaleNamespacer unversionedextensions.ScalesGetter, hpaNamespacer unversionedextensions.HorizontalPodAutoscalersGetter, metricsClient metrics.MetricsClient, resyncPeriod time.Duration) *HorizontalController {
broadcaster := record.NewBroadcaster()
broadcaster.StartRecordingToSink(&unversionedcore.EventSinkImpl{evtNamespacer.Events("")})
broadcaster.StartRecordingToSink(&unversionedcore.EventSinkImpl{Interface: evtNamespacer.Events("")})
recorder := broadcaster.NewRecorder(api.EventSource{Component: "horizontal-pod-autoscaler"})
controller := &HorizontalController{

View File

@@ -333,7 +333,7 @@ func (tc *testCase) runTest(t *testing.T) {
metricsClient := metrics.NewHeapsterMetricsClient(testClient, metrics.DefaultHeapsterNamespace, metrics.DefaultHeapsterScheme, metrics.DefaultHeapsterService, metrics.DefaultHeapsterPort)
broadcaster := record.NewBroadcasterForTests(0)
broadcaster.StartRecordingToSink(&unversionedcore.EventSinkImpl{testClient.Core().Events("")})
broadcaster.StartRecordingToSink(&unversionedcore.EventSinkImpl{Interface: testClient.Core().Events("")})
recorder := broadcaster.NewRecorder(api.EventSource{Component: "horizontal-pod-autoscaler"})
hpaController := &HorizontalController{

View File

@@ -344,7 +344,7 @@ func stringBody(body string) io.ReadCloser {
// }
//}
func ExamplePrintReplicationControllerWithNamespace() {
func Example_printReplicationControllerWithNamespace() {
f, tf, codec := NewAPIFactory()
tf.Printer = kubectl.NewHumanReadablePrinter(false, true, false, false, false, false, []string{})
tf.Client = &fake.RESTClient{
@@ -390,7 +390,7 @@ func ExamplePrintReplicationControllerWithNamespace() {
// beep foo 1 1 10y
}
func ExamplePrintMultiContainersReplicationControllerWithWide() {
func Example_printMultiContainersReplicationControllerWithWide() {
f, tf, codec := NewAPIFactory()
tf.Printer = kubectl.NewHumanReadablePrinter(false, false, true, false, false, false, []string{})
tf.Client = &fake.RESTClient{
@@ -439,7 +439,7 @@ func ExamplePrintMultiContainersReplicationControllerWithWide() {
// foo 1 1 10y foo,foo2 someimage,someimage2 foo=bar
}
func ExamplePrintReplicationController() {
func Example_printReplicationController() {
f, tf, codec := NewAPIFactory()
tf.Printer = kubectl.NewHumanReadablePrinter(false, false, false, false, false, false, []string{})
tf.Client = &fake.RESTClient{
@@ -488,7 +488,7 @@ func ExamplePrintReplicationController() {
// foo 1 1 10y
}
func ExamplePrintPodWithWideFormat() {
func Example_printPodWithWideFormat() {
f, tf, codec := NewAPIFactory()
tf.Printer = kubectl.NewHumanReadablePrinter(false, false, true, false, false, false, []string{})
tf.Client = &fake.RESTClient{
@@ -524,7 +524,7 @@ func ExamplePrintPodWithWideFormat() {
// test1 1/2 podPhase 6 10y kubernetes-minion-abcd
}
func ExamplePrintPodWithShowLabels() {
func Example_printPodWithShowLabels() {
f, tf, codec := NewAPIFactory()
tf.Printer = kubectl.NewHumanReadablePrinter(false, false, false, false, true, false, []string{})
tf.Client = &fake.RESTClient{
@@ -656,7 +656,7 @@ func newAllPhasePodList() *api.PodList {
}
}
func ExamplePrintPodHideTerminated() {
func Example_printPodHideTerminated() {
f, tf, codec := NewAPIFactory()
tf.Printer = kubectl.NewHumanReadablePrinter(false, false, false, false, false, false, []string{})
tf.Client = &fake.RESTClient{
@@ -677,7 +677,7 @@ func ExamplePrintPodHideTerminated() {
// test5 1/2 Unknown 6 10y
}
func ExamplePrintPodShowAll() {
func Example_printPodShowAll() {
f, tf, codec := NewAPIFactory()
tf.Printer = kubectl.NewHumanReadablePrinter(false, false, false, true, false, false, []string{})
tf.Client = &fake.RESTClient{
@@ -700,7 +700,7 @@ func ExamplePrintPodShowAll() {
// test5 1/2 Unknown 6 10y
}
func ExamplePrintServiceWithNamespacesAndLabels() {
func Example_printServiceWithNamespacesAndLabels() {
f, tf, codec := NewAPIFactory()
tf.Printer = kubectl.NewHumanReadablePrinter(false, true, false, false, false, false, []string{"l1"})
tf.Client = &fake.RESTClient{

View File

@@ -44,7 +44,7 @@ func newRedFederalCowHammerConfig() clientcmdapi.Config {
}
}
func ExampleView() {
func Example_view() {
expectedConfig := newRedFederalCowHammerConfig()
test := configCommandTest{
args: []string{"view"},

View File

@@ -415,14 +415,14 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
// TODO(madhusudancs): Make this smarter by admitting MatchExpressions with Equals
// operator, DoubleEquals operator and In operator with only one element in the set.
if len(t.Spec.Selector.MatchExpressions) > 0 {
return "", fmt.Errorf("couldn't convert expressions - \"%+v\" to map-based selector format")
return "", fmt.Errorf("couldn't convert expressions - \"%+v\" to map-based selector format", t.Spec.Selector.MatchExpressions)
}
return kubectl.MakeLabels(t.Spec.Selector.MatchLabels), nil
case *extensions.ReplicaSet:
// TODO(madhusudancs): Make this smarter by admitting MatchExpressions with Equals
// operator, DoubleEquals operator and In operator with only one element in the set.
if len(t.Spec.Selector.MatchExpressions) > 0 {
return "", fmt.Errorf("couldn't convert expressions - \"%+v\" to map-based selector format")
return "", fmt.Errorf("couldn't convert expressions - \"%+v\" to map-based selector format", t.Spec.Selector.MatchExpressions)
}
return kubectl.MakeLabels(t.Spec.Selector.MatchLabels), nil
default:

View File

@@ -56,10 +56,10 @@ import (
)
// setUp is a convience function for setting up for (most) tests.
func setUp(t *testing.T) (Master, *etcdtesting.EtcdTestServer, Config, *assert.Assertions) {
func setUp(t *testing.T) (*Master, *etcdtesting.EtcdTestServer, Config, *assert.Assertions) {
server := etcdtesting.NewEtcdTestClientServer(t)
master := Master{
master := &Master{
GenericAPIServer: &genericapiserver.GenericAPIServer{},
}
config := Config{

View File

@@ -42,7 +42,7 @@ type FooList struct {
unversioned.TypeMeta `json:",inline"`
unversioned.ListMeta `json:"metadata,omitempty" description:"standard list metadata; see http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#metadata"`
items []Foo `json:"items"`
Items []Foo `json:"items"`
}
func TestCodec(t *testing.T) {

View File

@@ -24,9 +24,9 @@ import (
)
type encodable struct {
e Encoder `json:"-"`
E Encoder `json:"-"`
obj Object
versions []unversioned.GroupVersion `json:"-"`
versions []unversioned.GroupVersion
}
func (e encodable) GetObjectKind() unversioned.ObjectKind { return e.obj.GetObjectKind() }
@@ -47,7 +47,7 @@ func (re encodable) UnmarshalJSON(in []byte) error {
// Marshal may get called on pointers or values, so implement MarshalJSON on value.
// http://stackoverflow.com/questions/21390979/custom-marshaljson-never-gets-called-in-go
func (re encodable) MarshalJSON() ([]byte, error) {
return Encode(re.e, re.obj)
return Encode(re.E, re.obj)
}
// NewEncodableList creates an object that will be encoded with the provided codec on demand.

View File

@@ -21,7 +21,7 @@ import (
"os"
)
func ExampleTrailingNewline() {
func Example_trailingNewline() {
ld := NewLineDelimiter(os.Stdout, "|")
defer ld.Flush()
fmt.Fprint(ld, " Hello \n World \n")
@@ -30,7 +30,7 @@ func ExampleTrailingNewline() {
// | World |
// ||
}
func ExampleNoTrailingNewline() {
func Example_noTrailingNewline() {
ld := NewLineDelimiter(os.Stdout, "|")
defer ld.Flush()
fmt.Fprint(ld, " Hello \n World ")

View File

@@ -31,8 +31,8 @@ import (
const pluginName = "kubernetes.io/flocker"
func newInitializedVolumePlugMgr(t *testing.T) (volume.VolumePluginMgr, string) {
plugMgr := volume.VolumePluginMgr{}
func newInitializedVolumePlugMgr(t *testing.T) (*volume.VolumePluginMgr, string) {
plugMgr := &volume.VolumePluginMgr{}
dir, err := utiltesting.MkTmpdir("flocker")
assert.NoError(t, err)
plugMgr.InitPlugins(ProbeVolumePlugins(), volumetest.NewFakeVolumeHost(dir, nil, nil))