Better error reporting for image policy evaluation

A more verbose message associated with the error should give the user
better understanding of the cause and the nature of the failure.

Fixes #143

Signed-off-by: Aurel Canciu <aurelcanciu@gmail.com>
This commit is contained in:
Aurel Canciu 2021-05-14 20:01:54 +03:00
parent de3de64add
commit 746f61edb3
No known key found for this signature in database
GPG Key ID: AB25339971E6F81E
3 changed files with 7 additions and 2 deletions

View File

@ -158,7 +158,7 @@ func (r *ImagePolicyReconciler) Reconcile(ctx context.Context, req ctrl.Request)
} }
if latest == "" { if latest == "" {
msg := "no image found for policy" msg := fmt.Sprintf("Cannot determine latest tag for policy: %s", err.Error())
pol.Status.LatestImage = "" pol.Status.LatestImage = ""
imagev1.SetImagePolicyReadiness( imagev1.SetImagePolicyReadiness(
&pol, &pol,

View File

@ -66,7 +66,7 @@ func (p *Numerical) Latest(versions []string) (string, error) {
switch { switch {
case i == 0: case i == 0:
break // First iteration, nothing to compare // First iteration, nothing to compare
case p.Order == NumericalOrderAsc && cv < pv, p.Order == NumericalOrderDesc && cv > pv: case p.Order == NumericalOrderAsc && cv < pv, p.Order == NumericalOrderDesc && cv > pv:
continue continue
} }

View File

@ -112,6 +112,11 @@ func TestNumerical_Latest(t *testing.T) {
order: NumericalOrderDesc, order: NumericalOrderDesc,
expectedVersion: "1", expectedVersion: "1",
}, },
{
label: "With invalid numerical value",
versions: []string{"0", "1a", "b"},
expectErr: true,
},
{ {
label: "Empty version list", label: "Empty version list",
versions: []string{}, versions: []string{},