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

Add support for --disable-software-updates to disable software updates by cli-flag and also prevents chaning their values #1470

Open
wants to merge 1 commit into
base: develop
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
40 changes: 39 additions & 1 deletion service/updates/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package updates

import (
"context"
"errors"

"github.com/tevino/abool"

Expand Down Expand Up @@ -29,6 +30,9 @@ var (
)

func registerConfig() error {
releaseLevelSet := abool.New()
softwareUpdateSet := abool.New()

err := config.Register(&config.Option{
Name: "Release Channel",
Key: helper.ReleaseChannelKey,
Expand All @@ -38,6 +42,23 @@ func registerConfig() error {
ReleaseLevel: config.ReleaseLevelStable,
RequiresRestart: true,
DefaultValue: helper.ReleaseChannelStable,
// TODO(ppacher): it would actually be better to hide the option from the UI
ValidationFunc: func(value interface{}) error {
if releaseLevelSet.SetToIf(false, true) || releaseChannel == nil {
return nil
}

v, ok := value.(string)
if !ok {
return errors.New("invalid value")
}

if softwareUpdatesDisabledByFlag && releaseChannel() != v {
return errors.New("automatic software updates are not supported by the choosen installation method")
}

return nil
},
PossibleValues: []config.PossibleValue{
{
Name: "Stable",
Expand Down Expand Up @@ -78,7 +99,24 @@ func registerConfig() error {
ExpertiseLevel: config.ExpertiseLevelExpert,
ReleaseLevel: config.ReleaseLevelStable,
RequiresRestart: false,
DefaultValue: true,
// TODO(ppacher): it would be better to actually hide the whole setting from the UI.
DefaultValue: !softwareUpdatesDisabledByFlag,
ValidationFunc: func(value interface{}) error {
if softwareUpdateSet.SetToIf(false, true) || enableSoftwareUpdates == nil {
return nil
}

v, ok := value.(bool)
if !ok {
return errors.New("invalid value")
}

if softwareUpdatesDisabledByFlag && v {
return errors.New("automatic software updates are not supported by the choosen installation method")
}

return nil
},
Annotations: config.Annotations{
config.DisplayOrderAnnotation: -12,
config.CategoryAnnotation: "Updates",
Expand Down
6 changes: 4 additions & 2 deletions service/updates/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ var (
module *modules.Module
registry *updater.ResourceRegistry

userAgentFromFlag string
updateServerFromFlag string
userAgentFromFlag string
updateServerFromFlag string
softwareUpdatesDisabledByFlag bool

updateTask *modules.Task
updateASAP bool
Expand Down Expand Up @@ -86,6 +87,7 @@ func init() {

flag.StringVar(&updateServerFromFlag, "update-server", "", "set an alternative update server (full URL)")
flag.StringVar(&userAgentFromFlag, "update-agent", "", "set an alternative user agent for requests to the update server")
flag.BoolVar(&softwareUpdatesDisabledByFlag, "disable-software-updates", false, "Disable automatic software updates")
}

func prep() error {
Expand Down