Skip to content

Commit 3660c88

Browse files
committed
updated code
1 parent cc8a751 commit 3660c88

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

cni/network/network.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -588,12 +588,8 @@ func (plugin *NetPlugin) Add(args *cniSkel.CmdArgs) error {
588588
// TODO: This proably needs to be changed as we return all interfaces...
589589
// sendEvent(plugin, fmt.Sprintf("Allocated IPAddress from ipam DefaultInterface: %+v, SecondaryInterfaces: %+v", ipamAddResult.interfaceInfo[ifIndex], ipamAddResult.interfaceInfo))
590590
}
591-
var swiftv2DefaultDenyACL []cni.KVPair = []cni.KVPair{}
592-
if len(ipamAddResult.defaultDenyACL) > 0 {
593-
swiftv2DefaultDenyACL = append(swiftv2DefaultDenyACL, ipamAddResult.defaultDenyACL...)
594-
}
595591

596-
nwCfg.AdditionalArgs = append(nwCfg.AdditionalArgs, swiftv2DefaultDenyACL...)
592+
nwCfg.AdditionalArgs = append(nwCfg.AdditionalArgs, ipamAddResult.defaultDenyACL...)
597593
policies := cni.GetPoliciesFromNwCfg(nwCfg.AdditionalArgs)
598594

599595
// moved to addIpamInvoker

cns/middlewares/k8sSwiftV2.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,24 @@ func (k *K8sSWIFTv2Middleware) IPConfigsRequestHandlerWrapper(defaultHandler, fa
5151
}, errors.New("failed to validate IP configs request")
5252
}
5353
ipConfigsResp, err := defaultHandler(ctx, req)
54+
5455
// If the pod is not v2, return the response from the handler
5556
if !req.SecondaryInterfacesExist {
5657
return ipConfigsResp, err
5758
}
59+
60+
// ipConfigsResp has infra IP configs -> if defaultDenyACLbool is enabled, add the default deny acl's pn the infra IP configs
61+
for i := range ipConfigsResp.PodIPInfo {
62+
ipInfo := &ipConfigsResp.PodIPInfo[i]
63+
// there will be no pod connectivity to and from those pods
64+
if defaultDenyACLbool {
65+
err := addDefaultDenyACL(ipInfo)
66+
if err != nil {
67+
errors.Wrapf(err, "failed to add default deny acl's for pod %s", podInfo.Name())
68+
}
69+
}
70+
}
71+
5872
// If the pod is v2, get the infra IP configs from the handler first and then add the SWIFTv2 IP config
5973
defer func() {
6074
// Release the default IP config if there is an error
@@ -82,12 +96,6 @@ func (k *K8sSWIFTv2Middleware) IPConfigsRequestHandlerWrapper(defaultHandler, fa
8296
// Set routes for the pod
8397
for i := range ipConfigsResp.PodIPInfo {
8498
ipInfo := &ipConfigsResp.PodIPInfo[i]
85-
if defaultDenyACLbool {
86-
err := addDefaultDenyACL(ipInfo)
87-
if err != nil {
88-
errors.Wrapf(err, "failed to add default deny acl's for pod %s", podInfo.Name())
89-
}
90-
}
9199
// Backend nics doesn't need routes to be set
92100
if ipInfo.NICType != cns.BackendNIC {
93101
err = k.setRoutes(ipInfo)
@@ -141,7 +149,10 @@ func (k *K8sSWIFTv2Middleware) validateIPConfigsRequest(ctx context.Context, req
141149
if !mtpnc.IsReady() {
142150
return nil, types.UnexpectedError, errMTPNCNotReady.Error(), defaultDenyACLbool
143151
}
152+
153+
// setting defaultDenyACLbool from mtpnc
144154
defaultDenyACLbool = mtpnc.Status.DefaultDenyACL
155+
145156
// If primary Ip is set in status field, it indicates the presence of secondary interfaces
146157
if mtpnc.Status.PrimaryIP != "" {
147158
req.SecondaryInterfacesExist = true

0 commit comments

Comments
 (0)