Skip to content

Conversation

@rverdile
Copy link
Contributor

Automatically transform CDN repository URLs to use latest snapshots from content sources API when no explicit SnapshotDate is provided. Non-CDN repos pass through unchanged.

ticket: https://issues.redhat.com/browse/HMS-8918

}
}

for _, r := range arch.Repositories {
Copy link
Collaborator

@lzap lzap Oct 24, 2025

Choose a reason for hiding this comment

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

This could be a single loop and errors could be collected and then joined via errors.Join. But this is fine enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't mind changing this

@lzap
Copy link
Collaborator

lzap commented Oct 24, 2025

Looks ok.

@croissanne
Copy link
Member

I wonder if we can just drop repositories from distributions for select distributions in this case

@rverdile rverdile marked this pull request as ready for review October 28, 2025 13:53
@rverdile rverdile requested a review from a team as a code owner October 28, 2025 13:53
@rverdile
Copy link
Contributor Author

I wonder if we can just drop repositories from distributions for select distributions in this case

@croissanne Happy to implement this however you guys want. What would that look like? Do you mean remove the definition of the repository from the distributions folder? I thought it might be simpler to let image builder maintain its own source of truth in terms of what should be available, since there are many repos not provided by content sources

Comment on lines 265 to 290
if len(r.ImageTypeTags) > 0 && !slices.Contains(r.ImageTypeTags, string(imageType)) {
continue
}

composerRepo := composer.Repository{
CheckGpg: r.CheckGpg,
}

if r.Rhsm {
// CDN repository - try to use latest snapshot
var matchedRepo *content_sources.ApiRepositoryResponse
for _, apiRepo := range repoMap {
if apiRepo.Url != nil && *apiRepo.Url == *r.Baseurl {
matchedRepo = &apiRepo
break
}
}

if matchedRepo != nil && matchedRepo.LatestSnapshotUrl != nil && *matchedRepo.LatestSnapshotUrl != "" {
repoURL, err := url.Parse(*matchedRepo.LatestSnapshotUrl)
if err != nil {
return nil, fmt.Errorf("failed to parse snapshot URL for repository %s: %w", *r.Baseurl, err)
}
composerRepo.Baseurl = common.ToPtr(h.server.csReposURL.JoinPath(repoURL.Path).String())
composerRepo.Rhsm = common.ToPtr(false)
if matchedRepo.GpgKey != nil && *matchedRepo.GpgKey != "" {
composerRepo.Gpgkey = matchedRepo.GpgKey
}
composerRepo.ModuleHotfixes = matchedRepo.ModuleHotfixes
composerRepo.CheckRepoGpg = matchedRepo.MetadataVerification
} else {
return nil, fmt.Errorf("no latest snapshot URL available for CDN repository %s", *r.Baseurl)
}
} else {
// Non-CDN repository - use as-is
composerRepo.Baseurl = r.Baseurl
composerRepo.Metalink = r.Metalink
composerRepo.Rhsm = common.ToPtr(r.Rhsm)
composerRepo.Gpgkey = r.GpgKey
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd even be up for extracting this into a separate function. This as a whole creates composerRepo.
This can have an early return after !r.Rhsm.

if !r.Rhsm {
		return &composer.Repository{
			CheckGpg: r.CheckGpg,
			Baseurl:  r.Baseurl,
			Metalink: r.Metalink,
			Rhsm:     common.ToPtr(r.Rhsm),
			Gpgkey:   r.GpgKey,
		}, nil
	}
...and then the rest

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, I can do something like that

@rverdile
Copy link
Contributor Author

Something else I noticed is this needs to fall back to the CDN when it's a repo we don't snapshot (like a RHEL minor release). I'll work on that too

@rverdile
Copy link
Contributor Author

rverdile commented Nov 3, 2025

I have pushed changes based on the feedback, thanks all

Copy link
Contributor

@avitova avitova left a comment

Choose a reason for hiding this comment

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

I hahve only one suggestion but not a blocker. Looks nice, thanks!

Comment on lines 250 to 251
if len(r.ImageTypeTags) == 0 || slices.Contains(r.ImageTypeTags, string(imageType)) {
if r.Rhsm {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if len(r.ImageTypeTags) == 0 || slices.Contains(r.ImageTypeTags, string(imageType)) {
if r.Rhsm {
if (len(r.ImageTypeTags) == 0 || slices.Contains(r.ImageTypeTags, string(imageType))) && r.Rhsm {

Copy link
Member

@croissanne croissanne left a comment

Choose a reason for hiding this comment

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

Thanks! Let's keep a set of repositories in ibcrc then, but I wonder if it's not possible to clean up the code a little / reduce duplication of generating composer repositories from snapshots. (and maybe unit test that separately as well).

@rverdile
Copy link
Contributor Author

rverdile commented Nov 7, 2025

I have pushed more changes based on the feedback, thanks all

croissanne
croissanne previously approved these changes Nov 13, 2025
Copy link
Member

@croissanne croissanne left a comment

Choose a reason for hiding this comment

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

Thank you! The only thing i'd maybe add is also a 'why' in the commit message. Like what is the benefit of switching to snapshots for everything.

Other than that lgtm :)

Automatically transform CDN repository URLs to use latest snapshots
from content sources API when no explicit SnapshotDate is provided.
Non-CDN repos pass through unchanged. If a snapshot is not available,
falls back to CDN

Switching to latest snapshot aligns the method of authentication with
the one used for other snapshots and templates, reducing some
complexity
@rverdile
Copy link
Contributor Author

Could someone merge this for me? I don't have merge access :)

@avitova avitova added this pull request to the merge queue Nov 26, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 26, 2025
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.

5 participants