Skip to content

Commit f949c48

Browse files
committed
addressed comments
1 parent d94c3a2 commit f949c48

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

cns/configuration/configuration.go

+7
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,24 @@ import (
1313
"github.com/pkg/errors"
1414
)
1515

16+
type SWIFTV2Mode string
17+
1618
const (
1719
// EnvCNSConfig is the CNS_CONFIGURATION_PATH env var key
1820
EnvCNSConfig = "CNS_CONFIGURATION_PATH"
1921
defaultConfigName = "cns_config.json"
22+
// Service Fabric SWIFTV2 mode
23+
SFSWIFTV2 SWIFTV2Mode = "SFSWIFTV2"
24+
// K8s SWIFTV2 mode
25+
K8sSWIFTV2 SWIFTV2Mode = "K8sSWIFTV2"
2026
)
2127

2228
type CNSConfig struct {
2329
ChannelMode string
2430
EnablePprof bool
2531
EnableSubnetScarcity bool
2632
EnableSwiftV2 bool
33+
SWIFTV2Mode SWIFTV2Mode
2734
InitializeFromCNI bool
2835
ManagedSettings ManagedSettings
2936
MetricsBindAddress string

cns/middlewares/k8sSwiftV2.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ type K8sSWIFTv2Middleware struct {
3737
// Verify interface compliance at compile time
3838
var _ cns.IPConfigsHandlerMiddleware = (*K8sSWIFTv2Middleware)(nil)
3939

40+
// IPConfigsRequestHandlerWrapper is the middleware function for handling SWIFT v2 IP configs requests for AKS-SWIFT. This function wrapped the default SWIFT request
41+
// and release IP configs handlers.
4042
func (m *K8sSWIFTv2Middleware) IPConfigsRequestHandlerWrapper(defaultHandler, failureHandler cns.IPConfigsHandlerFunc) cns.IPConfigsHandlerFunc {
4143
return func(ctx context.Context, req cns.IPConfigsRequest) (*cns.IPConfigsResponse, error) {
4244
podInfo, respCode, message := m.validateIPConfigsRequest(ctx, &req)
@@ -96,7 +98,7 @@ func (m *K8sSWIFTv2Middleware) IPConfigsRequestHandlerWrapper(defaultHandler, fa
9698
}
9799
}
98100

99-
// validateIPConfigsRequest validates if pod is multitenant by checking the pod labels, used in SWIFT V2 scenario.
101+
// validateIPConfigsRequest validates if pod is multitenant by checking the pod labels, used in SWIFT V2 AKS scenario.
100102
// nolint
101103
func (m *K8sSWIFTv2Middleware) validateIPConfigsRequest(ctx context.Context, req *cns.IPConfigsRequest) (podInfo cns.PodInfo, respCode types.ResponseCode, message string) {
102104
// Retrieve the pod from the cluster

cns/service/main.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -1382,8 +1382,17 @@ func InitializeCRDState(ctx context.Context, httpRestService cns.HTTPService, cn
13821382
}
13831383
// if SWIFT v2 is enabled on CNS, attach multitenant middleware to rest service
13841384
// switch here for different type of swift v2 middleware (k8s or SF)
1385-
swiftV2Middleware := middlewares.K8sSWIFTv2Middleware{Cli: manager.GetClient()}
1386-
httpRestService.AttachIPConfigsHandlerMiddleware(&swiftV2Middleware)
1385+
var swiftV2Middleware cns.IPConfigsHandlerMiddleware
1386+
switch cnsconfig.SWIFTV2Mode {
1387+
case configuration.K8sSWIFTV2:
1388+
swiftV2Middleware = &middlewares.K8sSWIFTv2Middleware{Cli: manager.GetClient()}
1389+
case configuration.SFSWIFTV2:
1390+
default:
1391+
// default to K8s middleware for now, in a later changes we where start to pass in
1392+
// SWIFT v2 mode in CNS config, this should throw an error if the mode is not set.
1393+
swiftV2Middleware = &middlewares.K8sSWIFTv2Middleware{Cli: manager.GetClient()}
1394+
}
1395+
httpRestService.AttachIPConfigsHandlerMiddleware(swiftV2Middleware)
13871396
}
13881397

13891398
// start the pool Monitor before the Reconciler, since it needs to be ready to receive an

0 commit comments

Comments
 (0)