Skip to content

Conversation

@aegal
Copy link
Contributor

@aegal aegal commented Mar 23, 2022

Reason for Change:

Issue Fixed:

Requirements:

Notes:

return network.GetHCNObj(), nil
}
return &hcn.HostComputeNetwork{}, nil
return nil, hcn.NetworkNotFoundError{}
Copy link
Member

Choose a reason for hiding this comment

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

just make sure cni code doesn't dereference pointer without checking for error

Copy link
Contributor Author

@aegal aegal Apr 9, 2022

Choose a reason for hiding this comment

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

this is the hns mock wrapper and only used by test code, no real cni code uses this type so there's no concerns.

log.Printf("[net] Creating hcn network: %+v", hcnNetwork)
hnsResponse, err := hnsv2.CreateNetwork(hcnNetwork)
// check if network exists, only create the network does not exist
hnsResponse, err := hnsv2.GetNetworkByName(hcnNetwork.Name)
Copy link
Member

Choose a reason for hiding this comment

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

can you also log if network exists

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, added it when err is empty

return nil, fmt.Errorf("Failed to create hcn network: %s due to error: %v", hcnNetwork.Name, err)
}
// if network not found, create the HNS network.
if errors.As(err, &hcn.NetworkNotFoundError{}) {
Copy link
Member

Choose a reason for hiding this comment

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

can you add ut for testing these cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added

@aegal aegal requested a review from tamilmani1989 April 9, 2022 15:34
Copy link
Member

@tamilmani1989 tamilmani1989 left a comment

Choose a reason for hiding this comment

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

lgtm 🚢

@aegal
Copy link
Contributor Author

aegal commented Apr 12, 2022

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@aegal
Copy link
Contributor Author

aegal commented Apr 14, 2022

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@aegal aegal changed the title skip if network already exists Skip network creation if network already exists in HNS Apr 14, 2022
@aegal aegal merged commit 2157d7a into master Apr 14, 2022
@aegal aegal deleted the skipNetworkIfFound branch April 14, 2022 20:41
matmerr pushed a commit to matmerr/azure-container-networking that referenced this pull request Jun 29, 2022
* skip network creation if network already exists

* address comments

* address feedback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants