@@ -61,8 +61,7 @@ func (plugin *ipamPlugin) Start(config *common.PluginConfig) error {
6161 }
6262
6363 // Initialize address manager.
64- environment := plugin .GetOption (common .OptEnvironmentKey )
65- err = plugin .am .Initialize (config , environment )
64+ err = plugin .am .Initialize (config , plugin .Options )
6665 if err != nil {
6766 log .Printf ("[ipam] Failed to initialize address manager, err:%v." , err )
6867 return err
@@ -138,12 +137,7 @@ func (plugin *ipamPlugin) Add(args *cniSkel.CmdArgs) error {
138137 IP4 : & cniTypes.IPConfig {IP : * cidr },
139138 }
140139
141- // Output response.
142- if nwCfg .Ipam .Result == "" {
143- result .Print ()
144- } else {
145- args .Args = result .String ()
146- }
140+ result .Print ()
147141
148142 log .Printf ("[ipam] ADD succeeded with output %+v." , result )
149143
@@ -164,69 +158,6 @@ func (plugin *ipamPlugin) Delete(args *cniSkel.CmdArgs) error {
164158
165159 log .Printf ("[ipam] Read network configuration %+v." , nwCfg )
166160
167- // Process command.
168- result , err := plugin .DeleteImpl (args , nwCfg )
169- if err != nil {
170- log .Printf ("[ipam] Failed to process command: %v." , err )
171- return nil
172- }
173-
174- // Output response.
175- if result != nil {
176- result .Print ()
177- }
178-
179- log .Printf ("[ipam] DEL succeeded with output %+v." , result )
180-
181- return err
182- }
183-
184- // AddImpl handles CNI add commands.
185- func (plugin * ipamPlugin ) AddImpl (args * cniSkel.CmdArgs , nwCfg * cni.NetworkConfig ) (* cniTypes.Result , error ) {
186- // Assume default address space if not specified.
187- if nwCfg .Ipam .AddrSpace == "" {
188- nwCfg .Ipam .AddrSpace = defaultAddressSpaceId
189- }
190-
191- // Check if an address pool is specified.
192- if nwCfg .Ipam .Subnet == "" {
193- // Allocate an address pool.
194- poolId , subnet , err := plugin .am .RequestPool (nwCfg .Ipam .AddrSpace , "" , "" , nil , false )
195- if err != nil {
196- log .Printf ("[ipam] Failed to allocate pool, err:%v." , err )
197- return nil , err
198- }
199-
200- nwCfg .Ipam .Subnet = subnet
201- log .Printf ("[ipam] Allocated address poolId %v with subnet %v." , poolId , subnet )
202- }
203-
204- // Allocate an address for the endpoint.
205- address , err := plugin .am .RequestAddress (nwCfg .Ipam .AddrSpace , nwCfg .Ipam .Subnet , nwCfg .Ipam .Address , nil )
206- if err != nil {
207- log .Printf ("[ipam] Failed to allocate address, err:%v." , err )
208- return nil , err
209- }
210-
211- log .Printf ("[ipam] Allocated address %v." , address )
212-
213- // Output the result.
214- ip , cidr , err := net .ParseCIDR (address )
215- cidr .IP = ip
216- if err != nil {
217- log .Printf ("[ipam] Failed to parse address, err:%v." , err )
218- return nil , err
219- }
220-
221- result := & cniTypes.Result {
222- IP4 : & cniTypes.IPConfig {IP : * cidr },
223- }
224-
225- return result , nil
226- }
227-
228- // DeleteImpl handles CNI delete commands.
229- func (plugin * ipamPlugin ) DeleteImpl (args * cniSkel.CmdArgs , nwCfg * cni.NetworkConfig ) (* cniTypes.Result , error ) {
230161 // Assume default address space if not specified.
231162 if nwCfg .Ipam .AddrSpace == "" {
232163 nwCfg .Ipam .AddrSpace = defaultAddressSpaceId
@@ -238,16 +169,18 @@ func (plugin *ipamPlugin) DeleteImpl(args *cniSkel.CmdArgs, nwCfg *cni.NetworkCo
238169 err := plugin .am .ReleaseAddress (nwCfg .Ipam .AddrSpace , nwCfg .Ipam .Subnet , nwCfg .Ipam .Address )
239170 if err != nil {
240171 log .Printf ("[cni] Failed to release address, err:%v." , err )
241- return nil , err
172+ return nil
242173 }
243174 } else {
244175 // Release the pool.
245176 err := plugin .am .ReleasePool (nwCfg .Ipam .AddrSpace , nwCfg .Ipam .Subnet )
246177 if err != nil {
247178 log .Printf ("[cni] Failed to release pool, err:%v." , err )
248- return nil , err
179+ return nil
249180 }
250181 }
251182
252- return nil , nil
183+ log .Printf ("[ipam] DEL succeeded." )
184+
185+ return err
253186}
0 commit comments