Skip to content

RHTAP-6522: Add ChartFS.ExtractTo Method#58

Merged
Roming22 merged 1 commit into
redhat-appstudio:mainfrom
otaviof:RHTAP-6522
May 6, 2026
Merged

RHTAP-6522: Add ChartFS.ExtractTo Method#58
Roming22 merged 1 commit into
redhat-appstudio:mainfrom
otaviof:RHTAP-6522

Conversation

@otaviof

@otaviof otaviof commented May 6, 2026

Copy link
Copy Markdown
Collaborator

ChartFS currently provides read-only in-memory access to Helm charts via fs.FS, which is sufficient for Helmet's own deployer but not for consumers that need charts materialized on disk. ArgoCD's Helm source type is one such consumer, it expects a real directory containing
Chart.yaml and templates to feed into helm template or helm install.

This PR adds ChartFS.ExtractTo(destDir string) error, which discovers all chart directories (those containing Chart.yaml) in the embedded filesystem and writes them to the given destination path. Root-level files like values.yaml.tpl and config.yaml are intentionally excluded, as are non-chart directories such as _common/. File permissions follow the existing convention: 0755 for directories, 0644 for files.

The implementation reuses the existing walkAndFindChartDirs for chart discovery and follows the file-extraction pattern established in internal/subcmd/installer.go. Two private helpers — extractChartDir and extractFile — keep the logic decomposed and testable.

Summary by CodeRabbit

  • New Features

    • Added ability to extract Helm charts to a specified directory.
  • Tests

    • Added comprehensive tests validating chart extraction functionality, including content verification and file permission checks.

@otaviof otaviof added the enhancement New feature or request label May 6, 2026
@coderabbitai

coderabbitai Bot commented May 6, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@otaviof has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 49 minutes and 6 seconds before requesting another review.

To continue reviewing without waiting, purchase usage credits in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9a05339e-63d8-4dac-b490-a271f66579b6

📥 Commits

Reviewing files that changed from the base of the PR and between 098c7b6 and 87e0cec.

📒 Files selected for processing (2)
  • internal/chartfs/chartfs.go
  • internal/chartfs/chartfs_test.go
📝 Walkthrough

Walkthrough

A new public method ExtractTo is added to ChartFS along with internal helper functions to extract embedded Helm chart directories to a destination on-disk location. The implementation walks the embedded filesystem, copies chart files with proper error handling, and is validated by comprehensive test coverage.

Changes

Chart Extraction Implementation

Layer / File(s) Summary
Dependencies & Utilities
internal/chartfs/chartfs.go (lines 3–5)
Import block extended with fmt and io standard library packages for formatting and file I/O operations.
Core Extraction Logic
internal/chartfs/chartfs.go (lines 104–156)
Introduces extractChartDir to recursively copy a chart directory from embedded filesystem, extractFile to copy individual files with destination creation, and exported ExtractTo(destDir string) error to orchestrate chart discovery and extraction to a specified on-disk location.
Test Coverage & Validation
internal/chartfs/chartfs_test.go (lines 4–5, 49–128)
New filepath import and comprehensive test function TestChartFS_ExtractTo validating directory extraction, file content fidelity, template presence, non-chart file exclusion, and permission checks.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • Roming22

Poem

Our ExtractTo hops through embedded delight,
Extracting Helm charts to filesystem bright,
With helpers skipping paths just right,
Charts flowing free—what a wonderful sight! 🐰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and specifically describes the main change: adding the ChartFS.ExtractTo method, which is the primary feature introduced in this pull request.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
internal/chartfs/chartfs.go (1)

149-152: ⚡ Quick win

Add chart directory context to extraction failures

When one chart fails, returning the raw error makes triage slower in multi-chart extraction flows. Wrapping with chartDir here will keep errors actionable.

Suggested fix
 	for _, chartDir := range chartDirs {
 		if err := c.extractChartDir(destDir, chartDir); err != nil {
-			return err
+			return fmt.Errorf("extracting chart %q: %w", chartDir, err)
 		}
 	}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/chartfs/chartfs.go` around lines 149 - 152, The loop over chartDirs
returns raw errors from extractChartDir which loses which chart failed; update
the loop in the function containing chartDirs to wrap/annotate the returned
error with the chartDir value (e.g., return fmt.Errorf("extractChartDir %s: %w",
chartDir, err) or use errors.Wrapf) so callers can see which chart directory
caused the failure; target the call to extractChartDir in the same loop to add
this context.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/chartfs/chartfs.go`:
- Around line 110-113: The code uses os.MkdirAll and os.OpenFile but doesn't
enforce the desired permission bits on pre-existing paths; update the extraction
logic around d.IsDir()/target and the file-write path (the block that uses
os.OpenFile and writes files) to explicitly set permissions after creation by
calling os.Chmod(target, 0o755) for directories and os.Chmod(target, 0o644) for
files (and do so unconditionally after creation/write so existing entries are
normalized); ensure you perform the Chmod even when MkdirAll or OpenFile reports
no error and apply the same change pattern in the other similar block referenced
(the file-write block that currently opens/writes files) so both directories and
files always end up with the intended modes.

---

Nitpick comments:
In `@internal/chartfs/chartfs.go`:
- Around line 149-152: The loop over chartDirs returns raw errors from
extractChartDir which loses which chart failed; update the loop in the function
containing chartDirs to wrap/annotate the returned error with the chartDir value
(e.g., return fmt.Errorf("extractChartDir %s: %w", chartDir, err) or use
errors.Wrapf) so callers can see which chart directory caused the failure;
target the call to extractChartDir in the same loop to add this context.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8bbbd470-f0dd-4431-8f66-189233e066a9

📥 Commits

Reviewing files that changed from the base of the PR and between 105ac3e and 098c7b6.

📒 Files selected for processing (2)
  • internal/chartfs/chartfs.go
  • internal/chartfs/chartfs_test.go

Comment thread internal/chartfs/chartfs.go
ArgoCD's Helm source type requires an actual directory with `Chart.yaml`
and templates on disk, but `ChartFS` only provides in-memory `fs.FS`
access. The method `ExtractTo` bridges this gap by discovering chart
directories via the existing `walkAndFindChartDirs` and writing their
contents to a destination directory, filtering out root-level files and
non-chart directories like `_common/`.

Assisted-by: Claude

@Roming22 Roming22 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@Roming22 Roming22 merged commit f1b2984 into redhat-appstudio:main May 6, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants