@@ -33,6 +33,8 @@ import (
3333type CNI interface {
3434 // Setup setup the network for the namespace
3535 Setup (ctx context.Context , id string , path string , opts ... NamespaceOpts ) (* Result , error )
36+ // SetupSerially sets up each of the network interfaces for the namespace in serial
37+ SetupSerially (ctx context.Context , id string , path string , opts ... NamespaceOpts ) (* Result , error )
3638 // Remove tears down the network of the namespace.
3739 Remove (ctx context.Context , id string , path string , opts ... NamespaceOpts ) error
3840 // Check checks if the network is still in desired state
@@ -165,6 +167,34 @@ func (c *libcni) Setup(ctx context.Context, id string, path string, opts ...Name
165167 return c .createResult (result )
166168}
167169
170+ // SetupSerially setups the network in the namespace and returns a Result
171+ func (c * libcni ) SetupSerially (ctx context.Context , id string , path string , opts ... NamespaceOpts ) (* Result , error ) {
172+ if err := c .Status (); err != nil {
173+ return nil , err
174+ }
175+ ns , err := newNamespace (id , path , opts ... )
176+ if err != nil {
177+ return nil , err
178+ }
179+ result , err := c .attachNetworksSerially (ctx , ns )
180+ if err != nil {
181+ return nil , err
182+ }
183+ return c .createResult (result )
184+ }
185+
186+ func (c * libcni ) attachNetworksSerially (ctx context.Context , ns * Namespace ) ([]* types100.Result , error ) {
187+ var results []* types100.Result
188+ for _ , network := range c .Networks () {
189+ r , err := network .Attach (ctx , ns )
190+ if err != nil {
191+ return nil , err
192+ }
193+ results = append (results , r )
194+ }
195+ return results , nil
196+ }
197+
168198type asynchAttachResult struct {
169199 index int
170200 res * types100.Result
0 commit comments