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

Log the error when tmp cleanup fails #533

Merged
merged 1 commit into from
Jan 7, 2022
Merged
Show file tree
Hide file tree
Changes from all 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 api/v1beta1/zz_generated.deepcopy.go

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

9 changes: 8 additions & 1 deletion controllers/bucket_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,21 @@ func (r *BucketReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
}

func (r *BucketReconciler) reconcile(ctx context.Context, bucket sourcev1.Bucket) (sourcev1.Bucket, error) {
log := ctrl.LoggerFrom(ctx)
var err error
var sourceBucket sourcev1.Bucket

tempDir, err := os.MkdirTemp("", bucket.Name)
if err != nil {
err = fmt.Errorf("tmp dir error: %w", err)
return sourcev1.BucketNotReady(bucket, sourcev1.StorageOperationFailedReason, err.Error()), err
}
defer os.RemoveAll(tempDir)
defer func() {
if err := os.RemoveAll(tempDir); err != nil {
log.Error(err, "failed to remove working directory", "path", tempDir)
}
}()

if bucket.Spec.Provider == sourcev1.GoogleBucketProvider {
sourceBucket, err = r.reconcileWithGCP(ctx, bucket, tempDir)
if err != nil {
Expand Down
8 changes: 7 additions & 1 deletion controllers/gitrepository_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,19 @@ func (r *GitRepositoryReconciler) checkDependencies(repository sourcev1.GitRepos
}

func (r *GitRepositoryReconciler) reconcile(ctx context.Context, repository sourcev1.GitRepository) (sourcev1.GitRepository, error) {
log := ctrl.LoggerFrom(ctx)

// create tmp dir for the Git clone
tmpGit, err := os.MkdirTemp("", repository.Name)
if err != nil {
err = fmt.Errorf("tmp dir error: %w", err)
return sourcev1.GitRepositoryNotReady(repository, sourcev1.StorageOperationFailedReason, err.Error()), err
}
defer os.RemoveAll(tmpGit)
defer func() {
if err := os.RemoveAll(tmpGit); err != nil {
log.Error(err, "failed to remove working directory", "path", tmpGit)
}
}()

// Configure auth options using secret
var authOpts *git.AuthOptions
Expand Down
6 changes: 5 additions & 1 deletion controllers/helmchart_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,11 @@ func (r *HelmChartReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
r.recordReadiness(ctx, chart)
return ctrl.Result{Requeue: true}, err
}
defer os.RemoveAll(workDir)
defer func() {
if err := os.RemoveAll(workDir); err != nil {
log.Error(err, "failed to remove working directory", "path", workDir)
}
}()

// Perform the reconciliation for the chart source type
var reconciledChart sourcev1.HelmChart
Expand Down
7 changes: 6 additions & 1 deletion controllers/helmrepository_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ func (r *HelmRepositoryReconciler) Reconcile(ctx context.Context, req ctrl.Reque
}

func (r *HelmRepositoryReconciler) reconcile(ctx context.Context, repo sourcev1.HelmRepository) (sourcev1.HelmRepository, error) {
log := ctrl.LoggerFrom(ctx)
clientOpts := []helmgetter.Option{
helmgetter.WithURL(repo.Spec.URL),
helmgetter.WithTimeout(repo.Spec.Timeout.Duration),
Expand All @@ -196,7 +197,11 @@ func (r *HelmRepositoryReconciler) reconcile(ctx context.Context, repo sourcev1.
err = fmt.Errorf("failed to create temporary working directory for credentials: %w", err)
return sourcev1.HelmRepositoryNotReady(repo, sourcev1.AuthenticationFailedReason, err.Error()), err
}
defer os.RemoveAll(authDir)
defer func() {
if err := os.RemoveAll(authDir); err != nil {
log.Error(err, "failed to remove working directory", "path", authDir)
}
}()

opts, err := getter.ClientOptionsFromSecret(authDir, secret)
if err != nil {
Expand Down