Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixing HNS network already exist error in Stateless CNI #3297

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 parallel CNI Add call has created the HNS network
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets add a log printing err.Error() before calling get hns network

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

hnsResponse, err = Hnsv2.GetNetworkByName(hcnNetwork.Name)
tamilmani1989 marked this conversation as resolved.
Show resolved Hide resolved
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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since you are logging whole struct, lets make sure its not printing any byte array

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Printed hnsreponse.ID instead in new commit

} 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
Loading