From 5e65717c7f149883285b596f86cde1952f841fc2 Mon Sep 17 00:00:00 2001 From: Adrian Dewhurst Date: Fri, 18 Nov 2022 10:58:58 -0500 Subject: [PATCH] ipn/ipnlocal: fix integration test failure in tkaSyncIfNeeded In main, some of the prefs handling was reworked and some of those changes were cherry picked to 1.32. This prevents failures for the internal integration test for TKA that was failing due to an uninitialized prefs.Persist. Signed-off-by: Adrian Dewhurst --- ipn/ipnlocal/local.go | 2 +- ipn/ipnlocal/network-lock.go | 5 +++-- ipn/ipnlocal/network-lock_test.go | 8 ++++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/ipn/ipnlocal/local.go b/ipn/ipnlocal/local.go index 836075d26..7e0aa648e 100644 --- a/ipn/ipnlocal/local.go +++ b/ipn/ipnlocal/local.go @@ -806,7 +806,7 @@ func (b *LocalBackend) setClientStatus(st controlclient.Status) { } if st.NetMap != nil { b.mu.Unlock() // respect locking rules for tkaSyncIfNeeded - if err := b.tkaSyncIfNeeded(st.NetMap); err != nil { + if err := b.tkaSyncIfNeeded(st.NetMap, prefs.View()); err != nil { b.logf("[v1] TKA sync error: %v", err) } b.mu.Lock() diff --git a/ipn/ipnlocal/network-lock.go b/ipn/ipnlocal/network-lock.go index bf2b9221a..2c7f48fe9 100644 --- a/ipn/ipnlocal/network-lock.go +++ b/ipn/ipnlocal/network-lock.go @@ -17,6 +17,7 @@ import ( "time" "tailscale.com/envknob" + "tailscale.com/ipn" "tailscale.com/ipn/ipnstate" "tailscale.com/tailcfg" "tailscale.com/tka" @@ -89,7 +90,7 @@ func (b *LocalBackend) tkaFilterNetmapLocked(nm *netmap.NetworkMap) { // // tkaSyncIfNeeded immediately takes b.takeSyncLock which is held throughout, // and may take b.mu as required. -func (b *LocalBackend) tkaSyncIfNeeded(nm *netmap.NetworkMap) error { +func (b *LocalBackend) tkaSyncIfNeeded(nm *netmap.NetworkMap, prefs ipn.PrefsView) error { if !envknob.UseWIPCode() { // If the feature flag is not enabled, pretend we don't exist. return nil @@ -100,7 +101,7 @@ func (b *LocalBackend) tkaSyncIfNeeded(nm *netmap.NetworkMap) error { b.mu.Lock() // take mu to protect access to synchronized fields. defer b.mu.Unlock() - ourNodeKey := b.prefs.Persist().PublicNodeKey() + ourNodeKey := prefs.Persist().PublicNodeKey() isEnabled := b.tka != nil wantEnabled := nm.TKAEnabled diff --git a/ipn/ipnlocal/network-lock_test.go b/ipn/ipnlocal/network-lock_test.go index eac318b74..214d79633 100644 --- a/ipn/ipnlocal/network-lock_test.go +++ b/ipn/ipnlocal/network-lock_test.go @@ -130,7 +130,7 @@ func TestTKAEnablementFlow(t *testing.T) { err = b.tkaSyncIfNeeded(&netmap.NetworkMap{ TKAEnabled: true, TKAHead: a1.Head(), - }) + }, b.prefs) if err != nil { t.Errorf("tkaSyncIfNeededLocked() failed: %v", err) } @@ -229,7 +229,7 @@ func TestTKADisablementFlow(t *testing.T) { err = b.tkaSyncIfNeeded(&netmap.NetworkMap{ TKAEnabled: false, TKAHead: authority.Head(), - }) + }, b.prefs) if err != nil { t.Errorf("tkaSyncIfNeededLocked() failed: %v", err) } @@ -242,7 +242,7 @@ func TestTKADisablementFlow(t *testing.T) { err = b.tkaSyncIfNeeded(&netmap.NetworkMap{ TKAEnabled: false, TKAHead: authority.Head(), - }) + }, b.prefs) if err != nil { t.Errorf("tkaSyncIfNeededLocked() failed: %v", err) } @@ -465,7 +465,7 @@ func TestTKASync(t *testing.T) { err = b.tkaSyncIfNeeded(&netmap.NetworkMap{ TKAEnabled: true, TKAHead: controlAuthority.Head(), - }) + }, b.prefs) if err != nil { t.Errorf("tkaSyncIfNeededLocked() failed: %v", err) }