From 519b0acb32514f08a652ca69471f398f333980f1 Mon Sep 17 00:00:00 2001 From: Jiayu Liu Date: Wed, 3 Jan 2018 11:38:29 +0800 Subject: [PATCH] Fix travis build errors due to lint issues (#257) * fixes #256 travis build failures * apply goimports -w to generated files to fix a bunch of lint issues. * There's no good way to tell whether a file was generated. a better way is to ensure that all files and newly submitted ones are goimported. also from now on I think it is better to enforce that even generated code are pre-goimported. * I didn't fix all the lint warnings because I am afraid of changing any code other than using goimport. I suggest that the original author do the changes instead. --- linter_config.json | 6 ++++- pkg/apis/tensorflow/helper/helpers.go | 7 +++--- pkg/apis/tensorflow/helper/helpers_test.go | 4 ++-- pkg/apis/tensorflow/v1alpha1/defaults.go | 3 --- pkg/apis/tensorflow/v1alpha1/register.go | 24 +++++++++---------- pkg/apis/tensorflow/v1alpha1/types.go | 13 +++++----- .../v1alpha1/zz_generated.deepcopy.go | 3 ++- pkg/apis/tensorflow/validation/validation.go | 5 ++-- .../clientset/versioned/fake/register.go | 9 ++++--- .../clientset/versioned/scheme/register.go | 5 ++-- .../informers/externalversions/factory.go | 7 +++--- .../informers/externalversions/generic.go | 1 + .../internalinterfaces/factory_interfaces.go | 3 ++- .../tensorflow/v1alpha1/tfjob.go | 3 ++- 14 files changed, 52 insertions(+), 41 deletions(-) diff --git a/linter_config.json b/linter_config.json index 3c435bc839..aa5852108f 100644 --- a/linter_config.json +++ b/linter_config.json @@ -19,7 +19,11 @@ "Aggregate": true, "WarnUnmatchedNolint": true, "LineLength": 240, - "Exclude": ["comment or be unexported", "comment on exported"], + "Exclude": [ + "redundant return statement", + "comment or be unexported", + "comment on exported" + ], "Deadline": "300s", "Skip": ["bin", "py"] } diff --git a/pkg/apis/tensorflow/helper/helpers.go b/pkg/apis/tensorflow/helper/helpers.go index 6b0a64e71c..d084085f0d 100644 --- a/pkg/apis/tensorflow/helper/helpers.go +++ b/pkg/apis/tensorflow/helper/helpers.go @@ -1,11 +1,12 @@ package helper import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - tfv1 "github.com/tensorflow/k8s/pkg/apis/tensorflow/v1alpha1" "fmt" - "k8s.io/api/core/v1" + + tfv1 "github.com/tensorflow/k8s/pkg/apis/tensorflow/v1alpha1" "github.com/tensorflow/k8s/pkg/util" + "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) // AsOwner make OwnerReference according to the parameter diff --git a/pkg/apis/tensorflow/helper/helpers_test.go b/pkg/apis/tensorflow/helper/helpers_test.go index cc13aa4c41..720e749301 100644 --- a/pkg/apis/tensorflow/helper/helpers_test.go +++ b/pkg/apis/tensorflow/helper/helpers_test.go @@ -5,10 +5,10 @@ import ( "testing" "github.com/gogo/protobuf/proto" + tfv1 "github.com/tensorflow/k8s/pkg/apis/tensorflow/v1alpha1" "github.com/tensorflow/k8s/pkg/util" - "k8s.io/apimachinery/pkg/api/resource" "k8s.io/api/core/v1" - tfv1 "github.com/tensorflow/k8s/pkg/apis/tensorflow/v1alpha1" + "k8s.io/apimachinery/pkg/api/resource" ) func TestAddAccelertor(t *testing.T) { diff --git a/pkg/apis/tensorflow/v1alpha1/defaults.go b/pkg/apis/tensorflow/v1alpha1/defaults.go index 0035085c1c..23c1a7c781 100644 --- a/pkg/apis/tensorflow/v1alpha1/defaults.go +++ b/pkg/apis/tensorflow/v1alpha1/defaults.go @@ -6,12 +6,10 @@ import ( "k8s.io/apimachinery/pkg/runtime" ) - func addDefaultingFuncs(scheme *runtime.Scheme) error { return RegisterDefaults(scheme) } - // SetDefaults_TfJob sets any unspecified values to defaults func SetDefaults_TfJob(obj *TfJob) { c := &obj.Spec @@ -71,4 +69,3 @@ func setDefault_PSPodTemplateSpec(r *TfReplicaSpec, tfImage string) { }, } } - diff --git a/pkg/apis/tensorflow/v1alpha1/register.go b/pkg/apis/tensorflow/v1alpha1/register.go index d8cc7a4141..bc5f05adec 100644 --- a/pkg/apis/tensorflow/v1alpha1/register.go +++ b/pkg/apis/tensorflow/v1alpha1/register.go @@ -1,14 +1,14 @@ package v1alpha1 import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" ) var ( - SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) - AddToScheme = SchemeBuilder.AddToScheme + SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) + AddToScheme = SchemeBuilder.AddToScheme ) // GroupName is the group name use in this package @@ -19,16 +19,16 @@ var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: CRDVersi // Resource takes an unqualified resource and returns a Group-qualified GroupResource. func Resource(resource string) schema.GroupResource { - return SchemeGroupVersion.WithResource(resource).GroupResource() + return SchemeGroupVersion.WithResource(resource).GroupResource() } // addKnownTypes adds the set of types defined in this package to the supplied scheme. func addKnownTypes(scheme *runtime.Scheme) error { - scheme.AddKnownTypes(SchemeGroupVersion, - &TfJob{}, - &TfJobList{}, - ) - metav1.AddToGroupVersion(scheme, SchemeGroupVersion) + scheme.AddKnownTypes(SchemeGroupVersion, + &TfJob{}, + &TfJobList{}, + ) + metav1.AddToGroupVersion(scheme, SchemeGroupVersion) - return nil + return nil } diff --git a/pkg/apis/tensorflow/v1alpha1/types.go b/pkg/apis/tensorflow/v1alpha1/types.go index 97c52840e8..579fb0e095 100644 --- a/pkg/apis/tensorflow/v1alpha1/types.go +++ b/pkg/apis/tensorflow/v1alpha1/types.go @@ -1,8 +1,8 @@ package v1alpha1 import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) const ( @@ -24,10 +24,10 @@ const ( // TFJob describes tfjob info type TfJob struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - Spec TfJobSpec `json:"spec"` - Status TfJobStatus `json:"status"` + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + Spec TfJobSpec `json:"spec"` + Status TfJobStatus `json:"status"` } type TfJobSpec struct { @@ -58,7 +58,6 @@ type ChiefSpec struct { ReplicaIndex int `json:"replicaIndex"` } - // TfReplicaType determines how a set of TF processes are handled. type TfReplicaType string @@ -87,7 +86,7 @@ type TfReplicaSpec struct { Replicas *int32 `json:"replicas,omitempty" protobuf:"varint,1,opt,name=replicas"` Template *v1.PodTemplateSpec `json:"template,omitempty" protobuf:"bytes,3,opt,name=template"` // TfPort is the port to use for TF services. - TfPort *int32 `json:"tfPort,omitempty" protobuf:"varint,1,opt,name=tfPort"` + TfPort *int32 `json:"tfPort,omitempty" protobuf:"varint,1,opt,name=tfPort"` TfReplicaType `json:"tfReplicaType"` // IsDefaultPS denotes if the parameter server should use the default grpc_tensorflow_server IsDefaultPS bool diff --git a/pkg/apis/tensorflow/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/tensorflow/v1alpha1/zz_generated.deepcopy.go index ee7862383c..2c98bb3872 100644 --- a/pkg/apis/tensorflow/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/tensorflow/v1alpha1/zz_generated.deepcopy.go @@ -21,10 +21,11 @@ limitations under the License. package v1alpha1 import ( + reflect "reflect" + v1 "k8s.io/api/core/v1" conversion "k8s.io/apimachinery/pkg/conversion" runtime "k8s.io/apimachinery/pkg/runtime" - reflect "reflect" ) func init() { diff --git a/pkg/apis/tensorflow/validation/validation.go b/pkg/apis/tensorflow/validation/validation.go index c575bfeb26..da712aef23 100644 --- a/pkg/apis/tensorflow/validation/validation.go +++ b/pkg/apis/tensorflow/validation/validation.go @@ -1,10 +1,11 @@ package validation import ( + "errors" + "fmt" + tfv1 "github.com/tensorflow/k8s/pkg/apis/tensorflow/v1alpha1" "github.com/tensorflow/k8s/pkg/util" - "fmt" - "errors" ) // ValidateTfJobSpec checks that the TfJobSpec is valid. diff --git a/pkg/client/clientset/versioned/fake/register.go b/pkg/client/clientset/versioned/fake/register.go index 877d2d50a6..0a3197b8a1 100644 --- a/pkg/client/clientset/versioned/fake/register.go +++ b/pkg/client/clientset/versioned/fake/register.go @@ -26,7 +26,9 @@ import ( var scheme = runtime.NewScheme() var codecs = serializer.NewCodecFactory(scheme) -var parameterCodec = runtime.NewParameterCodec(scheme) + +// TODO: unused +// var parameterCodec = runtime.NewParameterCodec(scheme) func init() { v1.AddToGroupVersion(scheme, schema.GroupVersion{Version: "v1"}) @@ -48,6 +50,7 @@ func init() { // After this, RawExtensions in Kubernetes types will serialize kube-aggregator types // correctly. func AddToScheme(scheme *runtime.Scheme) { - tensorflowv1alpha1.AddToScheme(scheme) - + if err := tensorflowv1alpha1.AddToScheme(scheme); err != nil { + panic(err) + } } diff --git a/pkg/client/clientset/versioned/scheme/register.go b/pkg/client/clientset/versioned/scheme/register.go index 69e6d17383..793c2717e3 100644 --- a/pkg/client/clientset/versioned/scheme/register.go +++ b/pkg/client/clientset/versioned/scheme/register.go @@ -48,6 +48,7 @@ func init() { // After this, RawExtensions in Kubernetes types will serialize kube-aggregator types // correctly. func AddToScheme(scheme *runtime.Scheme) { - tensorflowv1alpha1.AddToScheme(scheme) - + if err := tensorflowv1alpha1.AddToScheme(scheme); err != nil { + panic(err) + } } diff --git a/pkg/client/informers/externalversions/factory.go b/pkg/client/informers/externalversions/factory.go index 6f55275412..83fc44c01a 100644 --- a/pkg/client/informers/externalversions/factory.go +++ b/pkg/client/informers/externalversions/factory.go @@ -19,15 +19,16 @@ limitations under the License. package externalversions import ( + reflect "reflect" + sync "sync" + time "time" + versioned "github.com/tensorflow/k8s/pkg/client/clientset/versioned" internalinterfaces "github.com/tensorflow/k8s/pkg/client/informers/externalversions/internalinterfaces" tensorflow "github.com/tensorflow/k8s/pkg/client/informers/externalversions/tensorflow" runtime "k8s.io/apimachinery/pkg/runtime" schema "k8s.io/apimachinery/pkg/runtime/schema" cache "k8s.io/client-go/tools/cache" - reflect "reflect" - sync "sync" - time "time" ) type sharedInformerFactory struct { diff --git a/pkg/client/informers/externalversions/generic.go b/pkg/client/informers/externalversions/generic.go index 983d3cf671..3ba96600ee 100644 --- a/pkg/client/informers/externalversions/generic.go +++ b/pkg/client/informers/externalversions/generic.go @@ -20,6 +20,7 @@ package externalversions import ( "fmt" + v1alpha1 "github.com/tensorflow/k8s/pkg/apis/tensorflow/v1alpha1" schema "k8s.io/apimachinery/pkg/runtime/schema" cache "k8s.io/client-go/tools/cache" diff --git a/pkg/client/informers/externalversions/internalinterfaces/factory_interfaces.go b/pkg/client/informers/externalversions/internalinterfaces/factory_interfaces.go index b6e6bee39c..07c497a944 100644 --- a/pkg/client/informers/externalversions/internalinterfaces/factory_interfaces.go +++ b/pkg/client/informers/externalversions/internalinterfaces/factory_interfaces.go @@ -19,10 +19,11 @@ limitations under the License. package internalinterfaces import ( + time "time" + versioned "github.com/tensorflow/k8s/pkg/client/clientset/versioned" runtime "k8s.io/apimachinery/pkg/runtime" cache "k8s.io/client-go/tools/cache" - time "time" ) type NewInformerFunc func(versioned.Interface, time.Duration) cache.SharedIndexInformer diff --git a/pkg/client/informers/externalversions/tensorflow/v1alpha1/tfjob.go b/pkg/client/informers/externalversions/tensorflow/v1alpha1/tfjob.go index 0931f3a819..a1514ecf2d 100644 --- a/pkg/client/informers/externalversions/tensorflow/v1alpha1/tfjob.go +++ b/pkg/client/informers/externalversions/tensorflow/v1alpha1/tfjob.go @@ -19,6 +19,8 @@ limitations under the License. package v1alpha1 import ( + time "time" + tensorflow_v1alpha1 "github.com/tensorflow/k8s/pkg/apis/tensorflow/v1alpha1" versioned "github.com/tensorflow/k8s/pkg/client/clientset/versioned" internalinterfaces "github.com/tensorflow/k8s/pkg/client/informers/externalversions/internalinterfaces" @@ -27,7 +29,6 @@ import ( runtime "k8s.io/apimachinery/pkg/runtime" watch "k8s.io/apimachinery/pkg/watch" cache "k8s.io/client-go/tools/cache" - time "time" ) // TfJobInformer provides access to a shared informer and lister for