Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions cmd/index/eus/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -404,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)
Expand All @@ -425,16 +430,14 @@ 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 {
nonHeadBundleNamesPerChannel = append(nonHeadBundleNamesPerChannel, bundle.Name)
}
headBundle, _ := Channel.Head()
nonHeadBundleNamesPerChannel = remove(nonHeadBundleNamesPerChannel, headBundle.Name)
nonHeadBundleNames[i] = nonHeadBundleNamesPerChannel
i++
nonHeadBundleNames[indexOf(Channel.Name, grouping.ChannelNames)] = nonHeadBundleNamesPerChannel
}
}
}
Expand All @@ -443,6 +446,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 {
Expand Down
12 changes: 6 additions & 6 deletions pkg/actions/extract_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -47,21 +47,21 @@ 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 {
log.Infof("unable to extract index.db (probably file based config index) %s : %s", image, err)
}
// 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/<package_name>/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 {
Expand Down