diff --git a/config/option.go b/config/option.go index 07ec685..1f1cdd9 100644 --- a/config/option.go +++ b/config/option.go @@ -94,6 +94,10 @@ const ( // may be extended to hold references to other options in the // future. StackableAnnotation = "safing/portbase:options:stackable" + // RestartPendingAnnotation is automatically set on a configuration option + // that requires a restart and has been changed. + // The value must always be a boolean with value "true". + RestartPendingAnnotation = "safing/portbase:options:restart-pending" // QuickSettingAnnotation can be used to add quick settings to // a configuration option. A quick setting can support the user // by switching between pre-configured values. @@ -258,6 +262,12 @@ func (option *Option) SetAnnotation(key string, value interface{}) { option.Lock() defer option.Unlock() + option.setAnnotation(key, value) +} + +// setAnnotation sets the value of the annotation key overwritting an +// existing value if required. Does not lock the Option. +func (option *Option) setAnnotation(key string, value interface{}) { if option.Annotations == nil { option.Annotations = make(Annotations) } diff --git a/config/set.go b/config/set.go index f9c285a..b46cb8a 100644 --- a/config/set.go +++ b/config/set.go @@ -147,6 +147,11 @@ func setConfigOption(key string, value interface{}, push bool) (err error) { } } + // Add the "restart pending" annotation if the settings requires a restart. + if option.RequiresRestart { + option.setAnnotation(RestartPendingAnnotation, true) + } + handleOptionUpdate(option, push) option.Unlock() @@ -182,6 +187,11 @@ func setDefaultConfigOption(key string, value interface{}, push bool) (err error } } + // Add the "restart pending" annotation if the settings requires a restart. + if option.RequiresRestart { + option.setAnnotation(RestartPendingAnnotation, true) + } + handleOptionUpdate(option, push) option.Unlock()