diff --git a/internal/controller/nginx/config/policies/validator_test.go b/internal/controller/nginx/config/policies/validator_test.go index f30b7e7790..d10ca0cbdc 100644 --- a/internal/controller/nginx/config/policies/validator_test.go +++ b/internal/controller/nginx/config/policies/validator_test.go @@ -49,10 +49,10 @@ var _ = Describe("Policy CompositeValidator", func() { policies.ManagerConfig{ Validator: &policiesfakes.FakeValidator{ ValidateStub: func(_ policies.Policy) []conditions.Condition { - return []conditions.Condition{conditions.NewPolicyInvalid("apple error")} + return []conditions.Condition{conditions.NewPolicyInvalid("Apple error")} }, ValidateGlobalSettingsStub: func(_ policies.Policy, _ *policies.GlobalSettings) []conditions.Condition { - return []conditions.Condition{conditions.NewPolicyInvalid("apple global settings error")} + return []conditions.Condition{conditions.NewPolicyInvalid("Apple global settings error")} }, ConflictsStub: func(_ policies.Policy, _ policies.Policy) bool { return true }, }, @@ -61,10 +61,10 @@ var _ = Describe("Policy CompositeValidator", func() { policies.ManagerConfig{ Validator: &policiesfakes.FakeValidator{ ValidateStub: func(_ policies.Policy) []conditions.Condition { - return []conditions.Condition{conditions.NewPolicyInvalid("orange error")} + return []conditions.Condition{conditions.NewPolicyInvalid("Orange error")} }, ValidateGlobalSettingsStub: func(_ policies.Policy, _ *policies.GlobalSettings) []conditions.Condition { - return []conditions.Condition{conditions.NewPolicyInvalid("orange global settings error")} + return []conditions.Condition{conditions.NewPolicyInvalid("Orange global settings error")} }, ConflictsStub: func(_ policies.Policy, _ policies.Policy) bool { return false }, }, @@ -83,19 +83,18 @@ var _ = Describe("Policy CompositeValidator", func() { conds := mgr.Validate(applePolicy) Expect(conds).To(HaveLen(1)) - Expect(conds[0].Message).To(Equal("apple error")) + Expect(conds[0].Message).To(Equal("Apple error")) conds = mgr.ValidateGlobalSettings(applePolicy, globalSettings) Expect(conds).To(HaveLen(1)) - Expect(conds[0].Message).To(Equal("apple global settings error")) - + Expect(conds[0].Message).To(Equal("Apple global settings error")) conds = mgr.Validate(orangePolicy) Expect(conds).To(HaveLen(1)) - Expect(conds[0].Message).To(Equal("orange error")) + Expect(conds[0].Message).To(Equal("Orange error")) conds = mgr.ValidateGlobalSettings(orangePolicy, globalSettings) Expect(conds).To(HaveLen(1)) - Expect(conds[0].Message).To(Equal("orange global settings error")) + Expect(conds[0].Message).To(Equal("Orange global settings error")) }) It("Returns whether the policies conflict", func() { Expect(mgr.Conflicts(applePolicy, applePolicy)).To(BeTrue()) diff --git a/internal/controller/state/change_processor_test.go b/internal/controller/state/change_processor_test.go index 90bf948f07..6f2e338c07 100644 --- a/internal/controller/state/change_processor_test.go +++ b/internal/controller/state/change_processor_test.go @@ -1276,7 +1276,7 @@ var _ = Describe("ChangeProcessor", func() { expGraph.GatewayClass = nil gw := expGraph.Gateways[types.NamespacedName{Namespace: "test", Name: "gateway-1"}] - gw.Conditions = conditions.NewGatewayInvalid("GatewayClass doesn't exist") + gw.Conditions = conditions.NewGatewayInvalid("The GatewayClass doesn't exist") gw.Valid = false gw.Listeners = nil @@ -2253,7 +2253,7 @@ var _ = Describe("ChangeProcessor", func() { }, }, }, - Conditions: conditions.NewGatewayInvalid("GatewayClass doesn't exist"), + Conditions: conditions.NewGatewayInvalid("The GatewayClass doesn't exist"), DeploymentName: types.NamespacedName{ Namespace: "test", Name: "gateway-2-test-class", diff --git a/internal/controller/state/conditions/conditions.go b/internal/controller/state/conditions/conditions.go index 209f168ae4..cd672d8530 100644 --- a/internal/controller/state/conditions/conditions.go +++ b/internal/controller/state/conditions/conditions.go @@ -239,13 +239,13 @@ func NewDefaultGatewayClassConditions() []Condition { Type: string(v1.GatewayClassConditionStatusAccepted), Status: metav1.ConditionTrue, Reason: string(v1.GatewayClassReasonAccepted), - Message: "GatewayClass is accepted", + Message: "The GatewayClass is accepted", }, { Type: string(v1.GatewayClassConditionStatusSupportedVersion), Status: metav1.ConditionTrue, Reason: string(v1.GatewayClassReasonSupportedVersion), - Message: "Gateway API CRD versions are supported", + Message: "The Gateway API CRD versions are supported", }, } } @@ -260,7 +260,7 @@ func NewGatewayClassSupportedVersionBestEffort(recommendedVersion string) []Cond Status: metav1.ConditionFalse, Reason: string(v1.GatewayClassReasonUnsupportedVersion), Message: fmt.Sprintf( - "Gateway API CRD versions are not recommended. Recommended version is %s", + "The Gateway API CRD versions are not recommended. Recommended version is %s", recommendedVersion, ), }, @@ -276,7 +276,7 @@ func NewGatewayClassUnsupportedVersion(recommendedVersion string) []Condition { Status: metav1.ConditionFalse, Reason: string(v1.GatewayClassReasonUnsupportedVersion), Message: fmt.Sprintf( - "Gateway API CRD versions are not supported. Please install version %s", + "The Gateway API CRD versions are not supported. Please install version %s", recommendedVersion, ), }, @@ -285,7 +285,7 @@ func NewGatewayClassUnsupportedVersion(recommendedVersion string) []Condition { Status: metav1.ConditionFalse, Reason: string(v1.GatewayClassReasonUnsupportedVersion), Message: fmt.Sprintf( - "Gateway API CRD versions are not supported. Please install version %s", + "The Gateway API CRD versions are not supported. Please install version %s", recommendedVersion, ), }, @@ -318,18 +318,18 @@ func NewRouteNotAllowedByListeners() Condition { Type: string(v1.RouteConditionAccepted), Status: metav1.ConditionFalse, Reason: string(v1.RouteReasonNotAllowedByListeners), - Message: "Route is not allowed by any listener", + Message: "The Route is not allowed by any listener", } } -// NewRouteNoMatchingListenerHostname returns a Condition that indicates that the hostname of the listener +// NewRouteNoMatchingListenerHostname returns a Condition that indicates that the hostname of the Listener // does not match the hostnames of the Route. func NewRouteNoMatchingListenerHostname() Condition { return Condition{ Type: string(v1.RouteConditionAccepted), Status: metav1.ConditionFalse, Reason: string(v1.RouteReasonNoMatchingListenerHostname), - Message: "Listener hostname does not match the Route hostnames", + Message: "The Listener hostname does not match the Route hostnames", } } @@ -339,7 +339,7 @@ func NewRouteAccepted() Condition { Type: string(v1.RouteConditionAccepted), Status: metav1.ConditionTrue, Reason: string(v1.RouteReasonAccepted), - Message: "The route is accepted", + Message: "The Route is accepted", } } @@ -386,7 +386,7 @@ func NewRouteInvalidListener() Condition { Type: string(v1.RouteConditionAccepted), Status: metav1.ConditionFalse, Reason: string(RouteReasonInvalidListener), - Message: "Listener is invalid for this parent ref", + Message: "The Listener is invalid for this parent ref", } } @@ -397,7 +397,7 @@ func NewRouteHostnameConflict() Condition { Type: string(v1.RouteConditionAccepted), Status: metav1.ConditionFalse, Reason: string(RouteReasonHostnameConflict), - Message: "Hostname(s) conflict with another route of the same kind on the same port", + Message: "Hostname(s) conflict with another Route of the same kind on the same port", } } @@ -484,7 +484,7 @@ func NewRouteInvalidGateway() Condition { Type: string(v1.RouteConditionAccepted), Status: metav1.ConditionFalse, Reason: string(RouteReasonInvalidGateway), - Message: "Gateway is invalid", + Message: "The Gateway is invalid", } } @@ -495,7 +495,7 @@ func NewRouteNoMatchingParent() Condition { Type: string(v1.RouteConditionAccepted), Status: metav1.ConditionFalse, Reason: string(v1.RouteReasonNoMatchingParent), - Message: "Listener is not found for this parent ref", + Message: "The Listener is not found for this parent ref", } } @@ -550,7 +550,7 @@ func NewDefaultListenerConditions(existingConditions []Condition) []Condition { return defaultConds } -// hasConflictConditions checks if the listener has any conflict-related conditions. +// hasConflictConditions checks if the Listener has any conflict-related conditions. func hasConflictConditions(conditions []Condition) bool { for _, cond := range conditions { if cond.Type == string(v1.ListenerConditionConflicted) || @@ -567,7 +567,7 @@ func NewListenerAccepted() Condition { Type: string(v1.ListenerConditionAccepted), Status: metav1.ConditionTrue, Reason: string(v1.ListenerReasonAccepted), - Message: "Listener is accepted", + Message: "The Listener is accepted", } } @@ -577,7 +577,7 @@ func NewListenerProgrammed() Condition { Type: string(v1.ListenerConditionProgrammed), Status: metav1.ConditionTrue, Reason: string(v1.ListenerReasonProgrammed), - Message: "Listener is programmed", + Message: "The Listener is programmed", } } @@ -750,7 +750,7 @@ func NewGatewayClassResolvedRefs() Condition { Type: string(GatewayClassResolvedRefs), Status: metav1.ConditionTrue, Reason: string(GatewayClassReasonResolvedRefs), - Message: "ParametersRef resource is resolved", + Message: "The ParametersRef resource is resolved", } } @@ -761,7 +761,7 @@ func NewGatewayClassRefNotFound() Condition { Type: string(GatewayClassResolvedRefs), Status: metav1.ConditionFalse, Reason: string(GatewayClassReasonParamsRefNotFound), - Message: "ParametersRef resource could not be found", + Message: "The ParametersRef resource could not be found", } } @@ -784,7 +784,7 @@ func NewGatewayClassInvalidParameters(msg string) Condition { Type: string(v1.GatewayClassConditionStatusAccepted), Status: metav1.ConditionTrue, Reason: string(v1.GatewayClassReasonInvalidParameters), - Message: fmt.Sprintf("GatewayClass is accepted, but ParametersRef is ignored due to an error: %s", msg), + Message: fmt.Sprintf("The GatewayClass is accepted, but ParametersRef is ignored due to an error: %s", msg), } } @@ -802,7 +802,7 @@ func NewGatewayAccepted() Condition { Type: string(v1.GatewayConditionAccepted), Status: metav1.ConditionTrue, Reason: string(v1.GatewayReasonAccepted), - Message: "Gateway is accepted", + Message: "The Gateway is accepted", } } @@ -813,14 +813,14 @@ func NewGatewayAcceptedListenersNotValid() Condition { Type: string(v1.GatewayConditionAccepted), Status: metav1.ConditionTrue, Reason: string(v1.GatewayReasonListenersNotValid), - Message: "Gateway has at least one valid listener", + Message: "The Gateway has at least one valid listener", } } // NewGatewayNotAcceptedListenersNotValid returns Conditions that indicate the Gateway is not accepted, // because all listeners are invalid. func NewGatewayNotAcceptedListenersNotValid() []Condition { - msg := "Gateway has no valid listeners" + msg := "The Gateway has no valid listeners" return []Condition{ { Type: string(v1.GatewayConditionAccepted), @@ -885,7 +885,7 @@ func NewGatewayProgrammed() Condition { Type: string(v1.GatewayConditionProgrammed), Status: metav1.ConditionTrue, Reason: string(v1.GatewayReasonProgrammed), - Message: "Gateway is programmed", + Message: "The Gateway is programmed", } } @@ -907,7 +907,7 @@ func NewNginxGatewayValid() Condition { Type: string(ngfAPI.NginxGatewayConditionValid), Status: metav1.ConditionTrue, Reason: string(ngfAPI.NginxGatewayReasonValid), - Message: "NginxGateway is valid", + Message: "The NginxGateway is valid", } } @@ -928,7 +928,7 @@ func NewGatewayResolvedRefs() Condition { Type: string(GatewayResolvedRefs), Status: metav1.ConditionTrue, Reason: string(GatewayReasonResolvedRefs), - Message: "ParametersRef resource is resolved", + Message: "The ParametersRef resource is resolved", } } @@ -939,7 +939,7 @@ func NewGatewayRefNotFound() Condition { Type: string(GatewayResolvedRefs), Status: metav1.ConditionFalse, Reason: string(GatewayReasonParamsRefNotFound), - Message: "ParametersRef resource could not be found", + Message: "The ParametersRef resource could not be found", } } @@ -962,7 +962,7 @@ func NewGatewayInvalidParameters(msg string) Condition { Type: string(v1.GatewayConditionAccepted), Status: metav1.ConditionTrue, Reason: string(v1.GatewayReasonInvalidParameters), - Message: fmt.Sprintf("Gateway is accepted, but ParametersRef is ignored due to an error: %s", msg), + Message: fmt.Sprintf("The Gateway is accepted, but ParametersRef is ignored due to an error: %s", msg), } } @@ -973,7 +973,7 @@ func NewGatewayAcceptedUnsupportedField(msg string) Condition { Type: string(v1.GatewayConditionAccepted), Status: metav1.ConditionTrue, Reason: string(GatewayReasonUnsupportedField), - Message: fmt.Sprintf("Gateway accepted but the following unsupported parameters were ignored: %s", msg), + Message: fmt.Sprintf("The Gateway is accepted but the following unsupported parameters were ignored: %s", msg), } } @@ -983,7 +983,7 @@ func NewPolicyAccepted() Condition { Type: string(v1.PolicyConditionAccepted), Status: metav1.ConditionTrue, Reason: string(v1.PolicyReasonAccepted), - Message: "Policy is accepted", + Message: "The Policy is accepted", } } @@ -1071,7 +1071,7 @@ func NewSnippetsFilterAccepted() Condition { Type: string(ngfAPI.SnippetsFilterConditionTypeAccepted), Status: metav1.ConditionTrue, Reason: string(ngfAPI.SnippetsFilterConditionReasonAccepted), - Message: "SnippetsFilter is accepted", + Message: "The SnippetsFilter is accepted", } } @@ -1082,7 +1082,7 @@ func NewObservabilityPolicyAffected() Condition { Type: string(ObservabilityPolicyAffected), Status: metav1.ConditionTrue, Reason: string(PolicyAffectedReason), - Message: "ObservabilityPolicy is applied to the resource", + Message: "The ObservabilityPolicy is applied to the resource", } } @@ -1093,7 +1093,7 @@ func NewClientSettingsPolicyAffected() Condition { Type: string(ClientSettingsPolicyAffected), Status: metav1.ConditionTrue, Reason: string(PolicyAffectedReason), - Message: "ClientSettingsPolicy is applied to the resource", + Message: "The ClientSettingsPolicy is applied to the resource", } } @@ -1147,7 +1147,7 @@ func NewInferencePoolAccepted() Condition { Type: string(inference.InferencePoolConditionAccepted), Status: metav1.ConditionTrue, Reason: string(inference.InferencePoolConditionAccepted), - Message: "InferencePool is accepted by the Gateway.", + Message: "The InferencePool is accepted by the Gateway.", } } @@ -1158,7 +1158,7 @@ func NewInferencePoolResolvedRefs() Condition { Type: string(inference.InferencePoolConditionResolvedRefs), Status: metav1.ConditionTrue, Reason: string(inference.InferencePoolConditionResolvedRefs), - Message: "Inference pool references a valid ExtensionRef.", + Message: "The InferencePool references a valid ExtensionRef.", } } diff --git a/internal/controller/state/graph/backend_refs.go b/internal/controller/state/graph/backend_refs.go index f29bba0082..24da9013a4 100644 --- a/internal/controller/state/graph/backend_refs.go +++ b/internal/controller/state/graph/backend_refs.go @@ -419,7 +419,8 @@ func findBackendTLSPolicyForService( if beTLSPolicy != nil { beTLSPolicy.IsReferenced = true if !beTLSPolicy.Valid { - err = fmt.Errorf("the backend TLS policy is invalid: %s", beTLSPolicy.Conditions[0].Message) + //nolint:staticcheck // Capitalization required for alignment with other messages. + err = fmt.Errorf("The BackendTLSPolicy is invalid: %s", beTLSPolicy.Conditions[0].Message) } else { beTLSPolicy.Conditions = append(beTLSPolicy.Conditions, conditions.NewPolicyAccepted()) } @@ -460,10 +461,10 @@ func verifyIPFamily(npCfg *EffectiveNginxProxy, svcIPFamily []v1.IPFamily) error containsIPv6 := slices.Contains(svcIPFamily, v1.IPv6Protocol) containsIPv4 := slices.Contains(svcIPFamily, v1.IPv4Protocol) - //nolint: stylecheck // used in status condition which is normally capitalized - errIPv6Mismatch := errors.New("service configured with IPv6 family but NginxProxy is configured with IPv4") - //nolint: stylecheck // used in status condition which is normally capitalized - errIPv4Mismatch := errors.New("service configured with IPv4 family but NginxProxy is configured with IPv6") + //nolint: staticcheck // used in status condition which is normally capitalized + errIPv6Mismatch := errors.New("The Service configured with IPv6 family but NginxProxy is configured with IPv4") + //nolint: staticcheck // used in status condition which is normally capitalized + errIPv4Mismatch := errors.New("The Service configured with IPv4 family but NginxProxy is configured with IPv6") npIPFamily := npCfg.IPFamily @@ -686,8 +687,9 @@ func validateRouteBackendRefAppProtocol( appProtocol string, backendTLSPolicy *BackendTLSPolicy, ) error { + //nolint: staticcheck // used in status condition which is normally capitalized err := fmt.Errorf( - "route type %s does not support service port appProtocol %s", + "The Route type %s does not support service port appProtocol %s", routeType, appProtocol, ) @@ -748,8 +750,8 @@ func getServicePort(svc *v1.Service, port int32) (v1.ServicePort, error) { return p, nil } } - - return v1.ServicePort{}, fmt.Errorf("no matching port for Service %s and port %d", svc.Name, port) + //nolint: staticcheck // used in status condition which is normally capitalized + return v1.ServicePort{}, fmt.Errorf("No matching port for Service %s and port %d", svc.Name, port) } func getRefGrantFromResourceForRoute(routeType RouteType, routeNs string) fromResource { diff --git a/internal/controller/state/graph/backend_refs_test.go b/internal/controller/state/graph/backend_refs_test.go index 8d36c5a4a5..d45db3be12 100644 --- a/internal/controller/state/graph/backend_refs_test.go +++ b/internal/controller/state/graph/backend_refs_test.go @@ -616,7 +616,7 @@ func TestVerifyIPFamily(t *testing.T) { IPFamily: helpers.GetPointer(ngfAPIv1alpha2.IPv4), }, svcIPFamily: []v1.IPFamily{v1.IPv6Protocol}, - expErr: errors.New("service configured with IPv6 family but NginxProxy is configured with IPv4"), + expErr: errors.New("The Service configured with IPv6 family but NginxProxy is configured with IPv4"), }, { name: "Invalid - IPv6 configured for NGINX, service has only IPv4", @@ -624,7 +624,7 @@ func TestVerifyIPFamily(t *testing.T) { IPFamily: helpers.GetPointer(ngfAPIv1alpha2.IPv6), }, svcIPFamily: []v1.IPFamily{v1.IPv4Protocol}, - expErr: errors.New("service configured with IPv4 family but NginxProxy is configured with IPv6"), + expErr: errors.New("The Service configured with IPv4 family but NginxProxy is configured with IPv6"), }, { name: "Valid - When NginxProxy is nil", @@ -884,7 +884,7 @@ func TestAddBackendRefsToRules(t *testing.T) { Type: "Accepted", Status: "True", Reason: "Accepted", - Message: "Policy is accepted", + Message: "The Policy is accepted", }, }, Valid: true, @@ -899,7 +899,7 @@ func TestAddBackendRefsToRules(t *testing.T) { Type: "Accepted", Status: "True", Reason: "Accepted", - Message: "Policy is accepted", + Message: "The Policy is accepted", }, ) btpWSS := getBtp("btpWSS", "svcWSS", "test") @@ -985,12 +985,12 @@ func TestAddBackendRefsToRules(t *testing.T) { }, expectedConditions: []conditions.Condition{ conditions.NewRouteBackendRefUnsupportedProtocol( - "route type http does not support service port appProtocol kubernetes.io/h2c;" + + "The Route type http does not support service port appProtocol kubernetes.io/h2c;" + " nginx does not support proxying to upstreams with http2 or h2c", ), }, policies: emptyPolicies, - name: "invalid backendRef with service port appProtocol h2c and route type http", + name: "invalid backendRef with service port appProtocol h2c and Route type http", }, { route: createRoute("hr1", RouteTypeHTTP, "Service", 1, "svcWS"), @@ -1005,7 +1005,7 @@ func TestAddBackendRefsToRules(t *testing.T) { }, expectedConditions: nil, policies: emptyPolicies, - name: "valid backendRef with service port appProtocol ws and route type http", + name: "valid backendRef with service port appProtocol ws and Route type http", }, { route: createRoute("hr1", RouteTypeHTTP, "Service", 1, "svcWSS"), @@ -1022,7 +1022,7 @@ func TestAddBackendRefsToRules(t *testing.T) { expectedConditions: nil, policies: policiesMatching, name: "valid backendRef with service port appProtocol wss," + - " route type http, and corresponding BackendTLSPolicy", + " The Route type http, and corresponding BackendTLSPolicy", }, { route: createRoute("hr1", RouteTypeHTTP, "Service", 1, "svcWSS"), @@ -1037,12 +1037,12 @@ func TestAddBackendRefsToRules(t *testing.T) { }, expectedConditions: []conditions.Condition{ conditions.NewRouteBackendRefUnsupportedProtocol( - "route type http does not support service port appProtocol kubernetes.io/wss;" + + "The Route type http does not support service port appProtocol kubernetes.io/wss;" + " missing corresponding BackendTLSPolicy", ), }, policies: emptyPolicies, - name: "invalid backendRef with service port appProtocol wss, route type http, but missing BackendTLSPolicy", + name: "invalid backendRef with service port appProtocol wss, Route type http, but missing BackendTLSPolicy", }, { route: createRoute("gr1", RouteTypeGRPC, "Service", 1, "svcH2c"), @@ -1057,7 +1057,7 @@ func TestAddBackendRefsToRules(t *testing.T) { }, expectedConditions: nil, policies: emptyPolicies, - name: "valid backendRef with service port appProtocol h2c and route type grpc", + name: "valid backendRef with service port appProtocol h2c and Route type grpc", }, { route: createRoute("gr1", RouteTypeGRPC, "Service", 1, "svcWS"), @@ -1072,11 +1072,11 @@ func TestAddBackendRefsToRules(t *testing.T) { }, expectedConditions: []conditions.Condition{ conditions.NewRouteBackendRefUnsupportedProtocol( - "route type grpc does not support service port appProtocol kubernetes.io/ws", + "The Route type grpc does not support service port appProtocol kubernetes.io/ws", ), }, policies: emptyPolicies, - name: "invalid backendRef with service port appProtocol ws and route type grpc", + name: "invalid backendRef with service port appProtocol ws and Route type grpc", }, { route: createRoute("gr1", RouteTypeGRPC, "Service", 1, "svcWSS"), @@ -1091,11 +1091,11 @@ func TestAddBackendRefsToRules(t *testing.T) { }, expectedConditions: []conditions.Condition{ conditions.NewRouteBackendRefUnsupportedProtocol( - "route type grpc does not support service port appProtocol kubernetes.io/wss", + "The Route type grpc does not support service port appProtocol kubernetes.io/wss", ), }, policies: emptyPolicies, - name: "invalid backendRef with service port appProtocol wss and route type grpc", + name: "invalid backendRef with service port appProtocol wss and Route type grpc", }, { route: createRoute("hr1", RouteTypeHTTP, "Service", 1, "svcGRPC"), @@ -1111,7 +1111,7 @@ func TestAddBackendRefsToRules(t *testing.T) { expectedConditions: nil, policies: emptyPolicies, name: "valid backendRef with non-Kubernetes Standard Application Protocol" + - " service port appProtocol and route type http", + " service port appProtocol and Route type http", }, { route: createRoute("gr1", RouteTypeGRPC, "Service", 1, "svcGRPC"), @@ -1127,7 +1127,7 @@ func TestAddBackendRefsToRules(t *testing.T) { expectedConditions: nil, policies: emptyPolicies, name: "valid backendRef with non-Kubernetes Standard Application Protocol" + - " service port appProtocol and route type grpc", + " service port appProtocol and Route type grpc", }, { route: modRoute(createRoute("hr1", RouteTypeHTTP, "Service", 1, "svc1"), func(route *L7Route) *L7Route { @@ -1406,7 +1406,7 @@ func TestCreateBackend(t *testing.T) { }, Valid: false, Conditions: []conditions.Condition{ - conditions.NewPolicyInvalid("unsupported value"), + conditions.NewPolicyInvalid("Unsupported value"), }, } @@ -1528,7 +1528,7 @@ func TestCreateBackend(t *testing.T) { Valid: true, InvalidForGateways: map[types.NamespacedName]conditions.Condition{ {Namespace: "test", Name: "gateway"}: conditions.NewRouteInvalidIPFamily( - `service configured with IPv4 family but NginxProxy is configured with IPv6`, + `The Service configured with IPv4 family but NginxProxy is configured with IPv6`, ), }, }, @@ -1573,7 +1573,7 @@ func TestCreateBackend(t *testing.T) { expectedServicePortReference: "", expectedConditions: []conditions.Condition{ conditions.NewRouteBackendRefUnsupportedValue( - "the backend TLS policy is invalid: unsupported value", + "The BackendTLSPolicy is invalid: Unsupported value", ), }, name: "invalid policy", diff --git a/internal/controller/state/graph/backend_tls_policy.go b/internal/controller/state/graph/backend_tls_policy.go index 8e5fd100b6..1694ea2f20 100644 --- a/internal/controller/state/graph/backend_tls_policy.go +++ b/internal/controller/state/graph/backend_tls_policy.go @@ -75,7 +75,7 @@ func validateBackendTLSPolicy( if err := validateBackendTLSHostname(backendTLSPolicy); err != nil { valid = false - conds = append(conds, conditions.NewPolicyInvalid(fmt.Sprintf("invalid hostname: %s", err.Error()))) + conds = append(conds, conditions.NewPolicyInvalid(fmt.Sprintf("Invalid hostname: %s", err.Error()))) } caCertRefs := backendTLSPolicy.Spec.Validation.CACertificateRefs @@ -109,7 +109,7 @@ func validateBackendTLSPolicy( valid = false conds = append( conds, - conditions.NewPolicyInvalid("either CACertificateRefs or WellKnownCACertificates must be specified"), + conditions.NewPolicyInvalid("Either CACertificateRefs or WellKnownCACertificates must be specified"), ) } diff --git a/internal/controller/state/graph/gateway.go b/internal/controller/state/graph/gateway.go index 084674aa80..cd3abbfd90 100644 --- a/internal/controller/state/graph/gateway.go +++ b/internal/controller/state/graph/gateway.go @@ -9,6 +9,7 @@ import ( "github.com/nginx/nginx-gateway-fabric/v2/internal/controller/config" "github.com/nginx/nginx-gateway-fabric/v2/internal/controller/state/conditions" "github.com/nginx/nginx-gateway-fabric/v2/internal/framework/controller" + "github.com/nginx/nginx-gateway-fabric/v2/internal/framework/helpers" "github.com/nginx/nginx-gateway-fabric/v2/internal/framework/kinds" ) @@ -134,10 +135,11 @@ func validateGatewayParametersRef(npCfg *NginxProxy, ref v1.LocalParametersRefer if _, ok := supportedParamKinds[string(ref.Kind)]; !ok { err := field.NotSupported(path.Child("kind"), string(ref.Kind), []string{kinds.NginxProxy}) + condMsg := helpers.CapitalizeString(err.Error()) conds = append( conds, - conditions.NewGatewayRefInvalid(err.Error()), - conditions.NewGatewayInvalidParameters(err.Error()), + conditions.NewGatewayRefInvalid(condMsg), + conditions.NewGatewayInvalidParameters(condMsg), ) return conds @@ -156,7 +158,7 @@ func validateGatewayParametersRef(npCfg *NginxProxy, ref v1.LocalParametersRefer } if !npCfg.Valid { - msg := npCfg.ErrMsgs.ToAggregate().Error() + msg := helpers.CapitalizeString(npCfg.ErrMsgs.ToAggregate().Error()) conds = append( conds, conditions.NewGatewayRefInvalid(msg), @@ -174,16 +176,16 @@ func validateGateway(gw *v1.Gateway, gc *GatewayClass, npCfg *NginxProxy) ([]con var conds []conditions.Condition if gc == nil { - conds = append(conds, conditions.NewGatewayInvalid("GatewayClass doesn't exist")...) + conds = append(conds, conditions.NewGatewayInvalid("The GatewayClass doesn't exist")...) } else if !gc.Valid { - conds = append(conds, conditions.NewGatewayInvalid("GatewayClass is invalid")...) + conds = append(conds, conditions.NewGatewayInvalid("The GatewayClass is invalid")...) } // Set the unaccepted conditions here, because those make the gateway invalid. We set the unprogrammed conditions // elsewhere, because those do not make the gateway invalid. for _, address := range gw.Spec.Addresses { if address.Type == nil { - conds = append(conds, conditions.NewGatewayUnsupportedAddress("AddressType must be specified")) + conds = append(conds, conditions.NewGatewayUnsupportedAddress("The AddressType must be specified")) } else if *address.Type != v1.IPAddressType { conds = append(conds, conditions.NewGatewayUnsupportedAddress("Only AddressType IPAddress is supported")) } diff --git a/internal/controller/state/graph/gateway_listener.go b/internal/controller/state/graph/gateway_listener.go index cc88548d0a..9f08d96253 100644 --- a/internal/controller/state/graph/gateway_listener.go +++ b/internal/controller/state/graph/gateway_listener.go @@ -192,7 +192,7 @@ func (c *listenerConfigurator) configure(listener v1.Listener, gwNSName types.Na var err error allowedRouteSelector, err = metav1.LabelSelectorAsSelector(selector) if err != nil { - msg := fmt.Sprintf("invalid label selector: %s", err.Error()) + msg := fmt.Sprintf("Invalid label selector: %s", err.Error()) conds = append(conds, conditions.NewListenerUnsupportedValue(msg)...) valid = false } diff --git a/internal/controller/state/graph/gateway_test.go b/internal/controller/state/graph/gateway_test.go index 3b45c3cc77..a815dd3adf 100644 --- a/internal/controller/state/graph/gateway_test.go +++ b/internal/controller/state/graph/gateway_test.go @@ -730,7 +730,7 @@ func TestBuildGateway(t *testing.T) { Valid: false, Attachable: true, Conditions: conditions.NewListenerUnsupportedValue( - `invalid label selector: "invalid" is not a valid label selector operator`, + `Invalid label selector: "invalid" is not a valid label selector operator`, ), Routes: map[RouteKey]*L7Route{}, L4Routes: map[L4RouteKey]*L4Route{}, @@ -1142,7 +1142,7 @@ func TestBuildGateway(t *testing.T) { Name: controller.CreateNginxResourceName("gateway1", gcName), }, Valid: false, - Conditions: conditions.NewGatewayInvalid("GatewayClass is invalid"), + Conditions: conditions.NewGatewayInvalid("The GatewayClass is invalid"), }, }, name: "invalid gatewayclass", @@ -1160,7 +1160,7 @@ func TestBuildGateway(t *testing.T) { Name: controller.CreateNginxResourceName("gateway1", gcName), }, Valid: false, - Conditions: conditions.NewGatewayInvalid("GatewayClass doesn't exist"), + Conditions: conditions.NewGatewayInvalid("The GatewayClass doesn't exist"), }, }, name: "nil gatewayclass", @@ -1337,11 +1337,11 @@ func TestBuildGateway(t *testing.T) { Valid: true, // invalid parametersRef does not invalidate Gateway. Conditions: []conditions.Condition{ conditions.NewGatewayRefInvalid( - "spec.infrastructure.parametersRef.kind: Unsupported value: \"Invalid\": " + + "Spec.infrastructure.parametersRef.kind: Unsupported value: \"Invalid\": " + "supported values: \"NginxProxy\"", ), conditions.NewGatewayInvalidParameters( - "spec.infrastructure.parametersRef.kind: Unsupported value: \"Invalid\": " + + "Spec.infrastructure.parametersRef.kind: Unsupported value: \"Invalid\": " + "supported values: \"NginxProxy\"", ), }, @@ -1425,8 +1425,8 @@ func TestBuildGateway(t *testing.T) { Valid: false, }, Conditions: []conditions.Condition{ - conditions.NewGatewayRefInvalid("somePath: Required value: someField"), - conditions.NewGatewayInvalidParameters("somePath: Required value: someField"), + conditions.NewGatewayRefInvalid("SomePath: Required value: someField"), + conditions.NewGatewayInvalidParameters("SomePath: Required value: someField"), }, }, }, @@ -1456,9 +1456,9 @@ func TestBuildGateway(t *testing.T) { Valid: false, }, Conditions: append( - conditions.NewGatewayInvalid("GatewayClass is invalid"), - conditions.NewGatewayRefInvalid("somePath: Required value: someField"), - conditions.NewGatewayInvalidParameters("somePath: Required value: someField"), + conditions.NewGatewayInvalid("The GatewayClass is invalid"), + conditions.NewGatewayRefInvalid("SomePath: Required value: someField"), + conditions.NewGatewayInvalidParameters("SomePath: Required value: someField"), ), }, }, @@ -1485,7 +1485,7 @@ func TestBuildGateway(t *testing.T) { }, Valid: false, Conditions: []conditions.Condition{ - conditions.NewGatewayUnsupportedAddress("AddressType must be specified"), + conditions.NewGatewayUnsupportedAddress("The AddressType must be specified"), }, }, }, @@ -1607,10 +1607,10 @@ func TestBuildGateway(t *testing.T) { Conditions: []conditions.Condition{ conditions.NewGatewayAcceptedUnsupportedField("TLS"), conditions.NewGatewayRefInvalid( - "spec.infrastructure.parametersRef.kind: Unsupported value: \"wrong-kind\": supported values: \"NginxProxy\"", + "Spec.infrastructure.parametersRef.kind: Unsupported value: \"wrong-kind\": supported values: \"NginxProxy\"", ), conditions.NewGatewayInvalidParameters( - "spec.infrastructure.parametersRef.kind: Unsupported value: \"wrong-kind\": supported values: \"NginxProxy\"", + "Spec.infrastructure.parametersRef.kind: Unsupported value: \"wrong-kind\": supported values: \"NginxProxy\"", ), }, }, @@ -1660,11 +1660,11 @@ func TestValidateGatewayParametersRef(t *testing.T) { }, expConds: []conditions.Condition{ conditions.NewGatewayRefInvalid( - "spec.infrastructure.parametersRef.kind: Unsupported value: \"wrong-kind\": " + + "Spec.infrastructure.parametersRef.kind: Unsupported value: \"wrong-kind\": " + "supported values: \"NginxProxy\"", ), conditions.NewGatewayInvalidParameters( - "spec.infrastructure.parametersRef.kind: Unsupported value: \"wrong-kind\": " + + "Spec.infrastructure.parametersRef.kind: Unsupported value: \"wrong-kind\": " + "supported values: \"NginxProxy\"", ), }, @@ -1696,8 +1696,8 @@ func TestValidateGatewayParametersRef(t *testing.T) { Name: "np", }, expConds: []conditions.Condition{ - conditions.NewGatewayRefInvalid("somePath: Required value: someField"), - conditions.NewGatewayInvalidParameters("somePath: Required value: someField"), + conditions.NewGatewayRefInvalid("SomePath: Required value: someField"), + conditions.NewGatewayInvalidParameters("SomePath: Required value: someField"), }, }, { diff --git a/internal/controller/state/graph/gatewayclass.go b/internal/controller/state/graph/gatewayclass.go index 607552fac4..ff732899ef 100644 --- a/internal/controller/state/graph/gatewayclass.go +++ b/internal/controller/state/graph/gatewayclass.go @@ -10,6 +10,7 @@ import ( v1 "sigs.k8s.io/gateway-api/apis/v1" "github.com/nginx/nginx-gateway-fabric/v2/internal/controller/state/conditions" + "github.com/nginx/nginx-gateway-fabric/v2/internal/framework/helpers" "github.com/nginx/nginx-gateway-fabric/v2/internal/framework/kinds" ) @@ -130,7 +131,7 @@ func validateGatewayClassParametersRef(path *field.Path, ref v1.ParametersRefere } if len(errs) > 0 { - msg := errs.ToAggregate().Error() + msg := helpers.CapitalizeString(errs.ToAggregate().Error()) return []conditions.Condition{ conditions.NewGatewayClassRefInvalid(msg), conditions.NewGatewayClassInvalidParameters(msg), @@ -175,7 +176,7 @@ func validateGatewayClass( } if !npCfg.Valid { - msg := npCfg.ErrMsgs.ToAggregate().Error() + msg := helpers.CapitalizeString(npCfg.ErrMsgs.ToAggregate().Error()) conds = append( conds, conditions.NewGatewayClassRefInvalid(msg), diff --git a/internal/controller/state/graph/gatewayclass_test.go b/internal/controller/state/graph/gatewayclass_test.go index b7b01f9d15..de37da9c51 100644 --- a/internal/controller/state/graph/gatewayclass_test.go +++ b/internal/controller/state/graph/gatewayclass_test.go @@ -228,10 +228,10 @@ func TestBuildGatewayClass(t *testing.T) { Valid: true, Conditions: []conditions.Condition{ conditions.NewGatewayClassRefInvalid( - "spec.parametersRef.namespace: Required value: ParametersRef must specify Namespace", + "Spec.parametersRef.namespace: Required value: ParametersRef must specify Namespace", ), conditions.NewGatewayClassInvalidParameters( - "spec.parametersRef.namespace: Required value: ParametersRef must specify Namespace", + "Spec.parametersRef.namespace: Required value: ParametersRef must specify Namespace", ), }, }, @@ -244,10 +244,10 @@ func TestBuildGatewayClass(t *testing.T) { Valid: true, Conditions: []conditions.Condition{ conditions.NewGatewayClassRefInvalid( - "spec.parametersRef.kind: Unsupported value: \"Invalid\": supported values: \"NginxProxy\"", + "Spec.parametersRef.kind: Unsupported value: \"Invalid\": supported values: \"NginxProxy\"", ), conditions.NewGatewayClassInvalidParameters( - "spec.parametersRef.kind: Unsupported value: \"Invalid\": supported values: \"NginxProxy\"", + "Spec.parametersRef.kind: Unsupported value: \"Invalid\": supported values: \"NginxProxy\"", ), }, }, diff --git a/internal/controller/state/graph/httproute.go b/internal/controller/state/graph/httproute.go index 0f124b88cc..a8ee8ab158 100644 --- a/internal/controller/state/graph/httproute.go +++ b/internal/controller/state/graph/httproute.go @@ -54,7 +54,8 @@ func buildHTTPRoute( field.NewPath("spec").Child("hostnames"), ); err != nil { r.Valid = false - r.Conditions = append(r.Conditions, conditions.NewRouteUnsupportedValue(err.Error())) + condMsg := helpers.CapitalizeString(err.Error()) + r.Conditions = append(r.Conditions, conditions.NewRouteUnsupportedValue(condMsg)) return r } @@ -337,7 +338,7 @@ func processHTTPRouteRules( // resolve errors do not invalidate routes if len(allRulesErrors.resolve) > 0 { - msg := allRulesErrors.resolve.ToAggregate().Error() + msg := helpers.CapitalizeString(allRulesErrors.resolve.ToAggregate().Error()) conds = append(conds, conditions.NewRouteResolvedRefsInvalidFilter(msg)) } diff --git a/internal/controller/state/graph/httproute_test.go b/internal/controller/state/graph/httproute_test.go index 2cbdf3097e..01bd75ed9d 100644 --- a/internal/controller/state/graph/httproute_test.go +++ b/internal/controller/state/graph/httproute_test.go @@ -578,7 +578,7 @@ func TestBuildHTTPRoute(t *testing.T) { }, Conditions: []conditions.Condition{ conditions.NewRouteUnsupportedValue( - `spec.hostnames[0]: Invalid value: "": cannot be empty string`, + `Spec.hostnames[0]: Invalid value: "": cannot be empty string`, ), }, }, @@ -909,7 +909,7 @@ func TestBuildHTTPRoute(t *testing.T) { }, Conditions: []conditions.Condition{ conditions.NewRouteResolvedRefsInvalidFilter( - "spec.rules[0].filters[0].extensionRef: Not found: " + + "Spec.rules[0].filters[0].extensionRef: Not found: " + `{"group":"gateway.nginx.org","kind":"SnippetsFilter",` + `"name":"does-not-exist"}`, ), @@ -952,7 +952,7 @@ func TestBuildHTTPRoute(t *testing.T) { "Unsupported value: \"wrong\": supported values: \"gateway.nginx.org\"", ), conditions.NewRouteResolvedRefsInvalidFilter( - "spec.rules[0].filters[1].extensionRef: Not found: " + + "Spec.rules[0].filters[1].extensionRef: Not found: " + `{"group":"gateway.nginx.org","kind":"SnippetsFilter",` + `"name":"does-not-exist"}`, ), diff --git a/internal/controller/state/graph/inferencepools.go b/internal/controller/state/graph/inferencepools.go index 8f708bd62f..3ad8a2718a 100644 --- a/internal/controller/state/graph/inferencepools.go +++ b/internal/controller/state/graph/inferencepools.go @@ -156,7 +156,9 @@ func validateInferencePoolExtensionRef( } if _, ok := svc[eppNsName]; !ok { - failingCond = conditions.NewInferencePoolInvalidExtensionref("ExtensionRef Service not found: " + eppNsName.String()) + failingCond = conditions.NewInferencePoolInvalidExtensionref( + "The ExtensionRef Service not found: " + eppNsName.String(), + ) return &failingCond } diff --git a/internal/controller/state/graph/inferencepools_test.go b/internal/controller/state/graph/inferencepools_test.go index a3ef1b3ede..ffa7b7a17a 100644 --- a/internal/controller/state/graph/inferencepools_test.go +++ b/internal/controller/state/graph/inferencepools_test.go @@ -375,7 +375,7 @@ func TestBuildReferencedInferencePools(t *testing.T) { "Referenced HTTPRoute test/valid-route is not accepted by the Gateway", ), conditions.NewInferencePoolInvalidExtensionref( - "ExtensionRef Service not found: test/invalid-extension-ref", + "The ExtensionRef Service not found: test/invalid-extension-ref", ), }, }, @@ -451,7 +451,7 @@ func TestValidateInferencePoolExtensionRef(t *testing.T) { }, services: map[types.NamespacedName]*v1.Service{}, expCond: helpers.GetPointer( - conditions.NewInferencePoolInvalidExtensionref("ExtensionRef Service not found: test/does-not-exist"), + conditions.NewInferencePoolInvalidExtensionref("The ExtensionRef Service not found: test/does-not-exist"), ), }, { diff --git a/internal/controller/state/graph/policies.go b/internal/controller/state/graph/policies.go index f790f478e0..30e44fb014 100644 --- a/internal/controller/state/graph/policies.go +++ b/internal/controller/state/graph/policies.go @@ -205,7 +205,7 @@ func attachPolicyToService( if !gw.Valid { policy.InvalidForGateways[gwNsName] = struct{}{} - ancestor.Conditions = []conditions.Condition{conditions.NewPolicyTargetNotFound("Parent Gateway is invalid")} + ancestor.Conditions = []conditions.Condition{conditions.NewPolicyTargetNotFound("The Parent Gateway is invalid")} policy.Ancestors = append(policy.Ancestors, ancestor) continue } @@ -254,7 +254,7 @@ func attachPolicyToRoute( } if !route.Valid || !route.Attachable || len(route.ParentRefs) == 0 { - ancestor.Conditions = []conditions.Condition{conditions.NewPolicyTargetNotFound("TargetRef is invalid")} + ancestor.Conditions = []conditions.Condition{conditions.NewPolicyTargetNotFound("The TargetRef is invalid")} policy.Ancestors = append(policy.Ancestors, ancestor) return } @@ -334,14 +334,14 @@ func attachPolicyToGateway( if !exists || (gw != nil && gw.Source == nil) { policy.InvalidForGateways[ref.Nsname] = struct{}{} - ancestor.Conditions = []conditions.Condition{conditions.NewPolicyTargetNotFound("TargetRef is not found")} + ancestor.Conditions = []conditions.Condition{conditions.NewPolicyTargetNotFound("The TargetRef is not found")} policy.Ancestors = append(policy.Ancestors, ancestor) return } if !gw.Valid { policy.InvalidForGateways[ref.Nsname] = struct{}{} - ancestor.Conditions = []conditions.Condition{conditions.NewPolicyTargetNotFound("TargetRef is invalid")} + ancestor.Conditions = []conditions.Condition{conditions.NewPolicyTargetNotFound("The TargetRef is invalid")} policy.Ancestors = append(policy.Ancestors, ancestor) return } diff --git a/internal/controller/state/graph/policies_test.go b/internal/controller/state/graph/policies_test.go index ff9251cc72..251ab5aeb8 100644 --- a/internal/controller/state/graph/policies_test.go +++ b/internal/controller/state/graph/policies_test.go @@ -360,7 +360,7 @@ func TestAttachPolicyToRoute(t *testing.T) { expAncestors: []PolicyAncestor{ { Ancestor: createExpAncestor(kinds.HTTPRoute), - Conditions: []conditions.Condition{conditions.NewPolicyTargetNotFound("TargetRef is invalid")}, + Conditions: []conditions.Condition{conditions.NewPolicyTargetNotFound("The TargetRef is invalid")}, }, }, expAttached: false, @@ -373,7 +373,7 @@ func TestAttachPolicyToRoute(t *testing.T) { expAncestors: []PolicyAncestor{ { Ancestor: createExpAncestor(kinds.HTTPRoute), - Conditions: []conditions.Condition{conditions.NewPolicyTargetNotFound("TargetRef is invalid")}, + Conditions: []conditions.Condition{conditions.NewPolicyTargetNotFound("The TargetRef is invalid")}, }, }, expAttached: false, @@ -386,7 +386,7 @@ func TestAttachPolicyToRoute(t *testing.T) { expAncestors: []PolicyAncestor{ { Ancestor: createExpAncestor(kinds.HTTPRoute), - Conditions: []conditions.Condition{conditions.NewPolicyTargetNotFound("TargetRef is invalid")}, + Conditions: []conditions.Condition{conditions.NewPolicyTargetNotFound("The TargetRef is invalid")}, }, }, expAttached: false, @@ -595,7 +595,7 @@ func TestAttachPolicyToGateway(t *testing.T) { expAncestors: []PolicyAncestor{ { Ancestor: getGatewayParentRef(gateway2NsName), - Conditions: []conditions.Condition{conditions.NewPolicyTargetNotFound("TargetRef is not found")}, + Conditions: []conditions.Condition{conditions.NewPolicyTargetNotFound("The TargetRef is not found")}, }, }, expAttached: false, @@ -616,7 +616,7 @@ func TestAttachPolicyToGateway(t *testing.T) { expAncestors: []PolicyAncestor{ { Ancestor: getGatewayParentRef(gatewayNsName), - Conditions: []conditions.Condition{conditions.NewPolicyTargetNotFound("TargetRef is invalid")}, + Conditions: []conditions.Condition{conditions.NewPolicyTargetNotFound("The TargetRef is invalid")}, }, }, expAttached: false, @@ -810,7 +810,7 @@ func TestAttachPolicyToService(t *testing.T) { expAncestors: []PolicyAncestor{ { Ancestor: getGatewayParentRef(gwNsname), - Conditions: []conditions.Condition{conditions.NewPolicyTargetNotFound("Parent Gateway is invalid")}, + Conditions: []conditions.Condition{conditions.NewPolicyTargetNotFound("The Parent Gateway is invalid")}, }, }, }, @@ -1016,7 +1016,7 @@ func TestProcessPolicies(t *testing.T) { validator: &policiesfakes.FakeValidator{ ValidateStub: func(policy policies.Policy) []conditions.Condition { if policy.GetName() == "pol1" { - return []conditions.Condition{conditions.NewPolicyInvalid("invalid error")} + return []conditions.Condition{conditions.NewPolicyInvalid("Invalid error")} } return nil @@ -1037,7 +1037,7 @@ func TestProcessPolicies(t *testing.T) { }, }, Conditions: []conditions.Condition{ - conditions.NewPolicyInvalid("invalid error"), + conditions.NewPolicyInvalid("Invalid error"), }, Ancestors: []PolicyAncestor{}, InvalidForGateways: map[types.NamespacedName]struct{}{}, diff --git a/internal/controller/state/graph/tlsroute.go b/internal/controller/state/graph/tlsroute.go index db0b87e11e..d9b6fee74d 100644 --- a/internal/controller/state/graph/tlsroute.go +++ b/internal/controller/state/graph/tlsroute.go @@ -7,6 +7,7 @@ import ( "sigs.k8s.io/gateway-api/apis/v1alpha2" "github.com/nginx/nginx-gateway-fabric/v2/internal/controller/state/conditions" + "github.com/nginx/nginx-gateway-fabric/v2/internal/framework/helpers" ) func buildTLSRoute( @@ -36,7 +37,8 @@ func buildTLSRoute( field.NewPath("spec").Child("hostnames"), ); err != nil { r.Valid = false - r.Conditions = append(r.Conditions, conditions.NewRouteUnsupportedValue(err.Error())) + condMsg := helpers.CapitalizeString(err.Error()) + r.Conditions = append(r.Conditions, conditions.NewRouteUnsupportedValue(condMsg)) return r } diff --git a/internal/controller/state/graph/tlsroute_test.go b/internal/controller/state/graph/tlsroute_test.go index 29fac01b1e..c172fa384f 100644 --- a/internal/controller/state/graph/tlsroute_test.go +++ b/internal/controller/state/graph/tlsroute_test.go @@ -331,7 +331,7 @@ func TestBuildTLSRoute(t *testing.T) { Source: invalidHostnameGtr, ParentRefs: []ParentRef{parentRefGraph}, Conditions: []conditions.Condition{conditions.NewRouteUnsupportedValue( - "spec.hostnames[0]: Invalid value: \"hi....com\": a lowercase RFC 1" + + "Spec.hostnames[0]: Invalid value: \"hi....com\": a lowercase RFC 1" + "123 subdomain must consist of lower case alphanumeric characters" + ", '-' or '.', and must start and end with an alphanumeric charac" + "ter (e.g. 'example.com', regex used for validation is '[a-z0-9](" + @@ -383,7 +383,7 @@ func TestBuildTLSRoute(t *testing.T) { Attachable: true, Valid: true, Conditions: []conditions.Condition{conditions.NewRouteBackendRefUnsupportedProtocol( - "route type tls does not support service port appProtocol kubernetes.io/h2c", + "The Route type tls does not support service port appProtocol kubernetes.io/h2c", )}, }, gateway: createGateway(), @@ -412,7 +412,7 @@ func TestBuildTLSRoute(t *testing.T) { Attachable: true, Valid: true, Conditions: []conditions.Condition{conditions.NewRouteBackendRefUnsupportedProtocol( - "route type tls does not support service port appProtocol kubernetes.io/ws", + "The Route type tls does not support service port appProtocol kubernetes.io/ws", )}, }, gateway: createGateway(), @@ -587,7 +587,7 @@ func TestBuildTLSRoute(t *testing.T) { ServicePort: apiv1.ServicePort{Port: 80}, InvalidForGateways: map[types.NamespacedName]conditions.Condition{ {Namespace: "test", Name: "gateway"}: conditions.NewRouteInvalidIPFamily( - "service configured with IPv4 family but NginxProxy is configured with IPv6", + "The Service configured with IPv4 family but NginxProxy is configured with IPv6", ), }, Valid: true, diff --git a/internal/controller/status/prepare_requests_test.go b/internal/controller/status/prepare_requests_test.go index 7b9d16a697..7ddfdd5e0f 100644 --- a/internal/controller/status/prepare_requests_test.go +++ b/internal/controller/status/prepare_requests_test.go @@ -196,7 +196,7 @@ var ( ObservedGeneration: 3, LastTransitionTime: transitionTime, Reason: string(v1.RouteReasonAccepted), - Message: "The route is accepted", + Message: "The Route is accepted", }, { Type: string(v1.RouteConditionResolvedRefs), @@ -222,7 +222,7 @@ var ( ObservedGeneration: 3, LastTransitionTime: transitionTime, Reason: string(v1.RouteReasonAccepted), - Message: "The route is accepted", + Message: "The Route is accepted", }, { Type: string(v1.RouteConditionResolvedRefs), @@ -254,7 +254,7 @@ var ( ObservedGeneration: 3, LastTransitionTime: transitionTime, Reason: string(v1.RouteReasonAccepted), - Message: "The route is accepted", + Message: "The Route is accepted", }, { Type: string(v1.RouteConditionResolvedRefs), @@ -285,7 +285,7 @@ var ( ObservedGeneration: 3, LastTransitionTime: transitionTime, Reason: string(v1.RouteReasonAccepted), - Message: "The route is accepted", + Message: "The Route is accepted", }, { Type: string(v1.RouteConditionResolvedRefs), @@ -310,7 +310,7 @@ var ( ObservedGeneration: 3, LastTransitionTime: transitionTime, Reason: string(v1.RouteReasonAccepted), - Message: "The route is accepted", + Message: "The Route is accepted", }, { Type: string(v1.RouteConditionResolvedRefs), @@ -347,7 +347,7 @@ var ( ObservedGeneration: 3, LastTransitionTime: transitionTime, Reason: string(v1.RouteReasonAccepted), - Message: "The route is accepted", + Message: "The Route is accepted", }, { Type: string(v1.RouteConditionResolvedRefs), @@ -678,7 +678,7 @@ func TestBuildGatewayClassStatuses(t *testing.T) { ObservedGeneration: 1, LastTransitionTime: transitionTime, Reason: string(v1.GatewayClassReasonAccepted), - Message: "GatewayClass is accepted", + Message: "The GatewayClass is accepted", }, { Type: string(v1.GatewayClassReasonSupportedVersion), @@ -686,7 +686,7 @@ func TestBuildGatewayClassStatuses(t *testing.T) { ObservedGeneration: 1, LastTransitionTime: transitionTime, Reason: string(v1.GatewayClassReasonSupportedVersion), - Message: "Gateway API CRD versions are supported", + Message: "The Gateway API CRD versions are supported", }, }, }, @@ -760,7 +760,7 @@ func TestBuildGatewayStatuses(t *testing.T) { ObservedGeneration: 2, LastTransitionTime: transitionTime, Reason: string(v1.ListenerReasonAccepted), - Message: "Listener is accepted", + Message: "The Listener is accepted", }, { Type: string(v1.ListenerConditionProgrammed), @@ -768,7 +768,7 @@ func TestBuildGatewayStatuses(t *testing.T) { ObservedGeneration: 2, LastTransitionTime: transitionTime, Reason: string(v1.ListenerReasonProgrammed), - Message: "Listener is programmed", + Message: "The Listener is programmed", }, { Type: string(v1.ListenerConditionResolvedRefs), @@ -835,7 +835,7 @@ func TestBuildGatewayStatuses(t *testing.T) { ObservedGeneration: 2, LastTransitionTime: transitionTime, Reason: string(v1.GatewayReasonAccepted), - Message: "Gateway is accepted", + Message: "The Gateway is accepted", }, { Type: string(v1.GatewayConditionProgrammed), @@ -843,7 +843,7 @@ func TestBuildGatewayStatuses(t *testing.T) { ObservedGeneration: 2, LastTransitionTime: transitionTime, Reason: string(v1.GatewayReasonProgrammed), - Message: "Gateway is programmed", + Message: "The Gateway is programmed", }, }, Listeners: []v1.ListenerStatus{ @@ -874,7 +874,7 @@ func TestBuildGatewayStatuses(t *testing.T) { { Name: "listener-invalid", Valid: false, - Conditions: conditions.NewListenerUnsupportedValue("unsupported value"), + Conditions: conditions.NewListenerUnsupportedValue("Unsupported value"), }, }, Valid: true, @@ -889,7 +889,7 @@ func TestBuildGatewayStatuses(t *testing.T) { ObservedGeneration: 2, LastTransitionTime: transitionTime, Reason: string(v1.GatewayReasonProgrammed), - Message: "Gateway is programmed", + Message: "The Gateway is programmed", }, { // is it a bug? @@ -898,7 +898,7 @@ func TestBuildGatewayStatuses(t *testing.T) { ObservedGeneration: 2, LastTransitionTime: transitionTime, Reason: string(v1.GatewayReasonListenersNotValid), - Message: "Gateway has at least one valid listener", + Message: "The Gateway has at least one valid listener", }, }, Listeners: []v1.ListenerStatus{ @@ -917,7 +917,7 @@ func TestBuildGatewayStatuses(t *testing.T) { ObservedGeneration: 2, LastTransitionTime: transitionTime, Reason: string(conditions.ListenerReasonUnsupportedValue), - Message: "unsupported value", + Message: "Unsupported value", }, { Type: string(v1.ListenerConditionProgrammed), @@ -925,7 +925,7 @@ func TestBuildGatewayStatuses(t *testing.T) { ObservedGeneration: 2, LastTransitionTime: transitionTime, Reason: string(v1.ListenerReasonInvalid), - Message: "unsupported value", + Message: "Unsupported value", }, }, }, @@ -941,12 +941,12 @@ func TestBuildGatewayStatuses(t *testing.T) { { Name: "listener-invalid-1", Valid: false, - Conditions: conditions.NewListenerUnsupportedProtocol("unsupported protocol"), + Conditions: conditions.NewListenerUnsupportedProtocol("Unsupported protocol"), }, { Name: "listener-invalid-2", Valid: false, - Conditions: conditions.NewListenerUnsupportedValue("unsupported value"), + Conditions: conditions.NewListenerUnsupportedValue("Unsupported value"), }, }, Valid: true, @@ -961,7 +961,7 @@ func TestBuildGatewayStatuses(t *testing.T) { ObservedGeneration: 2, LastTransitionTime: transitionTime, Reason: string(v1.GatewayReasonListenersNotValid), - Message: "Gateway has no valid listeners", + Message: "The Gateway has no valid listeners", }, { Type: string(v1.GatewayConditionProgrammed), @@ -969,7 +969,7 @@ func TestBuildGatewayStatuses(t *testing.T) { ObservedGeneration: 2, LastTransitionTime: transitionTime, Reason: string(v1.GatewayReasonInvalid), - Message: "Gateway has no valid listeners", + Message: "The Gateway has no valid listeners", }, }, Listeners: []v1.ListenerStatus{ @@ -983,7 +983,7 @@ func TestBuildGatewayStatuses(t *testing.T) { ObservedGeneration: 2, LastTransitionTime: transitionTime, Reason: string(v1.ListenerReasonUnsupportedProtocol), - Message: "unsupported protocol", + Message: "Unsupported protocol", }, { Type: string(v1.ListenerConditionProgrammed), @@ -991,7 +991,7 @@ func TestBuildGatewayStatuses(t *testing.T) { ObservedGeneration: 2, LastTransitionTime: transitionTime, Reason: string(v1.ListenerReasonInvalid), - Message: "unsupported protocol", + Message: "Unsupported protocol", }, }, }, @@ -1005,7 +1005,7 @@ func TestBuildGatewayStatuses(t *testing.T) { ObservedGeneration: 2, LastTransitionTime: transitionTime, Reason: string(conditions.ListenerReasonUnsupportedValue), - Message: "unsupported value", + Message: "Unsupported value", }, { Type: string(v1.ListenerConditionProgrammed), @@ -1013,7 +1013,7 @@ func TestBuildGatewayStatuses(t *testing.T) { ObservedGeneration: 2, LastTransitionTime: transitionTime, Reason: string(v1.ListenerReasonInvalid), - Message: "unsupported value", + Message: "Unsupported value", }, }, }, @@ -1026,7 +1026,7 @@ func TestBuildGatewayStatuses(t *testing.T) { gateway: &graph.Gateway{ Source: createGateway(), Valid: false, - Conditions: conditions.NewGatewayInvalid("no gateway class"), + Conditions: conditions.NewGatewayInvalid("No GatewayClass"), }, expected: map[types.NamespacedName]v1.GatewayStatus{ {Namespace: "test", Name: "gateway"}: { @@ -1037,7 +1037,7 @@ func TestBuildGatewayStatuses(t *testing.T) { ObservedGeneration: 2, LastTransitionTime: transitionTime, Reason: string(v1.GatewayReasonInvalid), - Message: "no gateway class", + Message: "No GatewayClass", }, { Type: string(v1.GatewayConditionProgrammed), @@ -1045,7 +1045,7 @@ func TestBuildGatewayStatuses(t *testing.T) { ObservedGeneration: 2, LastTransitionTime: transitionTime, Reason: string(v1.GatewayReasonInvalid), - Message: "no gateway class", + Message: "No GatewayClass", }, }, }, @@ -1075,7 +1075,7 @@ func TestBuildGatewayStatuses(t *testing.T) { ObservedGeneration: 2, LastTransitionTime: transitionTime, Reason: string(v1.GatewayReasonAccepted), - Message: "Gateway is accepted", + Message: "The Gateway is accepted", }, { Type: string(v1.GatewayConditionProgrammed), @@ -1097,7 +1097,7 @@ func TestBuildGatewayStatuses(t *testing.T) { ObservedGeneration: 2, LastTransitionTime: transitionTime, Reason: string(v1.ListenerReasonAccepted), - Message: "Listener is accepted", + Message: "The Listener is accepted", }, { Type: string(v1.ListenerConditionResolvedRefs), @@ -1156,7 +1156,7 @@ func TestBuildGatewayStatuses(t *testing.T) { ObservedGeneration: 2, LastTransitionTime: transitionTime, Reason: string(v1.GatewayReasonAccepted), - Message: "Gateway is accepted", + Message: "The Gateway is accepted", }, { Type: string(v1.GatewayConditionProgrammed), @@ -1164,7 +1164,7 @@ func TestBuildGatewayStatuses(t *testing.T) { ObservedGeneration: 2, LastTransitionTime: transitionTime, Reason: string(v1.GatewayReasonProgrammed), - Message: "Gateway is programmed", + Message: "The Gateway is programmed", }, { Type: string(conditions.GatewayResolvedRefs), @@ -1172,7 +1172,7 @@ func TestBuildGatewayStatuses(t *testing.T) { ObservedGeneration: 2, LastTransitionTime: transitionTime, Reason: string(conditions.GatewayReasonResolvedRefs), - Message: "ParametersRef resource is resolved", + Message: "The ParametersRef resource is resolved", }, }, Listeners: []v1.ListenerStatus{ @@ -1199,7 +1199,7 @@ func TestBuildGatewayStatuses(t *testing.T) { Valid: true, Conditions: []conditions.Condition{ conditions.NewGatewayRefNotFound(), - conditions.NewGatewayInvalidParameters("ParametersRef not found"), + conditions.NewGatewayInvalidParameters("The ParametersRef not found"), }, }, expected: map[types.NamespacedName]v1.GatewayStatus{ @@ -1212,7 +1212,7 @@ func TestBuildGatewayStatuses(t *testing.T) { ObservedGeneration: 2, LastTransitionTime: transitionTime, Reason: string(v1.GatewayReasonProgrammed), - Message: "Gateway is programmed", + Message: "The Gateway is programmed", }, { Type: string(conditions.GatewayResolvedRefs), @@ -1220,7 +1220,7 @@ func TestBuildGatewayStatuses(t *testing.T) { ObservedGeneration: 2, LastTransitionTime: transitionTime, Reason: string(conditions.GatewayReasonParamsRefNotFound), - Message: "ParametersRef resource could not be found", + Message: "The ParametersRef resource could not be found", }, { Type: string(v1.GatewayConditionAccepted), @@ -1228,7 +1228,8 @@ func TestBuildGatewayStatuses(t *testing.T) { ObservedGeneration: 2, LastTransitionTime: transitionTime, Reason: string(v1.GatewayReasonInvalidParameters), - Message: "Gateway is accepted, but ParametersRef is ignored due to an error: ParametersRef not found", + Message: "The Gateway is accepted, but ParametersRef is ignored due to an error: " + + "The ParametersRef not found", }, }, Listeners: []v1.ListenerStatus{ @@ -1269,7 +1270,7 @@ func TestBuildGatewayStatuses(t *testing.T) { ObservedGeneration: 2, LastTransitionTime: transitionTime, Reason: string(v1.GatewayReasonAccepted), - Message: "Gateway is accepted", + Message: "The Gateway is accepted", }, { Type: string(v1.GatewayConditionProgrammed), @@ -1319,7 +1320,7 @@ func TestBuildGatewayStatuses(t *testing.T) { ObservedGeneration: 2, LastTransitionTime: transitionTime, Reason: string(v1.GatewayReasonAccepted), - Message: "Gateway is accepted", + Message: "The Gateway is accepted", }, { Type: string(v1.GatewayConditionProgrammed), @@ -1415,7 +1416,7 @@ func TestBuildBackendTLSPolicyStatuses(t *testing.T) { } attachedConds := []conditions.Condition{conditions.NewPolicyAccepted()} - invalidConds := []conditions.Condition{conditions.NewPolicyInvalid("invalid backendTLSPolicy")} + invalidConds := []conditions.Condition{conditions.NewPolicyInvalid("The BackendTLSPolicy is invalid")} validPolicyCfg := policyCfg{ Name: "valid-bt", @@ -1460,7 +1461,7 @@ func TestBuildBackendTLSPolicyStatuses(t *testing.T) { expected: map[types.NamespacedName]v1.PolicyStatus{}, }, { - name: "valid backendTLSPolicy", + name: "valid BackendTLSPolicy", backendTLSPolicies: map[types.NamespacedName]*graph.BackendTLSPolicy{ {Namespace: "test", Name: "valid-bt"}: getBackendTLSPolicy(validPolicyCfg), }, @@ -1483,7 +1484,7 @@ func TestBuildBackendTLSPolicyStatuses(t *testing.T) { ObservedGeneration: 1, LastTransitionTime: transitionTime, Reason: string(v1.PolicyReasonAccepted), - Message: "Policy is accepted", + Message: "The Policy is accepted", }, }, }, @@ -1502,7 +1503,7 @@ func TestBuildBackendTLSPolicyStatuses(t *testing.T) { ObservedGeneration: 1, LastTransitionTime: transitionTime, Reason: string(v1.PolicyReasonAccepted), - Message: "Policy is accepted", + Message: "The Policy is accepted", }, }, }, @@ -1511,7 +1512,7 @@ func TestBuildBackendTLSPolicyStatuses(t *testing.T) { }, }, { - name: "invalid backendTLSPolicy", + name: "invalid BackendTLSPolicy", backendTLSPolicies: map[types.NamespacedName]*graph.BackendTLSPolicy{ {Namespace: "test", Name: "invalid-bt"}: getBackendTLSPolicy(invalidPolicyCfg), }, @@ -1534,7 +1535,7 @@ func TestBuildBackendTLSPolicyStatuses(t *testing.T) { ObservedGeneration: 1, LastTransitionTime: transitionTime, Reason: string(v1.PolicyReasonInvalid), - Message: "invalid backendTLSPolicy", + Message: "The BackendTLSPolicy is invalid", }, }, }, @@ -1580,7 +1581,7 @@ func TestBuildBackendTLSPolicyStatuses(t *testing.T) { ObservedGeneration: 1, LastTransitionTime: transitionTime, Reason: string(v1.PolicyReasonAccepted), - Message: "Policy is accepted", + Message: "The Policy is accepted", }, }, }, @@ -1599,7 +1600,7 @@ func TestBuildBackendTLSPolicyStatuses(t *testing.T) { ObservedGeneration: 1, LastTransitionTime: transitionTime, Reason: string(v1.PolicyReasonAccepted), - Message: "Policy is accepted", + Message: "The Policy is accepted", }, }, }, @@ -1671,7 +1672,7 @@ func TestBuildNginxGatewayStatus(t *testing.T) { ObservedGeneration: 3, LastTransitionTime: transitionTime, Reason: string(ngfAPI.NginxGatewayReasonValid), - Message: "NginxGateway is valid", + Message: "The NginxGateway is valid", }, }, }, @@ -1763,8 +1764,8 @@ func TestBuildNGFPolicyStatuses(t *testing.T) { } } - invalidConds := []conditions.Condition{conditions.NewPolicyInvalid("invalid")} - targetRefNotFoundConds := []conditions.Condition{conditions.NewPolicyTargetNotFound("target not found")} + invalidConds := []conditions.Condition{conditions.NewPolicyInvalid("Invalid")} + targetRefNotFoundConds := []conditions.Condition{conditions.NewPolicyTargetNotFound("The Target not found")} validPolicyKey := graph.PolicyKey{ NsName: types.NamespacedName{Namespace: "test", Name: "valid-pol"}, @@ -1880,7 +1881,7 @@ func TestBuildNGFPolicyStatuses(t *testing.T) { ObservedGeneration: 2, LastTransitionTime: transitionTime, Reason: string(v1.PolicyReasonInvalid), - Message: "invalid", + Message: "Invalid", }, }, }, @@ -1896,7 +1897,7 @@ func TestBuildNGFPolicyStatuses(t *testing.T) { ObservedGeneration: 2, LastTransitionTime: transitionTime, Reason: string(v1.PolicyReasonInvalid), - Message: "invalid", + Message: "Invalid", }, }, }, @@ -1916,7 +1917,7 @@ func TestBuildNGFPolicyStatuses(t *testing.T) { ObservedGeneration: 2, LastTransitionTime: transitionTime, Reason: string(v1.PolicyReasonTargetNotFound), - Message: "target not found", + Message: "The Target not found", }, }, }, @@ -1936,7 +1937,7 @@ func TestBuildNGFPolicyStatuses(t *testing.T) { ObservedGeneration: 2, LastTransitionTime: transitionTime, Reason: string(v1.PolicyReasonAccepted), - Message: "Policy is accepted", + Message: "The Policy is accepted", }, }, }, @@ -1952,7 +1953,7 @@ func TestBuildNGFPolicyStatuses(t *testing.T) { ObservedGeneration: 2, LastTransitionTime: transitionTime, Reason: string(v1.PolicyReasonAccepted), - Message: "Policy is accepted", + Message: "The Policy is accepted", }, }, }, @@ -1980,7 +1981,7 @@ func TestBuildNGFPolicyStatuses(t *testing.T) { ObservedGeneration: 2, LastTransitionTime: transitionTime, Reason: string(v1.PolicyReasonInvalid), - Message: "invalid", + Message: "Invalid", }, }, }, @@ -2059,7 +2060,7 @@ func TestBuildSnippetsFilterStatuses(t *testing.T) { Generation: 1, }, }, - Conditions: []conditions.Condition{conditions.NewSnippetsFilterInvalid("invalid snippetsFilter")}, + Conditions: []conditions.Condition{conditions.NewSnippetsFilterInvalid("Invalid SnippetsFilter")}, Valid: false, } @@ -2091,7 +2092,7 @@ func TestBuildSnippetsFilterStatuses(t *testing.T) { ObservedGeneration: 1, LastTransitionTime: transitionTime, Reason: string(ngfAPI.SnippetsFilterConditionReasonAccepted), - Message: "SnippetsFilter is accepted", + Message: "The SnippetsFilter is accepted", }, }, ControllerName: gatewayCtlrName, @@ -2117,7 +2118,7 @@ func TestBuildSnippetsFilterStatuses(t *testing.T) { ObservedGeneration: 1, LastTransitionTime: transitionTime, Reason: string(ngfAPI.SnippetsFilterConditionReasonInvalid), - Message: "invalid snippetsFilter", + Message: "Invalid SnippetsFilter", }, }, ControllerName: gatewayCtlrName, @@ -2169,7 +2170,7 @@ func TestBuildInferencePoolStatuses(t *testing.T) { ObservedGeneration: 1, LastTransitionTime: transitionTime, Reason: string(inference.InferencePoolReasonAccepted), - Message: "InferencePool is accepted by the Gateway.", + Message: "The InferencePool is accepted by the Gateway.", } validResolvedRefsCondition := metav1.Condition{ @@ -2178,7 +2179,7 @@ func TestBuildInferencePoolStatuses(t *testing.T) { ObservedGeneration: 1, LastTransitionTime: transitionTime, Reason: string(inference.InferencePoolConditionResolvedRefs), - Message: "Inference pool references a valid ExtensionRef.", + Message: "The InferencePool references a valid ExtensionRef.", } referencedGateways := map[types.NamespacedName]*graph.Gateway{ @@ -2317,7 +2318,7 @@ func TestBuildInferencePoolStatuses(t *testing.T) { }, }, { - name: "an inference pool has accepted valid status and is referenced by invalid extension ref", + name: "an inference pool has accepted valid status and is referenced by invalid ExtensionRef", referencedInferencePool: map[types.NamespacedName]*graph.ReferencedInferencePool{ {Namespace: "test", Name: "valid-inference-pool"}: { Source: validInferencePoolWithInvalidExtensionRef, @@ -2330,7 +2331,7 @@ func TestBuildInferencePoolStatuses(t *testing.T) { }, }, Conditions: []conditions.Condition{ - conditions.NewInferencePoolInvalidExtensionref("Invalid extension ref: test/invalid-extension-ref"), + conditions.NewInferencePoolInvalidExtensionref("Invalid ExtensionRef: test/invalid-extension-ref"), }, }, }, @@ -2352,7 +2353,7 @@ func TestBuildInferencePoolStatuses(t *testing.T) { ObservedGeneration: 1, LastTransitionTime: transitionTime, Reason: string(inference.InferencePoolReasonInvalidExtensionRef), - Message: "Invalid extension ref: test/invalid-extension-ref", + Message: "Invalid ExtensionRef: test/invalid-extension-ref", }, }, ParentRef: inference.ParentReference{ @@ -2367,7 +2368,7 @@ func TestBuildInferencePoolStatuses(t *testing.T) { }, }, { - name: "an inference pool is referencing an invalid route and is referenced by invalid extension ref", + name: "an inference pool is referencing an invalid route and is referenced by invalid ExtensionRef", referencedInferencePool: map[types.NamespacedName]*graph.ReferencedInferencePool{ {Namespace: "test", Name: "valid-inference-pool"}: { Source: validInferencePool, @@ -2381,7 +2382,7 @@ func TestBuildInferencePoolStatuses(t *testing.T) { }, Conditions: []conditions.Condition{ conditions.NewInferencePoolInvalidHTTPRouteNotAccepted("Invalid HTTPRoute: test/invalid-route not accepted"), - conditions.NewInferencePoolInvalidExtensionref("Invalid extension ref: test/invalid-extension-ref"), + conditions.NewInferencePoolInvalidExtensionref("Invalid ExtensionRef: test/invalid-extension-ref"), }, }, }, @@ -2410,7 +2411,7 @@ func TestBuildInferencePoolStatuses(t *testing.T) { ObservedGeneration: 1, LastTransitionTime: transitionTime, Reason: string(inference.InferencePoolReasonInvalidExtensionRef), - Message: "Invalid extension ref: test/invalid-extension-ref", + Message: "Invalid ExtensionRef: test/invalid-extension-ref", }, }, ParentRef: inference.ParentReference{ diff --git a/internal/framework/helpers/helpers.go b/internal/framework/helpers/helpers.go index 15e51aa9ac..5678405481 100644 --- a/internal/framework/helpers/helpers.go +++ b/internal/framework/helpers/helpers.go @@ -4,6 +4,7 @@ package helpers import ( "bytes" "fmt" + "strings" "text/template" "github.com/google/go-cmp/cmp" @@ -87,3 +88,12 @@ func MustExecuteTemplate(templ *template.Template, data interface{}) []byte { return buf.Bytes() } + +// CapitalizeString capitalizes the first letter of the string. +func CapitalizeString(s string) string { + if s == "" { + return s + } + + return strings.ToUpper(s[:1]) + s[1:] +} diff --git a/internal/framework/helpers/helpers_test.go b/internal/framework/helpers/helpers_test.go index 9d8a3eb188..917a04d628 100644 --- a/internal/framework/helpers/helpers_test.go +++ b/internal/framework/helpers/helpers_test.go @@ -108,3 +108,47 @@ func TestMustExecuteTemplatePanics(t *testing.T) { g.Expect(execute).To(Panic()) } + +func TestCapitalizeString(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + in string + out string + }{ + { + name: "empty string", + in: "", + out: "", + }, + { + name: "single lowercase letter", + in: "a", + out: "A", + }, + { + name: "lowercase word", + in: "gateway", + out: "Gateway", + }, + { + name: "Phrase with mixed case", + in: "gateway API not found", + out: "Gateway API not found", + }, + { + name: "non-letter first char", + in: "1abc", + out: "1abc", + }, + } + + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + g := NewWithT(t) + g.Expect(helpers.CapitalizeString(tc.in)).To(Equal(tc.out)) + }) + } +}