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

ensure all the structs include proper yaml labels #69

Merged
merged 1 commit into from
Jul 22, 2022

Conversation

fgiudici
Copy link
Member

@fgiudici fgiudici commented Jul 20, 2022

we need also to add the 'mapstructure' tag to the CACert field to allow proper yaml decode from viper: viper takes care of
merging the configuration from the yaml file and uses mapstructure for decoding the yaml file.
The only fields merged by viper are the URL and the CACert, so added the mapstructure tags only to those.

Part of #51

@fgiudici fgiudici changed the title ensure all the structs include proper yaml labels WiP: ensure all the structs include proper yaml labels Jul 20, 2022
@fgiudici fgiudici force-pushed the struct_yaml_labels branch from 7d545c1 to 6eef8eb Compare July 21, 2022 16:00
@fgiudici fgiudici changed the title WiP: ensure all the structs include proper yaml labels ensure all the structs include proper yaml labels Jul 21, 2022
@codecov-commenter
Copy link

codecov-commenter commented Jul 21, 2022

Codecov Report

Merging #69 (fba0f86) into main (09ab845) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main      #69   +/-   ##
=======================================
  Coverage   29.74%   29.74%           
=======================================
  Files           5        5           
  Lines         353      353           
=======================================
  Hits          105      105           
  Misses        244      244           
  Partials        4        4           
Impacted Files Coverage Δ
pkg/config/config.go 0.00% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 09ab845...fba0f86. Read the comment docs.

NoSMBIOS bool `json:"noSMBIOS,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
URL string `json:"url,omitempty" yaml:"url,omitempty" mapstructure:"url"`
CACert string `json:"ca-cert,omitempty" yaml:"ca-cert,omitempty" mapstructure:"ca-cert"`
Copy link
Member Author

Choose a reason for hiding this comment

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

understanding we needed a mapstructure tag here has been tricky! 😅

Copy link
Contributor

@davidcassany davidcassany Jul 22, 2022

Choose a reason for hiding this comment

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

OMG! At which stage do we convert a struct to a map!? All this way more convoluted that it should, there should only be a single procedure to serialize and another one to deserialize 😅

I am wondering why do we only need it for these two, it is weird that only two fields of the struct are dumped to or loaded from a map, while other not.

Copy link
Member Author

Choose a reason for hiding this comment

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

the mapstructure package is used by viper to do the MergeInConfig here, which processes the yaml file we put in the iso (which basically has only url and ca-cert values).
Only the url and the ca-cert are needed at that point to connect to the operator (cluster side). Once there we get the full yaml config, from which we do our "standard" yaml deserialization without passing through viper MergeInConfig 😅

Copy link
Contributor

@davidcassany davidcassany Jul 22, 2022

Choose a reason for hiding this comment

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

Oh yes, it's true, viper it's based on mapstructure, this why we have mapstructure and yaml labels in elemental-cli.

Good catch! Thanks for the insights

Copy link
Contributor

@davidcassany davidcassany left a comment

Choose a reason for hiding this comment

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

Looks, good, just curious about the map (de)serialization

NoSMBIOS bool `json:"noSMBIOS,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
URL string `json:"url,omitempty" yaml:"url,omitempty" mapstructure:"url"`
CACert string `json:"ca-cert,omitempty" yaml:"ca-cert,omitempty" mapstructure:"ca-cert"`
Copy link
Contributor

@davidcassany davidcassany Jul 22, 2022

Choose a reason for hiding this comment

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

OMG! At which stage do we convert a struct to a map!? All this way more convoluted that it should, there should only be a single procedure to serialize and another one to deserialize 😅

I am wondering why do we only need it for these two, it is weird that only two fields of the struct are dumped to or loaded from a map, while other not.

@fgiudici fgiudici enabled auto-merge (rebase) July 22, 2022 15:08
note that we need also to add the 'mapstructure' tag to the CACert
field to allow proper yaml decode from viper: viper takes care of
merging the configuration from the yaml file and uses mapstructure
for decoding the yaml file.
The only fields merged by viper are the URL and the CACert.

Signed-off-by: Francesco Giudici <francesco.giudici@suse.com>
@fgiudici fgiudici force-pushed the struct_yaml_labels branch from 6eef8eb to fba0f86 Compare July 22, 2022 15:09
@fgiudici fgiudici merged commit a7b0e9e into main Jul 22, 2022
@fgiudici fgiudici deleted the struct_yaml_labels branch July 22, 2022 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants