Skip to content

Commit

Permalink
Fix clean up logic on reconcile (#203)
Browse files Browse the repository at this point in the history
* Fix clean up logic on reconcile

Signed-off-by: Liam White <[email protected]>

* changelog

Signed-off-by: Liam White <[email protected]>

* Update pkg/controller/stack/stack_controller.go

Co-authored-by: Vivek Lakshmanan <[email protected]>

Co-authored-by: Vivek Lakshmanan <[email protected]>
  • Loading branch information
liamawhite and viveklak authored Oct 1, 2021
1 parent ec29da4 commit ac382a6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ CHANGELOG
=========

## HEAD (Unreleased)
- Fix clean up logic on reconcile [#203](https://github.com/pulumi/pulumi-kubernetes-operator/pull/203)
- Fix stack refresh for BYO backend [#200](https://github.com/pulumi/pulumi-kubernetes-operator/pull/200)

## 0.0.20 (2021-09-27)
Expand Down
18 changes: 10 additions & 8 deletions pkg/controller/stack/stack_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ func (r *ReconcileStack) Reconcile(ctx context.Context, request reconcile.Reques
return reconcile.Result{}, err
}

// Delete the working directory after the reconciliation is completed (regardless of success or failure).
defer sess.CleanupPulumiWorkdir()
// Delete the temporary directory after the reconciliation is completed (regardless of success or failure).
defer sess.CleanupPulumiDir()

currentCommit, err := revisionAtWorkingDir(sess.workdir)
if err != nil {
Expand Down Expand Up @@ -391,6 +391,7 @@ type reconcileStackSession struct {
autoStack *auto.Stack
namespace string
workdir string
rootDir string
}

// blank assignment to verify that reconcileStackSession implements pulumiv1alpha1.StackController.
Expand Down Expand Up @@ -605,11 +606,12 @@ func (sess *reconcileStackSession) SetupPulumiWorkdir(gitAuth *auto.GitAuth) err
if err != nil {
return errors.Wrap(err, "unable to create tmp directory for workspace")
}
sess.rootDir = dir

// Cleanup the workdir on failure setting up the workspace.
// Cleanup the rootdir on failure setting up the workspace.
defer func() {
if err != nil {
_ = os.RemoveAll(dir)
_ = os.RemoveAll(sess.rootDir)
}
}()

Expand Down Expand Up @@ -697,10 +699,10 @@ func (sess *reconcileStackSession) ensureStackSettings(ctx context.Context, w au
return nil
}

func (sess *reconcileStackSession) CleanupPulumiWorkdir() {
if sess.workdir != "" {
if err := os.RemoveAll(sess.workdir); err != nil {
sess.logger.Error(err, "Failed to delete working dir: %s", sess.workdir)
func (sess *reconcileStackSession) CleanupPulumiDir() {
if sess.rootDir != "" {
if err := os.RemoveAll(sess.rootDir); err != nil {
sess.logger.Error(err, "Failed to delete temporary root dir: %s", sess.rootDir)
}
}
}
Expand Down

0 comments on commit ac382a6

Please sign in to comment.