()
| 182 | } |
| 183 | |
| 184 | func (c *LocalCluster) createNetwork() error { |
| 185 | c.net.name = c.conf.prefix + "-net" |
| 186 | |
| 187 | ctx, cancel := context.WithTimeout(context.Background(), requestTimeout) |
| 188 | defer cancel() |
| 189 | |
| 190 | // Check if network already exists |
| 191 | existingNet, err := c.dcli.NetworkInspect(ctx, c.net.name, network.InspectOptions{}) |
| 192 | if err == nil { |
| 193 | // Network exists, reuse it |
| 194 | log.Printf("[INFO] reusing existing network %s (ID: %s)", c.net.name, existingNet.ID) |
| 195 | c.net.id = existingNet.ID |
| 196 | return nil |
| 197 | } |
| 198 | |
| 199 | // Network doesn't exist, create it |
| 200 | opts := network.CreateOptions{ |
| 201 | Driver: "bridge", |
| 202 | IPAM: &network.IPAM{Driver: "default"}, |
| 203 | } |
| 204 | |
| 205 | networkResp, err := c.dcli.NetworkCreate(ctx, c.net.name, opts) |
| 206 | if err != nil { |
| 207 | // If network already exists (race condition), try to inspect and reuse it |
| 208 | if strings.Contains(err.Error(), "already exists") { |
| 209 | log.Printf("[INFO] network %s already exists (race condition), inspecting", c.net.name) |
| 210 | existingNet, inspectErr := c.dcli.NetworkInspect(ctx, c.net.name, network.InspectOptions{}) |
| 211 | if inspectErr == nil { |
| 212 | log.Printf("[INFO] reusing existing network %s (ID: %s)", c.net.name, existingNet.ID) |
| 213 | c.net.id = existingNet.ID |
| 214 | return nil |
| 215 | } |
| 216 | // If inspect also fails, return original create error |
| 217 | log.Printf("[WARNING] failed to inspect network after creation conflict: %v", inspectErr) |
| 218 | } |
| 219 | return errors.Wrap(err, "error creating network") |
| 220 | } |
| 221 | c.net.id = networkResp.ID |
| 222 | |
| 223 | return nil |
| 224 | } |
| 225 | |
| 226 | func (c *LocalCluster) createVolume(name string) error { |
| 227 | ctx, cancel := context.WithTimeout(context.Background(), requestTimeout) |
no test coverage detected