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

Better error reporting for image policy evaluation #144

Merged
merged 1 commit into from
May 25, 2021
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 controllers/imagepolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (r *ImagePolicyReconciler) Reconcile(ctx context.Context, req ctrl.Request)
}

if latest == "" {
msg := "no image found for policy"
msg := fmt.Sprintf("Cannot determine latest tag for policy: %s", err.Error())
pol.Status.LatestImage = ""
imagev1.SetImagePolicyReadiness(
&pol,
Expand Down
2 changes: 1 addition & 1 deletion internal/policy/numerical.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (p *Numerical) Latest(versions []string) (string, error) {

switch {
case i == 0:
break // First iteration, nothing to compare
// First iteration, nothing to compare
Copy link
Member

Choose a reason for hiding this comment

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

I like the explicit break, since it disambiguates for people who have trouble remembering whether Go's case has fall-through or not (like me).

Copy link
Member Author

Choose a reason for hiding this comment

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

I just went with the linter recommendation. I can definitely revert back to using break if you think it's worth it, no problem.

Copy link
Member

Choose a reason for hiding this comment

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

I often find myself disagreeing with linters. Maybe I should consider .... rewriting all the linters ...

Copy link
Member

Choose a reason for hiding this comment

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

Not a blocker, I leave it to your judgement @relu :-)

case p.Order == NumericalOrderAsc && cv < pv, p.Order == NumericalOrderDesc && cv > pv:
continue
}
Expand Down
5 changes: 5 additions & 0 deletions internal/policy/numerical_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ func TestNumerical_Latest(t *testing.T) {
order: NumericalOrderDesc,
expectedVersion: "1",
},
{
label: "With invalid numerical value",
versions: []string{"0", "1a", "b"},
expectErr: true,
},
{
label: "Empty version list",
versions: []string{},
Expand Down