Skip to content

Commit

Permalink
log when the OCI temp credentials file can't be deleted
Browse files Browse the repository at this point in the history
Signed-off-by: Max Jonas Werner <mail@makk.es>
  • Loading branch information
Max Jonas Werner committed May 23, 2022
1 parent 9dd8b2f commit dc218a3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
9 changes: 8 additions & 1 deletion controllers/helmchart_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,14 @@ func (r *HelmChartReconciler) buildFromHelmRepository(ctx context.Context, obj *

if file != "" {
defer func() {
os.Remove(file)
if err := os.Remove(file); err != nil {
r.eventLogf(ctx,
obj,
corev1.EventTypeWarning,
meta.FailedReason,
"failed to delete temporary credentials file: %s",
err)
}
}()
}

Expand Down
16 changes: 13 additions & 3 deletions controllers/helmrepository_controller_oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (r *HelmRepositoryOCIReconciler) Reconcile(ctx context.Context, req ctrl.Re
r.Metrics.RecordDuration(ctx, obj, start)
}()

// Add finalizer first if not exist to avoid the race condition
// Add finalizer first if it doesn't exist to avoid the race condition
// between init and delete
if !controllerutil.ContainsFinalizer(obj, sourcev1.SourceFinalizer) {
controllerutil.AddFinalizer(obj, sourcev1.SourceFinalizer)
Expand Down Expand Up @@ -303,7 +303,7 @@ func (r *HelmRepositoryOCIReconciler) validateSource(ctx context.Context, obj *s
registryClient, file, err := r.RegistryClientGenerator(logOpts != nil)
if err != nil {
e := &serror.Stalling{
Err: fmt.Errorf("failed to create registry client:: %w", err),
Err: fmt.Errorf("failed to create registry client: %w", err),
Reason: meta.FailedReason,
}
conditions.MarkFalse(obj, meta.ReadyCondition, e.Reason, e.Err.Error())
Expand All @@ -312,7 +312,17 @@ func (r *HelmRepositoryOCIReconciler) validateSource(ctx context.Context, obj *s

if file != "" {
defer func() {
os.Remove(file)
if err := os.Remove(file); err != nil {
log := ctrl.LoggerFrom(ctx)
log.Error(err, "failed to delete temporary credentials file")
r.Eventf(
obj,
corev1.EventTypeWarning,
meta.FailedReason,
"failed to delete temporary credentials file: %s",
err,
)
}
}()
}

Expand Down

0 comments on commit dc218a3

Please sign in to comment.