Skip to content

Commit 43e0c77

Browse files
committed
Fix error messages 2
1 parent 4bf7eeb commit 43e0c77

File tree

7 files changed

+27
-36
lines changed

7 files changed

+27
-36
lines changed

internal/controller/state/conditions/conditions.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ func NewRouteUnsupportedField(msg string) Condition {
376376
Type: string(RouteConditionUnsupportedField),
377377
Status: metav1.ConditionTrue,
378378
Reason: string(RouteReasonUnsupportedField),
379-
Message: fmt.Sprintf("Some parameters are ignored because they are not supported: %s", msg),
379+
Message: fmt.Sprintf("The following unsupported parameters were ignored: %s", msg),
380380
}
381381
}
382382

@@ -978,7 +978,7 @@ func NewGatewayUnsupportedField(msg string) Condition {
978978
Type: string(GatewayConditionUnsupportedField),
979979
Status: metav1.ConditionTrue,
980980
Reason: string(GatewayReasonUnsupportedField),
981-
Message: fmt.Sprintf("Gateway is accepted, but some parameters are ignored because they are not supported: %s", msg),
981+
Message: fmt.Sprintf("Gateway accepted but the following unsupported parameters were ignored: %s", msg),
982982
}
983983
}
984984

internal/controller/state/graph/gateway.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,11 +275,11 @@ func validateUnsupportedGatewayFields(gw *v1.Gateway) []conditions.Condition {
275275
var conds []conditions.Condition
276276

277277
if gw.Spec.AllowedListeners != nil {
278-
conds = append(conds, conditions.NewGatewayUnsupportedField("AllowedListeners are not supported"))
278+
conds = append(conds, conditions.NewGatewayUnsupportedField("AllowedListeners"))
279279
}
280280

281281
if gw.Spec.BackendTLS != nil {
282-
conds = append(conds, conditions.NewGatewayUnsupportedField("BackendTLS is not supported"))
282+
conds = append(conds, conditions.NewGatewayUnsupportedField("BackendTLS"))
283283
}
284284

285285
return conds

internal/controller/state/graph/gateway_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,7 +1561,7 @@ func TestBuildGateway(t *testing.T) {
15611561
},
15621562
},
15631563
Conditions: []conditions.Condition{
1564-
conditions.NewGatewayUnsupportedField("AllowedListeners are not supported"),
1564+
conditions.NewGatewayUnsupportedField("AllowedListeners"),
15651565
conditions.NewGatewayResolvedRefs(),
15661566
},
15671567
},
@@ -1603,7 +1603,7 @@ func TestBuildGateway(t *testing.T) {
16031603
IPFamily: helpers.GetPointer(ngfAPIv1alpha2.Dual),
16041604
},
16051605
Conditions: []conditions.Condition{
1606-
conditions.NewGatewayUnsupportedField("BackendTLS is not supported"),
1606+
conditions.NewGatewayUnsupportedField("BackendTLS"),
16071607
conditions.NewGatewayRefInvalid(
16081608
"spec.infrastructure.parametersRef.kind: Unsupported value: \"wrong-kind\": supported values: \"NginxProxy\"",
16091609
),
@@ -1946,7 +1946,7 @@ func TestValidateUnsupportedGatewayFields(t *testing.T) {
19461946
},
19471947
},
19481948
expectedConds: []conditions.Condition{
1949-
conditions.NewGatewayUnsupportedField("AllowedListeners are not supported"),
1949+
conditions.NewGatewayUnsupportedField("AllowedListeners"),
19501950
},
19511951
},
19521952
{
@@ -1958,8 +1958,8 @@ func TestValidateUnsupportedGatewayFields(t *testing.T) {
19581958
},
19591959
},
19601960
expectedConds: []conditions.Condition{
1961-
conditions.NewGatewayUnsupportedField("AllowedListeners are not supported"),
1962-
conditions.NewGatewayUnsupportedField("BackendTLS is not supported"),
1961+
conditions.NewGatewayUnsupportedField("AllowedListeners"),
1962+
conditions.NewGatewayUnsupportedField("BackendTLS"),
19631963
},
19641964
},
19651965
}

internal/controller/state/graph/grpcroute.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,7 @@ func processGRPCRouteRules(
267267

268268
// add warning condition for unsupported fields if any
269269
if len(allRulesErrors.warn) > 0 {
270-
msg := "There are rules with unsupported fields configurations: " + allRulesErrors.warn.ToAggregate().Error()
271-
conds = append(conds, conditions.NewRouteUnsupportedField(msg))
270+
conds = append(conds, conditions.NewRouteUnsupportedField(allRulesErrors.warn.ToAggregate().Error()))
272271
}
273272

274273
if len(allRulesErrors.invalid) > 0 {
@@ -462,13 +461,13 @@ func checkForUnsupportedGRPCFields(rule v1.GRPCRouteRule, rulePath *field.Path)
462461
if rule.Name != nil {
463462
ruleErrors = append(ruleErrors, field.Forbidden(
464463
rulePath.Child("name"),
465-
"rule names are not supported",
464+
"Name",
466465
))
467466
}
468467
if rule.SessionPersistence != nil {
469468
ruleErrors = append(ruleErrors, field.Forbidden(
470469
rulePath.Child("sessionPersistence"),
471-
"sessionPersistence is not supported",
470+
"SessionPersistence",
472471
))
473472
}
474473

internal/controller/state/graph/grpcroute_test.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,8 +1140,7 @@ func TestBuildGRPCRoute(t *testing.T) {
11401140
},
11411141
},
11421142
Conditions: []conditions.Condition{
1143-
conditions.NewRouteUnsupportedField("There are rules with unsupported fields configurations: " +
1144-
"spec.rules[0].name: Forbidden: rule names are not supported"),
1143+
conditions.NewRouteUnsupportedField("spec.rules[0].name: Forbidden: Name"),
11451144
},
11461145
},
11471146
name: "valid route with unsupported field",
@@ -1176,8 +1175,7 @@ func TestBuildGRPCRoute(t *testing.T) {
11761175
},
11771176
},
11781177
Conditions: []conditions.Condition{
1179-
conditions.NewRouteUnsupportedField("There are rules with unsupported fields configurations: " +
1180-
"spec.rules[0].name: Forbidden: rule names are not supported"),
1178+
conditions.NewRouteUnsupportedField("spec.rules[0].name: Forbidden: Name"),
11811179
conditions.NewRouteUnsupportedValue(
11821180
"All rules are invalid: [spec.rules[0].matches[0].method.service: Required value: service is required, " +
11831181
"spec.rules[0].matches[0].method.method: Required value: method is required]",
@@ -1573,8 +1571,7 @@ func TestProcessGRPCRouteRules_UnsupportedFields(t *testing.T) {
15731571
},
15741572
expectedValid: true,
15751573
expectedConds: []conditions.Condition{
1576-
conditions.NewRouteUnsupportedField("There are rules with unsupported fields configurations: spec.rules[0].name: " +
1577-
"Forbidden: rule names are not supported"),
1574+
conditions.NewRouteUnsupportedField("spec.rules[0].name: Forbidden: Name"),
15781575
},
15791576
expectedWarns: 1,
15801577
},
@@ -1590,9 +1587,8 @@ func TestProcessGRPCRouteRules_UnsupportedFields(t *testing.T) {
15901587
},
15911588
expectedValid: true,
15921589
expectedConds: []conditions.Condition{
1593-
conditions.NewRouteUnsupportedField("There are rules with unsupported fields configurations: " +
1594-
"[spec.rules[0].name: Forbidden: rule names are not supported, " +
1595-
"spec.rules[0].sessionPersistence: Forbidden: sessionPersistence is not supported]"),
1590+
conditions.NewRouteUnsupportedField("[spec.rules[0].name: Forbidden: Name, " +
1591+
"spec.rules[0].sessionPersistence: Forbidden: SessionPersistence]"),
15961592
},
15971593
expectedWarns: 2,
15981594
},

internal/controller/state/graph/httproute.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,7 @@ func processHTTPRouteRules(
274274

275275
// add warning condition for unsupported fields if any
276276
if len(allRulesErrors.warn) > 0 {
277-
msg := "There are rules with unsupported fields configurations: " + allRulesErrors.warn.ToAggregate().Error()
278-
conds = append(conds, conditions.NewRouteUnsupportedField(msg))
277+
conds = append(conds, conditions.NewRouteUnsupportedField(allRulesErrors.warn.ToAggregate().Error()))
279278
valid = true
280279
}
281280

@@ -537,25 +536,25 @@ func checkForUnsupportedHTTPFields(rule v1.HTTPRouteRule, rulePath *field.Path)
537536
if rule.Name != nil {
538537
ruleErrors = append(ruleErrors, field.Forbidden(
539538
rulePath.Child("name"),
540-
"rule names are not supported",
539+
"Name",
541540
))
542541
}
543542
if rule.Timeouts != nil {
544543
ruleErrors = append(ruleErrors, field.Forbidden(
545544
rulePath.Child("timeouts"),
546-
"timeouts are not supported",
545+
"Timeouts",
547546
))
548547
}
549548
if rule.Retry != nil {
550549
ruleErrors = append(ruleErrors, field.Forbidden(
551550
rulePath.Child("retry"),
552-
"retry is not supported",
551+
"Retry",
553552
))
554553
}
555554
if rule.SessionPersistence != nil {
556555
ruleErrors = append(ruleErrors, field.Forbidden(
557556
rulePath.Child("sessionPersistence"),
558-
"sessionPersistence is not supported",
557+
"SessionPersistence",
559558
))
560559
}
561560

internal/controller/state/graph/httproute_test.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -978,8 +978,7 @@ func TestBuildHTTPRoute(t *testing.T) {
978978
},
979979
},
980980
Conditions: []conditions.Condition{
981-
conditions.NewRouteUnsupportedField("There are rules with unsupported fields configurations: " +
982-
"spec.rules[0].name: Forbidden: rule names are not supported"),
981+
conditions.NewRouteUnsupportedField("spec.rules[0].name: Forbidden: Name"),
983982
},
984983
},
985984
name: "valid route with unsupported field",
@@ -1782,8 +1781,7 @@ func TestProcessHTTPRouteRules_UnsupportedFields(t *testing.T) {
17821781
},
17831782
expectedValid: true,
17841783
expectedConds: []conditions.Condition{
1785-
conditions.NewRouteUnsupportedField("There are rules with unsupported fields configurations: spec.rules[0].name: " +
1786-
"Forbidden: rule names are not supported"),
1784+
conditions.NewRouteUnsupportedField("spec.rules[0].name: Forbidden: Name"),
17871785
},
17881786
expectedWarns: 1,
17891787
},
@@ -1803,10 +1801,9 @@ func TestProcessHTTPRouteRules_UnsupportedFields(t *testing.T) {
18031801
},
18041802
expectedValid: true,
18051803
expectedConds: []conditions.Condition{
1806-
conditions.NewRouteUnsupportedField("There are rules with unsupported fields configurations: " +
1807-
"[spec.rules[0].name: Forbidden: rule names are not supported, spec.rules[0].timeouts: " +
1808-
"Forbidden: timeouts are not supported, spec.rules[0].retry: Forbidden: retry is not supported, " +
1809-
"spec.rules[0].sessionPersistence: Forbidden: sessionPersistence is not supported]"),
1804+
conditions.NewRouteUnsupportedField("[spec.rules[0].name: Forbidden: Name, spec.rules[0].timeouts: " +
1805+
"Forbidden: Timeouts, spec.rules[0].retry: Forbidden: Retry, " +
1806+
"spec.rules[0].sessionPersistence: Forbidden: SessionPersistence]"),
18101807
},
18111808
expectedWarns: 4,
18121809
},

0 commit comments

Comments
 (0)