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 authored and mnecas committed Jan 23, 2025
1 parent 5221dd7 commit f712593
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 @@ -388,7 +386,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 @@ -428,7 +425,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 @@ -278,12 +278,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 @@ -379,6 +373,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 @@ -410,6 +409,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 @@ -437,6 +441,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 f712593

Please sign in to comment.