@@ -144,7 +144,10 @@ func (bd *bridgeDriver) setBridgeName(net *netutil.NetworkConfig, bridgeName str
144
144
return fmt .Errorf ("bridge name %s already in use by network %s" , bridgeName , bridgeNet .Name )
145
145
}
146
146
147
- configFilename := bd .getConfigPathForNetworkName (net .Name )
147
+ configFilename , err := bd .getConfigPathForNetworkName (net .Name )
148
+ if err != nil {
149
+ return err
150
+ }
148
151
netMap , bridgePlugin , err := bd .parseBridgeConfig (configFilename )
149
152
if err != nil {
150
153
return err
@@ -180,7 +183,10 @@ func (bd *bridgeDriver) setBridgeName(net *netutil.NetworkConfig, bridgeName str
180
183
func (bd * bridgeDriver ) getBridgeName (net * netutil.NetworkConfig ) (string , error ) {
181
184
var bridgeName string
182
185
err := lockutil .WithDirLock (bd .getDirForNetworkName ("" ), func () error {
183
- configFilename := bd .getConfigPathForNetworkName (net .Name )
186
+ configFilename , err := bd .getConfigPathForNetworkName (net .Name )
187
+ if err != nil {
188
+ return err
189
+ }
184
190
_ , bridgePlugin , err := bd .parseBridgeConfig (configFilename )
185
191
if err != nil {
186
192
return err
@@ -311,6 +317,21 @@ func (bd *bridgeDriver) getDirForNetworkName(netName string) string {
311
317
}
312
318
313
319
// From https://github.com/containerd/nerdctl/blob/v2.0.0/pkg/netutil/netutil.go#L277C18-L283
314
- func (bd * bridgeDriver ) getConfigPathForNetworkName (netName string ) string {
315
- return filepath .Join (bd .getDirForNetworkName (netName ), "nerdctl-" + netName + ".conflist" )
320
+ // getConfigPathForNetworkName returns the path to the network config file.
321
+ func (bd * bridgeDriver ) getConfigPathForNetworkName (netName string ) (string , error ) {
322
+ namespacedPath := filepath .Join (bd .getDirForNetworkName (netName ), "nerdctl-" + netName + ".conflist" )
323
+ if _ , err := os .Stat (namespacedPath ); err == nil {
324
+ return namespacedPath , nil
325
+ }
326
+
327
+ // For backward compatibility, try the legacy non-namespaced path.
328
+ // Prior to nerdctl v2.0.0, namespaced networks were placed in the default network config dir.
329
+ legacyPath := filepath .Join (bd .netClient .NetconfPath (), "nerdctl-" + netName + ".conflist" )
330
+ if _ , err := os .Stat (legacyPath ); err == nil {
331
+ return legacyPath , nil
332
+ }
333
+
334
+ // If neither exists, return the namespaced path as the default
335
+ // This will be used for creating new config files
336
+ return "" , fmt .Errorf ("network config file not found for network %s" , netName )
316
337
}
0 commit comments