Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(policy): added better message when no proxyTypes #12754

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package v1alpha1

import (
"fmt"

common_api "github.com/kumahq/kuma/api/common/v1alpha1"
mesh_proto "github.com/kumahq/kuma/api/mesh/v1alpha1"
"github.com/kumahq/kuma/pkg/core/resources/apis/mesh"
Expand Down Expand Up @@ -55,7 +57,8 @@ func (r *MeshFaultInjectionResource) validateTop(targetRef *common_api.TargetRef
func validateFrom(topTargetRef common_api.TargetRef, from []From) validators.ValidationError {
var verr validators.ValidationError
if common_api.IncludesGateways(topTargetRef) && len(from) != 0 {
verr.AddViolationAt(validators.RootedAt("from"), validators.MustNotBeDefined)
verr.AddViolationAt(validators.RootedAt("from"),
fmt.Sprintf("%s when the scope includes a Gateway, exclude non-gateway resources or select only gateways and use spec.to", validators.MustNotBeDefined))
return verr
}
for idx, fromItem := range from {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ from:
[]validators.Violation{
{
Field: "spec.from",
Message: "must not be defined",
Message: "must not be defined when the scope includes a Gateway, exclude non-gateway resources or select only gateways and use spec.to",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"exclude non-gateway" has the same meaning as "select only gateways" :) probably should be

must not be defined when the scope includes a Gateway, select only proxyType Sidecar or select only gateways and use spec.to

},
{
Field: "spec.to[1].targetRef.kind",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v1alpha1

import (
"fmt"
"time"

common_api "github.com/kumahq/kuma/api/common/v1alpha1"
Expand Down Expand Up @@ -58,11 +59,13 @@ func (r *MeshRateLimitResource) validateTop(targetRef *common_api.TargetRef, isI
func validateFrom(topTargetRef common_api.TargetRef, from []From) validators.ValidationError {
var verr validators.ValidationError
if common_api.IncludesGateways(topTargetRef) && len(from) != 0 {
verr.AddViolationAt(validators.RootedAt("from"), validators.MustNotBeDefined)
verr.AddViolationAt(validators.RootedAt("from"),
fmt.Sprintf("%s when the scope includes a Gateway, exclude non-gateway resources or select only gateways and use spec.to", validators.MustNotBeDefined))
return verr
}
if topTargetRef.Kind == common_api.MeshHTTPRoute && len(from) != 0 {
verr.AddViolationAt(validators.RootedAt("from"), validators.MustNotBeDefined)
verr.AddViolationAt(validators.RootedAt("from"),
fmt.Sprintf("%s when spec.kind is MeshHTTPRoute", validators.MustNotBeDefined))
return verr
}
for idx, fromItem := range from {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ from:
expected: `
violations:
- field: spec.from
message: 'must not be defined'`,
message: 'must not be defined when the scope includes a Gateway, exclude non-gateway resources or select only gateways and use spec.to'`,
}),
Entry("invalid gateway example when targeting MeshHTTPRoute", testCase{
inputYaml: `
Expand All @@ -401,7 +401,7 @@ from:
expected: `
violations:
- field: spec.from
message: 'must not be defined'`,
message: 'must not be defined when the scope includes a Gateway, exclude non-gateway resources or select only gateways and use spec.to'`,
}),
)
})
Expand Down
Loading