From 321cccf017049fdc9e1b28dd7626b21cf80dbf75 Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Fri, 1 Nov 2024 15:21:10 -0400 Subject: [PATCH] plume/release: inject `oci-images` key in release index When updating the release index, gather the OCI pullspecs across all arches for a given release into a single list and inject it into the new `oci-images` key, the same way we do for OSTree commits and `commits`. Part of https://github.com/coreos/fedora-coreos-tracker/issues/1823. --- mantle/cmd/plume/release.go | 39 +++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/mantle/cmd/plume/release.go b/mantle/cmd/plume/release.go index 7a8da3f76c..2f3a3a2e7f 100644 --- a/mantle/cmd/plume/release.go +++ b/mantle/cmd/plume/release.go @@ -294,15 +294,21 @@ func modifyReleaseMetadataIndex(api *aws.API, rel release.Release) { } var commits []release.IndexReleaseCommit + var pullspecs []release.IndexReleaseOciImage for arch, vals := range rel.Architectures { commits = append(commits, release.IndexReleaseCommit{ Architecture: arch, Checksum: vals.Commit, }) + pullspecs = append(pullspecs, release.IndexReleaseOciImage{ + Architecture: arch, + ContainerImage: *vals.OciImage, + }) } newIdxRelease := release.IndexRelease{ Commits: commits, + OciImages: pullspecs, Version: specVersion, MetadataURL: url.String(), } @@ -313,19 +319,20 @@ func modifyReleaseMetadataIndex(api *aws.API, rel release.Release) { plog.Fatalf("build is already present and is not the latest release") } - comp := compareCommits(rel.Commits, newIdxRelease.Commits) - if comp == 0 { + compCommits := compareCommits(rel.Commits, newIdxRelease.Commits) + compImages := compareOciImages(rel.OciImages, newIdxRelease.OciImages) + if compCommits == 0 && compImages == 0 { // the build is already the latest release, exit plog.Notice("build is already present and is the latest release") return - } else if comp == -1 { + } else if compCommits == -1 || compImages == -1 { // the build is present and contains a subset of the new release data, // pop the old entry and add the new version releaseIdx.Releases = releaseIdx.Releases[:len(releaseIdx.Releases)-1] break } else { // the commit hash of the new build is not a superset of the current release - plog.Fatalf("build is present but commit hashes are not a superset of latest release") + plog.Fatalf("build is present but commit hashes or images are not a superset of latest release") } } } @@ -385,3 +392,27 @@ func compareCommits(a, b []release.IndexReleaseCommit) int { } return -1 } + +// returns -1 if a is a subset of b, 0 if equal, 1 if a is not a subset of b +func compareOciImages(a, b []release.IndexReleaseOciImage) int { + if len(a) > len(b) { + return 1 + } + sameLength := len(a) == len(b) + for _, aImage := range a { + found := false + for _, bImage := range b { + if aImage.Architecture == bImage.Architecture && aImage.ContainerImage == bImage.ContainerImage { + found = true + break + } + } + if !found { + return 1 + } + } + if sameLength { + return 0 + } + return -1 +}