Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scheduler func for clearing batch scheduling on completed #1079

Merged
merged 5 commits into from
Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/batchscheduler/interface/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ type BatchScheduler interface {

ShouldSchedule(app *v1beta2.SparkApplication) bool
DoBatchSchedulingOnSubmission(app *v1beta2.SparkApplication) error
CleanupOnCompletion(app *v1beta2.SparkApplication) error
}
6 changes: 6 additions & 0 deletions pkg/batchscheduler/volcano/volcano_scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ func (v *VolcanoBatchScheduler) syncPodGroup(app *v1beta2.SparkApplication, size
return nil
}

func (v *VolcanoBatchScheduler) CleanupOnCompletion(app *v1beta2.SparkApplication) error {
podGroupName := v.getAppPodGroupName(app)
//Remove pod group for Spark Application
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is not needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove it

return v.volcanoClient.SchedulingV1beta1().PodGroups(app.Namespace).Delete(podGroupName, &metav1.DeleteOptions{})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should ignore the error if it's NotFound.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw this comments at now, I will update code that ignores NotFound error here

}

func New(config *rest.Config) (schedulerinterface.BatchScheduler, error) {
vkClient, err := volcanoclient.NewForConfig(config)
if err != nil {
Expand Down
21 changes: 21 additions & 0 deletions pkg/controller/sparkapplication/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,14 @@ func (c *Controller) syncSparkApplication(key string) error {
glog.Errorf("failed to update SparkApplication %s/%s: %v", app.Namespace, app.Name, err)
return err
}

if state := appCopy.Status.AppState.State; state == v1beta2.CompletedState ||
state == v1beta2.FailedState {
if err := c.cleanUpOnTermination(app, appCopy); err != nil {
glog.Errorf("failed to clean up resources for SparkApplication %s/%s: %v", app.Namespace, app.Name, err)
return err
}
}
}

return nil
Expand Down Expand Up @@ -1001,3 +1009,16 @@ func (c *Controller) hasApplicationExpired(app *v1beta2.SparkApplication) bool {

return false
}

// Clean up when the spark application is terminated.
func (c *Controller) cleanUpOnTermination(oldApp, newApp *v1beta2.SparkApplication) error {
if needScheduling, scheduler := c.shouldDoBatchScheduling(newApp); needScheduling {
// batch schduler is cleaned up only when state is changed to completion state
if newApp.Status.AppState.State != oldApp.Status.AppState.State {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is not needed if deletion is idempotent, i.e., if we ignore NotFound error above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks reasonable
updated to

if needScheduling, scheduler := c.shouldDoBatchScheduling(newApp); needScheduling {
	if err := scheduler.CleanupOnCompletion(newApp); err != nil && !errors.IsNotFound(err) {
		return err
	}
}

if err := scheduler.CleanupOnCompletion(newApp); err != nil {
return err
}
}
}
return nil
}