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

Add unit tests to check for API backward compatibility #11856

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Sreeja1725
Copy link

What this PR does

Before this PR: There are no unit tests which check for API backward compatibility

After this PR:

  1. API reviewers can say if changes in current version will break older clients upon upgrade
  2. During upgrades, vendors can check the API changes going into the upgrade using simple differ and get a better synopsis of what is failing during upgrade.

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

      NONE

@kubevirt-bot kubevirt-bot added release-note-none Denotes a PR that doesn't merit a release note. dco-signoff: no Indicates the PR's author has not DCO signed all their commits. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API labels May 6, 2024
@kubevirt-bot
Copy link
Contributor

Hi @Sreeja1725. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

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.

@kubevirt-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign acardace for approval. For more information see the Kubernetes Code Review Process.

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@Sreeja1725 Sreeja1725 force-pushed the sreeja-kubevirt-api-testing branch from 7db22b1 to 83827c1 Compare May 7, 2024 11:34
@alaypatel07
Copy link
Contributor

/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",
Copy link
Member

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 ?

Copy link
Contributor

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

Copy link
Member

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?

Copy link
Contributor

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

Copy link
Member

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 .

Copy link
Contributor

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

Copy link
Member

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?

Copy link
Member

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.

@Sreeja1725 Sreeja1725 force-pushed the sreeja-kubevirt-api-testing branch from 83827c1 to 34d0795 Compare May 8, 2024 12:19
@kubevirt-bot kubevirt-bot added dco-signoff: yes Indicates the PR's author has DCO signed all their commits. and removed dco-signoff: no Indicates the PR's author has not DCO signed all their commits. labels May 8, 2024
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
Copy link
Contributor

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

Copy link
Member

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:
Copy link
Contributor

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

Copy link
Author

Choose a reason for hiding this comment

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

Done added

@Sreeja1725 Sreeja1725 force-pushed the sreeja-kubevirt-api-testing branch 2 times, most recently from 06b792e to 8061198 Compare May 15, 2024 06:17
@EdDev
Copy link
Member

EdDev commented May 15, 2024

/cc

@kubevirt-bot kubevirt-bot requested a review from EdDev May 15, 2024 13:18
Copy link
Contributor

@alaypatel07 alaypatel07 left a 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:
Copy link
Contributor

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:

Copy link
Author

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/
Copy link
Contributor

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
Copy link
Contributor

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.
Copy link
Contributor

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

@kubevirt-bot kubevirt-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 16, 2024
@Sreeja1725
Copy link
Author

Added some comments.

@Sreeja1725 can you also take a look at the Previous Version test and check if downgrading is tested?

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.

@kubevirt-bot kubevirt-bot added dco-signoff: no Indicates the PR's author has not DCO signed all their commits. sig/buildsystem Denotes an issue or PR that relates to changes in the build system. sig/network sig/observability Denotes an issue or PR that relates to observability. sig/storage and removed dco-signoff: yes Indicates the PR's author has DCO signed all their commits. labels May 17, 2024
@kubevirt-bot kubevirt-bot added sig/compute sig/scale needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels May 28, 2024
@Sreeja1725 Sreeja1725 force-pushed the sreeja-kubevirt-api-testing branch 3 times, most recently from 3c1f9c9 to 1cc40e4 Compare May 28, 2024 17:11
@kubevirt-bot kubevirt-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 28, 2024
@Sreeja1725
Copy link
Author

/test pull-kubevirt-unit-test
/test pull-kubevirt-build

@kubevirt-bot
Copy link
Contributor

@Sreeja1725: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/test pull-kubevirt-unit-test
/test pull-kubevirt-build

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.

@kubevirt-bot
Copy link
Contributor

@Sreeja1725: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

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.

@alaypatel07
Copy link
Contributor

/test pull-kubevirt-unit-test
/test pull-kubevirt-build

@Sreeja1725 Sreeja1725 force-pushed the sreeja-kubevirt-api-testing branch from 1cc40e4 to 7d5aab7 Compare May 28, 2024 17:42
@Sreeja1725
Copy link
Author

/retest

@kubevirt-bot
Copy link
Contributor

@Sreeja1725: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

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.

@alaypatel07
Copy link
Contributor

/test pull-kubevirt-unit-test
/test pull-kubevirt-build

@Sreeja1725 Sreeja1725 force-pushed the sreeja-kubevirt-api-testing branch from 7d5aab7 to f49f7f6 Compare May 29, 2024 06:28
@alaypatel07
Copy link
Contributor

/test pull-kubevirt-build

@alaypatel07
Copy link
Contributor

/test pull-kubevirt-unit-test

@alaypatel07
Copy link
Contributor

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
Copy link
Contributor

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

Copy link
Author

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"
Copy link
Contributor

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"
)

Copy link
Contributor

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

Copy link
Author

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>
@Sreeja1725 Sreeja1725 force-pushed the sreeja-kubevirt-api-testing branch from f49f7f6 to 202c0db Compare May 29, 2024 13:46
@@ -0,0 +1,445 @@
/*
Copyright 2023 The KubeVirt Authors.
Copy link
Contributor

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>
@Sreeja1725 Sreeja1725 force-pushed the sreeja-kubevirt-api-testing branch from 202c0db to ef4c711 Compare May 29, 2024 16:10
@alaypatel07
Copy link
Contributor

/test all

/lgtm

@kubevirt-bot kubevirt-bot added the lgtm Indicates that a PR is ready to be merged. label May 29, 2024
@kubevirt-bot
Copy link
Contributor

@Sreeja1725: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-kubevirt-e2e-k8s-1.30-sig-operator ef4c711 link true /test pull-kubevirt-e2e-k8s-1.30-sig-operator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/instancetype area/virtctl dco-signoff: yes Indicates the PR's author has DCO signed all their commits. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/build-change Categorizes PRs as related to changing build files of virt-* components lgtm Indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. sig/buildsystem Denotes an issue or PR that relates to changes in the build system. sig/compute sig/network sig/observability Denotes an issue or PR that relates to observability. sig/scale sig/storage size/XXL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

create a unit test for VirtualMachineInstance api that test encoding/decoding
7 participants