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

feat: add update-collection-v3 boilerplate #241

Merged
merged 1 commit into from
Apr 25, 2022

Conversation

pmalek-sumo
Copy link
Contributor

No description provided.

@pmalek-sumo pmalek-sumo requested a review from a team as a code owner March 29, 2022 15:13
@pmalek-sumo pmalek-sumo self-assigned this Mar 29, 2022
Comment on lines +36 to +37
There is a PR pending that would add that functionality but unfortunately `go-yaml`
doesn't seem to be actively maintained.
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to use not actively maintain package?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's the only one I found with a reasonable number of Github stars (obviously important).

There's also this one as an alternative.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I meant this one: https://github.com/goccy/go-yaml.

Perhaps this would be a good choice given that it allows parsing yaml using path: https://github.com/goccy/go-yaml#5-use-yamlpath

Comment on lines +35 to +49
func parseValues(path string) (ValuesV2, error) {
f, err := os.Open(path)
if err != nil {
return ValuesV2{}, fmt.Errorf("cannot open file %s: %w", path, err)
}

decoder := yaml.NewDecoder(bufio.NewReader(f))

var valuesV2 ValuesV2
if err := decoder.Decode(&valuesV2); err != nil {
return ValuesV2{}, fmt.Errorf("cannot unmarshal data from %s: %w", path, err)
}

return valuesV2, nil
}
Copy link
Contributor

@sumo-drosiek sumo-drosiek Mar 30, 2022

Choose a reason for hiding this comment

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

What happens for partial values.yaml or for values.yaml with additional keys?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean by partial?

Additional ( if I understand it correctly by not defined in the struct) ones will be dropped. Maybe this could be worked around using yaml.Node

Copy link
Contributor

Choose a reason for hiding this comment

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

What do you mean by partial?

with missing keys, e.g.:

sumologic:
  accessId: xxx

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is nothing missing in the yaml snippet you posted. There is no notion of "required" in this package.

Copy link
Contributor

Choose a reason for hiding this comment

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

my doubt is, that Stringifying ValuesV2 will override defaults with empty strings

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, so I've checked this and yes, it will print all the values - also the empty ones.

The nuance here is that if we'd use omitempty then we couldn't e.g. override a default boolean true in our chart because false wouldn't be serialized. Even adding omitempty wouldn't help because then we'd get all the values.

EDIT: changed field to be pointer fields and added omitempty. This should do the trick.

@pmalek-sumo pmalek-sumo force-pushed the feat-add-update-collection-v3 branch from 385c6e4 to 1fa2762 Compare March 30, 2022 10:21
LoadConfigFile *bool `yaml:"load_config_file,omitempty"`
} `yaml:"cluster,omitempty"`
CollectionMonitoring *bool `yaml:"collectionMonitoring,omitempty"`
PodLabels struct{} `yaml:"podLabels,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

does it deserialize:

podLabels:
  label1: value1

correctly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. This will probably have to be either defined as struct or as map[string]interface{}.

Given this is just a boilerplate PR I'll leave this for future PRs to decide and add tests for it :)

Copy link
Contributor

Choose a reason for hiding this comment

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

TBH I am not sure now if typed language is good for the migration case
On the other hand we will have a typed schema for our collection

Copy link
Contributor

@sumo-drosiek sumo-drosiek left a comment

Choose a reason for hiding this comment

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

I have mixed feelings about using go for this case, but let's see where it will get us

@swiatekm swiatekm force-pushed the feat-add-update-collection-v3 branch from 1fa2762 to a253927 Compare April 25, 2022 13:48
@swiatekm swiatekm merged commit b0e37a7 into main Apr 25, 2022
@swiatekm swiatekm deleted the feat-add-update-collection-v3 branch April 25, 2022 13:52
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.

4 participants