From 7dd3b3af91a6521e061d1b6f1bccda433dfd6a9c Mon Sep 17 00:00:00 2001 From: Brett Tofel Date: Fri, 3 Mar 2023 11:14:01 +0100 Subject: [PATCH 1/3] Fix adds rm in-use container so rmi can succeed Fixes https://issues.redhat.com/browse/PORTENABLE-481 --- cmd/index/eus/command.go | 4 ++++ pkg/actions/extract_index.go | 12 ++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/cmd/index/eus/command.go b/cmd/index/eus/command.go index 065258f0..70aae69b 100644 --- a/cmd/index/eus/command.go +++ b/cmd/index/eus/command.go @@ -126,6 +126,10 @@ func run(cmd *cobra.Command, args []string) error { EUSReportColumn = append(EUSReportColumn, channelGrouping) } EUSReportTable = append(EUSReportTable, EUSReportColumn) + + // must rm container so all rmi succeed + command := exec.Command(flags.ContainerEngine, "rm", actions.CatalogIndex) + _, _ = pkg.RunCommand(command) // always remove catalog images, so always non-"server-mode" as elsewhere rmiCmd := exec.Command(flags.ContainerEngine, "rmi", flags.Indexes[index]) _, _ = pkg.RunCommand(rmiCmd) diff --git a/pkg/actions/extract_index.go b/pkg/actions/extract_index.go index 23569d48..511f4acb 100644 --- a/pkg/actions/extract_index.go +++ b/pkg/actions/extract_index.go @@ -23,16 +23,16 @@ import ( log "github.com/sirupsen/logrus" ) -const catalogIndex = "audit-catalog-index" +const CatalogIndex = "audit-catalog-index" func ExtractIndexDBorCatalogs(image string, containerEngine string) error { log.Info("Extracting database...") // Remove image if exists already - command := exec.Command(containerEngine, "rm", catalogIndex) + command := exec.Command(containerEngine, "rm", CatalogIndex) _, _ = pkg.RunCommand(command) // Download the image - command = exec.Command(containerEngine, "create", "--name", catalogIndex, image, "\"yes\"") + command = exec.Command(containerEngine, "create", "--name", CatalogIndex, image, "\"yes\"") _, err := pkg.RunCommand(command) if err != nil { return fmt.Errorf("unable to create container image %s : %s", image, err) @@ -47,7 +47,7 @@ func ExtractIndexDBorCatalogs(image string, containerEngine string) error { log.Fatal(err) } // sqlite db - command = exec.Command(containerEngine, "cp", fmt.Sprintf("%s:/database/index.db", catalogIndex), + command = exec.Command(containerEngine, "cp", fmt.Sprintf("%s:/database/index.db", CatalogIndex), "./output/"+versionTag+"/") _, err = pkg.RunCommand(command) if err != nil { @@ -55,13 +55,13 @@ func ExtractIndexDBorCatalogs(image string, containerEngine string) error { } // transitional indexes have a hidden sqlite db, copy it, and change the name to just index.db command = exec.Command(containerEngine, "cp", - fmt.Sprintf("%s:/var/lib/iib/_hidden/do.not.edit.db", catalogIndex), "./output/"+versionTag+"/index.db") + fmt.Sprintf("%s:/var/lib/iib/_hidden/do.not.edit.db", CatalogIndex), "./output/"+versionTag+"/index.db") _, err = pkg.RunCommand(command) if err != nil { log.Infof("unable to extract the image for index.db (transition or file based config index) %s : %s", image, err) } // For FBC extract they are on the image, in /configs//catalog.json - command = exec.Command(containerEngine, "cp", fmt.Sprintf("%s:/configs/", catalogIndex), + command = exec.Command(containerEngine, "cp", fmt.Sprintf("%s:/configs/", CatalogIndex), "./output/"+versionTag+"/") _, errFbc := pkg.RunCommand(command) if errFbc != nil { From 58fefadee25ed86ce4d4e99a3bcba19428308e21 Mon Sep 17 00:00:00 2001 From: Brett Tofel Date: Sat, 11 Mar 2023 09:59:02 +0100 Subject: [PATCH 2/3] Fix mis-ordering channels bundle data for FBC --- cmd/index/eus/command.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/cmd/index/eus/command.go b/cmd/index/eus/command.go index 70aae69b..c82f5314 100644 --- a/cmd/index/eus/command.go +++ b/cmd/index/eus/command.go @@ -429,7 +429,6 @@ func getNonHeadBundles(modelOrDb interface{}, grouping channelGrouping) [][]stri case model.Model: for _, Package := range modelOrDb { if Package.Name == grouping.OperatorName { - i := 0 for _, Channel := range Package.Channels { var nonHeadBundleNamesPerChannel []string for _, bundle := range Channel.Bundles { @@ -437,8 +436,7 @@ func getNonHeadBundles(modelOrDb interface{}, grouping channelGrouping) [][]stri } headBundle, _ := Channel.Head() nonHeadBundleNamesPerChannel = remove(nonHeadBundleNamesPerChannel, headBundle.Name) - nonHeadBundleNames[i] = nonHeadBundleNamesPerChannel - i++ + nonHeadBundleNames[indexOf(Channel.Name, grouping.ChannelNames)] = nonHeadBundleNamesPerChannel } } } @@ -447,6 +445,15 @@ func getNonHeadBundles(modelOrDb interface{}, grouping channelGrouping) [][]stri return nonHeadBundleNames } +func indexOf(word string, data []string) int { + for k, v := range data { + if word == v { + return k + } + } + return -1 +} + func remove(nonHeadBundles []string, headBundle string) []string { for i, v := range nonHeadBundles { if v == headBundle { From 2eb6f04b5b654c449ec5854851466f15d2f0b463 Mon Sep 17 00:00:00 2001 From: Brett Tofel Date: Sat, 11 Mar 2023 10:33:58 +0100 Subject: [PATCH 3/3] Fix duplicate bundles for SQLite-based catalogs --- cmd/index/eus/command.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmd/index/eus/command.go b/cmd/index/eus/command.go index c82f5314..e63b13d9 100644 --- a/cmd/index/eus/command.go +++ b/cmd/index/eus/command.go @@ -408,7 +408,8 @@ func getNonHeadBundles(modelOrDb interface{}, grouping channelGrouping) [][]stri FROM operatorbundle INNER JOIN channel_entry ON operatorbundle.name=channel_entry.operatorbundle_name - WHERE channel_entry.package_name = ? AND channel_entry.channel_name = ?;` + WHERE channel_entry.package_name = ? AND channel_entry.channel_name = ? + GROUP BY operatorbundle.name;` row, err := modelOrDb.Query(sql, grouping.OperatorName, channelName) if err != nil { log.Errorf("unable to query the index db for maxOCPs : %s", err)