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

state, filter: Fix the interpretation of ifaces names #709

Merged
merged 4 commits into from
Mar 3, 2021

Conversation

EdDev
Copy link
Member

@EdDev EdDev commented Mar 2, 2021

Is this a BUG FIX or a FEATURE ?:
/kind bug

What this PR does / why we need it:
In scenarios where an interface has only numeric characters, the
application panics with a failure to extract a string type from a Go
interface (which is actually a float64).

In order to fix the problem, the parsing of the interface name is performed
using a dedicated interface-state structure.

In addition, the representation of special numeric values that an interface name can have is also fixed, such that 0xfe can be correctly represented back and not shown as an integer (254).


In order to support this, a type structure that represents the basic state root items has been used.
This structure includes:

  • interfaces
  • routes:
    • config
    • running

In order to keep the generic nature of these items content,
they use as value a generic Go interface{}.

Special notes for your reviewer:

Release note:

Support interface names with numeric values (e.g. 123, 1.0, 0xfe).

@kubevirt-bot kubevirt-bot requested review from phoracek and qinqon March 2, 2021 08:47
@kubevirt-bot kubevirt-bot added dco-signoff: yes Indicates the PR's author has DCO signed all their commits. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. size/L release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Mar 2, 2021
@EdDev EdDev force-pushed the fix-nmstate-state-interpretation branch from b0fe982 to 98bc857 Compare March 2, 2021 09:12
@EdDev
Copy link
Member Author

EdDev commented Mar 2, 2021

change: Fixed gofmt

pkg/state/type.go Outdated Show resolved Hide resolved
In order to ease the interpretation of the state yaml data, use a type
structure that represents the basic root items of state:
- interfaces
- routes:
  - config
  - running

In order to keep the generic nature of these items content,
they use as value a generic Go interface{}.

The filter helper functions, with this change, have been also made
immutable. They now return the filtered values.

Signed-off-by: Edward Haas <[email protected]>
@EdDev EdDev force-pushed the fix-nmstate-state-interpretation branch from 98bc857 to d735b2c Compare March 2, 2021 09:45
@EdDev
Copy link
Member Author

EdDev commented Mar 2, 2021

change: Do not expose the new state types

Copy link
Member

@qinqon qinqon left a comment

Choose a reason for hiding this comment

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

Just a question

pkg/state/filter.go Show resolved Hide resolved
pkg/state/filter.go Outdated Show resolved Hide resolved
pkg/state/filter.go Outdated Show resolved Hide resolved
@EdDev EdDev force-pushed the fix-nmstate-state-interpretation branch 3 times, most recently from 0390c71 to 1212087 Compare March 3, 2021 07:51
Copy link
Member

@qinqon qinqon left a comment

Choose a reason for hiding this comment

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

Good work I know how much time to end with this kind of solutions, added some coments to simplify stuff.

pkg/state/type.go Outdated Show resolved Hide resolved
pkg/state/filter.go Outdated Show resolved Hide resolved
pkg/state/filter.go Show resolved Hide resolved
@EdDev EdDev force-pushed the fix-nmstate-state-interpretation branch from be618a0 to 651d6d6 Compare March 3, 2021 09:42
Copy link
Member

@qinqon qinqon left a comment

Choose a reason for hiding this comment

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

/hold

First I want to see how so nmstate team is reporting that quotes are included and why we don't see it here.

@kubevirt-bot kubevirt-bot added lgtm Indicates that a PR is ready to be merged. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Mar 3, 2021
@qinqon
Copy link
Member

qinqon commented Mar 3, 2021

Looks like problem is just with float64

ip link add 60e+02 type dummy
name: 60e+02

@EdDev can you add a unit test for that ?

EdDev added 3 commits March 3, 2021 14:40
Interfaces names with numeric values are accepted by the kernel.
Introduce tests that checks the behavior when using numeric names.

Signed-off-by: Edward Haas <[email protected]>
In scenarios where an interface name is composed of numbers in
scientific notation without a dot, the application panics with a failure
to extract a string type from a Go interface (which is actually a float64).

In order to fix the problem, the parsing of the interface name is performed
using a dedicated interface-state structure.

Note: this change does not solve the problem of incorrectly representing
valid scientific numeric values like `10e+02` as strings (they are now
represented back as full integers: "1000").
This is due to the YAML-to-JSON conversion which does not obey to
the defined member type.

ref: yaml/pyyaml#173

Signed-off-by: Edward Haas <[email protected]>
This change solves the problem of incorrectly representing
valid scientific numeric valuesi without a dot in them (e.g. `10e20`)
as strings (e.g. represented back as `1000`).

The problem originates from the YAML-to-JSON conversion which does not obey
to the defined member type.

Fixed by using the go-yaml package (which does not perform such a
conversion from YAML to JSON).
The go-yaml is used just to unmarshal the name from the original raw
byte stream and update the state structure with the proper name string.

Signed-off-by: Edward Haas <[email protected]>
@EdDev EdDev force-pushed the fix-nmstate-state-interpretation branch from 651d6d6 to 4db577f Compare March 3, 2021 12:59
@kubevirt-bot kubevirt-bot removed the lgtm Indicates that a PR is ready to be merged. label Mar 3, 2021
@EdDev
Copy link
Member Author

EdDev commented Mar 3, 2021

Looks like problem is just with float64

ip link add 60e+02 type dummy
name: 60e+02

@EdDev can you add a unit test for that ?

I have changed a bit the commits to show better what has been done and what each fixes.

@qinqon
Copy link
Member

qinqon commented Mar 3, 2021

/lgtm
/approve
/unhold

We will do a follow up to try to use just one yaml parser.

@kubevirt-bot kubevirt-bot added lgtm Indicates that a PR is ready to be merged. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Mar 3, 2021
@kubevirt-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: qinqon

The full list of commands accepted by this bot can be found here.

The pull request process is described 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

@kubevirt-bot kubevirt-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 3, 2021
@kubevirt-bot
Copy link
Collaborator

@EdDev: The following test failed, say /retest to rerun all failed tests:

Test name Commit Details Rerun command
pull-kubernetes-nmstate-e2e-handler-k8s-future 4db577f link /test pull-kubernetes-nmstate-e2e-handler-k8s-future

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. I understand the commands that are listed here.

@kubevirt-bot kubevirt-bot merged commit fdfbe87 into nmstate:master Mar 3, 2021
@qinqon qinqon mentioned this pull request Nov 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. kind/bug lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants