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
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '~1.16'
go-version: '~1.17'
- run: make build
2 changes: 1 addition & 1 deletion .github/workflows/license-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: '1.15'
go-version: '1.17'
- name: Perform the test
run: make test-license
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '~1.16'
go-version: '~1.17'
- run: |
make build
chmod +x bin/audit-tool
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: '1.16'
go-version: '1.17'
- name: Perform the test
run: make test
coverage:
Expand All @@ -34,7 +34,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: '1.16'
go-version: '1.17'
- name: Generate the coverage output
run: make test-coverage
- name: Send the coverage output
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ generate-dashboards:
go run ./hack/deprecate-api/generate.go
go run ./hack/maxocpversion/generate.go
go run ./hack/grade/generate.go
go run ./hack/catalogs/generate.go
go run ./hack/muiltarch/generate.go
go run ./hack/index/generate.go

Expand All @@ -107,3 +108,8 @@ generate-all:
make generate-testdata
make generate-dashboards

.PHONY: generate-test ## Generate the full testdata directory
generate-test: install
$(CONTAINER_ENGINE) login https://registry.redhat.io
go run ./hack/report/bundles/generate.go
go run ./hack/deprecate-api/generate.go
116 changes: 116 additions & 0 deletions cmd/custom/catalogs/command.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
// Copyright 2021 The Audit Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this File except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package catalogs

import (
"html/template"
"os"
"path/filepath"
"strings"

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"

"github.com/operator-framework/audit/pkg"
"github.com/operator-framework/audit/pkg/reports/custom"
)

var name string

func NewCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "catalogs",
Short: "generates a custom report to let us know all distributions which are shipped in more than a catalog",
Long: "use this command with the result of `audit index bundles [OPTIONS]` to check a dashboard in HTML format " +
"with the packages data",
PreRunE: validation,
RunE: run,
}

currentPath, err := os.Getwd()
if err != nil {
log.Error(err)
os.Exit(1)
}

cmd.Flags().StringVar(&custom.Flags.Files, "files", "",
"path of the JSON File(s) using result of the command audit-tool index bundles --index-image=<image> [OPTIONS]")
if err := cmd.MarkFlagRequired("files"); err != nil {
log.Fatalf("Failed to mark `file` flag for `index` sub-command as required")
}
cmd.Flags().StringVar(&custom.Flags.OutputPath, "output-path", currentPath,
"inform the path of the directory to output the report. (Default: current directory)")
cmd.Flags().StringVar(&custom.Flags.Template, "template", "",
"inform the path of the template that should be used. If not informed the default will be used")
cmd.Flags().StringVar(&custom.Flags.Filter, "filter", "",
"filter by the packages names which are like *filter*")
cmd.Flags().StringVar(&name, "name", "",
"inform the report name")
return cmd
}

func validation(cmd *cobra.Command, args []string) error {
if len(custom.Flags.OutputPath) > 0 {
if _, err := os.Stat(custom.Flags.OutputPath); os.IsNotExist(err) {
return err
}
}
return nil
}

func run(cmd *cobra.Command, args []string) error {
log.Info("Starting ...")

currentPath, err := os.Getwd()
if err != nil {
return err
}

allBundlesReport, err := custom.ParseMultiBundlesJSONReport()
if err != nil {
return err
}

catalogReport := custom.NewCatalogReportReport(allBundlesReport, custom.Flags.Filter, name)

reportName := strings.ReplaceAll(name, " ", "_")
dashOutputPath := filepath.Join(custom.Flags.OutputPath,
pkg.GetReportName(reportName, "catalog", "html"))

f, err := os.Create(dashOutputPath)
if err != nil {
log.Fatal(err)
}

if len(custom.Flags.Template) == 0 {
custom.Flags.Template = getTemplatePath(currentPath)
}

t := template.Must(template.ParseFiles(custom.Flags.Template))
err = t.Execute(f, catalogReport)
if err != nil {
panic(err)
}

f.Close()
log.Infof("Operation completed.")

return nil
}

//todo: this template requires to be embed
func getTemplatePath(currentPath string) string {
return filepath.Join(currentPath, "/cmd/custom/catalogs/template.go.tmpl")
}
172 changes: 172 additions & 0 deletions cmd/custom/catalogs/template.go.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport"
content="width=device-width, initial-scale=1">
<meta name="description" content="">
<title>Deprecated API(s) Dashboard</title>

<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/dt-1.10.24/datatables.min.css"/>

<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">


<style>
div.dataTables_wrapper {
width: 98%;
margin: 0 auto;
}

table.minimalistBlack {
border: 3px solid #000000;
}
table.minimalistBlack td, table.minimalistBlack th {
border: 1px solid #000000;
font-size: 10px;
text-align: left;
}
table.minimalistBlack tbody td {
font-size: 10px;
}
table.minimalistBlack thead {
border-bottom: 3px solid #000000;
text-align: center;
}
table.minimalistBlack thead th {
font-size: 12px;
color: white;
text-align: center;
}

.themed-container {
padding: .75rem;
margin-bottom: 1.5rem;
background-color: #F0F0F0;
border: 1px solid #0D0C0C;
}
</style>


</head>
<body class="py-4">

<script type="text/javascript" src="https://cdn.datatables.net/v/dt/dt-1.10.24/datatables.min.js"></script>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.24/js/jquery.dataTables.min.js"></script>

<!-- Option 1: Bootstrap Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-gtEjrD/SeCtmISkJkNUaaKMoLD0//ElJ19smozuHV6z3Iehds+3Ulb9Bn9Plx0x4" crossorigin="anonymous"></script>

<script >

$(document).ready(function() {
$('#list').DataTable( {
"scrollX": true
} );
$('#list1').DataTable( {
"scrollX": true
});
$('#list2').DataTable( {
"scrollX": true
});

} );

</script>

<main>

<h1>Catalog Conflicts Dashboard - {{ .Name }}</h1>
<p>This report aims to try to identify the package distributions that are duplicated in the index informed.</p>

<div class="container-fluid themed-container">
<h5 class="display-12 fw-bold">Data from:</h5>
<p>Image names: </p>
<ul>
{{ range .ImageNames }}
<li>{{ . }}</li>
{{ end }}
</ul>
<p>GeneratedAt : {{ .GeneratedAt }} </p>

</div>

<div class="container-fluid themed-container">
<h5 class="display-12 fw-bold">Same Package Name:</h5>
<p>The following are the packages found in more than one index with the same package name</p>
<table id="list1" class="minimalistBlack" style="background-color: #ec8f1c; width:98%">
<thead>
<tr>
<th>Package Name</th>
<th>Catalogs</th>
</tr>
</thead>
<tbody>
{{ with .ByPropertiesPackageName }}
{{ range . }}
{{ if ne .PackageName "" }}
<tr>
<th>{{ .PackageName }}</th>
<th>
<ul>
{{ range .Catalogs }}
<li>{{ . }}</li>
{{ end }}
</ul>
</th>
</tr>
{{ end }}
{{ end }}
{{ end }}
</tbody>
</table>
</div>

<div class="container-fluid themed-container">
<h5 class="display-12 fw-bold">Same APIs:</h5>
<p>The following are the packages found in more than one index which are using the same apis</p>
<table id="list2" class="minimalistBlack" style="background-color: #ec8f1c; width:98%">
<thead>
<tr>
<th>Packages</th>
<th>Catalogs</th>
<th>GKVs</th>
</tr>
</thead>
<tbody>
{{ with .ByPropertiesGKV }}
{{ range . }}
<tr>
<th>
<ul>
{{ range .PackageNames }}
<li>{{ . }}</li>
{{ end }}
</ul>
</th>
<th>
<ul>
{{ range .Catalogs }}
<li>{{ . }}</li>
{{ end }}
</ul>
</th>
<th>
<ul>
{{ range .GKV }}
<li>{{ . }}</li>
{{ end }}
</ul>
</th>
</tr>
{{ end }}
{{ end }}
</tbody>
</table>
</div>
</main>

</body>
</html>
19 changes: 14 additions & 5 deletions cmd/custom/deprecate/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package deprecate

import (
"fmt"
"html/template"
"os"
"path/filepath"
Expand All @@ -28,9 +29,11 @@ import (

func NewCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "deprecate-apis",
Short: "generates a custom report based on defined criteria over the deprecated apis scenario for 1.22",
Long: "use this command with the result of `audit index bundles [OPTIONS]` to check a dashboard in HTML format " +
Use: "deprecate-apis",
Short: "generates a custom report based on defined criteria over the " +
"deprecated apis scenario for 1.22 by default or the version informed",
Long: "use this command with the result of `audit index bundles [OPTIONS]` " +
"to check a dashboard in HTML format " +
"with the packages data",
PreRunE: validation,
RunE: run,
Expand All @@ -51,6 +54,12 @@ func NewCmd() *cobra.Command {
"inform the path of the directory to output the report. (Default: current directory)")
cmd.Flags().StringVar(&custom.Flags.Template, "template", "",
"inform the path of the template that should be used. If not informed the default will be used")
optionalValueEmpty := map[string]string{}
cmd.Flags().StringToStringVarP(&custom.Flags.OptionalValues, "optional-values", "", optionalValueEmpty,
"Inform a []string map of key=values which can be used by the report. e.g. to check the usage of deprecated APIs "+
"against an Kubernetes version that it is intended to be distributed use `--optional-values=k8s-version=1.22`")
cmd.Flags().StringVar(&custom.Flags.Filter, "filter", "",
"filter by the packages names which are like *filter*")
return cmd
}

Expand All @@ -76,10 +85,10 @@ func run(cmd *cobra.Command, args []string) error {
return err
}

apiDashReport := custom.NewAPIDashReport(bundlesReport)
apiDashReport := custom.NewAPIDashReport(bundlesReport, custom.Flags.OptionalValues, custom.Flags.Filter)

dashOutputPath := filepath.Join(custom.Flags.OutputPath,
pkg.GetReportName(apiDashReport.ImageName, "deprecate-apis", "html"))
pkg.GetReportName(apiDashReport.ImageName, fmt.Sprintf("deprecate-apis-%s", apiDashReport.K8SVersion), "html"))

f, err := os.Create(dashOutputPath)
if err != nil {
Expand Down
Loading