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

Avoid error log when unmarshalling config for MC controller #6744

Conversation

antoninbas
Copy link
Contributor

The MultiClusterConfig struct does not have yaml tags, only json tags. Therefore, trying to unmarshal it as YAML (by calling yaml.UnmarshalLenient) will not work, and will show a log indicating that strict unmarshalling has failed. The resulting struct object will be all empty, since none of the fields can be decoded without a tag.

A key observation is that calling yaml.UnmarshalLenient does not serve any purpose, as we are also calling runtime.DecodeInto (which will first convert the YAML data to JSON data, before unmarshalling). Hence we can just remove the call to yaml.UnmarshalLenient.

We add a couple of unit tests, and in particular we validate that the default controller_manager_config.yaml config can be unmarshalled (strictly) to MultiClusterConfig. While this is slightly orthogonal to the issue being addressed here, it may help avoid issues in the future as it ensures that the default config is always in sync with the struct definition.

@antoninbas antoninbas requested review from tnqn and luolanzone October 15, 2024 22:22
@antoninbas antoninbas added the area/multi-cluster Issues or PRs related to multi cluster. label Oct 15, 2024
The MultiClusterConfig struct does not have yaml tags, only json tags.
Therefore, trying to unmarshal it as YAML (by calling
yaml.UnmarshalLenient) will not work, and will show a log indicating
that strict unmarshalling has failed. The resulting struct object will
be all empty, since none of the fields can be decoded without a tag.

A key observation is that calling yaml.UnmarshalLenient does not serve
any purpose, as we are also calling runtime.DecodeInto (which will first
convert the YAML data to JSON data, before unmarshalling). Hence we can
just remove the call to yaml.UnmarshalLenient.

We add a couple of unit tests, and in particular we validate that the
default controller_manager_config.yaml config can be unmarshalled
(strictly) to MultiClusterConfig. While this is slightly orthogonal to
the issue being addressed here, it may help avoid issues in the future
as it ensures that the default config is always in sync with the struct
definition.

Signed-off-by: Antonin Bas <antonin.bas@broadcom.com>
@antoninbas antoninbas force-pushed the remove-error-log-when-unmarshalling-config-for-multicluster-controller branch from 2ce03d9 to 88207cd Compare October 15, 2024 22:38
Copy link
Contributor

@luolanzone luolanzone left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for fixing it.

Copy link
Member

@tnqn tnqn left a comment

Choose a reason for hiding this comment

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

LGTM

@antoninbas
Copy link
Contributor Author

/test-multicluster-e2e

1 similar comment
@antoninbas
Copy link
Contributor Author

/test-multicluster-e2e

@luolanzone
Copy link
Contributor

@antoninbas We can ignore the multicluster e2e failure which should be fixed by the PR #6742

@antoninbas
Copy link
Contributor Author

Thanks @luolanzone

@antoninbas antoninbas merged commit b1b0cac into antrea-io:main Oct 17, 2024
44 of 62 checks passed
@antoninbas antoninbas deleted the remove-error-log-when-unmarshalling-config-for-multicluster-controller branch October 17, 2024 04:36
@antoninbas antoninbas added the action/release-note Indicates a PR that should be included in release notes. label Oct 17, 2024
hangyan pushed a commit to hangyan/antrea that referenced this pull request Oct 29, 2024
…o#6744)

The MultiClusterConfig struct does not have yaml tags, only json tags.
Therefore, trying to unmarshal it as YAML (by calling
yaml.UnmarshalLenient) will not work, and will show a log indicating
that strict unmarshalling has failed. The resulting struct object will
be all empty, since none of the fields can be decoded without a tag.

A key observation is that calling yaml.UnmarshalLenient does not serve
any purpose, as we are also calling runtime.DecodeInto (which will first
convert the YAML data to JSON data, before unmarshalling). Hence we can
just remove the call to yaml.UnmarshalLenient.

We add a couple of unit tests, and in particular we validate that the
default controller_manager_config.yaml config can be unmarshalled
(strictly) to MultiClusterConfig. While this is slightly orthogonal to
the issue being addressed here, it may help avoid issues in the future
as it ensures that the default config is always in sync with the struct
definition.

Signed-off-by: Antonin Bas <antonin.bas@broadcom.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action/release-note Indicates a PR that should be included in release notes. area/multi-cluster Issues or PRs related to multi cluster.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants