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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@
**/testdata/reports/contacts/**
**/testdata/reports/deprecate-all/**
**/testdata/reports/deprecate-green/**
**/testdata/reports/deprecate-json/**
**/testdata/reports/deprecate-json/**
**compare.json**
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ generate-testdata:
.PHONY: generate-dashboards ## Generate the testdata custom dashboards
generate-dashboards:
go run ./hack/deprecate-api/generate.go
go run ./hack/maxocpversion/generate.go
go run ./hack/grade/generate.go
go run ./hack/index/generate.go

Expand Down
9 changes: 8 additions & 1 deletion cmd/custom/deprecate/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ func NewCmd() *cobra.Command {
}
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")
return cmd
}

Expand Down Expand Up @@ -84,7 +86,11 @@ func run(cmd *cobra.Command, args []string) error {
log.Fatal(err)
}

t := template.Must(template.ParseFiles(getTemplatePath(currentPath)))
if len(custom.Flags.Template) == 0 {
custom.Flags.Template = getTemplatePath(currentPath)
}

t := template.Must(template.ParseFiles(custom.Flags.Template))
err = t.Execute(f, apiDashReport)
if err != nil {
panic(err)
Expand All @@ -96,6 +102,7 @@ func run(cmd *cobra.Command, args []string) error {
return nil
}

//todo: this template requires to be embed
func getTemplatePath(currentPath string) string {
return filepath.Join(currentPath, "/cmd/custom/deprecate/template.go.tmpl")
}
65 changes: 6 additions & 59 deletions cmd/custom/deprecate/template.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -102,66 +102,13 @@
</ul>
<h5 class="display-12 fw-bold">3. What does it mean for a package to be in red, amber or green?</h5>
<ul>
<li> <b>(Red) Not complying:</b> these are packages which have no head of channel bundles compatible with 4.9(uses removed API(s) on k8s 1.22/ocp 4.9), and no head of channel has a Max OCP annotation set </li>
<li> <b>(Green) Complying:</b> these are packages for which all head of channel bundles are compatible with 4.9(do not use removed API(s) in k8s 1.22/ocp 4.9) or at least has one of the head of channel bundles is compatible with 4.9 and the rest of the head of channel bundles use the Max OCP version annotation properly</li>
<li> <b>(Amber) Partially Complying:</b> these are packages which are not in red or green falls in the amber category. The ones that are partially complying with the requirements but not fully. E.g. at least one head of channel bundles is not compatible with 4.9 and does not declare an appropriate Max OCP version, or none of the head of channel bundles are compatible with 4.9.</li>
<li> <b>(Green) Complying:</b> these are packages that we cannot found the removed APIs in k8s 1.22/OCP 4.9 in at least one bundle version</li>
<li> <b>(Amber) Not complying:</b> these are the packages that we cannot found any versions which is not using the removed APIs in in k8s 1.22/OCP 4.9</li>
</ul>
</div>

<div class="container-fluid themed-container">
<h5 class="display-12 fw-bold">Not complying with the recommendations</h5>
<table id="migrate" class="minimalistBlack" style="background-color: #EC1C1C; width:98%">
<thead>
<tr>
<th>Package Name</th>
<th>Kinds to migrate</th>
<th>Channels</th>
<th>Bundles uses API(s)</th>
<th>Bundles Migrated</th>
</tr>
</thead>
<tbody>
{{ with .NotComplying }}
{{ range . }}
<tr>
<th>{{ .Name }}</th>
<th>
<ul>
{{ range .Kinds }}
<li>{{ . }}</li>
{{ end }}
</ul>
</th>
<th>
<ul>
{{ range .Channels }}
<li>{{ . }}</li>
{{ end }}
</ul>
</th>
<th>
<ul>
{{ range .Bundles }}
<li>{{ . }}</li>
{{ end }}
</ul>
</th>
<th>
<ul>
{{ range .BundlesMigrated }}
<li>{{ . }}</li>
{{ end }}
</ul>
</th>
</tr>
{{ end }}
{{ end }}
</tbody>
</table>
</div>

<div class="container-fluid themed-container">
<h5 class="display-12 fw-bold">Partially complying with the recommendations</h5>
<h5 class="display-12 fw-bold">Using deprecated APIs</h5>
<table id="mechanism" class="minimalistBlack" style="background-color: #ec8f1c; width:98%">
<thead>
<tr>
Expand All @@ -173,7 +120,7 @@
</tr>
</thead>
<tbody>
{{ with .PartialComplying }}
{{ with .NotMigrated }}
{{ range . }}
<tr>
<th>{{ .Name }}</th>
Expand Down Expand Up @@ -213,7 +160,7 @@
</div>

<div class="container-fluid themed-container">
<h5 class="display-12 fw-bold">Fully complying with the recommendations</h5>
<h5 class="display-12 fw-bold">Has a bundle that we could not find the deprecate APIs</h5>
<table id="ok" class="minimalistBlack" style="background-color:#3FA91E;width:98%">
<thead>
<tr>
Expand All @@ -225,7 +172,7 @@
</tr>
</thead>
<tbody>
{{ with .OK }}
{{ with .Migrated }}
{{ range . }}
<tr>
<th>{{ .Name }}</th>
Expand Down
9 changes: 8 additions & 1 deletion cmd/custom/grade/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ func NewCmd() *cobra.Command {
}
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")

return cmd
}

Expand Down Expand Up @@ -85,7 +88,11 @@ func run(cmd *cobra.Command, args []string) error {
log.Fatal(err)
}

t := template.Must(template.ParseFiles(getTemplatePath(currentPath)))
if len(custom.Flags.Template) == 0 {
custom.Flags.Template = getTemplatePath(currentPath)
}

t := template.Must(template.ParseFiles(custom.Flags.Template))
err = t.Execute(f, apiDashReport)
if err != nil {
panic(err)
Expand Down
2 changes: 2 additions & 0 deletions cmd/custom/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package custom

import (
"github.com/operator-framework/audit/cmd/custom/maxocp"
"github.com/spf13/cobra"

"github.com/operator-framework/audit/cmd/custom/deprecate"
Expand All @@ -30,6 +31,7 @@ func NewCmd() *cobra.Command {
indexCmd.AddCommand(
deprecate.NewCmd(),
grade.NewCmd(),
maxocp.NewCmd(),
)

return indexCmd
Expand Down
109 changes: 109 additions & 0 deletions cmd/custom/maxocp/command.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// 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 maxocp

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

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

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

func NewCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "maxocp",
Short: "generates a custom report based on defined criteria over the max ocp version and the removed apis " +
"for 1.22",
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.File, "file", "",
"path of the JSON File result of the command audit-tool index bundles --index-image=<image> [OPTIONS]")
if err := cmd.MarkFlagRequired("file"); 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")
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
}

bundlesReport, err := custom.ParseBundlesJSONReport()
if err != nil {
return err
}

maxDashReport := custom.NewMaxDashReport(bundlesReport)

dashOutputPath := filepath.Join(custom.Flags.OutputPath,
pkg.GetReportName(maxDashReport.ImageName, "maxocp", "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, maxDashReport)
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/maxocp/template.go.tmpl")
}
Loading