Skip to content

Commit

Permalink
fix(setting): check both setting and definition default for possible …
Browse files Browse the repository at this point in the history
…change.

Signed-off-by: James Munson <james.munson@suse.com>
  • Loading branch information
james-munson committed Feb 27, 2024
1 parent 5c5566b commit c56bc11
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions datastore/longhorn.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (s *DataStore) filterCustomizedDefaultSettings(customizedDefaultSettings ma
availableCustomizedDefaultSettings := make(map[string]string)

for name, value := range customizedDefaultSettings {
if !s.isSettingValueChanged(types.SettingName(name), value) {
if !s.isEitherValueChanged(types.SettingName(name), value) {
continue
}

Expand All @@ -114,8 +114,9 @@ func (s *DataStore) filterCustomizedDefaultSettings(customizedDefaultSettings ma
return availableCustomizedDefaultSettings
}

// isSettingValueChanged check if the customized default setting and value was changed
func (s *DataStore) isSettingValueChanged(name types.SettingName, value string) bool {
// isEitherValueChanged checks whether the proposed value differs from either the setting definition's
// default value or the current setting's value.
func (s *DataStore) isEitherValueChanged(name types.SettingName, value string) bool {
setting, err := s.GetSettingExactRO(name)
if err != nil {
if !ErrorIsNotFound(err) {
Expand All @@ -124,10 +125,15 @@ func (s *DataStore) isSettingValueChanged(name types.SettingName, value string)
}
return true
}
if setting.Value == value {
return false

// Also check the setting definition.
definition, ok := types.GetSettingDefinition(name)
if !ok {
logrus.Errorf("customized default setting %v is not defined", name)
return true
}
return true

return (setting.Value != value || definition.Default != value)
}

func (s *DataStore) syncSettingsWithDefaultImages(defaultImages map[types.SettingName]string) error {
Expand Down

0 comments on commit c56bc11

Please sign in to comment.