@@ -40,7 +40,9 @@ var _ cns.IPConfigsHandlerMiddleware = (*K8sSWIFTv2Middleware)(nil)
4040// and release IP configs handlers.
4141func (k * K8sSWIFTv2Middleware ) IPConfigsRequestHandlerWrapper (defaultHandler , failureHandler cns.IPConfigsHandlerFunc ) cns.IPConfigsHandlerFunc {
4242 return func (ctx context.Context , req cns.IPConfigsRequest ) (* cns.IPConfigsResponse , error ) {
43- podInfo , respCode , message := k .validateIPConfigsRequest (ctx , & req )
43+ podInfo , respCode , message , defaultDenyACLbool := k .validateIPConfigsRequest (ctx , & req )
44+
45+ logger .Printf ("defaultDenyACLbool value is: %v" , defaultDenyACLbool )
4446
4547 if respCode != types .Success {
4648 return & cns.IPConfigsResponse {
@@ -55,6 +57,19 @@ func (k *K8sSWIFTv2Middleware) IPConfigsRequestHandlerWrapper(defaultHandler, fa
5557 if ! req .SecondaryInterfacesExist {
5658 return ipConfigsResp , err
5759 }
60+
61+ // ipConfigsResp has infra IP configs -> if defaultDenyACLbool is enabled, add the default deny acl's pn the infra IP configs
62+ for i := range ipConfigsResp .PodIPInfo {
63+ ipInfo := & ipConfigsResp .PodIPInfo [i ]
64+ // there will be no pod connectivity to and from those pods
65+ if defaultDenyACLbool {
66+ err = addDefaultDenyACL (ipInfo )
67+ if err != nil {
68+ logger .Errorf ("failed to add default deny acl's for pod %v with err %v" , podInfo .Name (), err )
69+ }
70+ }
71+ }
72+
5873 // If the pod is v2, get the infra IP configs from the handler first and then add the SWIFTv2 IP config
5974 defer func () {
6075 // Release the default IP config if there is an error
@@ -102,19 +117,21 @@ func (k *K8sSWIFTv2Middleware) IPConfigsRequestHandlerWrapper(defaultHandler, fa
102117
103118// validateIPConfigsRequest validates if pod is multitenant by checking the pod labels, used in SWIFT V2 AKS scenario.
104119// nolint
105- func (k * K8sSWIFTv2Middleware ) validateIPConfigsRequest (ctx context.Context , req * cns.IPConfigsRequest ) (podInfo cns.PodInfo , respCode types.ResponseCode , message string ) {
120+ func (k * K8sSWIFTv2Middleware ) validateIPConfigsRequest (ctx context.Context , req * cns.IPConfigsRequest ) (podInfo cns.PodInfo , respCode types.ResponseCode , message string , defaultDenyACL bool ) {
121+ defaultDenyACLbool := false
122+
106123 // Retrieve the pod from the cluster
107124 podInfo , err := cns .UnmarshalPodInfo (req .OrchestratorContext )
108125 if err != nil {
109126 errBuf := errors .Wrapf (err , "failed to unmarshalling pod info from ipconfigs request %+v" , req )
110- return nil , types .UnexpectedError , errBuf .Error ()
127+ return nil , types .UnexpectedError , errBuf .Error (), defaultDenyACLbool
111128 }
112129 logger .Printf ("[SWIFTv2Middleware] validate ipconfigs request for pod %s" , podInfo .Name ())
113130 podNamespacedName := k8stypes.NamespacedName {Namespace : podInfo .Namespace (), Name : podInfo .Name ()}
114131 pod := v1.Pod {}
115132 if err := k .Cli .Get (ctx , podNamespacedName , & pod ); err != nil {
116133 errBuf := errors .Wrapf (err , "failed to get pod %+v" , podNamespacedName )
117- return nil , types .UnexpectedError , errBuf .Error ()
134+ return nil , types .UnexpectedError , errBuf .Error (), defaultDenyACLbool
118135 }
119136
120137 // check the pod labels for Swift V2, set the request's SecondaryInterfaceSet flag to true and check if its MTPNC CRD is ready
@@ -126,12 +143,16 @@ func (k *K8sSWIFTv2Middleware) validateIPConfigsRequest(ctx context.Context, req
126143 mtpnc := v1alpha1.MultitenantPodNetworkConfig {}
127144 mtpncNamespacedName := k8stypes.NamespacedName {Namespace : podInfo .Namespace (), Name : podInfo .Name ()}
128145 if err := k .Cli .Get (ctx , mtpncNamespacedName , & mtpnc ); err != nil {
129- return nil , types .UnexpectedError , fmt .Errorf ("failed to get pod's mtpnc from cache : %w" , err ).Error ()
146+ return nil , types .UnexpectedError , fmt .Errorf ("failed to get pod's mtpnc from cache : %w" , err ).Error (), defaultDenyACLbool
130147 }
131148 // Check if the MTPNC CRD is ready. If one of the fields is empty, return error
132149 if ! mtpnc .IsReady () {
133- return nil , types .UnexpectedError , errMTPNCNotReady .Error ()
150+ return nil , types .UnexpectedError , errMTPNCNotReady .Error (), defaultDenyACLbool
134151 }
152+
153+ // copying defaultDenyACL bool from mtpnc
154+ defaultDenyACLbool = mtpnc .Status .DefaultDenyACL
155+
135156 // If primary Ip is set in status field, it indicates the presence of secondary interfaces
136157 if mtpnc .Status .PrimaryIP != "" {
137158 req .SecondaryInterfacesExist = true
@@ -140,7 +161,7 @@ func (k *K8sSWIFTv2Middleware) validateIPConfigsRequest(ctx context.Context, req
140161 for _ , interfaceInfo := range interfaceInfos {
141162 if interfaceInfo .DeviceType == v1alpha1 .DeviceTypeInfiniBandNIC {
142163 if interfaceInfo .MacAddress == "" || interfaceInfo .NCID == "" {
143- return nil , types .UnexpectedError , errMTPNCNotReady .Error ()
164+ return nil , types .UnexpectedError , errMTPNCNotReady .Error (), defaultDenyACLbool
144165 }
145166 req .BackendInterfaceExist = true
146167 req .BackendInterfaceMacAddresses = append (req .BackendInterfaceMacAddresses , interfaceInfo .MacAddress )
@@ -154,7 +175,7 @@ func (k *K8sSWIFTv2Middleware) validateIPConfigsRequest(ctx context.Context, req
154175 logger .Printf ("[SWIFTv2Middleware] pod %s has secondary interface : %v" , podInfo .Name (), req .SecondaryInterfacesExist )
155176 logger .Printf ("[SWIFTv2Middleware] pod %s has backend interface : %v" , podInfo .Name (), req .BackendInterfaceExist )
156177 // retrieve podinfo from orchestrator context
157- return podInfo , types .Success , ""
178+ return podInfo , types .Success , "" , defaultDenyACLbool
158179}
159180
160181// getIPConfig returns the pod's SWIFT V2 IP configuration.
0 commit comments