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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

behzad-mir
Copy link
Contributor

Reason for Change:
This PR fix an issue in stateless CNI where the "HNS network already exists" error was not being handled correctly.
Since Stateless CNI add calls work in parallel, it is possible that two add process make API calls to create HNS netwrok at the same time and one of them fails since the other one successfully created the network (HNS process calls sequentially). In that case the second process should not exit in error and instead fetch the HNS network that was created by the first process and continue with the add call.

Notes:

@behzad-mir behzad-mir added the cni Related to CNI. label Jan 2, 2025
@behzad-mir behzad-mir requested a review from a team as a code owner January 2, 2025 23:03
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

if err != nil {
return nil, fmt.Errorf("Failed to get hcn network: %s due to error: %v", hcnNetwork.Name, err)
}
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

@behzad-mir behzad-mir force-pushed the behzad-HNSNetwork branch 5 times, most recently from 945e04f to 22e2cc8 Compare January 3, 2025 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cni Related to CNI.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants