From 746f61edb31f20bda6ae173cd46be126dbcf6a96 Mon Sep 17 00:00:00 2001 From: Aurel Canciu Date: Fri, 14 May 2021 20:01:54 +0300 Subject: [PATCH] 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 --- controllers/imagepolicy_controller.go | 2 +- internal/policy/numerical.go | 2 +- internal/policy/numerical_test.go | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/controllers/imagepolicy_controller.go b/controllers/imagepolicy_controller.go index d96d816..845148a 100644 --- a/controllers/imagepolicy_controller.go +++ b/controllers/imagepolicy_controller.go @@ -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, diff --git a/internal/policy/numerical.go b/internal/policy/numerical.go index 721ef35..b7f32a0 100644 --- a/internal/policy/numerical.go +++ b/internal/policy/numerical.go @@ -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 case p.Order == NumericalOrderAsc && cv < pv, p.Order == NumericalOrderDesc && cv > pv: continue } diff --git a/internal/policy/numerical_test.go b/internal/policy/numerical_test.go index 784e05f..497c790 100644 --- a/internal/policy/numerical_test.go +++ b/internal/policy/numerical_test.go @@ -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{},