Skip to content

Commit

Permalink
fixed some golint warning (#486)
Browse files Browse the repository at this point in the history
* fixed some golint warning

* fixed some golint warning

* updated linter_config.json
  • Loading branch information
kayush2O6 authored and k8s-ci-robot committed Mar 23, 2018
1 parent 771c4f9 commit c7e3940
Show file tree
Hide file tree
Showing 26 changed files with 91 additions and 26 deletions.
3 changes: 3 additions & 0 deletions cmd/tf-operator/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ var (
retryPeriod = 3 * time.Second
)

// Run starts the tf-operator service
func Run(opt *options.ServerOption) error {

// Check if the -version flag was passed and, if so, print the version and exit.
Expand Down Expand Up @@ -127,6 +128,7 @@ func Run(opt *options.ServerOption) error {
return nil
}

// readControllerConfig reads the controller config file and maps it to controller config object
func readControllerConfig(controllerConfigFile string) *v1alpha1.ControllerConfig {
controllerConfig := &v1alpha1.ControllerConfig{}
if controllerConfigFile != "" {
Expand All @@ -147,6 +149,7 @@ func readControllerConfig(controllerConfigFile string) *v1alpha1.ControllerConfi
return controllerConfig
}

// createClients creates clients three clients for given client configuration
func createClients(config *rest.Config) (clientset.Interface, clientset.Interface, tfjobclient.Interface, error) {
kubeClient, err := clientset.NewForConfig(rest.AddUserAgent(config, "tfjob_operator"))
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion dashboard/backend/client/manager.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Client is a package handling authentication/communication with kubernetes API
// client is a package handling authentication/communication with kubernetes API
package client

import (
Expand All @@ -16,6 +16,7 @@ type ClientManager struct {
TFJobClient *versioned.Clientset
}

// init methods initiates the TFJob client for given cluster config
func (c *ClientManager) init() {
restCfg, err := k8sutil.GetClusterConfig()
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion linter_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
"comment or be unexported",
"comment on exported",
"pkg/apis/tensorflow/v1alpha1/zz_generated.deepcopy.go",
"pkg/apis/tensorflow/v1alpha1/zz_generated.defaults.go"
"pkg/apis/tensorflow/v1alpha1/zz_generated.defaults.go",
"pkg/apis/tensorflow/v1alpha1/defaults.go",
"pkg/apis/tensorflow/v1alpha1/defaults_test.go",
"pkg/apis/tensorflow/validation/validation_test.go"
],
"Deadline": "300s",
"Skip": ["pkg/client"]
Expand Down
4 changes: 3 additions & 1 deletion pkg/apis/tensorflow/helper/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func ConfigureAcceleratorsForTFJobSpec(c *tfv1.TFJobSpec, accelerators map[strin

lists := []v1.ResourceList{c.Resources.Limits, c.Resources.Requests}
for _, resources := range lists {
for name, _ := range resources {
for name := range resources {

if _, ok := accelerators[string(name)]; !ok {
continue
Expand Down Expand Up @@ -110,10 +110,12 @@ func Cleanup(c *tfv1.TFJobSpec) {
// We should have default container images so user doesn't have to provide these.
}

// CRDName returns the custom resource definition name which is combination of kind and group
func CRDName() string {
return fmt.Sprintf("%s.%s", tfv1.CRDKindPlural, tfv1.CRDGroup)
}

// scalingReason returns the reason for scaling the cluster size
func scalingReason(from, to int) string {
return fmt.Sprintf("Current cluster size: %d, desired cluster size: %d", from, to)
}
2 changes: 1 addition & 1 deletion pkg/apis/tensorflow/v1alpha1/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func addDefaultingFuncs(scheme *runtime.Scheme) error {
return RegisterDefaults(scheme)
}

// SetDefaults_TFJob sets any unspecified values to defaults
// SetDefaults_TFJob initializes any uninitialized values to default values
func SetDefaults_TFJob(obj *TFJob) {
c := &obj.Spec

Expand Down
1 change: 1 addition & 0 deletions pkg/apis/tensorflow/v1alpha1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
)

var (
// SchemaBuilder is an object of runtime.SchemaBuilder
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
AddToScheme = SchemeBuilder.AddToScheme
)
Expand Down
13 changes: 12 additions & 1 deletion pkg/apis/tensorflow/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type TFJob struct {
Status TFJobStatus `json:"status"`
}

// TFJobSpec structure for storing the TFJob specifications
type TFJobSpec struct {
// TODO(jlewi): Can we we get rid of this and use some value from Kubernetes or a random ide.
RuntimeId string
Expand All @@ -61,11 +62,13 @@ type TFJobSpec struct {
SchedulerName string `json:"schedulerName,omitempty"`
}

// TerminationPolicySpec structure for storing specifications for process termination
type TerminationPolicySpec struct {
// Chief policy waits for a particular process (which is the chief) to exit.
Chief *ChiefSpec `json:"chief,omitempty"`
}

// ChiefSpec structure storing the replica name and replica index
type ChiefSpec struct {
ReplicaName string `json:"replicaName"`
ReplicaIndex int `json:"replicaIndex"`
Expand All @@ -86,7 +89,7 @@ const (
)

// TODO(jlewi): We probably want to add a name field. This would allow us to have more than 1 type of each worker.
// This might be useful if you wanted to have a separate set of workers to do eval.
// // TFReplicaSpec might be useful if you wanted to have a separate set of workers to do eval.
type TFReplicaSpec struct {
// Replicas is the number of desired replicas.
// This is a pointer to distinguish between explicit zero and unspecified.
Expand All @@ -100,6 +103,7 @@ type TFReplicaSpec struct {
TFReplicaType `json:"tfReplicaType"`
}

// TFJobPhase is a enum to store the phase of tf job
type TFJobPhase string

const (
Expand All @@ -111,6 +115,7 @@ const (
TFJobPhaseDone TFJobPhase = "Done"
)

// State is a enum to store the state of tf job
type State string

const (
Expand All @@ -120,6 +125,7 @@ const (
StateFailed State = "Failed"
)

// TFJobStatus is a structure for storing the status of tf jobs
type TFJobStatus struct {
// Phase is the TFJob running phase
Phase TFJobPhase `json:"phase"`
Expand All @@ -132,6 +138,7 @@ type TFJobStatus struct {
ReplicaStatuses []*TFReplicaStatus `json:"replicaStatuses"`
}

// ReplicaState is a enum to store the status of replica
type ReplicaState string

const (
Expand All @@ -141,6 +148,7 @@ const (
ReplicaStateSucceeded ReplicaState = "Succeeded"
)

// TFReplicaStatus is a structure for storing the status of tf replica
type TFReplicaStatus struct {
TFReplicaType `json:"tf_replica_type"`

Expand All @@ -164,6 +172,7 @@ type TFJobList struct {
Items []TFJob `json:"items"`
}

// ControllerConfig is a structure for storing the controller configuration
type ControllerConfig struct {
// Accelerators is a map from the name of the accelerator to the config for that accelerator.
// This should match the value specified as a container limit.
Expand All @@ -182,11 +191,13 @@ type AcceleratorVolume struct {
MountPath string
}

// AcceleratorConfig represents accelerator volumes to be mounted into container along with environment variables.
type AcceleratorConfig struct {
Volumes []AcceleratorVolume
EnvVars []EnvironmentVariableConfig
}

// EnvironmentVariableConfig represents the environment variables and their values.
type EnvironmentVariableConfig struct {
Name string
Value string
Expand Down
3 changes: 1 addition & 2 deletions pkg/apis/tensorflow/v1alpha1/zz_generated.deepcopy.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,8 @@ func (in *TFJob) DeepCopy() *TFJob {
func (in *TFJob) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
} else {
return nil
}
return nil
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
Expand Down
4 changes: 3 additions & 1 deletion pkg/apis/tensorflow/v1alpha1/zz_generated.defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// This file was autogenerated by defaulter-gen. Do not edit it manually!
// This file was auto generated by defaulter-gen. Do not edit it manually!

package v1alpha1

Expand All @@ -33,10 +33,12 @@ func RegisterDefaults(scheme *runtime.Scheme) error {
return nil
}

// SetObjectDefaults_TFJob creates SetDefaultsTFJob object for a given TFJob
func SetObjectDefaults_TFJob(in *TFJob) {
SetDefaults_TFJob(in)
}

// SetObjectDefaults_TFJobList creates SetDefaultsTFJob object for each TFJob from given list of TFJobs
func SetObjectDefaults_TFJobList(in *TFJobList) {
for i := range in.Items {
a := &in.Items[i]
Expand Down
4 changes: 3 additions & 1 deletion pkg/client/clientset/versioned/clientset.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
flowcontrol "k8s.io/client-go/util/flowcontrol"
)

// Interface represents the combination of three interfaces Discovery, Kubeflow and Kubeflowv1alpha1
type Interface interface {
Discovery() discovery.DiscoveryInterface
KubeflowV1alpha1() kubeflowv1alpha1.KubeflowV1alpha1Interface
Expand All @@ -40,8 +41,9 @@ func (c *Clientset) KubeflowV1alpha1() kubeflowv1alpha1.KubeflowV1alpha1Interfac
return c.kubeflowV1alpha1
}

// Deprecated: Kubeflow retrieves the default version of KubeflowClient.
// Kubeflow retrieves the default version of KubeflowClient.
// Please explicitly pick a version.
// [DEPRECATED]
func (c *Clientset) Kubeflow() kubeflowv1alpha1.KubeflowV1alpha1Interface {
return c.kubeflowV1alpha1
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/clientset/versioned/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@

// This package is generated by client-gen with custom arguments.

// This package has the automatically generated clientset.
// Package versioned has the automatically generated clientset.
package versioned
1 change: 1 addition & 0 deletions pkg/client/clientset/versioned/fake/clientset_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type Clientset struct {
discovery *fakediscovery.FakeDiscovery
}

//Discovery retrieves the DiscoveryClient
func (c *Clientset) Discovery() discovery.DiscoveryInterface {
return c.discovery
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/clientset/versioned/fake/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@

// This package is generated by client-gen with custom arguments.

// This package has the automatically generated fake clientset.
// Package fake has the automatically generated fake clientset.
package fake
2 changes: 1 addition & 1 deletion pkg/client/clientset/versioned/scheme/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@

// This package is generated by client-gen with custom arguments.

// This package contains the scheme of the automatically generated clientset.
// Package scheme contains the scheme of the automatically generated clientset.
package scheme
7 changes: 7 additions & 0 deletions pkg/client/clientset/versioned/scheme/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,17 @@ import (
serializer "k8s.io/apimachinery/pkg/runtime/serializer"
)

// Scheme is exported variables of runtime class
var Scheme = runtime.NewScheme()

// Codecs is exported variables of serializer class
var Codecs = serializer.NewCodecFactory(Scheme)

// ParameterCodec is exported variables of runtime class
var ParameterCodec = runtime.NewParameterCodec(Scheme)


// init method adds the group version to scheme
func init() {
v1.AddToGroupVersion(Scheme, schema.GroupVersion{Version: "v1"})
AddToScheme(Scheme)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@

// This package is generated by client-gen with custom arguments.

// This package has the automatically generated typed clients.
// Package v1alpha1 has the automatically generated typed clients.
package v1alpha1
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ import (
testing "k8s.io/client-go/testing"
)

// FakeKubeflowV1alpha1 represents a fake structure for testing
type FakeKubeflowV1alpha1 struct {
*testing.Fake
}

// TFJobs returns a fake tf-job instance for testing
func (c *FakeKubeflowV1alpha1) TFJobs(namespace string) v1alpha1.TFJobInterface {
return &FakeTFJobs{c, namespace}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Package v1alpha1
package v1alpha1

// TFJobExpansion represents interface for supporting TFJob expansion
type TFJobExpansion interface{}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
rest "k8s.io/client-go/rest"
)

// KubeflowV1alpha1Interface represents interface for setting the REST client and TFJobsGetter
type KubeflowV1alpha1Interface interface {
RESTClient() rest.Interface
TFJobsGetter
Expand All @@ -30,6 +31,7 @@ type KubeflowV1alpha1Client struct {
restClient rest.Interface
}

// TFJobs returns current TFJobs for given namespace
func (c *KubeflowV1alpha1Client) TFJobs(namespace string) TFJobInterface {
return newTFJobs(c, namespace)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
time "time"
)

// NewInformerFunc a helping method for SharedInformerFactory interface
type NewInformerFunc func(versioned.Interface, time.Duration) cache.SharedIndexInformer

// SharedInformerFactory a small interface to allow for adding an informer without an import cycle
Expand Down
6 changes: 4 additions & 2 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const (
)

var (
// ErrVersionOutdated is a exported var to capture the error in apiserver
ErrVersionOutdated = errors.New("requested version is outdated in apiserver")

// IndexerInformer uses a delta queue, therefore for deletes we have to use this
Expand All @@ -59,6 +60,7 @@ var (
MaxJobBackOff = 360 * time.Second
)

// Controller is structure to manage various service clients
type Controller struct {
KubeClient kubernetes.Interface
TFJobClient tfjobclient.Interface
Expand All @@ -85,6 +87,7 @@ type Controller struct {
enableGangScheduling bool
}

// New method sets up service client handles and returns controller object
func New(kubeClient kubernetes.Interface, tfJobClient tfjobclient.Interface,
config tfv1alpha1.ControllerConfig, tfJobInformerFactory informers.SharedInformerFactory,
enableGangScheduling bool) (*Controller, error) {
Expand Down Expand Up @@ -254,9 +257,8 @@ func (c *Controller) syncTFJob(key string) (bool, error) {
// case we should forget about a job when the appropriate condition is reached.
if tfJob.Status.Phase == tfv1alpha1.TFJobPhaseCleanUp {
return true, nil
} else {
return false, nil
}
return false, nil

}

Expand Down
Loading

0 comments on commit c7e3940

Please sign in to comment.