Skip to content

Fix devfile registry resource download to work with any registry#5946

Open
vrubezhny wants to merge 1 commit into
redhat-developer:mainfrom
vrubezhny:fix-registry-resource-download
Open

Fix devfile registry resource download to work with any registry#5946
vrubezhny wants to merge 1 commit into
redhat-developer:mainfrom
vrubezhny:fix-registry-resource-download

Conversation

@vrubezhny

Copy link
Copy Markdown
Contributor

This commit fixes resource downloading to work with any devfile registry (not just hard-coded GitHub URLs) and implements proper URI resolution matching the behavior of the devfile/library Go implementation.

Problem:

  • Resources were downloaded using hard-coded GitHub URLs
  • Parent devfile resources were resolved against wrong source URLs
  • Resources downloaded AFTER merging, losing parent URL context
  • No support for both downloadResources (save to disk) and inlineResources modes

Solution:

  1. DevfileUriResolver (new file)

  2. DevfileResolver refactoring

    • Added DevfileResolveOptions interface: - downloadResources: Save resources to disk (for odo init) - inlineResources: Inline content into devfile (for odo deploy/dev) - resourcesBasePath: Where to save downloaded files
    • Changed resolveParentChain() to return DevfileWithSource[] tracking source URL
    • Process resources BEFORE merging to preserve URL context
    • Each devfile in parent chain keeps its source URL for correct URI resolution
  3. DevfileRegistryWrapper update

    • downloadFromRegistryRepo() now accepts registryUrl parameter
    • Uses DevfileUriResolver instead of hard-coded GitHub URLs
    • Works with any devfile registry endpoint
  4. Init component integration

    • Removed separate downloadStackExtraFiles() function
    • Resource downloading now integrated into resolve() process
    • Properly handles both parent and child resources with correct URLs

Key architectural changes:

  • Two-phase approach: resolveParentChain() returns DevfileWithSource[]
  • Resources processed BEFORE merging (not after)
  • Source URL tracked through entire parent chain
  • URI resolution happens at the correct context (per devfile, not once at end)

Testing:

  • 11 unit tests for DevfileUriResolver (URI resolution logic)
  • 7 unit tests for DevfileResolver (resource processing with mocked data)
  • 3 integration tests using real go-basic devfile from registry.devfile.io:
    • downloadResources mode (saves to disk)
    • inlineResources mode (inlines into devfile)
    • no options mode (URIs unchanged)

Assisted-By: Claude Sonnet 4.5 noreply@anthropic.com

@codecov

codecov Bot commented Jul 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 82.20859% with 29 lines in your changes missing coverage. Please review.
✅ Project coverage is 49.22%. Comparing base (da60441) to head (0e5c8a8).
⚠️ Report is 1866 commits behind head on main.

Files with missing lines Patch % Lines
src/devfile/devfileResolver.ts 84.90% 16 Missing ⚠️
src/devfile/devfileUriResolver.ts 84.21% 6 Missing ⚠️
src/devfile-registry/devfileRegistryWrapper.ts 0.00% 5 Missing ⚠️
src/devfile/init.ts 84.61% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #5946       +/-   ##
===========================================
+ Coverage   32.37%   49.22%   +16.85%     
===========================================
  Files          85      111       +26     
  Lines        6505    10153     +3648     
  Branches     1349     2293      +944     
===========================================
+ Hits         2106     4998     +2892     
- Misses       4399     5150      +751     
- Partials        0        5        +5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@vrubezhny vrubezhny force-pushed the fix-registry-resource-download branch 15 times, most recently from 5c097b7 to fbb9ab1 Compare July 9, 2026 10:15
This commit fixes resource downloading to work with any devfile registry
(not just hard-coded GitHub URLs) and implements proper URI resolution
matching the behavior of the devfile/library Go implementation.

**Problem:**
- Resources were downloaded using hard-coded GitHub URLs
- Parent devfile resources were resolved against wrong source URLs
- Resources downloaded AFTER merging, losing parent URL context
- No support for both downloadResources (save to disk) and inlineResources modes

**Solution:**

1. **DevfileUriResolver** (new file)
   - Implements proper URI resolution matching Go devfile/library
   - Handles: absolute HTTP URLs, relative to file, relative to registry URL
   - Example: "kubernetes/deploy.yaml" + "https://registry.devfile.io/devfiles/go/2.6.0"
     → "https://registry.devfile.io/devfiles/go/2.6.0/kubernetes/deploy.yaml"
   - Includes retry with exponential backoff for HTTP 429 (Too Many Requests)

2. **DevfileResolver refactoring**
   - Added DevfileResolveOptions interface:
     - downloadResources: Save resources to disk (for odo init)
     - inlineResources: Inline content into devfile (for odo deploy/dev)
     - resourcesBasePath: Where to save downloaded files
   - Changed resolveParentChain() to return DevfileWithSource[] tracking source URL
   - Process resources BEFORE merging to preserve URL context
   - Each devfile in parent chain keeps its source URL for correct URI resolution

3. **DevfileRegistryWrapper update**
   - downloadFromRegistryRepo() now accepts registryUrl parameter
   - Uses DevfileUriResolver instead of hard-coded GitHub URLs
   - Works with any devfile registry endpoint

4. **Init component integration**
   - Removed separate downloadStackExtraFiles() function
   - Resource downloading now integrated into resolve() process
   - Properly handles both parent and child resources with correct URLs

**Key architectural changes:**
- Two-phase approach: resolveParentChain() returns DevfileWithSource[]
- Resources processed BEFORE merging (not after)
- Source URL tracked through entire parent chain
- URI resolution happens at the correct context (per devfile, not once at end)

**Testing:**
- 11 unit tests for DevfileUriResolver (URI resolution logic)
- 7 unit tests for DevfileResolver (resource processing with mocked data)
- 3 integration tests using real go-basic devfile from registry.devfile.io:
  - downloadResources mode (saves to disk)
  - inlineResources mode (inlines into devfile)
  - no options mode (URIs unchanged)

Signed-off-by: Victor Rubezhny <vrubezhny@redhat.com>
Assisted-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@vrubezhny vrubezhny force-pushed the fix-registry-resource-download branch from fbb9ab1 to 0e5c8a8 Compare July 9, 2026 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant