@@ -10,6 +10,7 @@ import (
1010 "github.com/Azure/azure-container-networking/cns/middlewares/utils"
1111 "github.com/Azure/azure-container-networking/cns/types"
1212 "github.com/Azure/azure-container-networking/crd/multitenancy/api/v1alpha1"
13+ "github.com/Azure/azure-container-networking/network/policy"
1314 "github.com/pkg/errors"
1415 v1 "k8s.io/api/core/v1"
1516 k8stypes "k8s.io/apimachinery/pkg/types"
@@ -40,7 +41,7 @@ var _ cns.IPConfigsHandlerMiddleware = (*K8sSWIFTv2Middleware)(nil)
4041// and release IP configs handlers.
4142func (k * K8sSWIFTv2Middleware ) IPConfigsRequestHandlerWrapper (defaultHandler , failureHandler cns.IPConfigsHandlerFunc ) cns.IPConfigsHandlerFunc {
4243 return func (ctx context.Context , req cns.IPConfigsRequest ) (* cns.IPConfigsResponse , error ) {
43- podInfo , respCode , message , defaultDenyACLbool := k .GetPodInfoForIPConfigsRequest (ctx , & req )
44+ podInfo , respCode , defaultDenyACLbool , message := k .GetPodInfoForIPConfigsRequest (ctx , & req )
4445
4546 logger .Printf ("defaultDenyACLbool value is: %v" , defaultDenyACLbool )
4647
@@ -61,12 +62,14 @@ func (k *K8sSWIFTv2Middleware) IPConfigsRequestHandlerWrapper(defaultHandler, fa
6162 // ipConfigsResp has infra IP configs -> if defaultDenyACLbool is enabled, add the default deny acl's pn the infra IP configs
6263 for i := range ipConfigsResp .PodIPInfo {
6364 ipInfo := & ipConfigsResp .PodIPInfo [i ]
65+ var defaultDenyEndpointPolicies []policy.Policy
6466 // there will be no pod connectivity to and from those pods
6567 if defaultDenyACLbool && ipInfo .NICType == cns .InfraNIC {
66- err = addDefaultDenyACL (ipInfo )
68+ defaultDenyEndpointPolicies , err = addDefaultDenyACL ()
6769 if err != nil {
6870 logger .Errorf ("failed to add default deny acl's for pod %v with err %v" , podInfo .Name (), err )
6971 }
72+ ipInfo .EndpointPolicies = append (ipInfo .EndpointPolicies , defaultDenyEndpointPolicies ... )
7073 break
7174 }
7275 }
@@ -118,21 +121,21 @@ func (k *K8sSWIFTv2Middleware) IPConfigsRequestHandlerWrapper(defaultHandler, fa
118121
119122// GetPodInfoForIPConfigsRequest validates if pod is multitenant by checking the pod labels, used in SWIFT V2 AKS scenario.
120123// nolint
121- func (k * K8sSWIFTv2Middleware ) GetPodInfoForIPConfigsRequest (ctx context.Context , req * cns.IPConfigsRequest ) (podInfo cns.PodInfo , respCode types.ResponseCode , message string , defaultDenyACL bool ) {
124+ func (k * K8sSWIFTv2Middleware ) GetPodInfoForIPConfigsRequest (ctx context.Context , req * cns.IPConfigsRequest ) (podInfo cns.PodInfo , respCode types.ResponseCode , defaultDenyACL bool , message string ) {
122125 defaultDenyACLbool := false
123126
124127 // Retrieve the pod from the cluster
125128 podInfo , err := cns .UnmarshalPodInfo (req .OrchestratorContext )
126129 if err != nil {
127130 errBuf := errors .Wrapf (err , "failed to unmarshalling pod info from ipconfigs request %+v" , req )
128- return nil , types .UnexpectedError , errBuf .Error (), defaultDenyACLbool
131+ return nil , types .UnexpectedError , defaultDenyACLbool , errBuf .Error ()
129132 }
130133 logger .Printf ("[SWIFTv2Middleware] validate ipconfigs request for pod %s" , podInfo .Name ())
131134 podNamespacedName := k8stypes.NamespacedName {Namespace : podInfo .Namespace (), Name : podInfo .Name ()}
132135 pod := v1.Pod {}
133136 if err := k .Cli .Get (ctx , podNamespacedName , & pod ); err != nil {
134137 errBuf := errors .Wrapf (err , "failed to get pod %+v" , podNamespacedName )
135- return nil , types .UnexpectedError , errBuf .Error (), defaultDenyACLbool
138+ return nil , types .UnexpectedError , defaultDenyACLbool , errBuf .Error ()
136139 }
137140
138141 // check the pod labels for Swift V2, set the request's SecondaryInterfaceSet flag to true and check if its MTPNC CRD is ready
@@ -144,11 +147,11 @@ func (k *K8sSWIFTv2Middleware) GetPodInfoForIPConfigsRequest(ctx context.Context
144147 mtpnc := v1alpha1.MultitenantPodNetworkConfig {}
145148 mtpncNamespacedName := k8stypes.NamespacedName {Namespace : podInfo .Namespace (), Name : podInfo .Name ()}
146149 if err := k .Cli .Get (ctx , mtpncNamespacedName , & mtpnc ); err != nil {
147- return nil , types .UnexpectedError , fmt .Errorf ("failed to get pod's mtpnc from cache : %w" , err ).Error (), defaultDenyACLbool
150+ return nil , types .UnexpectedError , defaultDenyACLbool , fmt .Errorf ("failed to get pod's mtpnc from cache : %w" , err ).Error ()
148151 }
149152 // Check if the MTPNC CRD is ready. If one of the fields is empty, return error
150153 if ! mtpnc .IsReady () {
151- return nil , types .UnexpectedError , errMTPNCNotReady .Error (), defaultDenyACLbool
154+ return nil , types .UnexpectedError , defaultDenyACLbool , errMTPNCNotReady .Error ()
152155 }
153156
154157 // copying defaultDenyACL bool from mtpnc
@@ -162,7 +165,7 @@ func (k *K8sSWIFTv2Middleware) GetPodInfoForIPConfigsRequest(ctx context.Context
162165 for _ , interfaceInfo := range interfaceInfos {
163166 if interfaceInfo .DeviceType == v1alpha1 .DeviceTypeInfiniBandNIC {
164167 if interfaceInfo .MacAddress == "" || interfaceInfo .NCID == "" {
165- return nil , types .UnexpectedError , errMTPNCNotReady .Error (), defaultDenyACLbool
168+ return nil , types .UnexpectedError , defaultDenyACLbool , errMTPNCNotReady .Error ()
166169 }
167170 req .BackendInterfaceExist = true
168171 req .BackendInterfaceMacAddresses = append (req .BackendInterfaceMacAddresses , interfaceInfo .MacAddress )
@@ -176,7 +179,7 @@ func (k *K8sSWIFTv2Middleware) GetPodInfoForIPConfigsRequest(ctx context.Context
176179 logger .Printf ("[SWIFTv2Middleware] pod %s has secondary interface : %v" , podInfo .Name (), req .SecondaryInterfacesExist )
177180 logger .Printf ("[SWIFTv2Middleware] pod %s has backend interface : %v" , podInfo .Name (), req .BackendInterfaceExist )
178181 // retrieve podinfo from orchestrator context
179- return podInfo , types .Success , "" , defaultDenyACLbool
182+ return podInfo , types .Success , defaultDenyACLbool , ""
180183}
181184
182185// getIPConfig returns the pod's SWIFT V2 IP configuration.
0 commit comments