-
Notifications
You must be signed in to change notification settings - Fork 373
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
Improve Antrea-native Policy CRD schema verification #2125
Conversation
Codecov Report
@@ Coverage Diff @@
## main #2125 +/- ##
===========================================
+ Coverage 41.41% 61.25% +19.83%
===========================================
Files 131 269 +138
Lines 16502 20453 +3951
===========================================
+ Hits 6834 12528 +5694
+ Misses 9084 6631 -2453
- Partials 584 1294 +710
Flags with carried forward coverage won't be shown. Click here to find out more.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you remove the ending ";" and issue ID from the commit title?
22559c6
to
4463d19
Compare
4907307
to
a59b35b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the PR ready for review? I see commented code
yes, wait for code review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM overall, maybe @Dyanngg can take a look too.
test/e2e/antreapolicy_test.go
Outdated
|
||
t.Run("TestGroupInvalidLabelSelectorInResource", func(t *testing.T) { | ||
t.Run("Case=InvalidACNPPodSelectorNsSelectorMatchExpressions", func(t *testing.T) { | ||
testInvalidACNPPodSelectorNsSelectorMatchExpressions(t) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add it to TestGroupValidateAntreaNativePolicies
? it seems not different from cases in that group.
And maybe remove testInvalidCGPPodSelectorNsSelectorMatchExpressions
as it uses same verification as policies (normally it's fine to have a separate test for ClusterGroup but we are working on reducing e2e runtime #2014 so let's avoid adding it unless it can cover something new)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in a new commit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/test-all |
All e2e tests failed on antrea networkpolicy case, which seems related to this change. @wenqiq could you take a look at the failures? |
well, I will check, It sames the e2e tests fails even with the upstream/main branch as I test yesterday. |
Improve Antrea-native Policy CRD schema verification
We run e2e tests on VMs and Kind clusters, all tests related to Antrea policy failed on all platforms, and only they failed. This indicated it's related to the PR. |
2a50612
to
c6183c3
Compare
build/yamls/base/crds.yml
Outdated
items: | ||
type: string | ||
matchLabels: | ||
type: object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you need to set "x-kubernetes-preserve-unknown-fields: true" for matchLabels, otherwise all keys are pruned so the e2e tests failed. Glad to see it's caught by the tests.
https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#controlling-pruning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for advice,obviously,some resource can not created as expected in e2e test cases cause the fails, but I have verified those crds in my local kind cluster; I tried reviewing the e2e test cases to find sth, however I did not find an efficient method to implement the e2e test in my local dev env.
https://github.com/vmware-tanzu/antrea/runs/2463089906?check_suite_focus=true
It sames work, thks so much.
e2e test back to normal, pls review the latest changes, thanks a lot @tnqn |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, LGTM
/test-all |
/test-windows-e2e |
@@ -14,3 +14,4 @@ bin | |||
|
|||
.idea/ | |||
.vscode/ | |||
vendor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this should be a local ignore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
github/gitignore/Go.gitignore doesn't add vendor/ to its .gitignore file.
# Dependency directories (remove the comment below to include it)
# vendor/
gitignore.io/api/go does add vendor/ to its .gitignore.
# Dependency directories (remove the comment below to include it)
# vendor/
### Go Patch ###
/vendor/
/Godeps/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wenqiq Normally it would be better to add this via a separate PR if it is controversial so this PR can proceed faster.
Anyway Antrea doesn't include vendor directory in the repo so at least it's harmless to add it here for the convenience of vendor mode developers. @Dyanngg Do you have strong opinion to remove it from this PR? If not, I'm going to merge it as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a strong opinion for this. Merged.
/test-networkpolicy |
Add namespaceSelector/podSelector validations in all CRD schema.
The incorrect input of labelSelector fields that have known schema should be rejected;
In the following example, we want to create ClusterNetworkPolicy resource:
spec.appliedTo.namespaceSelector must be matchLabels or matchExpressions,
actually in the existing version the spelling mistake ‘matchLables’ can not be checked out.
Save the CustomResourceDefinition to resourcedefinition.yaml:
cat acnp_demo.yaml
We created it succeeded without any error.
After fixed the issue, we will get the following error message as expected:
kubectl create -f acnp_demo.yaml
error: error validating "acnp_demo.yaml": error validating data: ValidationError(ClusterNetworkPolicy.spec.appliedTo[0].namespaceSelector): unknown field "matchLables" in io.antrea.crd.v1alpha1.ClusterNetworkPolicy.spec.appliedTo.namespaceSelector; if you choose to ignore these errors, turn validation off with --validate=false
In addition, all of namespaceSelector/podSelector parameters verification in CRD schema will be improved.
Fix #2090