From f457f6ad935f6fd8b2b74a50fe960c4dc2dd2da2 Mon Sep 17 00:00:00 2001 From: Kshitija Murudi Date: Thu, 25 Jan 2024 14:04:50 -0800 Subject: [PATCH] feat: change middleware initialization at right cns channel mode --- cns/middlewares/SFSwiftV2.go | 2 -- cns/service/main.go | 24 ++++++++++++------------ 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/cns/middlewares/SFSwiftV2.go b/cns/middlewares/SFSwiftV2.go index 9543da47c0..22ac14b2df 100644 --- a/cns/middlewares/SFSwiftV2.go +++ b/cns/middlewares/SFSwiftV2.go @@ -8,7 +8,6 @@ import ( "github.com/Azure/azure-container-networking/cns/logger" "github.com/Azure/azure-container-networking/cns/types" "github.com/pkg/errors" - "sigs.k8s.io/controller-runtime/pkg/client" "time" ) @@ -19,7 +18,6 @@ const ( ) type SFSWIFTv2Middleware struct { - Cli client.Client } // Verify interface compliance at compile time diff --git a/cns/service/main.go b/cns/service/main.go index 67f0e8da59..df98da2041 100644 --- a/cns/service/main.go +++ b/cns/service/main.go @@ -789,6 +789,13 @@ func main() { if platform.HasMellanoxAdapter() { go platform.MonitorAndSetMellanoxRegKeyPriorityVLANTag(rootCtx, cnsconfig.MellanoxMonitorIntervalSecs) } + // if swiftv2 scenario is enabled, we need to initialize the Service Fabric (standalone) swiftv2 middleware to process IP configs requests + if cnsconfig.EnableSwiftV2 { + if cnsconfig.SWIFTV2Mode == configuration.SFSWIFTV2 { + swiftV2Middleware := &middlewares.SFSWIFTv2Middleware{} + httpRestService.AttachIPConfigsHandlerMiddleware(swiftV2Middleware) + } + } } // Initialze state in if CNS is running in CRD mode @@ -1381,19 +1388,12 @@ func InitializeCRDState(ctx context.Context, httpRestService cns.HTTPService, cn return errors.Wrapf(err, "failed to setup mtpnc reconciler with manager") } // if SWIFT v2 is enabled on CNS, attach multitenant middleware to rest service - // switch here for different type of swift v2 middleware (k8s or SF) - var swiftV2Middleware cns.IPConfigsHandlerMiddleware - switch cnsconfig.SWIFTV2Mode { - case configuration.K8sSWIFTV2: - swiftV2Middleware = &middlewares.K8sSWIFTv2Middleware{Cli: manager.GetClient()} - case configuration.SFSWIFTV2: - swiftV2Middleware = &middlewares.SFSWIFTv2Middleware{Cli: manager.GetClient()} - default: - // default to K8s middleware for now, in a later changes we where start to pass in - // SWIFT v2 mode in CNS config, this should throw an error if the mode is not set. - swiftV2Middleware = &middlewares.K8sSWIFTv2Middleware{Cli: manager.GetClient()} + // here for AKS(K8s) swiftv2 middleware to process IP configs requests + if cnsconfig.SWIFTV2Mode == configuration.K8sSWIFTV2 { + swiftV2Middleware := &middlewares.K8sSWIFTv2Middleware{Cli: manager.GetClient()} + httpRestService.AttachIPConfigsHandlerMiddleware(swiftV2Middleware) } - httpRestService.AttachIPConfigsHandlerMiddleware(swiftV2Middleware) + } // start the pool Monitor before the Reconciler, since it needs to be ready to receive an