Skip to content

Commit

Permalink
fix: fixing HNS network already exist error in Stateless CNI
Browse files Browse the repository at this point in the history
  • Loading branch information
behzad-mir committed Jan 2, 2025
1 parent 4f312cf commit bdaa36f
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions network/network_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,20 @@ func (nm *networkManager) newNetworkImplHnsV2(nwInfo *EndpointInfo, extIf *exter
if errors.As(err, &hcn.NetworkNotFoundError{}) {
logger.Info("Creating hcn network", zap.Any("hcnNetwork", hcnNetwork))
hnsResponse, err = Hnsv2.CreateNetwork(hcnNetwork)
if err != nil {
return nil, fmt.Errorf("Failed to create hcn network: %s due to error: %v", hcnNetwork.Name, err)
if err == nil {
logger.Info("Successfully created hcn network with response", zap.Any("hnsResponse", hnsResponse))
} else {
if strings.Contains(err.Error(), "already exists") {
// fetch the network name again since the paralel CNI Add call has created the HNS network

Check failure on line 367 in network/network_windows.go

View workflow job for this annotation

GitHub Actions / Lint (1.22.x, windows-latest)

`paralel` is a misspelling of `parallel` (misspell)

Check failure on line 367 in network/network_windows.go

View workflow job for this annotation

GitHub Actions / Lint (1.23.x, windows-latest)

`paralel` is a misspelling of `parallel` (misspell)
hnsResponse, err = Hnsv2.GetNetworkByName(hcnNetwork.Name)
if err != nil {
return nil, fmt.Errorf("Failed to get hcn network: %s due to error: %v", hcnNetwork.Name, err)

Check failure on line 370 in network/network_windows.go

View workflow job for this annotation

GitHub Actions / Lint (1.22.x, windows-latest)

do not define dynamic errors, use wrapped static errors instead: "fmt.Errorf(\"Failed to get hcn network: %s due to error: %v\", hcnNetwork.Name, err)" (err113)

Check failure on line 370 in network/network_windows.go

View workflow job for this annotation

GitHub Actions / Lint (1.23.x, windows-latest)

do not define dynamic errors, use wrapped static errors instead: "fmt.Errorf(\"Failed to get hcn network: %s due to error: %v\", hcnNetwork.Name, err)" (err113)
}
logger.Info("Successfully fetched hcn network with response", zap.Any("hnsResponse", hnsResponse))
} else {
return nil, fmt.Errorf("Failed to create hcn network: %s due to error: %v", hcnNetwork.Name, err)

Check failure on line 374 in network/network_windows.go

View workflow job for this annotation

GitHub Actions / Lint (1.22.x, windows-latest)

do not define dynamic errors, use wrapped static errors instead: "fmt.Errorf(\"Failed to create hcn network: %s due to error: %v\", hcnNetwork.Name, err)" (err113)

Check failure on line 374 in network/network_windows.go

View workflow job for this annotation

GitHub Actions / Lint (1.23.x, windows-latest)

do not define dynamic errors, use wrapped static errors instead: "fmt.Errorf(\"Failed to create hcn network: %s due to error: %v\", hcnNetwork.Name, err)" (err113)
}
}
logger.Info("Successfully created hcn network with response", zap.Any("hnsResponse", hnsResponse))
} else {
// we can't validate if the network already exists, don't continue
return nil, fmt.Errorf("Failed to create hcn network: %s, failed to query for existing network with error: %v", hcnNetwork.Name, err)
Expand Down

0 comments on commit bdaa36f

Please sign in to comment.