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

Fix crash when deleting the Secret storing BGP passwords #7042

Merged
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
2 changes: 1 addition & 1 deletion pkg/agent/controller/bgp/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ func (c *Controller) updateBGPPeerPasswords(secret *corev1.Secret) {
defer c.bgpPeerPasswordsMutex.Unlock()

c.bgpPeerPasswords = make(map[string]string)
if secret.Data != nil {
if secret != nil && secret.Data != nil {
for k, v := range secret.Data {
c.bgpPeerPasswords[k] = string(v)
}
Expand Down
32 changes: 25 additions & 7 deletions pkg/agent/controller/bgp/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1625,7 +1625,7 @@ func TestEgressLifecycle(t *testing.T) {
doneDummyEvent(t, c)
}

func TestBGPSecretUpdate(t *testing.T) {
func TestBGPPasswordUpdate(t *testing.T) {
policy := generateBGPPolicy(bgpPolicyName1,
creationTimestamp,
nodeLabels1,
Expand Down Expand Up @@ -1698,12 +1698,30 @@ func TestBGPSecretUpdate(t *testing.T) {

// Wait for the dummy event triggered by Secret update event, and mark it done.
waitAndGetDummyEvent(t, c)
updatedIPv4Peer1Config := ipv4Peer1Config
updatedIPv4Peer3Config := ipv4Peer3Config
updatedIPv4Peer1Config.Password = "updated-" + peer1AuthPassword
updatedIPv4Peer3Config.Password = "updated-" + peer3AuthPassword
mockBGPServer.EXPECT().UpdatePeer(gomock.Any(), updatedIPv4Peer1Config)
mockBGPServer.EXPECT().UpdatePeer(gomock.Any(), updatedIPv4Peer3Config)
expectedIPv4Peer1Config := ipv4Peer1Config
expectedIPv4Peer3Config := ipv4Peer3Config
expectedIPv4Peer1Config.Password = "updated-" + peer1AuthPassword
expectedIPv4Peer3Config.Password = "updated-" + peer3AuthPassword
mockBGPServer.EXPECT().UpdatePeer(gomock.Any(), expectedIPv4Peer1Config)
mockBGPServer.EXPECT().UpdatePeer(gomock.Any(), expectedIPv4Peer3Config)
require.NoError(t, c.syncBGPPolicy(ctx))
// Done with the dummy event.
doneDummyEvent(t, c)

// Delete the Secret.
err = c.client.CoreV1().Secrets(namespaceKubeSystem).Delete(context.TODO(), secret.Name, metav1.DeleteOptions{})
require.NoError(t, err)
// Wait for the dummy event triggered by Secret delete event, and mark it done.
waitAndGetDummyEvent(t, c)
expectedIPv4Peer1Config = ipv4Peer1Config
expectedIPv4Peer2Config := ipv4Peer2Config
expectedIPv4Peer3Config = ipv4Peer3Config
expectedIPv4Peer1Config.Password = ""
expectedIPv4Peer2Config.Password = ""
expectedIPv4Peer3Config.Password = ""
mockBGPServer.EXPECT().UpdatePeer(gomock.Any(), expectedIPv4Peer1Config)
mockBGPServer.EXPECT().UpdatePeer(gomock.Any(), expectedIPv4Peer2Config)
mockBGPServer.EXPECT().UpdatePeer(gomock.Any(), expectedIPv4Peer3Config)
require.NoError(t, c.syncBGPPolicy(ctx))
// Done with the dummy event.
doneDummyEvent(t, c)
Expand Down