Skip to content

Commit

Permalink
Lint: fix godot issue
Browse files Browse the repository at this point in the history
Signed-off-by: Xiang Dai <[email protected]>
  • Loading branch information
daixiang0 committed May 23, 2020
1 parent 8247d11 commit 2e180cc
Show file tree
Hide file tree
Showing 62 changed files with 329 additions and 307 deletions.
16 changes: 16 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,27 @@ issues:
linters:
- gomnd
- dupl
<<<<<<< HEAD
- path: v1beta1
=======
- path: pkg/apis/scheduling/v1beta1/conversion.go
linters:
- golint
- path: clientset
linters:
- godot
- path: informers
linters:
- godot
- path: v1alpha1
linters:
- godot
- path: generated
linters:
- golint
- deadcode
- path: fake
linters:
- golint
- deadcode
- godot
4 changes: 2 additions & 2 deletions pkg/apis/batch/v1alpha1/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ type JobState struct {
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty" protobuf:"bytes,4,opt,name=lastTransitionTime"`
}

// JobStatus represents the current status of a Job
// JobStatus represents the current status of a Job.
type JobStatus struct {
// Current state of Job.
// +optional
Expand Down Expand Up @@ -269,7 +269,7 @@ type JobStatus struct {

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// JobList defines the list of jobs
// JobList defines the list of jobs.
type JobList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
Expand Down
18 changes: 10 additions & 8 deletions pkg/apis/helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ var CommandKind = vcbus.SchemeGroupVersion.WithKind("Command")
// V1beta1QueueKind is queue kind with v1alpha2 version.
var V1beta1QueueKind = schedulerv1beta1.SchemeGroupVersion.WithKind("Queue")

// CreateOrUpdateConfigMap :
// 1. creates config map resource if not present
// 2. updates config map is necessary
/*
CreateOrUpdateConfigMap :
1. creates config map resource if not present
2. updates config map is necessary.
*/
func CreateOrUpdateConfigMap(job *vcbatch.Job, kubeClients kubernetes.Interface, data map[string]string, cmName string) error {
// If ConfigMap does not exist, create one for Job.
cmOld, err := kubeClients.CoreV1().ConfigMaps(job.Namespace).Get(cmName, metav1.GetOptions{})
Expand Down Expand Up @@ -97,7 +99,7 @@ func CreateOrUpdateConfigMap(job *vcbatch.Job, kubeClients kubernetes.Interface,
return nil
}

// CreateSecret create secret
// CreateSecret create secret.
func CreateSecret(job *vcbatch.Job, kubeClients kubernetes.Interface, data map[string][]byte, secretName string) error {
secret := &v1.Secret{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -118,7 +120,7 @@ func CreateSecret(job *vcbatch.Job, kubeClients kubernetes.Interface, data map[s
return err
}

// DeleteConfigmap deletes the config map resource
// DeleteConfigmap deletes the config map resource.
func DeleteConfigmap(job *vcbatch.Job, kubeClients kubernetes.Interface, cmName string) error {
if _, err := kubeClients.CoreV1().ConfigMaps(job.Namespace).Get(cmName, metav1.GetOptions{}); err != nil {
if !apierrors.IsNotFound(err) {
Expand All @@ -141,7 +143,7 @@ func DeleteConfigmap(job *vcbatch.Job, kubeClients kubernetes.Interface, cmName
return nil
}

// DeleteSecret delete secret
// DeleteSecret delete secret.
func DeleteSecret(job *vcbatch.Job, kubeClients kubernetes.Interface, secretName string) error {
err := kubeClients.CoreV1().Secrets(job.Namespace).Delete(secretName, nil)
if err != nil && true == apierrors.IsNotFound(err) {
Expand All @@ -151,7 +153,7 @@ func DeleteSecret(job *vcbatch.Job, kubeClients kubernetes.Interface, secretName
return err
}

// GeneratePodgroupName generate podgroup name of normal pod
// GeneratePodgroupName generate podgroup name of normal pod.
func GeneratePodgroupName(pod *v1.Pod) string {
pgName := vcbatch.PodgroupNamePrefix

Expand All @@ -169,7 +171,7 @@ func GeneratePodgroupName(pod *v1.Pod) string {
return pgName
}

// StartHealthz register healthz interface
// StartHealthz register healthz interface.
func StartHealthz(healthzBindAddress, name string) error {
listener, err := net.Listen("tcp", healthzBindAddress)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/scheduling/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
// PodGroupPhase is the phase of a pod group at the current time.
type PodGroupPhase string

// QueueState is state type of queue
// QueueState is state type of queue.
type QueueState string

const (
Expand Down Expand Up @@ -113,7 +113,7 @@ const (
NotEnoughPodsReason string = "NotEnoughTasks"
)

// QueueEvent represent the phase of queue
// QueueEvent represent the phase of queue.
type QueueEvent string

const (
Expand Down
4 changes: 2 additions & 2 deletions pkg/cli/job/suspend.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ type suspendFlags struct {

var suspendJobFlags = &suspendFlags{}

// InitSuspendFlags init suspend related flags
// InitSuspendFlags init suspend related flags.
func InitSuspendFlags(cmd *cobra.Command) {
initFlags(cmd, &suspendJobFlags.commonFlags)

cmd.Flags().StringVarP(&suspendJobFlags.Namespace, "namespace", "n", "default", "the namespace of job")
cmd.Flags().StringVarP(&suspendJobFlags.JobName, "name", "N", "", "the name of job")
}

// SuspendJob suspends the job
// SuspendJob suspends the job.
func SuspendJob() error {
config, err := util.BuildConfig(suspendJobFlags.Master, suspendJobFlags.Kubeconfig)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/job/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func translateTimestampSince(timestamp metav1.Time) string {
return HumanDuration(time.Since(timestamp.Time))
}

// HumanDuration translate time.Duration to human readable time string
// HumanDuration translate time.Duration to human readable time string.
func HumanDuration(d time.Duration) string {
// Allow deviation no more than 2 seconds(excluded) to tolerate machine time
// inconsistence, it can be considered as almost now.
Expand Down
14 changes: 7 additions & 7 deletions pkg/cli/job/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type viewFlags struct {
JobName string
}

// level of print indent
// level of print indent.
const (
Level0 = iota
Level1
Expand All @@ -51,15 +51,15 @@ const (

var viewJobFlags = &viewFlags{}

// InitViewFlags init the view command flags
// InitViewFlags init the view command flags.
func InitViewFlags(cmd *cobra.Command) {
initFlags(cmd, &viewJobFlags.commonFlags)

cmd.Flags().StringVarP(&viewJobFlags.Namespace, "namespace", "n", "default", "the namespace of job")
cmd.Flags().StringVarP(&viewJobFlags.JobName, "name", "N", "", "the name of job")
}

// ViewJob gives full details of the job
// ViewJob gives full details of the job.
func ViewJob() error {
config, err := util.BuildConfig(viewJobFlags.Master, viewJobFlags.Kubeconfig)
if err != nil {
Expand All @@ -84,7 +84,7 @@ func ViewJob() error {
return nil
}

// PrintJobInfo print the job detailed info into writer
// PrintJobInfo print the job detailed info into writer.
func PrintJobInfo(job *v1alpha1.Job, writer io.Writer) {
WriteLine(writer, Level0, "Name: \t%s\n", job.Name)
WriteLine(writer, Level0, "Namespace: \t%s\n", job.Namespace)
Expand Down Expand Up @@ -198,7 +198,7 @@ func PrintJobInfo(job *v1alpha1.Job, writer io.Writer) {
}
}

// PrintEvents print event info to writer
// PrintEvents print event info to writer.
func PrintEvents(events []coreV1.Event, writer io.Writer) {
if len(events) > 0 {
WriteLine(writer, Level0, "%s:\n%-15s\t%-40s\t%-30s\t%-40s\t%s\n", "Events", "Type", "Reason", "Age", "Form", "Message")
Expand Down Expand Up @@ -228,7 +228,7 @@ func PrintEvents(events []coreV1.Event, writer io.Writer) {

}

// GetEvents get the job event by config
// GetEvents get the job event by config.
func GetEvents(config *rest.Config, job *v1alpha1.Job) []coreV1.Event {
kubernetes, err := kubernetes.NewForConfig(config)
if err != nil {
Expand All @@ -245,7 +245,7 @@ func GetEvents(config *rest.Config, job *v1alpha1.Job) []coreV1.Event {
return jobEvents
}

// WriteLine write lines with specified indent
// WriteLine write lines with specified indent.
func WriteLine(writer io.Writer, spaces int, content string, params ...interface{}) {
prefix := ""
for i := 0; i < spaces; i++ {
Expand Down
4 changes: 2 additions & 2 deletions pkg/cli/queue/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type createFlags struct {

var createQueueFlags = &createFlags{}

// InitCreateFlags is used to init all flags during queue creating
// InitCreateFlags is used to init all flags during queue creating.
func InitCreateFlags(cmd *cobra.Command) {
initFlags(cmd, &createQueueFlags.commonFlags)

Expand All @@ -46,7 +46,7 @@ func InitCreateFlags(cmd *cobra.Command) {
cmd.Flags().StringVarP(&createQueueFlags.State, "state", "S", "Open", "the state of queue")
}

// CreateQueue create queue
// CreateQueue create queue.
func CreateQueue() error {
config, err := buildConfig(createQueueFlags.Master, createQueueFlags.Kubeconfig)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/cli/queue/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ type deleteFlags struct {

var deleteQueueFlags = &deleteFlags{}

// InitDeleteFlags is used to init all flags during queue deleting
// InitDeleteFlags is used to init all flags during queue deleting.
func InitDeleteFlags(cmd *cobra.Command) {
initFlags(cmd, &deleteQueueFlags.commonFlags)

cmd.Flags().StringVarP(&deleteQueueFlags.Name, "name", "n", "", "the name of queue")
}

// DeleteQueue delete queue
// DeleteQueue delete queue.
func DeleteQueue() error {
config, err := buildConfig(deleteQueueFlags.Master, deleteQueueFlags.Kubeconfig)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions pkg/cli/queue/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ type getFlags struct {

var getQueueFlags = &getFlags{}

// InitGetFlags is used to init all flags
// InitGetFlags is used to init all flags.
func InitGetFlags(cmd *cobra.Command) {
initFlags(cmd, &getQueueFlags.commonFlags)

cmd.Flags().StringVarP(&getQueueFlags.Name, "name", "n", "", "the name of queue")

}

// GetQueue gets a queue
// GetQueue gets a queue.
func GetQueue() error {
config, err := buildConfig(getQueueFlags.Master, getQueueFlags.Kubeconfig)
if err != nil {
Expand All @@ -68,7 +68,7 @@ func GetQueue() error {
return nil
}

// PrintQueue prints queue information
// PrintQueue prints queue information.
func PrintQueue(queue *v1beta1.Queue, writer io.Writer) {
_, err := fmt.Fprintf(writer, "%-25s%-8s%-8s%-8s%-8s%-8s%-8s\n",
Name, Weight, State, Inqueue, Pending, Running, Unknown)
Expand Down
6 changes: 3 additions & 3 deletions pkg/cli/queue/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ const (

var listQueueFlags = &listFlags{}

// InitListFlags inits all flags
// InitListFlags inits all flags.
func InitListFlags(cmd *cobra.Command) {
initFlags(cmd, &listQueueFlags.commonFlags)
}

// ListQueue lists all the queue
// ListQueue lists all the queue.
func ListQueue() error {
config, err := buildConfig(listQueueFlags.Master, listQueueFlags.Kubeconfig)
if err != nil {
Expand All @@ -85,7 +85,7 @@ func ListQueue() error {
return nil
}

// PrintQueues prints queue information
// PrintQueues prints queue information.
func PrintQueues(queues *v1beta1.QueueList, writer io.Writer) {
_, err := fmt.Fprintf(writer, "%-25s%-8s%-8s%-8s%-8s%-8s%-8s\n",
Name, Weight, State, Inqueue, Pending, Running, Unknown)
Expand Down
4 changes: 2 additions & 2 deletions pkg/cli/queue/operate.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type operateFlags struct {

var operateQueueFlags = &operateFlags{}

// InitOperateFlags is used to init all flags during queue operating

func InitOperateFlags(cmd *cobra.Command) {
initFlags(cmd, &operateQueueFlags.commonFlags)

Expand All @@ -59,7 +59,7 @@ func InitOperateFlags(cmd *cobra.Command) {
"operate action to queue, valid actions are open, close, update")
}

// OperateQueue operates queue

func OperateQueue() error {
config, err := buildConfig(operateQueueFlags.Master, operateQueueFlags.Kubeconfig)
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions pkg/cli/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type CommonFlags struct {
Kubeconfig string
}

// InitFlags initializes the common flags for most command lines
// InitFlags initializes the common flags for most command lines.
func InitFlags(cmd *cobra.Command, cf *CommonFlags) {
cmd.Flags().StringVarP(&cf.Master, "master", "s", "", "the address of apiserver")

Expand All @@ -55,15 +55,15 @@ func InitFlags(cmd *cobra.Command, cf *CommonFlags) {
cmd.Flags().StringVarP(&cf.Kubeconfig, "kubeconfig", "k", kubeConfFile, "(optional) absolute path to the kubeconfig file")
}

// HomeDir gets the env $HOME
// HomeDir gets the env $HOME.
func HomeDir() string {
if h := os.Getenv("HOME"); h != "" {
return h
}
return os.Getenv("USERPROFILE") // windows
}

// BuildConfig builds the configure file for command lines
// BuildConfig builds the configure file for command lines.
func BuildConfig(master, kubeconfig string) (*rest.Config, error) {
return clientcmd.BuildConfigFromFlags(master, kubeconfig)
}
Expand Down Expand Up @@ -92,7 +92,7 @@ func PopulateResourceListV1(spec string) (v1.ResourceList, error) {
return result, nil
}

// CreateJobCommand executes a command such as resume/suspend
// CreateJobCommand executes a command such as resume/suspend.
func CreateJobCommand(config *rest.Config, ns, name string, action vcbus.Action) error {
jobClient := versioned.NewForConfigOrDie(config)
job, err := jobClient.BatchV1alpha1().Jobs(ns).Get(name, metav1.GetOptions{})
Expand Down Expand Up @@ -121,15 +121,15 @@ func CreateJobCommand(config *rest.Config, ns, name string, action vcbus.Action)
return nil
}

// TranslateTimestampSince translates the time stamp
// TranslateTimestampSince translates the time stamp.
func TranslateTimestampSince(timestamp metav1.Time) string {
if timestamp.IsZero() {
return "<unknown>"
}
return HumanDuration(time.Since(timestamp.Time))
}

// HumanDuration translate time.Duration to human readable time string
// HumanDuration translate time.Duration to human readable time string.
func HumanDuration(d time.Duration) string {
// Allow deviation no more than 2 seconds(excluded) to tolerate machine time
// inconsistence, it can be considered as almost now.
Expand Down
Loading

0 comments on commit 2e180cc

Please sign in to comment.