Skip to content

Commit 1129ad6

Browse files
authored
Fix crash when deleting the Secret storing BGP passwords (#7042) (#7045)
Signed-off-by: Hongliang Liu <[email protected]>
1 parent eb0b700 commit 1129ad6

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

pkg/agent/controller/bgp/controller.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ func (c *Controller) updateBGPPeerPasswords(secret *corev1.Secret) {
976976
defer c.bgpPeerPasswordsMutex.Unlock()
977977

978978
c.bgpPeerPasswords = make(map[string]string)
979-
if secret.Data != nil {
979+
if secret != nil && secret.Data != nil {
980980
for k, v := range secret.Data {
981981
c.bgpPeerPasswords[k] = string(v)
982982
}

pkg/agent/controller/bgp/controller_test.go

+25-7
Original file line numberDiff line numberDiff line change
@@ -1625,7 +1625,7 @@ func TestEgressLifecycle(t *testing.T) {
16251625
doneDummyEvent(t, c)
16261626
}
16271627

1628-
func TestBGPSecretUpdate(t *testing.T) {
1628+
func TestBGPPasswordUpdate(t *testing.T) {
16291629
policy := generateBGPPolicy(bgpPolicyName1,
16301630
creationTimestamp,
16311631
nodeLabels1,
@@ -1698,12 +1698,30 @@ func TestBGPSecretUpdate(t *testing.T) {
16981698

16991699
// Wait for the dummy event triggered by Secret update event, and mark it done.
17001700
waitAndGetDummyEvent(t, c)
1701-
updatedIPv4Peer1Config := ipv4Peer1Config
1702-
updatedIPv4Peer3Config := ipv4Peer3Config
1703-
updatedIPv4Peer1Config.Password = "updated-" + peer1AuthPassword
1704-
updatedIPv4Peer3Config.Password = "updated-" + peer3AuthPassword
1705-
mockBGPServer.EXPECT().UpdatePeer(gomock.Any(), updatedIPv4Peer1Config)
1706-
mockBGPServer.EXPECT().UpdatePeer(gomock.Any(), updatedIPv4Peer3Config)
1701+
expectedIPv4Peer1Config := ipv4Peer1Config
1702+
expectedIPv4Peer3Config := ipv4Peer3Config
1703+
expectedIPv4Peer1Config.Password = "updated-" + peer1AuthPassword
1704+
expectedIPv4Peer3Config.Password = "updated-" + peer3AuthPassword
1705+
mockBGPServer.EXPECT().UpdatePeer(gomock.Any(), expectedIPv4Peer1Config)
1706+
mockBGPServer.EXPECT().UpdatePeer(gomock.Any(), expectedIPv4Peer3Config)
1707+
require.NoError(t, c.syncBGPPolicy(ctx))
1708+
// Done with the dummy event.
1709+
doneDummyEvent(t, c)
1710+
1711+
// Delete the Secret.
1712+
err = c.client.CoreV1().Secrets(namespaceKubeSystem).Delete(context.TODO(), secret.Name, metav1.DeleteOptions{})
1713+
require.NoError(t, err)
1714+
// Wait for the dummy event triggered by Secret delete event, and mark it done.
1715+
waitAndGetDummyEvent(t, c)
1716+
expectedIPv4Peer1Config = ipv4Peer1Config
1717+
expectedIPv4Peer2Config := ipv4Peer2Config
1718+
expectedIPv4Peer3Config = ipv4Peer3Config
1719+
expectedIPv4Peer1Config.Password = ""
1720+
expectedIPv4Peer2Config.Password = ""
1721+
expectedIPv4Peer3Config.Password = ""
1722+
mockBGPServer.EXPECT().UpdatePeer(gomock.Any(), expectedIPv4Peer1Config)
1723+
mockBGPServer.EXPECT().UpdatePeer(gomock.Any(), expectedIPv4Peer2Config)
1724+
mockBGPServer.EXPECT().UpdatePeer(gomock.Any(), expectedIPv4Peer3Config)
17071725
require.NoError(t, c.syncBGPPolicy(ctx))
17081726
// Done with the dummy event.
17091727
doneDummyEvent(t, c)

0 commit comments

Comments
 (0)