fix: mixed case labels in configmap store#144
Open
nobbs wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR fixes the issue with mixed case labels in the config map by switching from Viper’s built-in unmarshal to the go.yaml.in/yaml/v3 unmarshal method.
- Added new tests in labelstore_test.go to cover mixed case labels.
- Updated labelstore.go to use direct file reading and YAML unmarshalling.
- Updated go.mod and configs/labels.yaml to support the new behavior.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| labelstore_test.go | Added tests for handling mixed case labels. |
| labelstore.go | Refactored config file unmarshalling to use yaml/v3. |
| go.mod | Added yaml/v3 dependency and adjusted dependency ordering. |
| configs/labels.yaml | Introduced mixed case label values for testing. |
Comment on lines
+70
to
72
| err = yaml.Unmarshal(cfgBytes, &c.labels) | ||
| if err != nil { | ||
| log.Fatal().Err(err).Msg("Error while unmarshalling config file") |
There was a problem hiding this comment.
The YAML unmarshalling logic is duplicated in both the Connect method and the OnConfigChange callback. Consider extracting it into a helper function to reduce code duplication and improve maintainability.
Suggested change
| err = yaml.Unmarshal(cfgBytes, &c.labels) | |
| if err != nil { | |
| log.Fatal().Err(err).Msg("Error while unmarshalling config file") | |
| err = c.loadLabelsFromConfig(cfg) | |
| if err != nil { | |
| log.Fatal().Err(err).Msg("Error while loading labels from config") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR extends the config map labelstore tests with some mixed case labels. As reported in #136 and possibly also in #133 the multena-proxy does not handle mixed case labels correctly - the spf13/viper library's Unmarshal function simply converts all keys to lower case, thus making it impossible to match against mixed case labels.
This PR fixes the issue by using the Unmarshal function of the go.yaml.in/yaml/v3 library instead of the spf13/viper library's built-in Unmarshal function. Code changes are minimal, so no breaking changes should occur.