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

[vtadmin] viper config support #9154

Merged
merged 3 commits into from
Nov 8, 2021
Merged

[vtadmin] viper config support #9154

merged 3 commits into from
Nov 8, 2021

Conversation

ajm188
Copy link
Contributor

@ajm188 ajm188 commented Nov 6, 2021

Description

This PR switches vtadmin FileConfig.Set to use viper to load configs.

This issue does a good job explaining the why behind this
admittedly-hacky code. What I would have preferred to do is add
UnmarshalJSON, UnmarshalTOML, (and so on) methods to both
FileConfig and Config, but switching to viper means we don't invoke
those custom unmarshalers at all, because viper is going from
$file_bytes=>map[string]interface{}=(via mapstructure)>$your_type.

So, we define a temporary struct (so far, so good) that will play nicely
with mapstructure's unmarshaling. We then take those string maps and
hand them off to the individual Config structs to run through the
kv-parseOne loop as before.

Since we're using viper to load from files now (and viper does not
invoke our custom unmarshal functions ...), we no longer need them, so I
deleted all of that code as well.

This now means we support loading JSON/TOML/HCL configs in addition to YAML.

Related Issue(s)

vitessio/enhancements#8

Checklist

  • Should this PR be backported? no
  • Tests were added or are not required
  • Documentation was added or is not required

I also started the local vtadmin with both yaml and json config files, works as expected.

Deployment Notes

Signed-off-by: Andrew Mason <amason@slack-corp.com>
[This issue][1] does a good job explaining the why behind this
admittedly-hacky code. What I would have preferred to do is add
`UnmarshalJSON`, `UnmarshalTOML`, (and so on) methods to both
`FileConfig` and `Config`, but switching to viper means we don't invoke
those custom unmarshalers _at all_, because viper is going from
$file_bytes=>`map[string]interface{}`=(via mapstructure)>$your_type.

So, we define a temporary struct (so far, so good) that will play nicely
with mapstructure's unmarshaling. We then take those string maps and
hand them off to the individual Config structs to run through the
kv-`parseOne` loop as before.

Since we're using viper to load from files now (and viper does not
invoke our custom unmarshal functions ...), we no longer need them, so I
deleted all of that code as well.

[1]: spf13/viper#338 (comment)

Signed-off-by: Andrew Mason <amason@slack-corp.com>
@ajm188 ajm188 added Type: Enhancement Logical improvement (somewhere between a bug and feature) Component: VTAdmin VTadmin interface labels Nov 6, 2021
@ajm188 ajm188 requested a review from doeg November 6, 2021 13:27
Signed-off-by: Andrew Mason <amason@slack-corp.com>
@ajm188 ajm188 merged commit 0391c06 into vitessio:main Nov 8, 2021
@ajm188 ajm188 deleted the vtadmin-viper branch November 8, 2021 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: VTAdmin VTadmin interface Type: Enhancement Logical improvement (somewhere between a bug and feature)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants