diff --git a/pkg/agent/controller/bgp/controller.go b/pkg/agent/controller/bgp/controller.go index 4eb2a44fefb..76a53c01e71 100644 --- a/pkg/agent/controller/bgp/controller.go +++ b/pkg/agent/controller/bgp/controller.go @@ -110,7 +110,8 @@ type Controller struct { endpointSliceLister discoverylisters.EndpointSliceLister endpointSliceListerSynced cache.InformerSynced - secretInformer cache.SharedIndexInformer + secretInformer cache.SharedIndexInformer + secretListerSynced cache.InformerSynced bgpPolicyState *bgpPolicyState @@ -226,6 +227,7 @@ func NewBGPPolicyController(nodeInformer coreinformers.NodeInformer, UpdateFunc: c.updateSecret, DeleteFunc: c.deleteSecret, }) + c.secretListerSynced = c.secretInformer.HasSynced return c, nil } @@ -241,6 +243,7 @@ func (c *Controller) Run(ctx context.Context) { c.serviceListerSynced, c.bgpPolicyListerSynced, c.endpointSliceListerSynced, + c.serviceListerSynced, } if c.egressEnabled { cacheSyncs = append(cacheSyncs, c.egressListerSynced) @@ -250,6 +253,7 @@ func (c *Controller) Run(ctx context.Context) { } go wait.UntilWithContext(ctx, c.worker, time.Second) + go c.secretInformer.Run(ctx.Done()) <-ctx.Done() } @@ -896,17 +900,20 @@ func (c *Controller) updateNode(oldObj, obj interface{}) { func (c *Controller) addSecret(obj interface{}) { secret := obj.(*corev1.Secret) + klog.V(2).InfoS("Processing Secret ADD event", "Secret", klog.KObj(secret)) c.updateBGPPeerPasswords(secret) c.queue.Add(dummyKey) } func (c *Controller) updateSecret(_, obj interface{}) { secret := obj.(*corev1.Secret) + klog.V(2).InfoS("Processing Secret UPDATE event", "Secret", klog.KObj(secret)) c.updateBGPPeerPasswords(secret) c.queue.Add(dummyKey) } -func (c *Controller) deleteSecret(_ interface{}) { +func (c *Controller) deleteSecret(obj interface{}) { + klog.V(2).InfoS("Processing Secret DELETE event", "Secret", klog.KObj(obj.(*corev1.Secret))) c.updateBGPPeerPasswords(nil) c.queue.Add(dummyKey) } diff --git a/test/e2e/bgppolicy_test.go b/test/e2e/bgppolicy_test.go index 7e902934173..91eb67df864 100644 --- a/test/e2e/bgppolicy_test.go +++ b/test/e2e/bgppolicy_test.go @@ -24,10 +24,10 @@ import ( "testing" "time" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/utils/ptr" @@ -75,6 +75,7 @@ func routesToStrings(routes []FRRRoute) []string { func TestBGPPolicy(t *testing.T) { skipIfNotIPv4Cluster(t) + skipIfHasWindowsNodes(t) skipIfExternalFRRNotSet(t) data, err := setupTest(t) @@ -217,10 +218,13 @@ func checkFRRRouterBGPRoutes(t *testing.T, expectedRouteStrings, notExpectedRout return false, err } gotRouteStrings := routesToStrings(gotRoutes) - if assert.NotSubset(t, gotRouteStrings, expectedRouteStrings) { + gotRoutesSet := sets.NewString(gotRouteStrings...) + notExpectedRoutesSet := sets.NewString(notExpectedRouteStrings...) + expectedRoutesSet := sets.NewString(expectedRouteStrings...) + if !gotRoutesSet.IsSuperset(expectedRoutesSet) { return false, nil } - if len(notExpectedRouteStrings) != 0 && assert.Subset(t, gotRouteStrings, notExpectedRouteStrings) { + if notExpectedRoutesSet.Len() != 0 && gotRoutesSet.IsSuperset(notExpectedRoutesSet) { return false, nil } return true, nil