Skip to content

Commit

Permalink
Refactor events/actions.
Browse files Browse the repository at this point in the history
Signed-off-by: Klaus Ma <klaus1982.cn@gmail.com>
  • Loading branch information
k82cn committed Jan 28, 2020
1 parent eb0521f commit 1f4b5f4
Show file tree
Hide file tree
Showing 45 changed files with 439 additions and 413 deletions.
60 changes: 4 additions & 56 deletions pkg/apis/batch/v1alpha1/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package v1alpha1
import (
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"volcano.sh/volcano/pkg/apis/bus/v1alpha1"
)

// +genclient
Expand Down Expand Up @@ -118,76 +119,23 @@ const (
JobStatusError JobEvent = "JobStatusError"
)

// Event represent the phase of Job, e.g. pod-failed.
type Event string

const (
// 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"
// 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"
// TaskCompletedEvent is triggered if the 'Replicas' amount of pods in one task are succeed
TaskCompletedEvent Event = "TaskCompleted"

// Note: events below are used internally, should not be used by users.

// OutOfSyncEvent is triggered if Pod/Job were updated
OutOfSyncEvent Event = "OutOfSync"
// CommandIssuedEvent is triggered if a command is raised by user
CommandIssuedEvent Event = "CommandIssued"
)

// Action is the action that Job controller will take according to the event.
type Action string

const (
// AbortJobAction if this action is set, the whole job will be aborted:
// all Pod of Job will be evicted, and no Pod will be recreated
AbortJobAction Action = "AbortJob"
// RestartJobAction if this action is set, the whole job will be restarted
RestartJobAction Action = "RestartJob"
// RestartTaskAction if this action is set, only the task will be restarted; default action.
// This action can not work together with job level events, e.g. JobUnschedulable
RestartTaskAction Action = "RestartTask"
// TerminateJobAction if this action is set, the whole job wil be terminated
// and can not be resumed: all Pod of Job will be evicted, and no Pod will be recreated.
TerminateJobAction Action = "TerminateJob"
// CompleteJobAction if this action is set, the unfinished pods will be killed, job completed.
CompleteJobAction Action = "CompleteJob"
// ResumeJobAction is the action to resume an aborted job.
ResumeJobAction Action = "ResumeJob"

// Note: actions below are only used internally, should not be used by users.

// SyncJobAction is the action to sync Job/Pod status.
SyncJobAction Action = "SyncJob"
// EnqueueAction is the action to sync Job inqueue status.
EnqueueAction Action = "EnqueueJob"
)

// LifecyclePolicy specifies the lifecycle and error handling of task and job.
type LifecyclePolicy struct {
// The action that will be taken to the PodGroup according to Event.
// One of "Restart", "None".
// Default to None.
// +optional
Action Action `json:"action,omitempty" protobuf:"bytes,1,opt,name=action"`
Action v1alpha1.Action `json:"action,omitempty" protobuf:"bytes,1,opt,name=action"`

// The Event recorded by scheduler; the controller takes actions
// according to this Event.
// +optional
Event Event `json:"event,omitempty" protobuf:"bytes,2,opt,name=event"`
Event v1alpha1.Event `json:"event,omitempty" protobuf:"bytes,2,opt,name=event"`

// The Events recorded by scheduler; the controller takes actions
// according to this Events.
// +optional
Events []Event `json:"events,omitempty" protobuf:"bytes,3,opt,name=events"`
Events []v1alpha1.Event `json:"events,omitempty" protobuf:"bytes,3,opt,name=events"`

// The exit code of the pod container, controller will take action
// according to this code.
Expand Down
3 changes: 2 additions & 1 deletion pkg/apis/batch/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 61 additions & 0 deletions pkg/apis/bus/v1alpha1/actions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
Copyright 2020 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 v1alpha1

// Action is the action that Job controller will take according to the event.
type Action string

const (

// AbortJobAction if this action is set, the whole job will be aborted:
// all Pod of Job will be evicted, and no Pod will be recreated
AbortJobAction Action = "AbortJob"

// RestartJobAction if this action is set, the whole job will be restarted
RestartJobAction Action = "RestartJob"

// RestartTaskAction if this action is set, only the task will be restarted; default action.
// This action can not work together with job level events, e.g. JobUnschedulable
RestartTaskAction Action = "RestartTask"

// TerminateJobAction if this action is set, the whole job wil be terminated
// and can not be resumed: all Pod of Job will be evicted, and no Pod will be recreated.
TerminateJobAction Action = "TerminateJob"

// CompleteJobAction if this action is set, the unfinished pods will be killed, job completed.
CompleteJobAction Action = "CompleteJob"

// ResumeJobAction is the action to resume an aborted job.
ResumeJobAction Action = "ResumeJob"

// Note: actions below are only used internally, should not be used by users.

// SyncJobAction is the action to sync Job/Pod status.
SyncJobAction Action = "SyncJob"

// EnqueueAction is the action to sync Job inqueue status.
EnqueueAction Action = "EnqueueJob"

// SyncQueueAction is the action to sync queue status.
SyncQueueAction Action = "SyncQueue"

// OpenQueueAction is the action to open queue
OpenQueueAction Action = "OpenQueue"

// CloseQueueAction is the action to close queue
CloseQueueAction Action = "CloseQueue"
)
File renamed without changes.
48 changes: 48 additions & 0 deletions pkg/apis/bus/v1alpha1/events.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
Copyright 2020 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 v1alpha1

// Event represent the phase of Job, e.g. pod-failed.
type Event string

const (

// 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"

// 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"

// TaskCompletedEvent is triggered if the 'Replicas' amount of pods in one task are succeed
TaskCompletedEvent Event = "TaskCompleted"

// Note: events below are used internally, should not be used by users.

// OutOfSyncEvent is triggered if Pod/Job were updated
OutOfSyncEvent Event = "OutOfSync"

// CommandIssuedEvent is triggered if a command is raised by user
CommandIssuedEvent Event = "CommandIssued"
)
33 changes: 0 additions & 33 deletions pkg/apis/scheduling/v1alpha2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,28 +113,6 @@ const (
NotEnoughPodsReason string = "NotEnoughTasks"
)

// QueueEvent represent the phase of queue
type QueueEvent string

const (
// QueueOutOfSyncEvent is triggered if PodGroup/Queue were updated
QueueOutOfSyncEvent QueueEvent = "OutOfSync"
// QueueCommandIssuedEvent is triggered if a command is raised by user
QueueCommandIssuedEvent QueueEvent = "CommandIssued"
)

// QueueAction is the action that queue controller will take according to the event.
type QueueAction string

const (
// SyncQueueAction is the action to sync queue status.
SyncQueueAction QueueAction = "SyncQueue"
// OpenQueueAction is the action to open queue
OpenQueueAction QueueAction = "OpenQueue"
// CloseQueueAction is the action to close queue
CloseQueueAction QueueAction = "CloseQueue"
)

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

Expand Down Expand Up @@ -279,14 +257,3 @@ type QueueList struct {
// items is the list of PodGroup
Items []Queue `json:"items" protobuf:"bytes,2,rep,name=items"`
}

// QueueRequest struct
type QueueRequest struct {
// Name is queue name
Name string

// Event is event of queue
Event QueueEvent
// Action is action to be performed
Action QueueAction
}
16 changes: 0 additions & 16 deletions pkg/apis/scheduling/v1alpha2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/cli/job/resume.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

"github.com/spf13/cobra"

"volcano.sh/volcano/pkg/apis/batch/v1alpha1"
"volcano.sh/volcano/pkg/apis/bus/v1alpha1"
)

type resumeFlags struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/job/suspend.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

"github.com/spf13/cobra"

"volcano.sh/volcano/pkg/apis/batch/v1alpha1"
"volcano.sh/volcano/pkg/apis/bus/v1alpha1"
)

type suspendFlags struct {
Expand Down
3 changes: 1 addition & 2 deletions pkg/cli/job/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"

vcbatch "volcano.sh/volcano/pkg/apis/batch/v1alpha1"
vcbus "volcano.sh/volcano/pkg/apis/bus/v1alpha1"
"volcano.sh/volcano/pkg/apis/helpers"
"volcano.sh/volcano/pkg/client/clientset/versioned"
Expand Down Expand Up @@ -71,7 +70,7 @@ func populateResourceListV1(spec string) (v1.ResourceList, error) {
return result, nil
}

func createJobCommand(config *rest.Config, ns, name string, action vcbatch.Action) error {
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{})
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions pkg/cli/queue/operate.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ package queue
import (
"fmt"

schedulingv1alpha2 "volcano.sh/volcano/pkg/apis/scheduling/v1alpha2"
"volcano.sh/volcano/pkg/client/clientset/versioned"

"github.com/spf13/cobra"

"k8s.io/apimachinery/pkg/types"

"volcano.sh/volcano/pkg/apis/bus/v1alpha1"
"volcano.sh/volcano/pkg/client/clientset/versioned"
)

const (
Expand Down Expand Up @@ -70,13 +70,13 @@ func OperateQueue() error {
return fmt.Errorf("Queue name must be specified")
}

var action schedulingv1alpha2.QueueAction
var action v1alpha1.Action

switch operateQueueFlags.Action {
case ActionOpen:
action = schedulingv1alpha2.OpenQueueAction
action = v1alpha1.OpenQueueAction
case ActionClose:
action = schedulingv1alpha2.CloseQueueAction
action = v1alpha1.CloseQueueAction
case ActionUpdate:
if operateQueueFlags.Weight == 0 {
return fmt.Errorf("When %s queue %s, weight must be specified, "+
Expand Down
3 changes: 1 addition & 2 deletions pkg/cli/queue/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (

busv1alpha1 "volcano.sh/volcano/pkg/apis/bus/v1alpha1"
"volcano.sh/volcano/pkg/apis/helpers"
schedulingv1alpha2 "volcano.sh/volcano/pkg/apis/scheduling/v1alpha2"
"volcano.sh/volcano/pkg/client/clientset/versioned"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -44,7 +43,7 @@ func buildConfig(master, kubeconfig string) (*rest.Config, error) {
return clientcmd.BuildConfigFromFlags(master, kubeconfig)
}

func createQueueCommand(config *rest.Config, action schedulingv1alpha2.QueueAction) error {
func createQueueCommand(config *rest.Config, action busv1alpha1.Action) error {
queueClient := versioned.NewForConfigOrDie(config)
queue, err := queueClient.SchedulingV1alpha2().Queues().Get(operateQueueFlags.Name, metav1.GetOptions{})
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions pkg/cli/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"

vcbatch "volcano.sh/volcano/pkg/apis/batch/v1alpha1"
vcbus "volcano.sh/volcano/pkg/apis/bus/v1alpha1"
"volcano.sh/volcano/pkg/apis/helpers"
"volcano.sh/volcano/pkg/client/clientset/versioned"
Expand Down Expand Up @@ -94,7 +93,7 @@ func PopulateResourceListV1(spec string) (v1.ResourceList, error) {
}

// CreateJobCommand executes a command such as resume/suspend
func CreateJobCommand(config *rest.Config, ns, name string, action vcbatch.Action) error {
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{})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/vresume/resume.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

"github.com/spf13/cobra"

"volcano.sh/volcano/pkg/apis/batch/v1alpha1"
"volcano.sh/volcano/pkg/apis/bus/v1alpha1"
"volcano.sh/volcano/pkg/cli/util"
)

Expand Down
Loading

0 comments on commit 1f4b5f4

Please sign in to comment.