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

feat(MeshHTTPRoute): add basic validation #5625

Merged

Conversation

michaelbeaumont
Copy link
Contributor

@michaelbeaumont michaelbeaumont commented Jan 9, 2023

Checklist prior to review

  • Link to docs PR or issue -- none
  • Link to UI issue or PR -- none
  • Is the issue worked on linked? -- MeshHTTPRoute basic api implementation #5470
  • The PR does not hardcode values that might break projects that depend on kuma (e.g. "kumahq" as a image registry) --
  • The PR will work for both Linux and Windows, system specific functions like syscall.Mkfifo have equivalent implementation on the other OS --
  • Unit Tests -- none
  • E2E Tests --
  • Manual Universal Tests --
  • Manual Kubernetes Tests --
  • Do you need to update UPGRADE.md? --
  • Does it need to be backported according to the backporting policy? --
  • Do you need to explicitly set a > Changelog: entry here or add a ci/ label to run fewer/more tests?

Changelog: feat(policy): implement MeshHTTPRoute policy

Signed-off-by: Mike Beaumont <mjboamail@gmail.com>
@michaelbeaumont michaelbeaumont requested review from a team, lahabana and slonka and removed request for a team January 9, 2023 16:58
Copy link
Contributor

@jakubdyszkiewicz jakubdyszkiewicz left a comment

Choose a reason for hiding this comment

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

Please add the tests

@michaelbeaumont
Copy link
Contributor Author

@jakubdyszkiewicz maybe that validation runs at all, but IMO there isn't validation complicated enough to write tests for yet. I'll just end up with a list of kinds in a test file that matches the declared list of kinds in the validation file. Might as well just make sure the one list is correct.

@jakubdyszkiewicz
Copy link
Contributor

IMO there isn't validation complicated enough to write tests for yet

I disagree. A restricted set of kinds on targetRef + to is an important part of the policy validation. I don't see why this unreasonable test.

@michaelbeaumont
Copy link
Contributor Author

michaelbeaumont commented Jan 10, 2023

I disagree. A restricted set of kinds on targetRef + to is an important part of the policy validation. I don't see why this unreasonable test.

Right but how do you check that the test is correct in the first place? You need to read the list of kinds that are listed in the tests. But there's already a perfectly readable, declarative list of kinds in the validation code, you can just read that instead when reviewing. There's no point to such a test IMO, it's not actually any safer.

Signed-off-by: Mike Beaumont <mjboamail@gmail.com>
Signed-off-by: Mike Beaumont <mjboamail@gmail.com>
@michaelbeaumont
Copy link
Contributor Author

@jakubdyszkiewicz are there enough tests in this PR in your opinion?

@slonka
Copy link
Contributor

slonka commented Jan 11, 2023

Right but how do you check that the test is correct in the first place? You need to read the list of kinds that are listed in the tests.

I wouldn't do it that way. I would go to MADR to check if there is an entry about which targetRefs are supported (maybe re-think if that entry is correct). Testing it is a bit much but because we have general tests for targetRef and the supported list for MeshHTTPRoute is (as you said) perfectly readable but I would just make sure that madr matches what is in the validator.

Copy link
Contributor

@slonka slonka left a comment

Choose a reason for hiding this comment

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

Looks ok, one thing I noticed looking around the code is that weight is defined as "int" but I think it should be >0

Copy link
Contributor

@jakubdyszkiewicz jakubdyszkiewicz left a comment

Choose a reason for hiding this comment

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

I'd also add an element in to, but yes. It's enough. The helper is also pretty cool :)

pkg/test/resources/validation.go Show resolved Hide resolved
@michaelbeaumont
Copy link
Contributor Author

michaelbeaumont commented Jan 11, 2023

Looks ok, one thing I noticed looking around the code is that weight is defined as "int" but I think it should be >0

I think we want to allow weights of 0 for turning off and on a backend but yeah actually it should be a uint

@michaelbeaumont
Copy link
Contributor Author

Waiting on #5652

Signed-off-by: Mike Beaumont <mjboamail@gmail.com>
@michaelbeaumont
Copy link
Contributor Author

michaelbeaumont commented Jan 11, 2023

Right but how do you check that the test is correct in the first place? You need to read the list of kinds that are listed in the tests.

I wouldn't do it that way. I would go to MADR to check if there is an entry about which targetRefs are supported (maybe re-think if that entry is correct). Testing it is a bit much but because we have general tests for targetRef and the supported list for MeshHTTPRoute is (as you said) perfectly readable

I mean if you had exhaustive tests for the supported kinds, you'd need to read which ones are in the tests to make sure the tests are correct. Which ones are correct you'd know from reading the MADR.

but I would just make sure that madr matches what is in the validator.

Which is what I mean by skipping the exhaustive tests entirely

@michaelbeaumont michaelbeaumont enabled auto-merge (squash) January 11, 2023 22:20
@michaelbeaumont michaelbeaumont merged commit 8e2cf89 into kumahq:master Jan 11, 2023
@michaelbeaumont michaelbeaumont deleted the feat/meshhttproute_valid_1 branch January 11, 2023 23:57
bartsmykla pushed a commit to bartsmykla/kuma that referenced this pull request Jan 14, 2023
Signed-off-by: Mike Beaumont <mjboamail@gmail.com>
Signed-off-by: Bart Smykla <bartek@smykla.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants