Skip to content

Commit 938b93e

Browse files
committed
Capitalize Condition messages
1 parent 08c5a4b commit 938b93e

19 files changed

+115
-102
lines changed

internal/controller/nginx/config/policies/validator_test.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ var _ = Describe("Policy CompositeValidator", func() {
4949
policies.ManagerConfig{
5050
Validator: &policiesfakes.FakeValidator{
5151
ValidateStub: func(_ policies.Policy) []conditions.Condition {
52-
return []conditions.Condition{conditions.NewPolicyInvalid("apple error")}
52+
return []conditions.Condition{conditions.NewPolicyInvalid("Apple error")}
5353
},
5454
ValidateGlobalSettingsStub: func(_ policies.Policy, _ *policies.GlobalSettings) []conditions.Condition {
55-
return []conditions.Condition{conditions.NewPolicyInvalid("apple global settings error")}
55+
return []conditions.Condition{conditions.NewPolicyInvalid("Apple global settings error")}
5656
},
5757
ConflictsStub: func(_ policies.Policy, _ policies.Policy) bool { return true },
5858
},
@@ -61,10 +61,10 @@ var _ = Describe("Policy CompositeValidator", func() {
6161
policies.ManagerConfig{
6262
Validator: &policiesfakes.FakeValidator{
6363
ValidateStub: func(_ policies.Policy) []conditions.Condition {
64-
return []conditions.Condition{conditions.NewPolicyInvalid("orange error")}
64+
return []conditions.Condition{conditions.NewPolicyInvalid("Orange error")}
6565
},
6666
ValidateGlobalSettingsStub: func(_ policies.Policy, _ *policies.GlobalSettings) []conditions.Condition {
67-
return []conditions.Condition{conditions.NewPolicyInvalid("orange global settings error")}
67+
return []conditions.Condition{conditions.NewPolicyInvalid("Orange global settings error")}
6868
},
6969
ConflictsStub: func(_ policies.Policy, _ policies.Policy) bool { return false },
7070
},
@@ -83,19 +83,18 @@ var _ = Describe("Policy CompositeValidator", func() {
8383

8484
conds := mgr.Validate(applePolicy)
8585
Expect(conds).To(HaveLen(1))
86-
Expect(conds[0].Message).To(Equal("apple error"))
86+
Expect(conds[0].Message).To(Equal("Apple error"))
8787

8888
conds = mgr.ValidateGlobalSettings(applePolicy, globalSettings)
8989
Expect(conds).To(HaveLen(1))
90-
Expect(conds[0].Message).To(Equal("apple global settings error"))
91-
90+
Expect(conds[0].Message).To(Equal("Apple global settings error"))
9291
conds = mgr.Validate(orangePolicy)
9392
Expect(conds).To(HaveLen(1))
94-
Expect(conds[0].Message).To(Equal("orange error"))
93+
Expect(conds[0].Message).To(Equal("Orange error"))
9594

9695
conds = mgr.ValidateGlobalSettings(orangePolicy, globalSettings)
9796
Expect(conds).To(HaveLen(1))
98-
Expect(conds[0].Message).To(Equal("orange global settings error"))
97+
Expect(conds[0].Message).To(Equal("Orange global settings error"))
9998
})
10099
It("Returns whether the policies conflict", func() {
101100
Expect(mgr.Conflicts(applePolicy, applePolicy)).To(BeTrue())

internal/controller/state/change_processor_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,7 @@ var _ = Describe("ChangeProcessor", func() {
12761276
expGraph.GatewayClass = nil
12771277

12781278
gw := expGraph.Gateways[types.NamespacedName{Namespace: "test", Name: "gateway-1"}]
1279-
gw.Conditions = conditions.NewGatewayInvalid("GatewayClass doesn't exist")
1279+
gw.Conditions = conditions.NewGatewayInvalid("The GatewayClass doesn't exist")
12801280
gw.Valid = false
12811281
gw.Listeners = nil
12821282

@@ -2253,7 +2253,7 @@ var _ = Describe("ChangeProcessor", func() {
22532253
},
22542254
},
22552255
},
2256-
Conditions: conditions.NewGatewayInvalid("GatewayClass doesn't exist"),
2256+
Conditions: conditions.NewGatewayInvalid("The GatewayClass doesn't exist"),
22572257
DeploymentName: types.NamespacedName{
22582258
Namespace: "test",
22592259
Name: "gateway-2-test-class",

internal/controller/state/graph/backend_refs.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -461,10 +461,10 @@ func verifyIPFamily(npCfg *EffectiveNginxProxy, svcIPFamily []v1.IPFamily) error
461461
containsIPv6 := slices.Contains(svcIPFamily, v1.IPv6Protocol)
462462
containsIPv4 := slices.Contains(svcIPFamily, v1.IPv4Protocol)
463463

464-
//nolint: stylecheck // used in status condition which is normally capitalized
465-
errIPv6Mismatch := errors.New("service configured with IPv6 family but NginxProxy is configured with IPv4")
466-
//nolint: stylecheck // used in status condition which is normally capitalized
467-
errIPv4Mismatch := errors.New("service configured with IPv4 family but NginxProxy is configured with IPv6")
464+
//nolint: staticcheck // used in status condition which is normally capitalized
465+
errIPv6Mismatch := errors.New("The Service configured with IPv6 family but NginxProxy is configured with IPv4")
466+
//nolint: staticcheck // used in status condition which is normally capitalized
467+
errIPv4Mismatch := errors.New("The Service configured with IPv4 family but NginxProxy is configured with IPv6")
468468

469469
npIPFamily := npCfg.IPFamily
470470

@@ -687,8 +687,9 @@ func validateRouteBackendRefAppProtocol(
687687
appProtocol string,
688688
backendTLSPolicy *BackendTLSPolicy,
689689
) error {
690+
//nolint: staticcheck // used in status condition which is normally capitalized
690691
err := fmt.Errorf(
691-
"route type %s does not support service port appProtocol %s",
692+
"The RouteType %s does not support service port appProtocol %s",
692693
routeType,
693694
appProtocol,
694695
)
@@ -749,8 +750,8 @@ func getServicePort(svc *v1.Service, port int32) (v1.ServicePort, error) {
749750
return p, nil
750751
}
751752
}
752-
753-
return v1.ServicePort{}, fmt.Errorf("no matching port for Service %s and port %d", svc.Name, port)
753+
//nolint: staticcheck // used in status condition which is normally capitalized
754+
return v1.ServicePort{}, fmt.Errorf("No matching port for Service %s and port %d", svc.Name, port)
754755
}
755756

756757
func getRefGrantFromResourceForRoute(routeType RouteType, routeNs string) fromResource {

internal/controller/state/graph/backend_refs_test.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -616,15 +616,15 @@ func TestVerifyIPFamily(t *testing.T) {
616616
IPFamily: helpers.GetPointer(ngfAPIv1alpha2.IPv4),
617617
},
618618
svcIPFamily: []v1.IPFamily{v1.IPv6Protocol},
619-
expErr: errors.New("service configured with IPv6 family but NginxProxy is configured with IPv4"),
619+
expErr: errors.New("The Service configured with IPv6 family but NginxProxy is configured with IPv4"),
620620
},
621621
{
622622
name: "Invalid - IPv6 configured for NGINX, service has only IPv4",
623623
npCfg: &EffectiveNginxProxy{
624624
IPFamily: helpers.GetPointer(ngfAPIv1alpha2.IPv6),
625625
},
626626
svcIPFamily: []v1.IPFamily{v1.IPv4Protocol},
627-
expErr: errors.New("service configured with IPv4 family but NginxProxy is configured with IPv6"),
627+
expErr: errors.New("The Service configured with IPv4 family but NginxProxy is configured with IPv6"),
628628
},
629629
{
630630
name: "Valid - When NginxProxy is nil",
@@ -985,12 +985,12 @@ func TestAddBackendRefsToRules(t *testing.T) {
985985
},
986986
expectedConditions: []conditions.Condition{
987987
conditions.NewRouteBackendRefUnsupportedProtocol(
988-
"route type http does not support service port appProtocol kubernetes.io/h2c;" +
988+
"The RouteType http does not support service port appProtocol kubernetes.io/h2c;" +
989989
" nginx does not support proxying to upstreams with http2 or h2c",
990990
),
991991
},
992992
policies: emptyPolicies,
993-
name: "invalid backendRef with service port appProtocol h2c and route type http",
993+
name: "invalid backendRef with service port appProtocol h2c and The RouteType http",
994994
},
995995
{
996996
route: createRoute("hr1", RouteTypeHTTP, "Service", 1, "svcWS"),
@@ -1005,7 +1005,7 @@ func TestAddBackendRefsToRules(t *testing.T) {
10051005
},
10061006
expectedConditions: nil,
10071007
policies: emptyPolicies,
1008-
name: "valid backendRef with service port appProtocol ws and route type http",
1008+
name: "valid backendRef with service port appProtocol ws and RouteType http",
10091009
},
10101010
{
10111011
route: createRoute("hr1", RouteTypeHTTP, "Service", 1, "svcWSS"),
@@ -1022,7 +1022,7 @@ func TestAddBackendRefsToRules(t *testing.T) {
10221022
expectedConditions: nil,
10231023
policies: policiesMatching,
10241024
name: "valid backendRef with service port appProtocol wss," +
1025-
" route type http, and corresponding BackendTLSPolicy",
1025+
" The RouteType http, and corresponding BackendTLSPolicy",
10261026
},
10271027
{
10281028
route: createRoute("hr1", RouteTypeHTTP, "Service", 1, "svcWSS"),
@@ -1037,12 +1037,12 @@ func TestAddBackendRefsToRules(t *testing.T) {
10371037
},
10381038
expectedConditions: []conditions.Condition{
10391039
conditions.NewRouteBackendRefUnsupportedProtocol(
1040-
"route type http does not support service port appProtocol kubernetes.io/wss;" +
1040+
"The RouteType http does not support service port appProtocol kubernetes.io/wss;" +
10411041
" missing corresponding BackendTLSPolicy",
10421042
),
10431043
},
10441044
policies: emptyPolicies,
1045-
name: "invalid backendRef with service port appProtocol wss, route type http, but missing BackendTLSPolicy",
1045+
name: "invalid backendRef with service port appProtocol wss, RouteType http, but missing BackendTLSPolicy",
10461046
},
10471047
{
10481048
route: createRoute("gr1", RouteTypeGRPC, "Service", 1, "svcH2c"),
@@ -1057,7 +1057,7 @@ func TestAddBackendRefsToRules(t *testing.T) {
10571057
},
10581058
expectedConditions: nil,
10591059
policies: emptyPolicies,
1060-
name: "valid backendRef with service port appProtocol h2c and route type grpc",
1060+
name: "valid backendRef with service port appProtocol h2c and RouteType grpc",
10611061
},
10621062
{
10631063
route: createRoute("gr1", RouteTypeGRPC, "Service", 1, "svcWS"),
@@ -1072,11 +1072,11 @@ func TestAddBackendRefsToRules(t *testing.T) {
10721072
},
10731073
expectedConditions: []conditions.Condition{
10741074
conditions.NewRouteBackendRefUnsupportedProtocol(
1075-
"route type grpc does not support service port appProtocol kubernetes.io/ws",
1075+
"The RouteType grpc does not support service port appProtocol kubernetes.io/ws",
10761076
),
10771077
},
10781078
policies: emptyPolicies,
1079-
name: "invalid backendRef with service port appProtocol ws and route type grpc",
1079+
name: "invalid backendRef with service port appProtocol ws and RouteType grpc",
10801080
},
10811081
{
10821082
route: createRoute("gr1", RouteTypeGRPC, "Service", 1, "svcWSS"),
@@ -1091,11 +1091,11 @@ func TestAddBackendRefsToRules(t *testing.T) {
10911091
},
10921092
expectedConditions: []conditions.Condition{
10931093
conditions.NewRouteBackendRefUnsupportedProtocol(
1094-
"route type grpc does not support service port appProtocol kubernetes.io/wss",
1094+
"The RouteType grpc does not support service port appProtocol kubernetes.io/wss",
10951095
),
10961096
},
10971097
policies: emptyPolicies,
1098-
name: "invalid backendRef with service port appProtocol wss and route type grpc",
1098+
name: "invalid backendRef with service port appProtocol wss and RouteType grpc",
10991099
},
11001100
{
11011101
route: createRoute("hr1", RouteTypeHTTP, "Service", 1, "svcGRPC"),
@@ -1111,7 +1111,7 @@ func TestAddBackendRefsToRules(t *testing.T) {
11111111
expectedConditions: nil,
11121112
policies: emptyPolicies,
11131113
name: "valid backendRef with non-Kubernetes Standard Application Protocol" +
1114-
" service port appProtocol and route type http",
1114+
" service port appProtocol and RouteType http",
11151115
},
11161116
{
11171117
route: createRoute("gr1", RouteTypeGRPC, "Service", 1, "svcGRPC"),
@@ -1127,7 +1127,7 @@ func TestAddBackendRefsToRules(t *testing.T) {
11271127
expectedConditions: nil,
11281128
policies: emptyPolicies,
11291129
name: "valid backendRef with non-Kubernetes Standard Application Protocol" +
1130-
" service port appProtocol and route type grpc",
1130+
" service port appProtocol and RouteType grpc",
11311131
},
11321132
{
11331133
route: modRoute(createRoute("hr1", RouteTypeHTTP, "Service", 1, "svc1"), func(route *L7Route) *L7Route {
@@ -1528,7 +1528,7 @@ func TestCreateBackend(t *testing.T) {
15281528
Valid: true,
15291529
InvalidForGateways: map[types.NamespacedName]conditions.Condition{
15301530
{Namespace: "test", Name: "gateway"}: conditions.NewRouteInvalidIPFamily(
1531-
`service configured with IPv4 family but NginxProxy is configured with IPv6`,
1531+
`The Service configured with IPv4 family but NginxProxy is configured with IPv6`,
15321532
),
15331533
},
15341534
},

internal/controller/state/graph/backend_tls_policy.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func validateBackendTLSPolicy(
7575

7676
if err := validateBackendTLSHostname(backendTLSPolicy); err != nil {
7777
valid = false
78-
conds = append(conds, conditions.NewPolicyInvalid(fmt.Sprintf("invalid hostname: %s", err.Error())))
78+
conds = append(conds, conditions.NewPolicyInvalid(fmt.Sprintf("Invalid hostname: %s", err.Error())))
7979
}
8080

8181
caCertRefs := backendTLSPolicy.Spec.Validation.CACertificateRefs
@@ -109,7 +109,7 @@ func validateBackendTLSPolicy(
109109
valid = false
110110
conds = append(
111111
conds,
112-
conditions.NewPolicyInvalid("either CACertificateRefs or WellKnownCACertificates must be specified"),
112+
conditions.NewPolicyInvalid("Either CACertificateRefs or WellKnownCACertificates must be specified"),
113113
)
114114
}
115115

internal/controller/state/graph/gateway.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package graph
22

33
import (
4+
"strings"
5+
46
"k8s.io/apimachinery/pkg/types"
57
"k8s.io/apimachinery/pkg/util/validation/field"
68
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -134,10 +136,11 @@ func validateGatewayParametersRef(npCfg *NginxProxy, ref v1.LocalParametersRefer
134136

135137
if _, ok := supportedParamKinds[string(ref.Kind)]; !ok {
136138
err := field.NotSupported(path.Child("kind"), string(ref.Kind), []string{kinds.NginxProxy})
139+
condMsg := strings.ToUpper(err.Error()[:1]) + err.Error()[1:] // Capitalize first letter
137140
conds = append(
138141
conds,
139-
conditions.NewGatewayRefInvalid(err.Error()),
140-
conditions.NewGatewayInvalidParameters(err.Error()),
142+
conditions.NewGatewayRefInvalid(condMsg),
143+
conditions.NewGatewayInvalidParameters(condMsg),
141144
)
142145

143146
return conds
@@ -157,6 +160,7 @@ func validateGatewayParametersRef(npCfg *NginxProxy, ref v1.LocalParametersRefer
157160

158161
if !npCfg.Valid {
159162
msg := npCfg.ErrMsgs.ToAggregate().Error()
163+
msg = strings.ToUpper(msg[:1]) + msg[1:]
160164
conds = append(
161165
conds,
162166
conditions.NewGatewayRefInvalid(msg),
@@ -174,16 +178,16 @@ func validateGateway(gw *v1.Gateway, gc *GatewayClass, npCfg *NginxProxy) ([]con
174178
var conds []conditions.Condition
175179

176180
if gc == nil {
177-
conds = append(conds, conditions.NewGatewayInvalid("GatewayClass doesn't exist")...)
181+
conds = append(conds, conditions.NewGatewayInvalid("The GatewayClass doesn't exist")...)
178182
} else if !gc.Valid {
179-
conds = append(conds, conditions.NewGatewayInvalid("GatewayClass is invalid")...)
183+
conds = append(conds, conditions.NewGatewayInvalid("The GatewayClass is invalid")...)
180184
}
181185

182186
// Set the unaccepted conditions here, because those make the gateway invalid. We set the unprogrammed conditions
183187
// elsewhere, because those do not make the gateway invalid.
184188
for _, address := range gw.Spec.Addresses {
185189
if address.Type == nil {
186-
conds = append(conds, conditions.NewGatewayUnsupportedAddress("AddressType must be specified"))
190+
conds = append(conds, conditions.NewGatewayUnsupportedAddress("The AddressType must be specified"))
187191
} else if *address.Type != v1.IPAddressType {
188192
conds = append(conds, conditions.NewGatewayUnsupportedAddress("Only AddressType IPAddress is supported"))
189193
}

internal/controller/state/graph/gateway_listener.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func (c *listenerConfigurator) configure(listener v1.Listener, gwNSName types.Na
192192
var err error
193193
allowedRouteSelector, err = metav1.LabelSelectorAsSelector(selector)
194194
if err != nil {
195-
msg := fmt.Sprintf("invalid label selector: %s", err.Error())
195+
msg := fmt.Sprintf("Invalid label selector: %s", err.Error())
196196
conds = append(conds, conditions.NewListenerUnsupportedValue(msg)...)
197197
valid = false
198198
}

0 commit comments

Comments
 (0)