-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add unit tests to check for API backward compatibility #11856
base: main
Are you sure you want to change the base?
Conversation
Hi @Sreeja1725. Thanks for your PR. PRs from untrusted users cannot be marked as trusted with I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
7db22b1
to
83827c1
Compare
/assign @alaypatel07 |
@@ -0,0 +1,21 @@ | |||
### Description: | |||
|
|||
1. This creates JSON and YAML files for all the API exposed by kubevirt in group-version "kubevirt.io/v1", |
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'm likely missing something here but why do we need this when we have https://github.com/kubevirt/api ?
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.
@lyarwood the contents of https://github.com/kubevirt/api are automatically mirror from the staging directory in this repository. Example this commit kubevirt/api@105e64b was picked from here 7cbd05c
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.
Yes my point was that we already have a versioned account of the API so do we need to generate anything in our tree? Shouldn't these tests also run as part of that project?
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.
@lyarwood we need it in-tree because the idea is that these tests will be plugged into CI so APK reviewers can investigate the failure of the test for backwards compatibility breakage. If we do it in kubevirt/api repo, the test will be run postmerge so it will defeat the - purpose of helping API reviewers. Besides contents of the kubevirt/api repo are also in-tree in the staging dir
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.
@alaypatel07 right apologies for the confusion about also running tests in that repo, that would be pointless if we ran them against the original PR in kubevirt/kubevirt already. However IMHO my point still remains that we don't need to generate yet more yaml/json in this repo to test the backward compatibility of a PR when we already have versioned copies of the API in https://github.com/kubevirt/api .
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.
@lyarwood sorry I was missing your point. The versioned copy of API unfortunately does not provide us with a guarantee that changes to APIs (any of the V1 apis for example) will be backward compatible. For instance:
the https://github.com/kubevirt/api/blob/main/core/v1/types.go#L86 this field in a v1 api could be changed to an int type in this release as follows and there are currently no automated tests to prevent that while it is clearly a backward incompatible change
PriorityClassName int `json:"priorityClassName,omitempty"`
Here is a real example that could be caught by this automation: https://github.com/kubevirt/kubevirt/pull/6709/files#diff-34a591e3aa47260cfad791064c20f34f98fdca4a63532fbf7184e68682f4fcb8R254, apologies for picking on this PR. Notice the field has +optional
tag but missing omitempty
in its json tags
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'm not suggesting that we don't need to write tests to pickup on these incompatible changes just the need to generate duplicate data in this repo when it already exists elsewhere. Could we not use the copies of the API in https://github.com/kubevirt/api to detect such a change?
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've spoken to @alaypatel07 on Slack about this and I unfortunately missed that this is common practice in core k8s. The alternative of hosting these generated manifests elsewhere also isn't simple so for now I'm going to remove my concern here. Thanks again for taking the time to talk about this @alaypatel07.
83827c1
to
34d0795
Compare
Makefile
Outdated
@@ -5,7 +5,7 @@ ifeq (${TIMESTAMP}, 1) | |||
SHELL = ./hack/timestamps.sh | |||
endif | |||
|
|||
all: format bazel-build manifests | |||
all: format bazel-build manifests update-generate-api-testdata |
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.
this should be dropped from here
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.
and moved to generate
?
@@ -232,6 +232,11 @@ lint-metrics: | |||
./hack/prom-metric-linter/metric_name_linter.sh --operator-name="kubevirt" --sub-operator-name="kubevirt" --metrics-file=metrics.json | |||
rm metrics.json | |||
|
|||
update-generate-api-testdata: |
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.
can we also add test-api-compat
that will invoke these tests without UPDATE_COMPATIBILITY_FIXTURE_DATA=true
for all three previous versions
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 added
06b792e
to
8061198
Compare
/cc |
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.
Added some comments.
@Sreeja1725 can you also take a look at the Previous Version test and check if downgrading is tested?
|
||
This directory tree contains serialized API objects in json and yaml formats. | ||
|
||
This creates JSON and YAML files for all the API exposed by kubevirt in group-version "kubevirt.io/v1", versioned by the release. The current version is in `HEAD` directory, previous versions are in `release-0.yy` releasedirectory. APIs includes, more APIs can be added in the future: |
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.
change this to
This creates JSON and YAML files for three APIs exposed by kubevirt in group-version "kubevirt.io/v1", versioned by the release. The main branch is will be stored in `HEAD` directory, previous versions are in `release-0.yy` release directory. While more APIs can be added in the future, the current list includes:
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.
Updated
|
||
To run serialization tests for a particular group/version/kind, like `apps/v1` `Deployment`: | ||
```sh | ||
go test staging/src/kubevirt.io/api -run /apps.v1.Deployment/ |
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: change this to a kubevirt api?
2. api-field: `status.runtimeUser` field was added[ref-3](https://github.com/kubevirt/kubevirt/pull/6709) | ||
|
||
|
||
## REVIEWRS GUIDE |
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.
typo: REVIEWERS
|
||
## REVIEWRS GUIDE | ||
|
||
Upon upgrade to API, the json and YAML files will be updated. |
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: change this to
With any change in go structs of the APIs, the corresponding JSON and YAML files will be updated
The current tests will alway test upgrade since the schema builder will be at a higher version than the json data (this is the upgrade scenario). For downgrade scenario we need the schema builder to be at a lower version than the json data which is currently not tested. |
3c1f9c9
to
1cc40e4
Compare
/test pull-kubevirt-unit-test |
@Sreeja1725: Cannot trigger testing until a trusted user reviews the PR and leaves an In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
@Sreeja1725: Cannot trigger testing until a trusted user reviews the PR and leaves an In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
/test pull-kubevirt-unit-test |
1cc40e4
to
7d5aab7
Compare
/retest |
@Sreeja1725: Cannot trigger testing until a trusted user reviews the PR and leaves an In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
/test pull-kubevirt-unit-test |
7d5aab7
to
f49f7f6
Compare
/test pull-kubevirt-build |
/test pull-kubevirt-unit-test |
LGTM. Thanks for getting this ready, great work @Sreeja1725! @xpivarc @EdDev this PR seems to be ready for a review. PTAL /ok-to-test |
@@ -0,0 +1,426 @@ | |||
package roundtrip |
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 and the other new go files need a license header. See this for reference:
https://github.com/kubevirt/kubevirt/blob/main/pkg/monitoring/rules/alerts/virt-controller.go#L1-L15
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, updated
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"k8s.io/apimachinery/pkg/runtime/serializer/json" | ||
"k8s.io/apimachinery/pkg/util/sets" | ||
v1 "kubevirt.io/api/core/v1" |
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: change the name to kubevirtv1
kubevirtv1 "kubevirt.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/sets" | ||
v1 "kubevirt.io/api/core/v1" | ||
) | ||
|
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.
can we please attribute the original tests here in the comments?
// This tests are largely take from k8s apitesting, in the future when it is possible it could be imported directly:
// https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apimachinery/pkg/api/apitesting/roundtrip/roundtrip.go
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.
Added
Signed-off-by: svarnam <svarnam@nvidia.com>
f49f7f6
to
202c0db
Compare
@@ -0,0 +1,445 @@ | |||
/* | |||
Copyright 2023 The KubeVirt Authors. |
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.
s/2023/2024/g
Signed-off-by: svarnam <svarnam@nvidia.com>
202c0db
to
ef4c711
Compare
/test all /lgtm |
@Sreeja1725: The following test failed, say
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
What this PR does
Before this PR: There are no unit tests which check for API backward compatibility
After this PR:
Fixes #11629
Why we need it and why it was done in this way
The following tradeoffs were made:
The following alternatives were considered:
Links to places where the discussion took place:
Special notes for your reviewer
A unit test that decodes from yaml to go structs and encodes from go structs to yaml objects. Both encoding and decoding passes for each API change. This unit test will be very helpful in automating tests for api changes in kubevirt.
blocked on updating the makefile.
Checklist
This checklist is not enforcing, but it's a reminder of items that could be relevant to every PR.
Approvers are expected to review this list.
Release note