Skip to content

Commit

Permalink
Merge pull request volcano-sh#225 from SrinivasChilveri/LintFixes
Browse files Browse the repository at this point in the history
Lint Fixes
  • Loading branch information
volcano-sh-bot authored Jun 17, 2019
2 parents bcd15cc + 706d364 commit 4fbcf16
Show file tree
Hide file tree
Showing 26 changed files with 147 additions and 45 deletions.
10 changes: 0 additions & 10 deletions hack/.golint_failures
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions pkg/apis/batch/v1alpha1/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ limitations under the License.
*/

// +k8s:deepcopy-gen=package

package v1alpha1
18 changes: 14 additions & 4 deletions pkg/apis/batch/v1alpha1/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (

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

// Job defines the volcano job
type Job struct {
metav1.TypeMeta `json:",inline"`

Expand Down Expand Up @@ -98,26 +100,31 @@ 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 event is generated if a command is raised by user
CommandIssued JobEvent = "CommandIssued"
PluginError JobEvent = "PluginError"
PVCError JobEvent = "PVCError"
// PluginError plugin error event is generated if error happens
PluginError JobEvent = "PluginError"
// PVCError pvc error event is generated if error happens during IO creation
PVCError JobEvent = "PVCError"
// PodGroupError pod grp error event is generated if error happens during pod grp creation
PodGroupError JobEvent = "PodGroupError"
)

// Event represent the phase of Job, e.g. pod-failed.
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"
Expand Down Expand Up @@ -198,6 +205,7 @@ type TaskSpec struct {
Policies []LifecyclePolicy `json:"policies,omitempty" protobuf:"bytes,4,opt,name=policies"`
}

// JobPhase defines the phase of the job
type JobPhase string

const (
Expand Down Expand Up @@ -285,6 +293,8 @@ type JobStatus struct {
}

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

// 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
14 changes: 10 additions & 4 deletions pkg/apis/batch/v1alpha1/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 used in pod annotation
TaskSpecKey = "volcano.sh/task-spec"
// JobNameKey job name key used in pod annotation / labels
JobNameKey = "volcano.sh/job-name"
// JobNamespaceKey job namespace key
JobNamespaceKey = "volcano.sh/job-namespace"
// DefaultTaskSpec default task spec value
DefaultTaskSpec = "default"
JobVersion = "volcano.sh/job-version"
JobTypeKey = "volcano.sh/job-type"
// JobVersion job version key used in pod annotation
JobVersion = "volcano.sh/job-version"
// JobTypeKey job type key used in labels
JobTypeKey = "volcano.sh/job-type"
)
4 changes: 3 additions & 1 deletion pkg/apis/batch/v1alpha1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/bus/v1alpha1/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ limitations under the License.
*/

// +k8s:deepcopy-gen=package

package v1alpha1
4 changes: 3 additions & 1 deletion pkg/apis/bus/v1alpha1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/bus/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (

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

// Command defines command structure
type Command struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
Expand All @@ -26,6 +28,8 @@ type Command struct {
}

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

// CommandList defines list of commands
type CommandList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
Expand Down
11 changes: 9 additions & 2 deletions pkg/apis/helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ import (
vkcorev1 "volcano.sh/volcano/pkg/apis/bus/v1alpha1"
)

// JobKind creates job GroupVersionKind
var JobKind = vkbatchv1.SchemeGroupVersion.WithKind("Job")

// CommandKind creates command GroupVersionKind
var CommandKind = vkcorev1.SchemeGroupVersion.WithKind("Command")

// GetController returns the controller uid
func GetController(obj interface{}) types.UID {
accessor, err := meta.Accessor(obj)
if err != nil {
Expand All @@ -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 {
Expand All @@ -63,6 +68,7 @@ func ControlledBy(obj interface{}, gvk schema.GroupVersionKind) bool {
return false
}

// 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{})
Expand Down Expand Up @@ -102,15 +108,16 @@ func CreateConfigMapIfNotExist(job *vkv1.Job, kubeClients kubernetes.Interface,
return nil
}

// 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) {
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 {
Expand Down
1 change: 1 addition & 0 deletions pkg/cli/job/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 2 additions & 0 deletions pkg/cli/job/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ type deleteFlags struct {

var deleteJobFlags = &deleteFlags{}

// InitDeleteFlags init the delete command flags
func InitDeleteFlags(cmd *cobra.Command) {
initFlags(cmd, &deleteJobFlags.commonFlags)

cmd.Flags().StringVarP(&deleteJobFlags.Namespace, "namespace", "N", "default", "the namespace of job")
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 {
Expand Down
45 changes: 32 additions & 13 deletions pkg/cli/job/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -36,31 +37,48 @@ 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 etc below key words are used in job print format
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)

cmd.Flags().StringVarP(&listJobFlags.Namespace, "namespace", "N", "default", "the namespace of job")
cmd.Flags().StringVarP(&listJobFlags.SchedulerName, "scheduler", "S", "", "list job with specified scheduler name")
}

// ListJobs lists all jobs details
func ListJobs() error {
config, err := buildConfig(listJobFlags.Master, listJobFlags.Kubeconfig)
if err != nil {
Expand All @@ -82,6 +100,7 @@ func ListJobs() error {
return nil
}

// 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),
Expand Down
3 changes: 3 additions & 0 deletions pkg/cli/job/resume.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -32,13 +33,15 @@ type resumeFlags struct {

var resumeJobFlags = &resumeFlags{}

// InitResumeFlags init resume command flags
func InitResumeFlags(cmd *cobra.Command) {
initFlags(cmd, &resumeJobFlags.commonFlags)

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

// ResumeJob resumes the job
func ResumeJob() error {
config, err := buildConfig(resumeJobFlags.Master, resumeJobFlags.Kubeconfig)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions pkg/cli/job/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -41,6 +42,7 @@ type runFlags struct {

var launchJobFlags = &runFlags{}

// InitRunFlags init the run flags
func InitRunFlags(cmd *cobra.Command) {
initFlags(cmd, &launchJobFlags.commonFlags)

Expand All @@ -56,6 +58,7 @@ func InitRunFlags(cmd *cobra.Command) {

var jobName = "job.volcano.sh"

// RunJob creates the job
func RunJob() error {
config, err := buildConfig(launchJobFlags.Master, launchJobFlags.Kubeconfig)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions pkg/cli/job/suspend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -31,13 +32,15 @@ type suspendFlags struct {

var suspendJobFlags = &suspendFlags{}

// 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
func SuspendJob() error {
config, err := buildConfig(suspendJobFlags.Master, suspendJobFlags.Kubeconfig)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/cli/job/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
Loading

0 comments on commit 4fbcf16

Please sign in to comment.