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(setting): check both setting and definition default for possible … #2573

Merged
Merged
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
48 changes: 23 additions & 25 deletions datastore/longhorn.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (s *DataStore) UpdateCustomizedSettings(defaultImages map[types.SettingName
return err
}

availableCustomizedDefaultSettings := s.filterCustomizedDefaultSettings(customizedDefaultSettings)
availableCustomizedDefaultSettings := s.filterCustomizedDefaultSettings(customizedDefaultSettings, defaultSettingCM.ResourceVersion)

if err := s.applyCustomizedDefaultSettingsToDefinitions(availableCustomizedDefaultSettings); err != nil {
return err
Expand Down Expand Up @@ -96,11 +96,11 @@ func (s *DataStore) createNonExistingSettingCRsWithDefaultSetting(configMapResou
return nil
}

func (s *DataStore) filterCustomizedDefaultSettings(customizedDefaultSettings map[string]string) map[string]string {
func (s *DataStore) filterCustomizedDefaultSettings(customizedDefaultSettings map[string]string, defaultSettingCMResourceVersion string) map[string]string {
availableCustomizedDefaultSettings := make(map[string]string)

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

Expand All @@ -114,8 +114,7 @@ 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 {
func (s *DataStore) shouldApplyCustomizedSettingValue(name types.SettingName, value string, defaultSettingCMResourceVersion string) bool {
setting, err := s.GetSettingExactRO(name)
if err != nil {
if !ErrorIsNotFound(err) {
Expand All @@ -124,10 +123,20 @@ func (s *DataStore) isSettingValueChanged(name types.SettingName, value string)
}
return true
}
if setting.Value == value {
return false

configMapResourceVersion := ""
if setting.Annotations != nil {
configMapResourceVersion = setting.Annotations[types.GetLonghornLabelKey(types.ConfigMapResourceVersionKey)]
}
return true

// 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 (setting.Value != value || configMapResourceVersion != defaultSettingCMResourceVersion || definition.Default != value)
}

func (s *DataStore) syncSettingsWithDefaultImages(defaultImages map[types.SettingName]string) error {
Expand Down Expand Up @@ -197,16 +206,6 @@ func (s *DataStore) applyCustomizedDefaultSettingsToDefinitions(customizedDefaul

func (s *DataStore) syncSettingCRsWithCustomizedDefaultSettings(customizedDefaultSettings map[string]string, defaultSettingCMResourceVersion string) error {
for _, sName := range types.SettingNameList {
configMapResourceVersion := ""
if s, err := s.GetSettingExactRO(sName); err != nil {
if !apierrors.IsNotFound(err) {
return err
}
} else {
if s.Annotations != nil {
configMapResourceVersion = s.Annotations[types.GetLonghornLabelKey(types.ConfigMapResourceVersionKey)]
}
}

definition, ok := types.GetSettingDefinition(sName)
if !ok {
Expand All @@ -218,13 +217,12 @@ func (s *DataStore) syncSettingCRsWithCustomizedDefaultSettings(customizedDefaul
continue
}

if configMapResourceVersion != defaultSettingCMResourceVersion {
if definition.Required && value == "" {
continue
}
if err := s.createOrUpdateSetting(sName, value, defaultSettingCMResourceVersion); err != nil {
return err
}
if definition.Required && value == "" {
continue
}

if err := s.createOrUpdateSetting(sName, value, defaultSettingCMResourceVersion); err != nil {
return err
}
}

Expand Down