Skip to content

Commit

Permalink
Move session cleanup down a level.
Browse files Browse the repository at this point in the history
Log out in migration instead of controller, much better results.

Signed-off-by: Matthew Arnold <marnold@redhat.com>
  • Loading branch information
mrnold committed Jan 22, 2025
1 parent 44dddf8 commit 02ae5f9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
4 changes: 0 additions & 4 deletions pkg/controller/plan/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ func (r *Reconciler) setPopulatorDataSourceLabels(plan *api.Plan) {
r.Log.Error(err, "Couldn't construct plan context when trying to set populator labels.")
} else {
runner := Migration{Context: ctx}
defer runner.logout()
runner.SetPopulatorDataSourceLabels()
planCopy := plan.DeepCopy()
if plan.Annotations == nil {
Expand Down Expand Up @@ -302,7 +301,6 @@ func (r *Reconciler) archive(plan *api.Plan) {
r.Log.Error(err, "Couldn't construct plan context while archiving plan.")
} else {
runner := Migration{Context: ctx}
defer runner.logout()
runner.Archive()
}
// Regardless of whether or not we can clean up, mark the plan archived.
Expand Down Expand Up @@ -395,7 +393,6 @@ func (r *Reconciler) execute(plan *api.Plan) (reQ time.Duration, err error) {
//
// Cancel.
runner := Migration{Context: ctx}
defer runner.logout()
err = runner.Cancel()
if err != nil {
return
Expand Down Expand Up @@ -435,7 +432,6 @@ func (r *Reconciler) execute(plan *api.Plan) (reQ time.Duration, err error) {
// Run the migration.
snapshot.BeginStagingConditions()
runner = Migration{Context: ctx}
defer runner.logout()
reQ, err = runner.Run()
if err != nil {
return
Expand Down
21 changes: 15 additions & 6 deletions pkg/controller/plan/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,6 @@ func (r *Migration) init() (err error) {
return
}

func (r *Migration) logout() {
if r.provider != nil {
r.provider.Close()
}
}

// Begin the migration.
func (r *Migration) begin() (err error) {
snapshot := r.Plan.Status.Migration.ActiveSnapshot()
Expand Down Expand Up @@ -381,6 +375,11 @@ func (r *Migration) begin() (err error) {
// Archive the plan.
// Best effort to remove any retained migration resources.
func (r *Migration) Archive() {
defer func() {
if r.provider != nil {
r.provider.Close()
}
}()
if err := r.init(); err != nil {
r.Log.Error(err, "Archive initialization failed.")
return
Expand Down Expand Up @@ -412,6 +411,11 @@ func (r *Migration) Archive() {
}

func (r *Migration) SetPopulatorDataSourceLabels() {
defer func() {
if r.provider != nil {
r.provider.Close()
}
}()
err := r.init()
if err != nil {
r.Log.Error(err, "Setting Populator Data Source labels failed.")
Expand Down Expand Up @@ -439,6 +443,11 @@ func (r *Migration) SetPopulatorDataSourceLabels() {
// Cancel the migration.
// Delete resources associated with VMs that have been marked canceled.
func (r *Migration) Cancel() error {
defer func() {
if r.provider != nil {
r.provider.Close()
}
}()
if err := r.init(); err != nil {
return liberr.Wrap(err)
}
Expand Down

0 comments on commit 02ae5f9

Please sign in to comment.