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 <[email protected]>
  • Loading branch information
Max Jonas Werner committed May 23, 2022
1 parent 9dd8b2f commit 5984fa7
Show file tree
Hide file tree
Showing 2 changed files with 22 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
17 changes: 14 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 @@ -222,6 +222,7 @@ func (r *HelmRepositoryOCIReconciler) notify(oldObj, newObj *sourcev1.HelmReposi
}

func (r *HelmRepositoryOCIReconciler) reconcile(ctx context.Context, obj *sourcev1.HelmRepository, reconcilers []helmRepositoryOCIReconcileFunc) (sreconcile.Result, error) {

oldObj := obj.DeepCopy()

// Mark as reconciling if generation differs.
Expand Down Expand Up @@ -303,7 +304,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 +313,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 5984fa7

Please sign in to comment.