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

fix: confInfo set higher priority filepath #165

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions source/configmap/configmap_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ func (cmSource *configMapSource) GetConfigurationByKey(key string) (interface{},

for ckey, confInfo := range cmSource.Configurations {
if confInfo == nil {
confInfo.Value = nil
continue
}

Expand Down Expand Up @@ -473,7 +472,6 @@ func (cmSource *configMapSource) compareUpdate(newconf map[string]interface{}, f

for key, confInfo := range cmSource.Configurations {
if confInfo == nil {
confInfo.Value = nil
continue
}

Expand Down Expand Up @@ -512,6 +510,7 @@ func (cmSource *configMapSource) compareUpdate(newconf map[string]interface{}, f

} else if filePathPriority < priority { // lower the vale higher is the priority
confInfo.Value = newConfValue
confInfo.FilePath = filePath
fileConfs[key] = confInfo
events = append(events, &event.Event{EventSource: ConfigMapConfigSourceConst,
Key: key, EventType: event.Update, Value: newConfValue})
Expand Down
2 changes: 1 addition & 1 deletion source/configmap/configmap_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ func TestDynamicConfigurations(t *testing.T) {
check(err)

cmSource := NewConfigMapSource()
cmSource.AddFile(filename3, 2, nil)
cmSource.AddFile(filename1, 0, nil)
cmSource.AddFile(filename2, 1, nil)
cmSource.AddFile(filename3, 2, nil)

dynHandler := new(TestDynamicConfigHandler)
cmSource.Watch(dynHandler)
Expand Down
13 changes: 4 additions & 9 deletions source/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,17 +293,12 @@ func (fSource *Source) GetConfigurationByKey(key string) (interface{}, error) {
fSource.RLock()
defer fSource.RUnlock()

for ckey, confInfo := range fSource.Configurations {
if confInfo == nil {
continue
}

if ckey == key {
return confInfo.Value, nil
}
confInfo, ok := fSource.Configurations[key]
if !ok || confInfo == nil {
return nil, source.ErrKeyNotExist
}

return nil, source.ErrKeyNotExist
return confInfo.Value, nil
}

//GetSourceName get name of source
Expand Down