ipn: apply tailnet-wide default for auto-updates (#10508)

When auto-update setting in local Prefs is unset, apply the tailnet
default value from control. This only happens once, when we apply the
default (or when the user manually overrides it), tailnet default no
longer affects the node.

Updates #16244

Signed-off-by: Andrew Lytvynov <awly@tailscale.com>
This commit is contained in:
Andrew Lytvynov
2023-12-18 16:57:03 -06:00
committed by GitHub
parent d05a572db4
commit 945cf836ee
12 changed files with 228 additions and 112 deletions
+15 -4
View File
@@ -21,6 +21,7 @@ import (
"tailscale.com/net/netaddr"
"tailscale.com/net/tsaddr"
"tailscale.com/tailcfg"
"tailscale.com/types/opt"
"tailscale.com/types/persist"
"tailscale.com/types/preftype"
"tailscale.com/types/views"
@@ -237,7 +238,17 @@ type AutoUpdatePrefs struct {
// Apply specifies whether background auto-updates are enabled. When
// enabled, tailscaled will apply available updates in the background.
// Check must also be set when Apply is set.
Apply bool
Apply opt.Bool
}
func (au1 AutoUpdatePrefs) Equals(au2 AutoUpdatePrefs) bool {
// This could almost be as easy as `au1.Apply == au2.Apply`, except that
// opt.Bool("") and opt.Bool("unset") should be treated as equal.
apply1, ok1 := au1.Apply.Get()
apply2, ok2 := au2.Apply.Get()
return au1.Check == au2.Check &&
apply1 == apply2 &&
ok1 == ok2
}
// AppConnectorPrefs are the app connector settings for the node agent.
@@ -533,14 +544,14 @@ func (p *Prefs) Equals(p2 *Prefs) bool {
compareStrings(p.AdvertiseTags, p2.AdvertiseTags) &&
p.Persist.Equals(p2.Persist) &&
p.ProfileName == p2.ProfileName &&
p.AutoUpdate == p2.AutoUpdate &&
p.AutoUpdate.Equals(p2.AutoUpdate) &&
p.AppConnector == p2.AppConnector &&
p.PostureChecking == p2.PostureChecking &&
p.NetfilterKind == p2.NetfilterKind
}
func (au AutoUpdatePrefs) Pretty() string {
if au.Apply {
if au.Apply.EqualBool(true) {
return "update=on "
}
if au.Check {
@@ -600,7 +611,7 @@ func NewPrefs() *Prefs {
NetfilterMode: preftype.NetfilterOn,
AutoUpdate: AutoUpdatePrefs{
Check: true,
Apply: false,
Apply: opt.Bool("unset"),
},
}
}