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 Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ test-license: ## Check if all files has the license

.PHONY: generate-samples ## Generate the samples in the testdata
generate-samples:
go run ./hack/generate_samples.go
go run ./hack/samples/generate_samples.go

.PHONY: full-report ## Generate the full report for all images in the the testdata
full-report:
Expand Down
43 changes: 40 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,46 @@ Note that you can also output the results in JSON format:
--head-only \
--output=json \
--output-path=testdata/json
```

### Options

Use the `--help` flag to check the options and the further information about its commands. Following an example:

```sh
$ ./bin/audit bundles --help
Provides reports with the details of all bundles operators ship in the index image informed according to the criteria defined via the flags.

**When this report is useful?**

This report is useful when is required to check the operator bundles details.

Usage:
audit bundles [flags]

Flags:
--disable-scorecard if set, will disable the scorecard tests
--disable-validators if set, will disable the validators tests
--filter string filter by operator bundle names which are *filter*
--head-only if set, will just check the operator bundle which are head of the channels
-h, --help help for bundles
--index-image string index image and tag which will be audit
--label string filter by bundles which has index images where contains *label*
--label-value string filter by bundles which has index images where contains *label=label-value*. This option can only be used with the --label flag.
--limit int32 limit the num of operator bundles to be audit
--output string inform the output format. [Flags: xls, json]. (Default: xls) (default "xls")
--output-path string inform the path of the directory to output the report. (Default: current directory) (default "/Users/camilamacedo/go/src/github.com/operator-framework/audit-1")
```

### Filtering results by names

See that you can use the `--filter` --flag to filter the results by the name of the kind of item audited. By using this option to create a report for the packages that means that the results will be filtered by its name which would like the `%value%` informed, see an example:

```sh
./bin/audit audit bundles --index-image=registry.redhat.io/redhat/redhat-operator-index:v4.5 --filter="mybundlename"
```

NOTE: Use the `--help` flag to check the options and the further information about its commands.
That would only return the bundles which contains `mybundlename` as part of its name.

## Reports

Expand Down Expand Up @@ -113,9 +150,9 @@ If you see a column with this information than that means that the specific crit
- OCP images: See [Understanding Operator catalogs](https://github.com/openshift/openshift-docs/blob/master/modules/olm-understanding-operator-catalog-images.adoc#understanding-operator-catalogs)
- Community operator image (`quay.io/operatorhubio/catalog:latest`): Its source is from [upstream-community-operators](https://github.com/operator-framework/community-operators/tree/master/upstream-community-operators)

### What are the reports in the testdata/reports/backport?
### What are the reports in the testdata/backport?

These reports were generated for we are able to identify the projects which are using the index image label `com.redhat.delivery.backport=true`
These reports were generated for we are able to identify the projects which are using the index image label `com.redhat.delivery.backport=true` and are distributed on 4.5.

[of-api]: https://github.com/operator-framework/api
[scorecard-config]: https://github.com/operator-framework/operator-sdk/blob/v1.5.0/testdata/go/v3/memcached-operator/bundle/tests/scorecard/config.yaml
Expand Down
2 changes: 1 addition & 1 deletion hack/backport/backport.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func main() {
// testdata is the path where all samples should be generate
const testdataPath = "/testdata/"

reportPath := filepath.Join(currentPath, testdataPath, "reports", "backport")
reportPath := filepath.Join(currentPath, testdataPath, "backport")
binPath := filepath.Join(currentPath, "bin", "audit")

command = exec.Command("rm", "-rf", reportPath)
Expand Down
8 changes: 4 additions & 4 deletions hack/report/full.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ func main() {
}

allimages := []string{
"registry.redhat.io/redhat/certified-operator-index:v4.8",
"registry.redhat.io/redhat/community-operator-index:v4.8",
"registry.redhat.io/redhat/redhat-marketplace-index:v4.8",
"registry.redhat.io/redhat/redhat-operator-index:v4.8",
"registry.redhat.io/redhat/certified-operator-index:v4.7",
"registry.redhat.io/redhat/community-operator-index:v4.7",
"registry.redhat.io/redhat/redhat-marketplace-index:v4.7",
"registry.redhat.io/redhat/redhat-operator-index:v4.7",
"quay.io/operatorhubio/catalog:latest",
}

Expand Down
52 changes: 34 additions & 18 deletions pkg/actions/get_bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ type Manifest struct {
Layers []string
}

type DockerConfigManifest struct {
type DockerInspectManifest struct {
Created string `json:"Created"`
DockerConfig DockerConfig `json:"Config"`
}

Expand All @@ -48,16 +49,24 @@ func GetDataFromBundleImage(auditBundle *models.AuditBundle,

downloadBundleImage(auditBundle)
bundleDir := createBundleDir(auditBundle)
dockerConfigManifest := extractBundleFromImage(auditBundle, bundleDir)
extractBundleFromImage(auditBundle, bundleDir)
inspectManifest := dockerInspect(auditBundle)

if len(label) > 0 {
value := dockerConfigManifest.DockerConfig.Labels[label]
value := inspectManifest.DockerConfig.Labels[label]
if value == labelValue {
auditBundle.FoundLabel = true
}
}

auditBundle.OCPLabel = dockerConfigManifest.DockerConfig.Labels["com.redhat.openshift.versions"]
// 4.8 images has note the build-date in the label
if len(inspectManifest.Created) > 0 {
auditBundle.BuildAt = inspectManifest.Created
} else {
auditBundle.BuildAt = inspectManifest.DockerConfig.Labels["build-date"]
}

auditBundle.OCPLabel = inspectManifest.DockerConfig.Labels["com.redhat.openshift.versions"]

// Read the bundle
var err error
Expand Down Expand Up @@ -105,7 +114,27 @@ func downloadBundleImage(auditBundle *models.AuditBundle) {
}
}

func extractBundleFromImage(auditBundle *models.AuditBundle, bundleDir string) DockerConfigManifest {
func dockerInspect(auditBundle *models.AuditBundle) DockerInspectManifest {
cmd := exec.Command("docker", "inspect", auditBundle.OperatorBundleImagePath)
output, err := pkg.RunCommand(cmd)
if err != nil || len(output) < 1 {
log.Errorf("unable to inspect the bundle image: %s", err)
auditBundle.Errors = append(auditBundle.Errors,
fmt.Errorf("unable to inspect the bundle image : %s", err))
return DockerInspectManifest{}
}

var dockerInspect []DockerInspectManifest
if err := json.Unmarshal(output, &dockerInspect); err != nil {
log.Errorf("unable to Unmarshal docker inspect result: %s", err)
auditBundle.Errors = append(auditBundle.Errors,
fmt.Errorf("unable to Unmarshal docker inspect result: %s", err))
return DockerInspectManifest{}
}
return dockerInspect[0]
}

func extractBundleFromImage(auditBundle *models.AuditBundle, bundleDir string) {
imageName := strings.Split(auditBundle.OperatorBundleImagePath, "@")[0]
tarPath := fmt.Sprintf("%s/%s.tar", bundleDir, auditBundle.OperatorBundleName)
cmd := exec.Command("docker", "save", imageName, "-o", tarPath)
Expand All @@ -132,7 +161,6 @@ func extractBundleFromImage(auditBundle *models.AuditBundle, bundleDir string) D
fmt.Errorf("error to create the bundle bundleDir : %s", err))
}

var dockerConfig DockerConfigManifest
bundleConfigFilePath := filepath.Join(bundleDir, "manifest.json")
existingFile, err := ioutil.ReadFile(bundleConfigFilePath)
if err == nil {
Expand All @@ -148,16 +176,6 @@ func extractBundleFromImage(auditBundle *models.AuditBundle, bundleDir string) D
fmt.Errorf("error to untar layers: %s", err))
}

bundleConfigFilePath := filepath.Join(bundleDir, bundleLayerConfig[0].Config)
existingFile, err := ioutil.ReadFile(bundleConfigFilePath)
if err == nil {
if err := json.Unmarshal(existingFile, &dockerConfig); err != nil {
log.Errorf("unable to Unmarshal manifest.json: %s", err)
auditBundle.Errors = append(auditBundle.Errors,
fmt.Errorf("unable to Unmarshal manifest.json: %s", err))
}
}

for _, layer := range bundleLayerConfig[0].Layers {
cmd = exec.Command("tar", "-xvf", filepath.Join(bundleDir, layer), "-C", filepath.Join(bundleDir, "bundle"))
_, err = pkg.RunCommand(cmd)
Expand Down Expand Up @@ -187,8 +205,6 @@ func extractBundleFromImage(auditBundle *models.AuditBundle, bundleDir string) D

cmd = exec.Command("rm", "-rf", fmt.Sprintf("%s/bundle/root/", bundleDir))
_, _ = pkg.RunCommand(cmd)

return dockerConfig
}

func cleanupBundleDir(auditBundle *models.AuditBundle, dir string) {
Expand Down
1 change: 1 addition & 0 deletions pkg/models/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type AuditBundle struct {
Bundle *apimanifests.Bundle
FoundLabel bool
OCPLabel string
BuildAt string
SkipRangeDB string
VersionDB string
SkipsDB string
Expand Down
4 changes: 1 addition & 3 deletions pkg/reports/bundles/columns.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (

const certifiedAnnotation = "certified"
const repositoryAnnotation = "repository"
const createAtAnnotation = "createdAt"
const archLabels = "operatorframework.io/arch."
const osLabel = "operatorframework.io/os."
const sdkBuilderAnnotation = "operators.operatorframework.io/builder"
Expand All @@ -43,7 +42,7 @@ type Columns struct {
BundlePath string `json:"bundlePath,omitempty"`
HasWebhook bool `json:"hasWebhook"`
HasV1beta1CRDs string `json:"hasV1beta1CRDs,omitempty"`
CreatedAt string `json:"createdAt,omitempty"`
BuildAt string `json:"buildAt,omitempty"`
Company string `json:"company,omitempty"`
Repository string `json:"repository,omitempty"`
BundleChannel string `json:"bundleChannel,omitempty"`
Expand Down Expand Up @@ -89,7 +88,6 @@ func (c *Columns) AddDataFromCSV(csv *v1alpha1.ClusterServiceVersion) {
certified := csv.ObjectMeta.Annotations[certifiedAnnotation]
c.Certified = len(certified) > 0 && certified == "true"
c.Repository = csv.ObjectMeta.Annotations[repositoryAnnotation]
c.CreatedAt = csv.ObjectMeta.Annotations[createAtAnnotation]
if len(csv.Spec.Version.String()) > 0 {
c.OperatorBundleVersion = csv.Spec.Version.String()
}
Expand Down
1 change: 1 addition & 0 deletions pkg/reports/bundles/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func (d *Data) PrepareReport() Report {
col.Replace = v.ReplacesDB
col.OperatorBundleVersion = v.VersionDB
col.OCPLabel = v.OCPLabel
col.BuildAt = v.BuildAt

var csv *v1alpha1.ClusterServiceVersion
if v.Bundle != nil && v.Bundle.CSV != nil {
Expand Down
6 changes: 3 additions & 3 deletions pkg/reports/bundles/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (r *Report) writeXls() error {
"N": "Operator Bundle Version",
"O": "Default Channel",
"P": "Bundle Channel",
"Q": "Create At",
"Q": "Build At",
"R": "Bundle Path",
"S": "Has webhooks?",
"T": "Builder",
Expand Down Expand Up @@ -164,8 +164,8 @@ func (r *Report) writeXls() error {
if err := f.SetCellValue(sheetName, fmt.Sprintf("P%d", line), v.BundleChannel); err != nil {
log.Errorf("to add BundleChannel cell value : %s", err)
}
if err := f.SetCellValue(sheetName, fmt.Sprintf("Q%d", line), v.CreatedAt); err != nil {
log.Errorf("to add CreatedAt cell value : %s", err)
if err := f.SetCellValue(sheetName, fmt.Sprintf("Q%d", line), v.BuildAt); err != nil {
log.Errorf("to add BuildAt cell value : %s", err)
}
if err := f.SetCellValue(sheetName, fmt.Sprintf("R%d", line), v.BundlePath); err != nil {
log.Errorf("to add BundlePath cell value : %s", err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/reports/packages/columns.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type Columns struct {
HasSupportForOwnNamespaces bool `json:"hasSupportForOwnNamespaces,omitempty"`
HasInfraSupport bool `json:"hasInfraSupport,omitempty"`
HasPossiblePerformIssues bool `json:"hasPossiblePerformIssues,omitempty"`
CreationDates []string `json:"creationDates,omitempty"`
BuildAtDates []string `json:"buildAtDates,omitempty"`
OCPLabel []string `json:"ocpLabel,omitempty"`
AuditErrors []error `json:"errors"`
}
7 changes: 5 additions & 2 deletions pkg/reports/packages/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (d *Data) PrepareReport() Report {
scorecardFailingTests = append(scorecardFailingTests, v.ScorecardFailingTests...)
muiltArchSupport = append(muiltArchSupport, v.MultipleArchitectures...)
ocpLabel = append(ocpLabel, v.OCPLabel)
creationDates = append(creationDates, v.CreatedAt)
creationDates = append(creationDates, v.BuildAt)

if !foundDeprecatedAPI {
switch v.HasV1beta1CRDs {
Expand Down Expand Up @@ -161,7 +161,7 @@ func (d *Data) PrepareReport() Report {
col.HasInfraSupport = foundInfraSupport
col.HasPossiblePerformIssues = foundPossiblePerformIssues
col.HasDependency = foundDependency
col.CreationDates = creationDates
col.BuildAtDates = creationDates
col.OCPLabel = ocpLabel

// If was not possible get any bundle then needs to be Unknown
Expand Down Expand Up @@ -201,6 +201,9 @@ func (d *Data) getAllBundles(auditPkg models.AuditPackage) []bundles.Columns {
bundles.AddDataFromScorecard(v.ScorecardResults)
bundles.AddDataFromValidators(v.ValidatorsResults)

bundles.BuildAt = v.BuildAt
bundles.OCPLabel = v.OCPLabel

allBundles = append(allBundles, bundles)
}
return allBundles
Expand Down
6 changes: 3 additions & 3 deletions pkg/reports/packages/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (r *Report) writeXls() error {
"P": "Has Support for Multi Namespaces",
"Q": "Has Infrastructure Support",
"R": "Has possible performance issues",
"S": "Creation Dates (by author)",
"S": "Build Dates (from index image)",
"T": "OCP Labels",
"U": "Issues (To process this report)",
}
Expand Down Expand Up @@ -199,8 +199,8 @@ func (r *Report) writeXls() error {
}

if err := f.SetCellValue(sheetName, fmt.Sprintf("S%d", line),
pkg.GetFormatArrayWithBreakLine(v.CreationDates)); err != nil {
log.Errorf("to add CreationDates cell value : %s", err)
pkg.GetFormatArrayWithBreakLine(v.BuildAtDates)); err != nil {
log.Errorf("to add BuildAtDates cell value : %s", err)
}

if err := f.SetCellValue(sheetName, fmt.Sprintf("T%d", line),
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading