@@ -33,7 +33,7 @@ import (
3333var _ = Describe ("BGPConfiguration controller" , func () {
3434 var bgpcfgName types.NamespacedName
3535 var meallbFRRCfgName types.NamespacedName
36- frrCfgNamespace := "metallb-system "
36+ frrCfgNamespace := "openshift-frr-k8s "
3737
3838 When ("a default BGPConfiguration gets created" , func () {
3939 BeforeEach (func () {
@@ -720,4 +720,92 @@ var _ = Describe("BGPConfiguration controller", func() {
720720 }, timeout , interval ).Should (Succeed ())
721721 })
722722 })
723+
724+ When ("legacy FRRConfigurations in metallb-system are cleaned up after default namespace change" , func () {
725+ var podFrrName types.NamespacedName
726+ var podName types.NamespacedName
727+ var legacyNS * corev1.Namespace
728+
729+ BeforeEach (func () {
730+ // Create the new default namespace (openshift-frr-k8s)
731+ defaultNS := th .CreateNamespace (frrCfgNamespace + "-" + namespace )
732+
733+ defaultFRRCfgName := types.NamespacedName {Namespace : defaultNS .Name , Name : "worker-0" }
734+ defaultFRRCfg := CreateFRRConfiguration (defaultFRRCfgName , GetMetalLBFRRConfigurationSpec ("worker-0" ))
735+ Expect (defaultFRRCfg ).To (Not (BeNil ()))
736+
737+ // Create the legacy metallb-system namespace with an owned FRRConfiguration
738+ legacyNS = th .CreateNamespace ("metallb-system-" + namespace )
739+ bgpReconciler .LegacyMetalLBNamespace = legacyNS .Name
740+ DeferCleanup (func () {
741+ bgpReconciler .LegacyMetalLBNamespace = ""
742+ })
743+
744+ nad := th .CreateNAD (types.NamespacedName {Namespace : namespace , Name : "internalapi" }, GetNADSpec ())
745+
746+ bgpcfg := CreateBGPConfiguration (namespace , GetBGPConfigurationSpec (defaultNS .Name ))
747+ bgpcfgName .Name = bgpcfg .GetName ()
748+ bgpcfgName .Namespace = bgpcfg .GetNamespace ()
749+
750+ podName = types.NamespacedName {Namespace : namespace , Name : uuid .New ().String ()}
751+ th .CreatePod (podName , GetPodAnnotation (namespace ), GetPodSpec ("worker-0" ))
752+ th .SimulatePodPhaseRunning (podName )
753+
754+ podFrrName .Name = podName .Namespace + "-" + podName .Name
755+ podFrrName .Namespace = defaultNS .Name
756+
757+ DeferCleanup (th .DeleteInstance , bgpcfg )
758+ DeferCleanup (th .DeleteInstance , nad )
759+ DeferCleanup (th .DeleteInstance , defaultFRRCfg )
760+ })
761+
762+ It ("should clean up owned FRRConfigurations from the legacy metallb-system namespace" , func () {
763+ // Wait for the FRRConfiguration to be created in the new default namespace
764+ Eventually (func (g Gomega ) {
765+ frr := GetFRRConfiguration (types.NamespacedName {Namespace : podFrrName .Namespace , Name : podFrrName .Name })
766+ g .Expect (frr ).To (Not (BeNil ()))
767+ g .Expect (frr .Spec .BGP .Routers [0 ].Prefixes [0 ]).To (Equal ("172.17.0.40/32" ))
768+ }, timeout , interval ).Should (Succeed ())
769+
770+ // Create an owned FRRConfiguration in the legacy namespace to simulate a pre-upgrade state
771+ legacyFRR := CreateFRRConfiguration (
772+ types.NamespacedName {Namespace : legacyNS .Name , Name : podFrrName .Name },
773+ GetMetalLBFRRConfigurationSpec ("worker-0" ),
774+ )
775+ Expect (legacyFRR ).To (Not (BeNil ()))
776+
777+ // Add owner labels matching the BGPConfiguration so cleanup will target it
778+ frr := & frrk8sv1.FRRConfiguration {}
779+ Eventually (func (g Gomega ) {
780+ g .Expect (k8sClient .Get (ctx , types.NamespacedName {Namespace : legacyNS .Name , Name : podFrrName .Name }, frr )).Should (Succeed ())
781+ }, timeout , interval ).Should (Succeed ())
782+
783+ bgpcfg := GetBGPConfiguration (bgpcfgName )
784+ frr .Labels = map [string ]string {
785+ "bgpconfiguration.openstack.org/name" : bgpcfg .Name ,
786+ "bgpconfiguration.openstack.org/namespace" : bgpcfg .Namespace ,
787+ }
788+ Expect (k8sClient .Update (ctx , frr )).Should (Succeed ())
789+
790+ // Trigger reconcile
791+ pod := th .GetPod (podName )
792+ if pod .Annotations == nil {
793+ pod .Annotations = map [string ]string {}
794+ }
795+ pod .Annotations ["trigger-reconcile" ] = "true"
796+ Eventually (func (g Gomega ) {
797+ g .Expect (k8sClient .Update (ctx , pod )).Should (Succeed ())
798+ }, timeout , interval ).Should (Succeed ())
799+
800+ // Verify the legacy FRRConfiguration is cleaned up
801+ Eventually (func (g Gomega ) {
802+ err := k8sClient .Get (ctx , types.NamespacedName {
803+ Namespace : legacyNS .Name ,
804+ Name : podFrrName .Name ,
805+ }, & frrk8sv1.FRRConfiguration {})
806+ g .Expect (err ).To (HaveOccurred ())
807+ g .Expect (k8s_errors .IsNotFound (err )).To (BeTrue ())
808+ }, timeout , interval ).Should (Succeed ())
809+ })
810+ })
723811})
0 commit comments