Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only store policy data once #2184

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 6 additions & 3 deletions cmd/validate/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ func validateImageCmd(validate imageValidationFunc) *cobra.Command {
close(jobs)

var components []applicationsnapshot.Component
var manyData [][]evaluator.Data
var evaluatorData [][]evaluator.Data
Copy link
Member

Choose a reason for hiding this comment

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

Should this be []evaludator.Data instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

Intuitively, I think so, but I don't know if it adds any value and there's an acceptance test for it even, so I'd prefer to leave it alone.

var manyPolicyInput [][]byte
var allErrors error = nil
for i := 0; i < numComponents; i++ {
Expand All @@ -410,7 +410,10 @@ func validateImageCmd(validate imageValidationFunc) *cobra.Command {
allErrors = errors.Join(allErrors, e)
} else {
components = append(components, r.component)
manyData = append(manyData, r.data)
// evaluator data is duplicated per component, so only collect it once.
if len(evaluatorData) == 0 {
evaluatorData = append(evaluatorData, r.data)
}
manyPolicyInput = append(manyPolicyInput, r.policyInput)
}
}
Expand All @@ -428,7 +431,7 @@ func validateImageCmd(validate imageValidationFunc) *cobra.Command {
data.output = append(data.output, fmt.Sprintf("%s=%s", applicationsnapshot.JSON, data.outputFile))
}

report, err := applicationsnapshot.NewReport(data.snapshot, components, data.policy, manyData, manyPolicyInput, showSuccesses)
report, err := applicationsnapshot.NewReport(data.snapshot, components, data.policy, evaluatorData, manyPolicyInput, showSuccesses)
if err != nil {
return err
}
Expand Down
9 changes: 6 additions & 3 deletions cmd/validate/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
close(ch)

var inputs []input.Input
var manyData [][]evaluator.Data
var evaluatorData [][]evaluator.Data

Check warning on line 169 in cmd/validate/input.go

View check run for this annotation

Codecov / codecov/patch

cmd/validate/input.go#L169

Added line #L169 was not covered by tests
var manyPolicyInput [][]byte
var allErrors error = nil

Expand All @@ -176,7 +176,10 @@
allErrors = errors.Join(allErrors, e)
} else {
inputs = append(inputs, r.input)
manyData = append(manyData, r.data)
// evaluator data is duplicated per component, so only collect it once.
if len(evaluatorData) == 0 {
evaluatorData = append(evaluatorData, r.data)
}

Check warning on line 182 in cmd/validate/input.go

View check run for this annotation

Codecov / codecov/patch

cmd/validate/input.go#L179-L182

Added lines #L179 - L182 were not covered by tests
manyPolicyInput = append(manyPolicyInput, r.policyInput)
}
}
Expand All @@ -189,7 +192,7 @@
return inputs[i].FilePath > inputs[j].FilePath
})

report, err := input.NewReport(inputs, data.policy, manyData, manyPolicyInput)
report, err := input.NewReport(inputs, data.policy, evaluatorData, manyPolicyInput)

Check warning on line 195 in cmd/validate/input.go

View check run for this annotation

Codecov / codecov/patch

cmd/validate/input.go#L195

Added line #L195 was not covered by tests
if err != nil {
return err
}
Expand Down
Loading