Skip to content

Commit

Permalink
add append '.' to err message for xpolicy
Browse files Browse the repository at this point in the history
Signed-off-by: shawnh2 <shawnhxh@outlook.com>
  • Loading branch information
shawnh2 committed Apr 29, 2024
1 parent 2322ef0 commit 9a75549
Show file tree
Hide file tree
Showing 33 changed files with 44 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ backendTLSPolicies:
sectionName: http
conditions:
- lastTransitionTime: null
message: No ca found in configmap no-ca-cmap
message: No ca found in configmap no-ca-cmap.
reason: Invalid
status: "False"
type: Accepted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ backendTLSPolicies:
conditions:
- lastTransitionTime: null
message: Target ref to Service backends/http-backend not permitted by any
ReferenceGrant
ReferenceGrant.
reason: Invalid
status: "False"
type: Accepted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ backendTrafficPolicies:
sectionName: http
conditions:
- lastTransitionTime: null
message: 'CircuitBreaker: invalid MaxRequestsPerConnection value -1'
message: 'CircuitBreaker: invalid MaxRequestsPerConnection value -1.'
reason: Invalid
status: "False"
type: Accepted
Expand Down Expand Up @@ -52,7 +52,7 @@ backendTrafficPolicies:
sectionName: http
conditions:
- lastTransitionTime: null
message: 'CircuitBreaker: invalid MaxParallelRetries value -1'
message: 'CircuitBreaker: invalid MaxParallelRetries value -1.'
reason: Invalid
status: "False"
type: Accepted
Expand Down Expand Up @@ -80,7 +80,7 @@ backendTrafficPolicies:
namespace: envoy-gateway
conditions:
- lastTransitionTime: null
message: 'CircuitBreaker: invalid MaxConnections value -1'
message: 'CircuitBreaker: invalid MaxConnections value -1.'
reason: Invalid
status: "False"
type: Accepted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ backendTrafficPolicies:
conditions:
- lastTransitionTime: null
message: 'RateLimit: local rateLimit rule limit unit must be a multiple of
the default limit unit'
the default limit unit.'
reason: Invalid
status: "False"
type: Accepted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ backendTrafficPolicies:
namespace: envoy-gateway
conditions:
- lastTransitionTime: null
message: 'RateLimit: local rateLimit does not support distinct HeaderMatch'
message: 'RateLimit: local rateLimit does not support distinct HeaderMatch.'
reason: Invalid
status: "False"
type: Accepted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ backendTrafficPolicies:
conditions:
- lastTransitionTime: null
message: 'RateLimit: local rateLimit can not have more than one rule without
clientSelectors'
clientSelectors.'
reason: Invalid
status: "False"
type: Accepted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ backendTrafficPolicies:
conditions:
- lastTransitionTime: null
message: 'RateLimit: regex "*.illegal.regex" is invalid: error parsing regexp:
missing argument to repetition operator: `*`'
missing argument to repetition operator: `*`.'
reason: Invalid
status: "False"
type: Accepted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ backendTrafficPolicies:
namespace: envoy-gateway
conditions:
- lastTransitionTime: null
message: 'Timeout: invalid MaxConnectionDuration value 22mib'
message: 'Timeout: invalid MaxConnectionDuration value 22mib.'
reason: Invalid
status: "False"
type: Accepted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ clientTrafficPolicies:
sectionName: http-1
conditions:
- lastTransitionTime: null
message: Invalid BufferLimit value 500m
message: Invalid BufferLimit value 500m.
reason: Invalid
status: "False"
type: Accepted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ clientTrafficPolicies:
sectionName: http-1
conditions:
- lastTransitionTime: null
message: BufferLimit value 100G is out of range, must be between 0 and 4294967295
message: BufferLimit value 100G is out of range, must be between 0 and 4294967295.
reason: Invalid
status: "False"
type: Accepted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ clientTrafficPolicies:
sectionName: http-1
conditions:
- lastTransitionTime: null
message: Invalid CloseDelay value 10mib
message: Invalid CloseDelay value 10mib.
reason: Invalid
status: "False"
type: Accepted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ clientTrafficPolicies:
sectionName: http-3
conditions:
- lastTransitionTime: null
message: Can't set http10 default host on listener with only wildcard hostnames
message: Can't set http10 default host on listener with only wildcard hostnames.
reason: Invalid
status: "False"
type: Accepted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ clientTrafficPolicies:
- lastTransitionTime: null
message: |-
InitialStreamWindowSize value 1Ki is out of range, must be between 65535 and 2147483647
InitialConnectionWindowSize value 1Ti is out of range, must be between 65535 and 2147483647
InitialConnectionWindowSize value 1Ti is out of range, must be between 65535 and 2147483647.
reason: Invalid
status: "False"
type: Accepted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ clientTrafficPolicies:
namespace: envoy-gateway
conditions:
- lastTransitionTime: null
message: 'Time: unknown unit "sec" in duration "10sec"'
message: 'Time: unknown unit "sec" in duration "10sec".'
reason: Invalid
status: "False"
type: Accepted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ clientTrafficPolicies:
namespace: envoy-gateway
conditions:
- lastTransitionTime: null
message: 'Time: unknown unit "sec" in duration "5sec"'
message: 'Time: unknown unit "sec" in duration "5sec".'
reason: Invalid
status: "False"
type: Accepted
Expand Down
2 changes: 1 addition & 1 deletion internal/gatewayapi/testdata/conflicting-policies.out.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ clientTrafficPolicies:
conditions:
- lastTransitionTime: null
message: ClientTrafficPolicy is being applied to multiple http (non https)
listeners (default/gateway-1/http) on the same port, which is not allowed
listeners (default/gateway-1/http) on the same port, which is not allowed.
reason: Invalid
status: "False"
type: Accepted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ envoyExtensionPolicies:
namespace: default
conditions:
- lastTransitionTime: null
message: TCP Port 4000 not found on service default/grpc-backend
message: TCP Port 4000 not found on service default/grpc-backend.
reason: Invalid
status: "False"
type: Accepted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ envoyExtensionPolicies:
conditions:
- lastTransitionTime: null
message: A valid port number corresponding to a port on the Service must be
specified
specified.
reason: Invalid
status: "False"
type: Accepted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ envoyExtensionPolicies:
conditions:
- lastTransitionTime: null
message: Backend ref to Service envoy-gateway/grpc-backend not permitted by
any ReferenceGrant
any ReferenceGrant.
reason: Invalid
status: "False"
type: Accepted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ envoyExtensionPolicies:
namespace: default
conditions:
- lastTransitionTime: null
message: Service envoy-gateway/grpc-backend not found
message: Service envoy-gateway/grpc-backend not found.
reason: Invalid
status: "False"
type: Accepted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ backendTrafficPolicies:
sectionName: http
conditions:
- lastTransitionTime: null
message: 'Timeout: invalid ConnectTimeout value 20kib'
message: 'Timeout: invalid ConnectTimeout value 20kib.'
reason: Invalid
status: "False"
type: Accepted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ httpRoutes:
- conditions:
- lastTransitionTime: null
message: 'Regex "*.foo.bar.com" is invalid: error parsing regexp: missing
argument to repetition operator: `*`'
argument to repetition operator: `*`.'
reason: UnsupportedValue
status: "False"
type: Accepted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ httpRoutes:
- conditions:
- lastTransitionTime: null
message: 'Regex "*regex*" is invalid: error parsing regexp: missing argument
to repetition operator: `*`'
to repetition operator: `*`.'
reason: UnsupportedValue
status: "False"
type: Accepted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ clientTrafficPolicies:
conditions:
- lastTransitionTime: null
message: ClientTrafficPolicy is being applied to multiple http (non https)
listeners (default/gateway-2/http-2) on the same port, which is not allowed
listeners (default/gateway-2/http-2) on the same port, which is not allowed.
reason: Invalid
status: "False"
type: Accepted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ securityPolicies:
namespace: default
conditions:
- lastTransitionTime: null
message: TCP Port 80 not found on service default/http-backend
message: TCP Port 80 not found on service default/http-backend.
reason: Invalid
status: "False"
type: Accepted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ securityPolicies:
conditions:
- lastTransitionTime: null
message: A valid port number corresponding to a port on the Service must be
specified
specified.
reason: Invalid
status: "False"
type: Accepted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ securityPolicies:
conditions:
- lastTransitionTime: null
message: Backend ref to Service envoy-gateway/http-backend not permitted by
any ReferenceGrant
any ReferenceGrant.
reason: Invalid
status: "False"
type: Accepted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ securityPolicies:
namespace: default
conditions:
- lastTransitionTime: null
message: Service default/http-backend not found
message: Service default/http-backend not found.
reason: Invalid
status: "False"
type: Accepted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ securityPolicies:
sectionName: http
conditions:
- lastTransitionTime: null
message: Secret default/client2-secret does not exist
message: Secret default/client2-secret does not exist.
reason: Invalid
status: "False"
type: Accepted
Expand Down Expand Up @@ -219,7 +219,7 @@ securityPolicies:
namespace: envoy-gateway
conditions:
- lastTransitionTime: null
message: Secret envoy-gateway/client1-secret does not exist
message: Secret envoy-gateway/client1-secret does not exist.
reason: Invalid
status: "False"
type: Accepted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ securityPolicies:
conditions:
- lastTransitionTime: null
message: 'Error fetching endpoints from issuer: invalid character ''<'' looking
for beginning of value'
for beginning of value.'
reason: Invalid
status: "False"
type: Accepted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ securityPolicies:
namespace: default
conditions:
- lastTransitionTime: null
message: Secret default/client1-secret does not exist
message: Secret default/client1-secret does not exist.
reason: Invalid
status: "False"
type: Accepted
Expand Down Expand Up @@ -234,7 +234,7 @@ securityPolicies:
namespace: default
conditions:
- lastTransitionTime: null
message: Secret ref namespace must be unspecified/empty or default
message: Secret ref namespace must be unspecified/empty or default.
reason: Invalid
status: "False"
type: Accepted
Expand Down Expand Up @@ -270,7 +270,7 @@ securityPolicies:
namespace: default
conditions:
- lastTransitionTime: null
message: Client secret not found in secret default/client3-secret
message: Client secret not found in secret default/client3-secret.
reason: Invalid
status: "False"
type: Accepted
Expand Down
8 changes: 7 additions & 1 deletion internal/status/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func conditionChanged(a, b metav1.Condition) bool {

// Error2ConditionMsg format the error string to a Status condition message.
// * Convert the first letter to capital
// * Append "." to the string if it doesn't exit
// * Append "." to the string if it doesn't exist
func Error2ConditionMsg(err error) string {
if err == nil {
return ""
Expand All @@ -161,6 +161,12 @@ func Error2ConditionMsg(err error) string {
runes[0] = unicode.ToUpper(runes[0])
}

// Check if the last rune is a punctuation '.' and append it if not
last := runes[len(runes)-1]
if !unicode.IsPunct(last) || last != '.' {
runes = append(runes, '.')
}

// Convert the rune slice back to a string
return string(runes)
}
2 changes: 1 addition & 1 deletion internal/status/conditions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ func TestError2ConditionMsg(t *testing.T) {
{
name: "error with message",
err: errors.New("something is wrong"),
expect: "Something is wrong",
expect: "Something is wrong.",
},
}
for _, tt := range testCases {
Expand Down

0 comments on commit 9a75549

Please sign in to comment.