@@ -20,9 +20,8 @@ import (
2020)
2121
2222var (
23- errEmtpyHostSubnetPrefix = errors .New ("empty host subnet prefix not allowed" )
24- errEmptyCNIArgs = errors .New ("empty CNI cmd args not allowed" )
25- errInvalidArgs = errors .New ("invalid arg(s)" )
23+ errEmptyCNIArgs = errors .New ("empty CNI cmd args not allowed" )
24+ errInvalidArgs = errors .New ("invalid arg(s)" )
2625)
2726
2827type CNSIPAMInvoker struct {
@@ -100,7 +99,7 @@ func (invoker *CNSIPAMInvoker) Add(addConfig IPAMAddConfig) (IPAMAddResult, erro
10099 log .Printf ("[cni-invoker-cns] Received info %+v for pod %v" , info , podInfo )
101100
102101 ncgw := net .ParseIP (info .ncGatewayIPAddress )
103- if ncgw == nil {
102+ if ncgw == nil && invoker . ipamMode != util . V4Overlay {
104103 return IPAMAddResult {}, errors .Wrap (errInvalidArgs , "%w: Gateway address " + info .ncGatewayIPAddress + " from response is invalid" )
105104 }
106105
@@ -133,29 +132,26 @@ func (invoker *CNSIPAMInvoker) Add(addConfig IPAMAddConfig) (IPAMAddResult, erro
133132 },
134133 }
135134
135+ // get the name of the primary IP address
136+ _ , hostIPNet , err := net .ParseCIDR (info .hostSubnet )
137+ if err != nil {
138+ return IPAMAddResult {}, fmt .Errorf ("unable to parse hostSubnet: %w" , err )
139+ }
140+
141+ addResult .hostSubnetPrefix = * hostIPNet
142+
136143 // set subnet prefix for host vm
137144 // setHostOptions will execute if IPAM mode is not v4 overlay
138145 if invoker .ipamMode != util .V4Overlay {
139- if err := setHostOptions (& addResult . hostSubnetPrefix , ncipnet , addConfig .options , & info ); err != nil {
146+ if err := setHostOptions (ncipnet , addConfig .options , & info ); err != nil {
140147 return IPAMAddResult {}, err
141148 }
142149 }
143150
144151 return addResult , nil
145152}
146153
147- func setHostOptions (hostSubnetPrefix , ncSubnetPrefix * net.IPNet , options map [string ]interface {}, info * IPv4ResultInfo ) error {
148- // get the name of the primary IP address
149- _ , hostIPNet , err := net .ParseCIDR (info .hostSubnet )
150- if err != nil {
151- return err
152- }
153-
154- if hostSubnetPrefix == nil {
155- return errEmtpyHostSubnetPrefix
156- }
157-
158- * hostSubnetPrefix = * hostIPNet
154+ func setHostOptions (ncSubnetPrefix * net.IPNet , options map [string ]interface {}, info * IPv4ResultInfo ) error {
159155
160156 // get the host ip
161157 hostIP := net .ParseIP (info .hostPrimaryIP )
0 commit comments