Skip to content

Commit c3091bd

Browse files
Improve error message for invalid Helm chart repository URLs
Wrap the errors from CacheIndex() and LoadFromPath() in reconcileSource with a helm-CLI-style message that includes the configured repository URL. When the index cannot be fetched or fails to parse (e.g. server returns HTML instead of YAML), the user now sees: looks like "https://example.com" is not a valid chart repository or cannot be reached: <underlying error> instead of the cryptic YAML parse error or generic fetch failure. Fixes #654 Signed-off-by: Ogulcan Aydogan <ogulcanaydogan@hotmail.com>
1 parent 524cf24 commit c3091bd

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

‎internal/controller/helmrepository_controller.go‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ func (r *HelmRepositoryReconciler) reconcileSource(ctx context.Context, sp *patc
450450
// Fetch the repository index from remote.
451451
if err := newChartRepo.CacheIndex(); err != nil {
452452
e := serror.NewGeneric(
453-
fmt.Errorf("failed to fetch Helm repository index: %w", err),
453+
invalidChartRepoError(obj.Spec.URL, err),
454454
meta.FailedReason,
455455
)
456456
conditions.MarkTrue(obj, sourcev1.FetchFailedCondition, e.Reason, "%s", e)
@@ -476,7 +476,7 @@ func (r *HelmRepositoryReconciler) reconcileSource(ctx context.Context, sp *patc
476476
// Load the cached repository index to ensure it passes validation.
477477
if err := chartRepo.LoadFromPath(); err != nil {
478478
e := serror.NewGeneric(
479-
fmt.Errorf("failed to load Helm repository from index YAML: %w", err),
479+
invalidChartRepoError(obj.Spec.URL, err),
480480
sourcev1.IndexationFailedReason,
481481
)
482482
conditions.MarkTrue(obj, sourcev1.FetchFailedCondition, e.Reason, "%s", e)
@@ -723,3 +723,10 @@ func (r *HelmRepositoryReconciler) migrationToStatic(ctx context.Context, sp *pa
723723

724724
return ctrl.Result{}, nil
725725
}
726+
727+
// invalidChartRepoError formats an error indicating the given URL is not
728+
// a valid Helm chart repository or cannot be reached, mirroring the
729+
// `helm repo add` CLI output.
730+
func invalidChartRepoError(repoURL string, err error) error {
731+
return fmt.Errorf("looks like %q is not a valid chart repository or cannot be reached: %w", repoURL, err)
732+
}

0 commit comments

Comments
 (0)