From d87cc807c186a67aa9454f66e553bedb21c3829d Mon Sep 17 00:00:00 2001 From: SrinivasChilveri Date: Tue, 11 Jun 2019 23:32:51 +0530 Subject: [PATCH 1/2] Lint Fixes --- hack/.golint_failures | 10 ----- pkg/apis/batch/v1alpha1/doc.go | 1 + pkg/apis/batch/v1alpha1/job.go | 18 ++++++-- pkg/apis/batch/v1alpha1/labels.go | 14 ++++-- pkg/apis/batch/v1alpha1/register.go | 4 +- pkg/apis/bus/v1alpha1/doc.go | 1 + pkg/apis/bus/v1alpha1/register.go | 4 +- pkg/apis/bus/v1alpha1/types.go | 4 ++ pkg/apis/helpers/helpers.go | 11 ++++- pkg/cli/job/common.go | 1 + pkg/cli/job/delete.go | 2 + pkg/cli/job/list.go | 44 +++++++++++++------ pkg/cli/job/resume.go | 3 ++ pkg/cli/job/run.go | 3 ++ pkg/cli/job/suspend.go | 3 ++ pkg/cli/job/util.go | 1 + pkg/cli/job/view.go | 19 ++++++++ pkg/controllers/job/helpers/helpers.go | 7 ++- pkg/controllers/job/plugins/env/env.go | 1 + pkg/controllers/job/plugins/env/types.go | 3 ++ pkg/controllers/job/plugins/factory.go | 7 ++- .../job/plugins/interface/interface.go | 4 +- pkg/controllers/job/plugins/ssh/ssh.go | 1 + pkg/controllers/job/plugins/ssh/types.go | 16 +++++-- pkg/controllers/job/plugins/svc/svc.go | 7 +-- pkg/controllers/job/plugins/svc/types.go | 2 + 26 files changed, 146 insertions(+), 45 deletions(-) diff --git a/hack/.golint_failures b/hack/.golint_failures index 0ce0e14469..7ea2ff67b7 100644 --- a/hack/.golint_failures +++ b/hack/.golint_failures @@ -1,16 +1,6 @@ volcano.sh/volcano/pkg/admission -volcano.sh/volcano/pkg/apis/batch/v1alpha1 -volcano.sh/volcano/pkg/apis/bus/v1alpha1 -volcano.sh/volcano/pkg/apis/helpers -volcano.sh/volcano/pkg/cli/job volcano.sh/volcano/pkg/controllers/apis volcano.sh/volcano/pkg/controllers/cache volcano.sh/volcano/pkg/controllers/job -volcano.sh/volcano/pkg/controllers/job/helpers -volcano.sh/volcano/pkg/controllers/job/plugins -volcano.sh/volcano/pkg/controllers/job/plugins/env -volcano.sh/volcano/pkg/controllers/job/plugins/interface -volcano.sh/volcano/pkg/controllers/job/plugins/ssh -volcano.sh/volcano/pkg/controllers/job/plugins/svc volcano.sh/volcano/pkg/controllers/job/state volcano.sh/volcano/test/e2e diff --git a/pkg/apis/batch/v1alpha1/doc.go b/pkg/apis/batch/v1alpha1/doc.go index 1c873db349..890d2ecd95 100644 --- a/pkg/apis/batch/v1alpha1/doc.go +++ b/pkg/apis/batch/v1alpha1/doc.go @@ -15,4 +15,5 @@ limitations under the License. */ // +k8s:deepcopy-gen=package + package v1alpha1 diff --git a/pkg/apis/batch/v1alpha1/job.go b/pkg/apis/batch/v1alpha1/job.go index d636eabd2c..2ce3a28c00 100644 --- a/pkg/apis/batch/v1alpha1/job.go +++ b/pkg/apis/batch/v1alpha1/job.go @@ -23,6 +23,8 @@ import ( // +genclient // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// Job volcano job struct type Job struct { metav1.TypeMeta `json:",inline"` @@ -98,12 +100,17 @@ type VolumeSpec struct { VolumeClaim *v1.PersistentVolumeClaimSpec `json:"volumeClaim,omitempty" protobuf:"bytes,3,opt,name=volumeClaim"` } +// JobEvent job event type JobEvent string const ( + // CommandIssued command issued CommandIssued JobEvent = "CommandIssued" - PluginError JobEvent = "PluginError" - PVCError JobEvent = "PVCError" + // PluginError plugin error + PluginError JobEvent = "PluginError" + // PVCError pvc error + PVCError JobEvent = "PVCError" + // PodGroupError pod grp error PodGroupError JobEvent = "PodGroupError" ) @@ -111,13 +118,13 @@ const ( type Event string const ( - // AllEvent means all event + // AnyEvent means all event AnyEvent Event = "*" // PodFailedEvent is triggered if Pod was failed PodFailedEvent Event = "PodFailed" // PodEvictedEvent is triggered if Pod was deleted PodEvictedEvent Event = "PodEvicted" - // These below are several events can lead to job 'Unknown' + // JobUnknownEvent These below are several events can lead to job 'Unknown' // 1. Task Unschedulable, this is triggered when part of // pods can't be scheduled while some are already running in gang-scheduling case. JobUnknownEvent Event = "Unknown" @@ -198,6 +205,7 @@ type TaskSpec struct { Policies []LifecyclePolicy `json:"policies,omitempty" protobuf:"bytes,4,opt,name=policies"` } +// JobPhase phase of the job type JobPhase string const ( @@ -285,6 +293,8 @@ type JobStatus struct { } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// JobList list of jobs type JobList struct { metav1.TypeMeta `json:",inline"` metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` diff --git a/pkg/apis/batch/v1alpha1/labels.go b/pkg/apis/batch/v1alpha1/labels.go index a0fdfbd1f2..be1a505533 100644 --- a/pkg/apis/batch/v1alpha1/labels.go +++ b/pkg/apis/batch/v1alpha1/labels.go @@ -17,10 +17,16 @@ limitations under the License. package v1alpha1 const ( - TaskSpecKey = "volcano.sh/task-spec" - JobNameKey = "volcano.sh/job-name" + // TaskSpecKey task spec key + TaskSpecKey = "volcano.sh/task-spec" + // JobNameKey job name key + JobNameKey = "volcano.sh/job-name" + // JobNamespaceKey job namespace key JobNamespaceKey = "volcano.sh/job-namespace" + // DefaultTaskSpec dfeault task spec DefaultTaskSpec = "default" - JobVersion = "volcano.sh/job-version" - JobTypeKey = "volcano.sh/job-type" + // JobVersion job version key + JobVersion = "volcano.sh/job-version" + // JobTypeKey job type key + JobTypeKey = "volcano.sh/job-type" ) diff --git a/pkg/apis/batch/v1alpha1/register.go b/pkg/apis/batch/v1alpha1/register.go index 0c5b9e96fd..ec3f6aeba7 100644 --- a/pkg/apis/batch/v1alpha1/register.go +++ b/pkg/apis/batch/v1alpha1/register.go @@ -23,8 +23,10 @@ import ( ) var ( + // SchemeBuilder points to a list of functions added to Scheme. SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) - AddToScheme = SchemeBuilder.AddToScheme + // AddToScheme applies all the stored functions to the scheme. + AddToScheme = SchemeBuilder.AddToScheme ) // GroupName is the group name used in this package. diff --git a/pkg/apis/bus/v1alpha1/doc.go b/pkg/apis/bus/v1alpha1/doc.go index 1c873db349..890d2ecd95 100644 --- a/pkg/apis/bus/v1alpha1/doc.go +++ b/pkg/apis/bus/v1alpha1/doc.go @@ -15,4 +15,5 @@ limitations under the License. */ // +k8s:deepcopy-gen=package + package v1alpha1 diff --git a/pkg/apis/bus/v1alpha1/register.go b/pkg/apis/bus/v1alpha1/register.go index 5c03343078..9165cb374d 100644 --- a/pkg/apis/bus/v1alpha1/register.go +++ b/pkg/apis/bus/v1alpha1/register.go @@ -23,8 +23,10 @@ import ( ) var ( + // SchemeBuilder points to a list of functions added to Scheme. SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) - AddToScheme = SchemeBuilder.AddToScheme + // AddToScheme applies all the stored functions to the scheme. + AddToScheme = SchemeBuilder.AddToScheme ) // GroupName is the group name used in this package. diff --git a/pkg/apis/bus/v1alpha1/types.go b/pkg/apis/bus/v1alpha1/types.go index cddb9954da..b725af492f 100644 --- a/pkg/apis/bus/v1alpha1/types.go +++ b/pkg/apis/bus/v1alpha1/types.go @@ -6,6 +6,8 @@ import ( // +genclient // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// Command command object type Command struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` @@ -26,6 +28,8 @@ type Command struct { } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// CommandList list of commands type CommandList struct { metav1.TypeMeta `json:",inline"` metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` diff --git a/pkg/apis/helpers/helpers.go b/pkg/apis/helpers/helpers.go index 571d5edb70..7f0f74fdcd 100644 --- a/pkg/apis/helpers/helpers.go +++ b/pkg/apis/helpers/helpers.go @@ -32,9 +32,13 @@ import ( vkcorev1 "volcano.sh/volcano/pkg/apis/bus/v1alpha1" ) +// JobKind job keind var JobKind = vkbatchv1.SchemeGroupVersion.WithKind("Job") + +// CommandKind command kid var CommandKind = vkcorev1.SchemeGroupVersion.WithKind("Command") +// GetController get the controller uid func GetController(obj interface{}) types.UID { accessor, err := meta.Accessor(obj) if err != nil { @@ -49,6 +53,7 @@ func GetController(obj interface{}) types.UID { return "" } +// ControlledBy controlled by func ControlledBy(obj interface{}, gvk schema.GroupVersionKind) bool { accessor, err := meta.Accessor(obj) if err != nil { @@ -63,6 +68,7 @@ func ControlledBy(obj interface{}, gvk schema.GroupVersionKind) bool { return false } +// CreateConfigMapIfNotExist create config map if not there func CreateConfigMapIfNotExist(job *vkv1.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{}) @@ -102,15 +108,16 @@ func CreateConfigMapIfNotExist(job *vkv1.Job, kubeClients kubernetes.Interface, return nil } +// DeleteConfigmap delete the config map func DeleteConfigmap(job *vkv1.Job, kubeClients kubernetes.Interface, cmName string) error { if _, err := kubeClients.CoreV1().ConfigMaps(job.Namespace).Get(cmName, metav1.GetOptions{}); err != nil { if !apierrors.IsNotFound(err) { glog.V(3).Infof("Failed to get Configmap for Job <%s/%s>: %v", job.Namespace, job.Name, err) return err - } else { - return nil } + return nil + } if err := kubeClients.CoreV1().ConfigMaps(job.Namespace).Delete(cmName, nil); err != nil { diff --git a/pkg/cli/job/common.go b/pkg/cli/job/common.go index 040b566112..9fa6b209de 100644 --- a/pkg/cli/job/common.go +++ b/pkg/cli/job/common.go @@ -13,6 +13,7 @@ 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 job import ( diff --git a/pkg/cli/job/delete.go b/pkg/cli/job/delete.go index e6f697b500..f2ed0fa152 100644 --- a/pkg/cli/job/delete.go +++ b/pkg/cli/job/delete.go @@ -34,6 +34,7 @@ type deleteFlags struct { var deleteJobFlags = &deleteFlags{} +// InitDeleteFlags init the delete command flags func InitDeleteFlags(cmd *cobra.Command) { initFlags(cmd, &deleteJobFlags.commonFlags) @@ -41,6 +42,7 @@ func InitDeleteFlags(cmd *cobra.Command) { cmd.Flags().StringVarP(&deleteJobFlags.JobName, "name", "n", "", "the name of job") } +// DeleteJob delete the job func DeleteJob() error { config, err := buildConfig(deleteJobFlags.Master, deleteJobFlags.Kubeconfig) if err != nil { diff --git a/pkg/cli/job/list.go b/pkg/cli/job/list.go index 534fe6db3d..7baf415514 100644 --- a/pkg/cli/job/list.go +++ b/pkg/cli/job/list.go @@ -13,6 +13,7 @@ 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 job import ( @@ -36,24 +37,39 @@ type listFlags struct { } const ( - Name string = "Name" - Creation string = "Creation" - Phase string = "Phase" - Replicas string = "Replicas" - Min string = "Min" - Scheduler string = "Scheduler" - Pending string = "Pending" - Running string = "Running" - Succeeded string = "Succeeded" + // Name name + Name string = "Name" + // Creation create + Creation string = "Creation" + // Phase phase + Phase string = "Phase" + // Replicas replicas + Replicas string = "Replicas" + // Min minimum + Min string = "Min" + // Scheduler scheduler + Scheduler string = "Scheduler" + // Pending pending + Pending string = "Pending" + // Running running + Running string = "Running" + // Succeeded success + Succeeded string = "Succeeded" + // Terminating terminating Terminating string = "Terminating" - Version string = "Version" - Failed string = "Failed" - RetryCount string = "RetryCount" - JobType string = "JobType" + // Version version + Version string = "Version" + // Failed failed + Failed string = "Failed" + // RetryCount retry count + RetryCount string = "RetryCount" + // JobType job type + JobType string = "JobType" ) var listJobFlags = &listFlags{} +// InitListFlags init list command flags func InitListFlags(cmd *cobra.Command) { initFlags(cmd, &listJobFlags.commonFlags) @@ -61,6 +77,7 @@ func InitListFlags(cmd *cobra.Command) { cmd.Flags().StringVarP(&listJobFlags.SchedulerName, "scheduler", "S", "", "list job with specified scheduler name") } +// ListJobs list all jobs func ListJobs() error { config, err := buildConfig(listJobFlags.Master, listJobFlags.Kubeconfig) if err != nil { @@ -82,6 +99,7 @@ func ListJobs() error { return nil } +// PrintJobs print all jobs func PrintJobs(jobs *v1alpha1.JobList, writer io.Writer) { maxNameLen := getMaxNameLen(jobs) _, err := fmt.Fprintf(writer, fmt.Sprintf("%%-%ds%%-25s%%-12s%%-12s%%-12s%%-6s%%-10s%%-10s%%-12s%%-10s%%-12s\n", maxNameLen), diff --git a/pkg/cli/job/resume.go b/pkg/cli/job/resume.go index d73c1d6dcd..025c1ccf44 100644 --- a/pkg/cli/job/resume.go +++ b/pkg/cli/job/resume.go @@ -13,6 +13,7 @@ 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 job import ( @@ -31,6 +32,7 @@ type resumeFlags struct { var resumeJobFlags = &resumeFlags{} +// InitResumeFlags init resume flags func InitResumeFlags(cmd *cobra.Command) { initFlags(cmd, &resumeJobFlags.commonFlags) @@ -38,6 +40,7 @@ func InitResumeFlags(cmd *cobra.Command) { cmd.Flags().StringVarP(&resumeJobFlags.JobName, "name", "n", "", "the name of job") } +// ResumeJob resume the job func ResumeJob() error { config, err := buildConfig(resumeJobFlags.Master, resumeJobFlags.Kubeconfig) if err != nil { diff --git a/pkg/cli/job/run.go b/pkg/cli/job/run.go index 4fc8c28afb..16efc6889d 100644 --- a/pkg/cli/job/run.go +++ b/pkg/cli/job/run.go @@ -13,6 +13,7 @@ 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 job import ( @@ -41,6 +42,7 @@ type runFlags struct { var launchJobFlags = &runFlags{} +// InitRunFlags init the run flags func InitRunFlags(cmd *cobra.Command) { initFlags(cmd, &launchJobFlags.commonFlags) @@ -56,6 +58,7 @@ func InitRunFlags(cmd *cobra.Command) { var jobName = "job.volcano.sh" +// RunJob run the job command func RunJob() error { config, err := buildConfig(launchJobFlags.Master, launchJobFlags.Kubeconfig) if err != nil { diff --git a/pkg/cli/job/suspend.go b/pkg/cli/job/suspend.go index 504cdd2381..5cc7d5d3b4 100644 --- a/pkg/cli/job/suspend.go +++ b/pkg/cli/job/suspend.go @@ -13,6 +13,7 @@ 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 job import ( @@ -31,6 +32,7 @@ type suspendFlags struct { var suspendJobFlags = &suspendFlags{} +// InitSuspendFlags init suspend related flags func InitSuspendFlags(cmd *cobra.Command) { initFlags(cmd, &suspendJobFlags.commonFlags) @@ -38,6 +40,7 @@ func InitSuspendFlags(cmd *cobra.Command) { cmd.Flags().StringVarP(&suspendJobFlags.JobName, "name", "n", "", "the name of job") } +// SuspendJob suspends the job func SuspendJob() error { config, err := buildConfig(suspendJobFlags.Master, suspendJobFlags.Kubeconfig) if err != nil { diff --git a/pkg/cli/job/util.go b/pkg/cli/job/util.go index a3c919e609..8a5db6a313 100644 --- a/pkg/cli/job/util.go +++ b/pkg/cli/job/util.go @@ -13,6 +13,7 @@ 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 job import ( diff --git a/pkg/cli/job/view.go b/pkg/cli/job/view.go index 65c11a37d5..1316ad5866 100644 --- a/pkg/cli/job/view.go +++ b/pkg/cli/job/view.go @@ -1,3 +1,19 @@ +/* +Copyright 2019 The Volcano Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +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 job import ( @@ -23,6 +39,7 @@ type viewFlags struct { var viewJobFlags = &viewFlags{} +// InitViewFlags init the view command flags func InitViewFlags(cmd *cobra.Command) { initFlags(cmd, &viewJobFlags.commonFlags) @@ -30,6 +47,7 @@ func InitViewFlags(cmd *cobra.Command) { cmd.Flags().StringVarP(&viewJobFlags.JobName, "name", "n", "", "the name of job") } +// ViewJob view the job func ViewJob() error { config, err := buildConfig(viewJobFlags.Master, viewJobFlags.Kubeconfig) if err != nil { @@ -54,6 +72,7 @@ func ViewJob() error { return nil } +// PrintJob print the job func PrintJob(job *v1alpha1.Job, writer io.Writer) { replicas := int32(0) for _, ts := range job.Spec.Tasks { diff --git a/pkg/controllers/job/helpers/helpers.go b/pkg/controllers/job/helpers/helpers.go index 10fd9a7dde..2df8081905 100644 --- a/pkg/controllers/job/helpers/helpers.go +++ b/pkg/controllers/job/helpers/helpers.go @@ -25,10 +25,13 @@ import ( ) const ( - PodNameFmt = "%s-%s-%d" + // PodNameFmt pod nameformat + PodNameFmt = "%s-%s-%d" + // VolumeClaimFmt volumeclaim name format VolumeClaimFmt = "%s-volume-%s" ) +// GetTaskIndex get task Index func GetTaskIndex(pod *v1.Pod) string { num := strings.Split(pod.Name, "-") if len(num) >= 3 { @@ -38,6 +41,7 @@ func GetTaskIndex(pod *v1.Pod) string { return "" } +// MakePodName construct pod name func MakePodName(jobName string, taskName string, index int) string { return fmt.Sprintf(PodNameFmt, jobName, taskName, index) } @@ -53,6 +57,7 @@ func genRandomStr(l int) string { return string(result) } +// MakeVolumeClaimName construct volume claim name func MakeVolumeClaimName(jobName string) string { return fmt.Sprintf(VolumeClaimFmt, jobName, genRandomStr(12)) } diff --git a/pkg/controllers/job/plugins/env/env.go b/pkg/controllers/job/plugins/env/env.go index 027fe3ce6f..c247b2d3ac 100644 --- a/pkg/controllers/job/plugins/env/env.go +++ b/pkg/controllers/job/plugins/env/env.go @@ -31,6 +31,7 @@ type envPlugin struct { Clientset vkinterface.PluginClientset } +// New construct plugin func New(client vkinterface.PluginClientset, arguments []string) vkinterface.PluginInterface { envPlugin := envPlugin{pluginArguments: arguments, Clientset: client} diff --git a/pkg/controllers/job/plugins/env/types.go b/pkg/controllers/job/plugins/env/types.go index 301b95746b..84d4f2614d 100644 --- a/pkg/controllers/job/plugins/env/types.go +++ b/pkg/controllers/job/plugins/env/types.go @@ -17,9 +17,12 @@ limitations under the License. package env const ( + // ConfigMapTaskHostFmt host format in config map ConfigMapTaskHostFmt = "%s.host" + // ConfigMapMountPath mount path ConfigMapMountPath = "/etc/volcano" + // TaskVkIndex index TaskVkIndex = "VK_TASK_INDEX" ) diff --git a/pkg/controllers/job/plugins/factory.go b/pkg/controllers/job/plugins/factory.go index dc6d2b9ef7..f227a67a06 100644 --- a/pkg/controllers/job/plugins/factory.go +++ b/pkg/controllers/job/plugins/factory.go @@ -36,15 +36,18 @@ var pluginMutex sync.Mutex // Plugin management var pluginBuilders = map[string]PluginBuilder{} -type PluginBuilder func(_interface.PluginClientset, []string) _interface.PluginInterface +// PluginBuilder func type +type PluginBuilder func(pluginsinterface.PluginClientset, []string) pluginsinterface.PluginInterface -func RegisterPluginBuilder(name string, pc func(_interface.PluginClientset, []string) _interface.PluginInterface) { +// RegisterPluginBuilder register plugin builders +func RegisterPluginBuilder(name string, pc func(pluginsinterface.PluginClientset, []string) pluginsinterface.PluginInterface) { pluginMutex.Lock() defer pluginMutex.Unlock() pluginBuilders[name] = pc } +// GetPluginBuilder get plugin builder func GetPluginBuilder(name string) (PluginBuilder, bool) { pluginMutex.Lock() defer pluginMutex.Unlock() diff --git a/pkg/controllers/job/plugins/interface/interface.go b/pkg/controllers/job/plugins/interface/interface.go index 8481e70327..8cbef8eb9c 100644 --- a/pkg/controllers/job/plugins/interface/interface.go +++ b/pkg/controllers/job/plugins/interface/interface.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package _interface +package pluginsinterface import ( "k8s.io/api/core/v1" @@ -23,10 +23,12 @@ import ( vkv1 "volcano.sh/volcano/pkg/apis/batch/v1alpha1" ) +// PluginClientset clientset type PluginClientset struct { KubeClients kubernetes.Interface } +// PluginInterface interface type PluginInterface interface { // The unique name of Plugin. Name() string diff --git a/pkg/controllers/job/plugins/ssh/ssh.go b/pkg/controllers/job/plugins/ssh/ssh.go index dd3775c4d1..f4d6e6c1fa 100644 --- a/pkg/controllers/job/plugins/ssh/ssh.go +++ b/pkg/controllers/job/plugins/ssh/ssh.go @@ -47,6 +47,7 @@ type sshPlugin struct { noRoot bool } +// New construct plugin func New(client vkinterface.PluginClientset, arguments []string) vkinterface.PluginInterface { sshPlugin := sshPlugin{pluginArguments: arguments, Clientset: client} diff --git a/pkg/controllers/job/plugins/ssh/types.go b/pkg/controllers/job/plugins/ssh/types.go index 2fc2a508b4..50e69cdd9f 100644 --- a/pkg/controllers/job/plugins/ssh/types.go +++ b/pkg/controllers/job/plugins/ssh/types.go @@ -17,11 +17,21 @@ limitations under the License. package ssh const ( - SSHPrivateKey = "id_rsa" - SSHPublicKey = "id_rsa.pub" + // SSHPrivateKey private key + SSHPrivateKey = "id_rsa" + + // SSHPublicKey public key + SSHPublicKey = "id_rsa.pub" + + // SSHAuthorizedKeys authkey SSHAuthorizedKeys = "authorized_keys" - SSHConfig = "config" + // SSHConfig ssh conf + SSHConfig = "config" + + // SSHAbsolutePath ssh abs path SSHAbsolutePath = "/root/.ssh" + + // SSHRelativePath ssh rel path SSHRelativePath = ".ssh" ) diff --git a/pkg/controllers/job/plugins/svc/svc.go b/pkg/controllers/job/plugins/svc/svc.go index 2bbcbcebb0..07ded32926 100644 --- a/pkg/controllers/job/plugins/svc/svc.go +++ b/pkg/controllers/job/plugins/svc/svc.go @@ -40,6 +40,7 @@ type servicePlugin struct { Clientset vkinterface.PluginClientset } +// New construct plugin func New(client vkinterface.PluginClientset, arguments []string) vkinterface.PluginInterface { servicePlugin := servicePlugin{pluginArguments: arguments, Clientset: client} @@ -156,11 +157,11 @@ func (sp *servicePlugin) createServiceIfNotExist(job *vkv1.Job) error { } if _, e := sp.Clientset.KubeClients.CoreV1().Services(job.Namespace).Create(svc); e != nil { - glog.V(3).Infof("Failed to create Service for Job <%s/%s>: %v", job.Namespace, job.Name, err) + glog.V(3).Infof("Failed to create Service for Job <%s/%s>: %v", job.Namespace, job.Name, e) return e - } else { - job.Status.ControlledResources["plugin-"+sp.Name()] = sp.Name() } + job.Status.ControlledResources["plugin-"+sp.Name()] = sp.Name() + } return nil diff --git a/pkg/controllers/job/plugins/svc/types.go b/pkg/controllers/job/plugins/svc/types.go index 0f91bb52a1..83e34484dd 100644 --- a/pkg/controllers/job/plugins/svc/types.go +++ b/pkg/controllers/job/plugins/svc/types.go @@ -17,7 +17,9 @@ limitations under the License. package svc const ( + // ConfigMapTaskHostFmt host format in config map ConfigMapTaskHostFmt = "%s.host" + // ConfigMapMountPath mount path ConfigMapMountPath = "/etc/volcano" ) From 5ecbd0794866e7d43e4a9def494298f665866d4c Mon Sep 17 00:00:00 2001 From: SrinivasChilveri Date: Wed, 12 Jun 2019 11:16:59 +0530 Subject: [PATCH 2/2] updated with proper decsriptions --- pkg/apis/batch/v1alpha1/job.go | 14 +++++++------- pkg/apis/batch/v1alpha1/labels.go | 10 +++++----- pkg/apis/bus/v1alpha1/types.go | 4 ++-- pkg/apis/helpers/helpers.go | 10 +++++----- pkg/cli/job/list.go | 7 ++++--- pkg/cli/job/resume.go | 4 ++-- pkg/cli/job/run.go | 2 +- pkg/cli/job/view.go | 4 ++-- pkg/controllers/job/helpers/helpers.go | 10 +++++----- pkg/controllers/job/plugins/env/env.go | 2 +- pkg/controllers/job/plugins/env/types.go | 4 ++-- pkg/controllers/job/plugins/factory.go | 4 ++-- pkg/controllers/job/plugins/ssh/ssh.go | 2 +- pkg/controllers/job/plugins/svc/svc.go | 2 +- pkg/controllers/job/plugins/svc/types.go | 2 +- 15 files changed, 41 insertions(+), 40 deletions(-) diff --git a/pkg/apis/batch/v1alpha1/job.go b/pkg/apis/batch/v1alpha1/job.go index 2ce3a28c00..e304ad195d 100644 --- a/pkg/apis/batch/v1alpha1/job.go +++ b/pkg/apis/batch/v1alpha1/job.go @@ -24,7 +24,7 @@ import ( // +genclient // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -// Job volcano job struct +// Job defines the volcano job type Job struct { metav1.TypeMeta `json:",inline"` @@ -104,13 +104,13 @@ type VolumeSpec struct { type JobEvent string const ( - // CommandIssued command issued + // CommandIssued command issued event is generated if a command is raised by user CommandIssued JobEvent = "CommandIssued" - // PluginError plugin error + // PluginError plugin error event is generated if error happens PluginError JobEvent = "PluginError" - // PVCError pvc error + // PVCError pvc error event is generated if error happens during IO creation PVCError JobEvent = "PVCError" - // PodGroupError pod grp error + // PodGroupError pod grp error event is generated if error happens during pod grp creation PodGroupError JobEvent = "PodGroupError" ) @@ -205,7 +205,7 @@ type TaskSpec struct { Policies []LifecyclePolicy `json:"policies,omitempty" protobuf:"bytes,4,opt,name=policies"` } -// JobPhase phase of the job +// JobPhase defines the phase of the job type JobPhase string const ( @@ -294,7 +294,7 @@ type JobStatus struct { // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -// JobList 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"` diff --git a/pkg/apis/batch/v1alpha1/labels.go b/pkg/apis/batch/v1alpha1/labels.go index be1a505533..78e01d8a7a 100644 --- a/pkg/apis/batch/v1alpha1/labels.go +++ b/pkg/apis/batch/v1alpha1/labels.go @@ -17,16 +17,16 @@ limitations under the License. package v1alpha1 const ( - // TaskSpecKey task spec key + // TaskSpecKey task spec key used in pod annotation TaskSpecKey = "volcano.sh/task-spec" - // JobNameKey job name key + // JobNameKey job name key used in pod annotation / labels JobNameKey = "volcano.sh/job-name" // JobNamespaceKey job namespace key JobNamespaceKey = "volcano.sh/job-namespace" - // DefaultTaskSpec dfeault task spec + // DefaultTaskSpec default task spec value DefaultTaskSpec = "default" - // JobVersion job version key + // JobVersion job version key used in pod annotation JobVersion = "volcano.sh/job-version" - // JobTypeKey job type key + // JobTypeKey job type key used in labels JobTypeKey = "volcano.sh/job-type" ) diff --git a/pkg/apis/bus/v1alpha1/types.go b/pkg/apis/bus/v1alpha1/types.go index b725af492f..d7c1543492 100644 --- a/pkg/apis/bus/v1alpha1/types.go +++ b/pkg/apis/bus/v1alpha1/types.go @@ -7,7 +7,7 @@ import ( // +genclient // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -// Command command object +// Command defines command structure type Command struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` @@ -29,7 +29,7 @@ type Command struct { // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -// CommandList list of commands +// CommandList defines list of commands type CommandList struct { metav1.TypeMeta `json:",inline"` metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` diff --git a/pkg/apis/helpers/helpers.go b/pkg/apis/helpers/helpers.go index 7f0f74fdcd..21476f3854 100644 --- a/pkg/apis/helpers/helpers.go +++ b/pkg/apis/helpers/helpers.go @@ -32,13 +32,13 @@ import ( vkcorev1 "volcano.sh/volcano/pkg/apis/bus/v1alpha1" ) -// JobKind job keind +// JobKind creates job GroupVersionKind var JobKind = vkbatchv1.SchemeGroupVersion.WithKind("Job") -// CommandKind command kid +// CommandKind creates command GroupVersionKind var CommandKind = vkcorev1.SchemeGroupVersion.WithKind("Command") -// GetController get the controller uid +// GetController returns the controller uid func GetController(obj interface{}) types.UID { accessor, err := meta.Accessor(obj) if err != nil { @@ -68,7 +68,7 @@ func ControlledBy(obj interface{}, gvk schema.GroupVersionKind) bool { return false } -// CreateConfigMapIfNotExist create config map if not there +// CreateConfigMapIfNotExist creates config map resource if not present func CreateConfigMapIfNotExist(job *vkv1.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{}) @@ -108,7 +108,7 @@ func CreateConfigMapIfNotExist(job *vkv1.Job, kubeClients kubernetes.Interface, return nil } -// DeleteConfigmap delete the config map +// DeleteConfigmap deletes the config map resource func DeleteConfigmap(job *vkv1.Job, kubeClients kubernetes.Interface, cmName string) error { if _, err := kubeClients.CoreV1().ConfigMaps(job.Namespace).Get(cmName, metav1.GetOptions{}); err != nil { if !apierrors.IsNotFound(err) { diff --git a/pkg/cli/job/list.go b/pkg/cli/job/list.go index 7baf415514..41dff254b6 100644 --- a/pkg/cli/job/list.go +++ b/pkg/cli/job/list.go @@ -37,7 +37,8 @@ type listFlags struct { } const ( - // Name name + + // Name name etc below key words are used in job print format Name string = "Name" // Creation create Creation string = "Creation" @@ -77,7 +78,7 @@ func InitListFlags(cmd *cobra.Command) { cmd.Flags().StringVarP(&listJobFlags.SchedulerName, "scheduler", "S", "", "list job with specified scheduler name") } -// ListJobs list all jobs +// ListJobs lists all jobs details func ListJobs() error { config, err := buildConfig(listJobFlags.Master, listJobFlags.Kubeconfig) if err != nil { @@ -99,7 +100,7 @@ func ListJobs() error { return nil } -// PrintJobs print all jobs +// PrintJobs prints all jobs details func PrintJobs(jobs *v1alpha1.JobList, writer io.Writer) { maxNameLen := getMaxNameLen(jobs) _, err := fmt.Fprintf(writer, fmt.Sprintf("%%-%ds%%-25s%%-12s%%-12s%%-12s%%-6s%%-10s%%-10s%%-12s%%-10s%%-12s\n", maxNameLen), diff --git a/pkg/cli/job/resume.go b/pkg/cli/job/resume.go index 025c1ccf44..1db9fbe74e 100644 --- a/pkg/cli/job/resume.go +++ b/pkg/cli/job/resume.go @@ -32,7 +32,7 @@ type resumeFlags struct { var resumeJobFlags = &resumeFlags{} -// InitResumeFlags init resume flags +// InitResumeFlags init resume command flags func InitResumeFlags(cmd *cobra.Command) { initFlags(cmd, &resumeJobFlags.commonFlags) @@ -40,7 +40,7 @@ func InitResumeFlags(cmd *cobra.Command) { cmd.Flags().StringVarP(&resumeJobFlags.JobName, "name", "n", "", "the name of job") } -// ResumeJob resume the job +// ResumeJob resumes the job func ResumeJob() error { config, err := buildConfig(resumeJobFlags.Master, resumeJobFlags.Kubeconfig) if err != nil { diff --git a/pkg/cli/job/run.go b/pkg/cli/job/run.go index 16efc6889d..1270aa7bff 100644 --- a/pkg/cli/job/run.go +++ b/pkg/cli/job/run.go @@ -58,7 +58,7 @@ func InitRunFlags(cmd *cobra.Command) { var jobName = "job.volcano.sh" -// RunJob run the job command +// RunJob creates the job func RunJob() error { config, err := buildConfig(launchJobFlags.Master, launchJobFlags.Kubeconfig) if err != nil { diff --git a/pkg/cli/job/view.go b/pkg/cli/job/view.go index 1316ad5866..4f7af6b696 100644 --- a/pkg/cli/job/view.go +++ b/pkg/cli/job/view.go @@ -47,7 +47,7 @@ func InitViewFlags(cmd *cobra.Command) { cmd.Flags().StringVarP(&viewJobFlags.JobName, "name", "n", "", "the name of job") } -// ViewJob view the job +// ViewJob gives full details of the job func ViewJob() error { config, err := buildConfig(viewJobFlags.Master, viewJobFlags.Kubeconfig) if err != nil { @@ -72,7 +72,7 @@ func ViewJob() error { return nil } -// PrintJob print the job +// PrintJob prints the job details func PrintJob(job *v1alpha1.Job, writer io.Writer) { replicas := int32(0) for _, ts := range job.Spec.Tasks { diff --git a/pkg/controllers/job/helpers/helpers.go b/pkg/controllers/job/helpers/helpers.go index 2df8081905..430a846cc1 100644 --- a/pkg/controllers/job/helpers/helpers.go +++ b/pkg/controllers/job/helpers/helpers.go @@ -25,13 +25,13 @@ import ( ) const ( - // PodNameFmt pod nameformat + // PodNameFmt pod name format PodNameFmt = "%s-%s-%d" - // VolumeClaimFmt volumeclaim name format + // VolumeClaimFmt volume claim name format VolumeClaimFmt = "%s-volume-%s" ) -// GetTaskIndex get task Index +// GetTaskIndex returns task Index func GetTaskIndex(pod *v1.Pod) string { num := strings.Split(pod.Name, "-") if len(num) >= 3 { @@ -41,7 +41,7 @@ func GetTaskIndex(pod *v1.Pod) string { return "" } -// MakePodName construct pod name +// MakePodName creates pod name func MakePodName(jobName string, taskName string, index int) string { return fmt.Sprintf(PodNameFmt, jobName, taskName, index) } @@ -57,7 +57,7 @@ func genRandomStr(l int) string { return string(result) } -// MakeVolumeClaimName construct volume claim name +// MakeVolumeClaimName creates volume claim name func MakeVolumeClaimName(jobName string) string { return fmt.Sprintf(VolumeClaimFmt, jobName, genRandomStr(12)) } diff --git a/pkg/controllers/job/plugins/env/env.go b/pkg/controllers/job/plugins/env/env.go index c247b2d3ac..7254d43e85 100644 --- a/pkg/controllers/job/plugins/env/env.go +++ b/pkg/controllers/job/plugins/env/env.go @@ -31,7 +31,7 @@ type envPlugin struct { Clientset vkinterface.PluginClientset } -// New construct plugin +// New creates env plugin func New(client vkinterface.PluginClientset, arguments []string) vkinterface.PluginInterface { envPlugin := envPlugin{pluginArguments: arguments, Clientset: client} diff --git a/pkg/controllers/job/plugins/env/types.go b/pkg/controllers/job/plugins/env/types.go index 84d4f2614d..5f751b5535 100644 --- a/pkg/controllers/job/plugins/env/types.go +++ b/pkg/controllers/job/plugins/env/types.go @@ -17,12 +17,12 @@ limitations under the License. package env const ( - // ConfigMapTaskHostFmt host format in config map + // ConfigMapTaskHostFmt key in config map ConfigMapTaskHostFmt = "%s.host" // ConfigMapMountPath mount path ConfigMapMountPath = "/etc/volcano" - // TaskVkIndex index + // TaskVkIndex used as key in container env TaskVkIndex = "VK_TASK_INDEX" ) diff --git a/pkg/controllers/job/plugins/factory.go b/pkg/controllers/job/plugins/factory.go index f227a67a06..ed87c2489d 100644 --- a/pkg/controllers/job/plugins/factory.go +++ b/pkg/controllers/job/plugins/factory.go @@ -36,7 +36,7 @@ var pluginMutex sync.Mutex // Plugin management var pluginBuilders = map[string]PluginBuilder{} -// PluginBuilder func type +// PluginBuilder func prototype type PluginBuilder func(pluginsinterface.PluginClientset, []string) pluginsinterface.PluginInterface // RegisterPluginBuilder register plugin builders @@ -47,7 +47,7 @@ func RegisterPluginBuilder(name string, pc func(pluginsinterface.PluginClientset pluginBuilders[name] = pc } -// GetPluginBuilder get plugin builder +// GetPluginBuilder returns plugin builder for a given plugin name func GetPluginBuilder(name string) (PluginBuilder, bool) { pluginMutex.Lock() defer pluginMutex.Unlock() diff --git a/pkg/controllers/job/plugins/ssh/ssh.go b/pkg/controllers/job/plugins/ssh/ssh.go index f4d6e6c1fa..a628762779 100644 --- a/pkg/controllers/job/plugins/ssh/ssh.go +++ b/pkg/controllers/job/plugins/ssh/ssh.go @@ -47,7 +47,7 @@ type sshPlugin struct { noRoot bool } -// New construct plugin +// New creates ssh plugin func New(client vkinterface.PluginClientset, arguments []string) vkinterface.PluginInterface { sshPlugin := sshPlugin{pluginArguments: arguments, Clientset: client} diff --git a/pkg/controllers/job/plugins/svc/svc.go b/pkg/controllers/job/plugins/svc/svc.go index 07ded32926..7856e1b0dd 100644 --- a/pkg/controllers/job/plugins/svc/svc.go +++ b/pkg/controllers/job/plugins/svc/svc.go @@ -40,7 +40,7 @@ type servicePlugin struct { Clientset vkinterface.PluginClientset } -// New construct plugin +// New creates service plugin func New(client vkinterface.PluginClientset, arguments []string) vkinterface.PluginInterface { servicePlugin := servicePlugin{pluginArguments: arguments, Clientset: client} diff --git a/pkg/controllers/job/plugins/svc/types.go b/pkg/controllers/job/plugins/svc/types.go index 83e34484dd..526500468a 100644 --- a/pkg/controllers/job/plugins/svc/types.go +++ b/pkg/controllers/job/plugins/svc/types.go @@ -17,7 +17,7 @@ limitations under the License. package svc const ( - // ConfigMapTaskHostFmt host format in config map + // ConfigMapTaskHostFmt key in config map ConfigMapTaskHostFmt = "%s.host" // ConfigMapMountPath mount path