From ac7dd45c597a58a9586078ee1c537031e6ebe8ce Mon Sep 17 00:00:00 2001 From: Ciara Stacke Date: Wed, 28 Jun 2023 12:55:46 +0100 Subject: [PATCH 1/2] Reverse order for validateBackendRef error conditions --- internal/state/graph/backend_refs.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/state/graph/backend_refs.go b/internal/state/graph/backend_refs.go index a4b0b9dc8f..eda17ba754 100644 --- a/internal/state/graph/backend_refs.go +++ b/internal/state/graph/backend_refs.go @@ -169,16 +169,16 @@ func validateBackendRef( ) (valid bool, cond conditions.Condition) { // Because all errors cause same condition but different reasons, we return as soon as we find an error - if ref.Group != nil && !(*ref.Group == "core" || *ref.Group == "") { - valErr := field.NotSupported(path.Child("group"), *ref.Group, []string{"core", ""}) - return false, conditions.NewRouteBackendRefUnsupportedValue(valErr.Error()) - } - if ref.Kind != nil && *ref.Kind != "Service" { valErr := field.NotSupported(path.Child("kind"), *ref.Kind, []string{"Service"}) return false, conditions.NewRouteBackendRefInvalidKind(valErr.Error()) } + if ref.Group != nil && !(*ref.Group == "core" || *ref.Group == "") { + valErr := field.NotSupported(path.Child("group"), *ref.Group, []string{"core", ""}) + return false, conditions.NewRouteBackendRefUnsupportedValue(valErr.Error()) + } + // no need to validate ref.Name if ref.Namespace != nil && string(*ref.Namespace) != routeNs { From 41cf065de7ea7ba231b61fdcfd130327cc57754a Mon Sep 17 00:00:00 2001 From: Ciara Stacke Date: Wed, 28 Jun 2023 15:33:37 +0100 Subject: [PATCH 2/2] Instead of reversing order, change condition reason for invalid group --- internal/state/graph/backend_refs.go | 10 +++++----- internal/state/graph/backend_refs_test.go | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/state/graph/backend_refs.go b/internal/state/graph/backend_refs.go index eda17ba754..61402604f9 100644 --- a/internal/state/graph/backend_refs.go +++ b/internal/state/graph/backend_refs.go @@ -169,14 +169,14 @@ func validateBackendRef( ) (valid bool, cond conditions.Condition) { // Because all errors cause same condition but different reasons, we return as soon as we find an error - if ref.Kind != nil && *ref.Kind != "Service" { - valErr := field.NotSupported(path.Child("kind"), *ref.Kind, []string{"Service"}) + if ref.Group != nil && !(*ref.Group == "core" || *ref.Group == "") { + valErr := field.NotSupported(path.Child("group"), *ref.Group, []string{"core", ""}) return false, conditions.NewRouteBackendRefInvalidKind(valErr.Error()) } - if ref.Group != nil && !(*ref.Group == "core" || *ref.Group == "") { - valErr := field.NotSupported(path.Child("group"), *ref.Group, []string{"core", ""}) - return false, conditions.NewRouteBackendRefUnsupportedValue(valErr.Error()) + if ref.Kind != nil && *ref.Kind != "Service" { + valErr := field.NotSupported(path.Child("kind"), *ref.Kind, []string{"Service"}) + return false, conditions.NewRouteBackendRefInvalidKind(valErr.Error()) } // no need to validate ref.Name diff --git a/internal/state/graph/backend_refs_test.go b/internal/state/graph/backend_refs_test.go index 054e874f1d..8169104c70 100644 --- a/internal/state/graph/backend_refs_test.go +++ b/internal/state/graph/backend_refs_test.go @@ -123,7 +123,7 @@ func TestValidateBackendRef(t *testing.T) { return backend }), expectedValid: false, - expectedCondition: conditions.NewRouteBackendRefUnsupportedValue( + expectedCondition: conditions.NewRouteBackendRefInvalidKind( `test.group: Unsupported value: "invalid": supported values: "core", ""`, ), },