Skip to content

Commit 0d65092

Browse files
authored
Fix crash when deleting the Secret storing BGP passwords (#7042) (#7046)
Signed-off-by: Hongliang Liu <[email protected]>
1 parent 9a7f459 commit 0d65092

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
@@ -946,7 +946,7 @@ func (c *Controller) updateBGPPeerPasswords(secret *corev1.Secret) {
946946
defer c.bgpPeerPasswordsMutex.Unlock()
947947

948948
c.bgpPeerPasswords = make(map[string]string)
949-
if secret.Data != nil {
949+
if secret != nil && secret.Data != nil {
950950
for k, v := range secret.Data {
951951
c.bgpPeerPasswords[k] = string(v)
952952
}

pkg/agent/controller/bgp/controller_test.go

+25-7
Original file line numberDiff line numberDiff line change
@@ -1602,7 +1602,7 @@ func TestEgressLifecycle(t *testing.T) {
16021602
doneDummyEvent(t, c)
16031603
}
16041604

1605-
func TestBGPSecretUpdate(t *testing.T) {
1605+
func TestBGPPasswordUpdate(t *testing.T) {
16061606
policy := generateBGPPolicy(bgpPolicyName1,
16071607
creationTimestamp,
16081608
nodeLabels1,
@@ -1681,12 +1681,30 @@ func TestBGPSecretUpdate(t *testing.T) {
16811681

16821682
// Wait for the dummy event triggered by Secret update event, and mark it done.
16831683
waitAndGetDummyEvent(t, c)
1684-
updatedIPv4Peer1Config := ipv4Peer1Config
1685-
updatedIPv4Peer3Config := ipv4Peer3Config
1686-
updatedIPv4Peer1Config.Password = "updated-" + peer1AuthPassword
1687-
updatedIPv4Peer3Config.Password = "updated-" + peer3AuthPassword
1688-
mockBGPServer.EXPECT().UpdatePeer(gomock.Any(), updatedIPv4Peer1Config)
1689-
mockBGPServer.EXPECT().UpdatePeer(gomock.Any(), updatedIPv4Peer3Config)
1684+
expectedIPv4Peer1Config := ipv4Peer1Config
1685+
expectedIPv4Peer3Config := ipv4Peer3Config
1686+
expectedIPv4Peer1Config.Password = "updated-" + peer1AuthPassword
1687+
expectedIPv4Peer3Config.Password = "updated-" + peer3AuthPassword
1688+
mockBGPServer.EXPECT().UpdatePeer(gomock.Any(), expectedIPv4Peer1Config)
1689+
mockBGPServer.EXPECT().UpdatePeer(gomock.Any(), expectedIPv4Peer3Config)
1690+
require.NoError(t, c.syncBGPPolicy(ctx))
1691+
// Done with the dummy event.
1692+
doneDummyEvent(t, c)
1693+
1694+
// Delete the Secret.
1695+
err = c.client.CoreV1().Secrets(namespaceKubeSystem).Delete(context.TODO(), secret.Name, metav1.DeleteOptions{})
1696+
require.NoError(t, err)
1697+
// Wait for the dummy event triggered by Secret delete event, and mark it done.
1698+
waitAndGetDummyEvent(t, c)
1699+
expectedIPv4Peer1Config = ipv4Peer1Config
1700+
expectedIPv4Peer2Config := ipv4Peer2Config
1701+
expectedIPv4Peer3Config = ipv4Peer3Config
1702+
expectedIPv4Peer1Config.Password = ""
1703+
expectedIPv4Peer2Config.Password = ""
1704+
expectedIPv4Peer3Config.Password = ""
1705+
mockBGPServer.EXPECT().UpdatePeer(gomock.Any(), expectedIPv4Peer1Config)
1706+
mockBGPServer.EXPECT().UpdatePeer(gomock.Any(), expectedIPv4Peer2Config)
1707+
mockBGPServer.EXPECT().UpdatePeer(gomock.Any(), expectedIPv4Peer3Config)
16901708
require.NoError(t, c.syncBGPPolicy(ctx))
16911709
// Done with the dummy event.
16921710
doneDummyEvent(t, c)

0 commit comments

Comments
 (0)