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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ generate-deprecate-all: install ## ensure that you have update the the date of t

.PHONY: generate-pkgs ## This method should be remove soon. It is only an internal helper
generate-pkgs: install ## ensure that you have update the the date of the report.
go run ./hack/scripts/packages/generate.go --image=testdata/reports/redhat_certified_operator_index/bundles_registry.redhat.io_redhat_certified_operator_index_v4.9_2021-08-22.json
go run ./hack/scripts/packages/generate.go --image=testdata/reports/redhat_redhat_marketplace_index/bundles_registry.redhat.io_redhat_redhat_marketplace_index_v4.9_2021-08-22.json
go run ./hack/scripts/packages/generate.go --image=testdata/reports/redhat_certified_operator_index/bundles_registry.redhat.io_redhat_certified_operator_index_v4.8_2021-08-21.json
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we should pass these in as env vars so it's not causing a git diff each time we want a new report target?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Why should we inform the required input which changes for can each report generate via env var instead of use flags?
the audit tool is a CLI tool. It is using Cobra which allows us to easily create commands and have their flags. If you run --help you can check all optional flags and the values that you can inform.

The helper in the makefile needs to be updated with the JSON file every time that we add re-generate the reports. See the comment ensure that you have update the the date of the report. The Makefile here was added just to make it easier re-generate these reports and make clear/understandable how to do it for others in case I cannot do it and another person requires to run.

Also, see the comment description of the helper which appears via make --help This method should be removed soon. It is only an internal helper

go run ./hack/scripts/packages/generate.go --image=testdata/reports/redhat_redhat_marketplace_index/bundles_registry.redhat.io_redhat_redhat_marketplace_index_v4.8_2021-08-21.json
go run ./hack/scripts/packages/generate.go --image=testdata/reports/redhat_redhat_operator_index/bundles_registry.redhat.io_redhat_redhat_operator_index_v4.8_2021-08-21.json
go run ./hack/scripts/packages/generate.go --image=testdata/reports/redhat_community_operator_index/bundles_registry.redhat.io_redhat_community_operator_index_v4.8_2021-08-21.json

Expand Down
154 changes: 152 additions & 2 deletions hack/scripts/packages/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,15 @@ import (
)

type File struct {
APIDashReport *custom.APIDashReport
APIDashReport *custom.APIDashReport
MigrateNotIn49 []custom.OK
NotMigrateWithReplaces []custom.PartialComplying
NotMigrateWithReplacesAllHeads []custom.PartialComplying
NotMigrateWithSkips []custom.PartialComplying
NotMigrateWithSkipsRange []custom.PartialComplying
NotMigrateUnknow []custom.PartialComplying
TotalWorking49 int
NotMigratesMix []custom.PartialComplying
}

//nolint: lll
Expand Down Expand Up @@ -75,9 +83,144 @@ func main() {
log.Fatal(err)
}

// Packages which has compatible version but none of them will end up on 4.9
var migrateNotIn49 []custom.OK
for _, v := range apiDashReport.OK {
foundIn49 := false
for _, b := range v.AllBundles {
if len(b.KindsDeprecateAPIs) == 0 && (len(b.OCPLabel) == 0 || !pkg.IsOcpLabelRangeLowerThan49(b.OCPLabel)) {
foundIn49 = true
break
}
}
if !foundIn49 {
migrateNotIn49 = append(migrateNotIn49, v)
continue
}
}

// Packages which does not nave any compatible version with 4.9 and are using replaces
var notMigrateWithReplaces []custom.PartialComplying
for _, v := range apiDashReport.PartialComplying {
foundReplace := false
headOfChannels := custom.GetHeadOfChannels(v.AllBundles)
for _, b := range headOfChannels {
if len(b.Replace) > 0 {
foundReplace = true
break
}
}
if foundReplace {
notMigrateWithReplaces = append(notMigrateWithReplaces, v)
continue
}
}

var notMigrateWithSkips []custom.PartialComplying
for _, v := range apiDashReport.PartialComplying {
foundSkips := false
headOfChannels := custom.GetHeadOfChannels(v.AllBundles)
for _, b := range headOfChannels {
if len(b.Skips) > 0 {
foundSkips = true
break
}
}
if foundSkips {
notMigrateWithSkips = append(notMigrateWithSkips, v)
continue
}
}

var notMigrateWithSkipRange []custom.PartialComplying
for _, v := range apiDashReport.PartialComplying {
foundSkipRange := false
headOfChannels := custom.GetHeadOfChannels(v.AllBundles)
for _, b := range headOfChannels {
if len(b.SkipRange) > 0 {
foundSkipRange = true
break
}
}
if foundSkipRange {
notMigrateWithSkipRange = append(notMigrateWithSkipRange, v)
continue
}
}

var notMigratesMix []custom.PartialComplying
for _, v := range apiDashReport.PartialComplying {
found := false
headOfChannels := custom.GetHeadOfChannels(v.AllBundles)
for _, b := range headOfChannels {
if len(b.Replace) > 0 && (len(b.Skips) > 0 || len(b.SkipRange) > 0) {
found = true
break
}
}
if !found {
notMigratesMix = append(notMigratesMix, v)
continue
}
}

var notMigrateUnknow []custom.PartialComplying
for _, v := range apiDashReport.PartialComplying {
found := false
headOfChannels := custom.GetHeadOfChannels(v.AllBundles)
for _, b := range headOfChannels {
if len(b.SkipRange) > 0 || len(b.Skips) > 0 || len(b.Replace) > 0 {
found = true
break
}
}
if !found {
notMigrateUnknow = append(notMigrateUnknow, v)
}
}

var notMigrateWithReplacesAllHeads []custom.PartialComplying
for _, v := range apiDashReport.PartialComplying {
notFoundReplace := false
headOfChannels := custom.GetHeadOfChannels(v.AllBundles)
for _, b := range headOfChannels {
if len(b.Replace) == 0 {
notFoundReplace = true
break
}
}
if !notFoundReplace {
notMigrateWithReplacesAllHeads = append(notMigrateWithReplacesAllHeads, v)
continue
}
}

sort.Slice(apiDashReport.PartialComplying[:], func(i, j int) bool {
return apiDashReport.PartialComplying[i].Name < apiDashReport.PartialComplying[j].Name
})
sort.Slice(migrateNotIn49[:], func(i, j int) bool {
return migrateNotIn49[i].Name < migrateNotIn49[j].Name
})
sort.Slice(notMigrateWithReplaces[:], func(i, j int) bool {
return notMigrateWithReplaces[i].Name < notMigrateWithReplaces[j].Name
})
sort.Slice(notMigrateWithReplacesAllHeads[:], func(i, j int) bool {
return notMigrateWithReplacesAllHeads[i].Name < notMigrateWithReplacesAllHeads[j].Name
})
sort.Slice(notMigrateWithSkips[:], func(i, j int) bool {
return notMigrateWithSkips[i].Name < notMigrateWithSkips[j].Name
})
sort.Slice(notMigrateWithSkipRange[:], func(i, j int) bool {
return notMigrateWithSkipRange[i].Name < notMigrateWithSkipRange[j].Name
})
sort.Slice(notMigrateUnknow[:], func(i, j int) bool {
return notMigrateUnknow[i].Name < notMigrateUnknow[j].Name
})
sort.Slice(notMigratesMix[:], func(i, j int) bool {
return notMigratesMix[i].Name < notMigratesMix[j].Name
})

totalWorking49 := len(apiDashReport.OK) - len(migrateNotIn49)

fp := filepath.Join(currentPath, outputPath, pkg.GetReportName(apiDashReport.ImageName, "package", "txt"))
f, err := os.Create(fp)
Expand All @@ -88,7 +231,14 @@ func main() {
defer f.Close()

t := template.Must(template.ParseFiles(filepath.Join(currentPath, "hack/scripts/packages/template.go.tmpl")))
err = t.Execute(f, File{APIDashReport: apiDashReport})
err = t.Execute(f, File{APIDashReport: apiDashReport,
MigrateNotIn49: migrateNotIn49,
NotMigrateWithReplaces: notMigrateWithReplaces,
NotMigrateWithReplacesAllHeads: notMigrateWithReplacesAllHeads,
TotalWorking49: totalWorking49,
NotMigrateWithSkips: notMigrateWithSkips,
NotMigrateWithSkipsRange: notMigrateWithSkipRange,
NotMigrateUnknow: notMigrateUnknow})
if err != nil {
panic(err)
}
Expand Down
Loading