-
Notifications
You must be signed in to change notification settings - Fork 53
internal/v1: use latest snapshots for CDN repos by default #1712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| } | ||
| } | ||
|
|
||
| for _, r := range arch.Repositories { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
|
Looks ok. |
|
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 |
| 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 | ||
| } |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
|
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 |
50a478c to
b21e1df
Compare
|
I have pushed changes based on the feedback, thanks all |
b21e1df to
0d04a01
Compare
avitova
left a comment
There was a problem hiding this 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!
internal/v1/handler_compose_image.go
Outdated
| if len(r.ImageTypeTags) == 0 || slices.Contains(r.ImageTypeTags, string(imageType)) { | ||
| if r.Rhsm { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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 { |
croissanne
left a comment
There was a problem hiding this 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).
0d04a01 to
677be75
Compare
|
I have pushed more changes based on the feedback, thanks all |
croissanne
left a comment
There was a problem hiding this 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 :)
677be75 to
7d6f0fa
Compare
7d6f0fa to
8de1ffc
Compare
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
8de1ffc to
28e49ba
Compare
|
Could someone merge this for me? I don't have merge access :) |
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