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

[Windows] Fix the race condition in ifConfigurator #2253

Merged
merged 1 commit into from
Jun 9, 2021
Merged
Changes from all commits
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
27 changes: 6 additions & 21 deletions pkg/agent/cniserver/interface_configuration_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,13 @@ const (
type ifConfigurator struct {
hnsNetwork *hcsshim.HNSNetwork
epCache *sync.Map
ifCache *sync.Map
}

func newInterfaceConfigurator(ovsDatapathType ovsconfig.OVSDatapathType, isOvsHardwareOffloadEnabled bool) (*ifConfigurator, error) {
hnsNetwork, err := hcsshim.GetHNSNetworkByName(util.LocalHNSNetwork)
if err != nil {
return nil, err
}
eps, err := hcsshim.HNSListEndpointRequest()
if err != nil {
return nil, err
Expand All @@ -59,29 +62,15 @@ func newInterfaceConfigurator(ovsDatapathType ovsconfig.OVSDatapathType, isOvsHa
epCache.Store(hnsEP.Name, hnsEP)
}
return &ifConfigurator{
epCache: epCache,
hnsNetwork: hnsNetwork,
epCache: epCache,
}, nil

}

func (ic *ifConfigurator) addEndpoint(ep *hcsshim.HNSEndpoint) {
ic.epCache.Store(ep.Name, ep)
}

// ensureHNSNetwork checks if the target HNSNetwork is created on the node or not. If the HNSNetwork does not exit,
// return error.
func (ic *ifConfigurator) ensureHNSNetwork() error {
if ic.hnsNetwork != nil {
return nil
}
hnsNetwork, err := hcsshim.GetHNSNetworkByName(util.LocalHNSNetwork)
if err != nil {
return err
}
ic.hnsNetwork = hnsNetwork
return nil
}

func (ic *ifConfigurator) getEndpoint(name string) (*hcsshim.HNSEndpoint, bool) {
value, ok := ic.epCache.Load(name)
if !ok {
Expand Down Expand Up @@ -171,10 +160,6 @@ func (ic *ifConfigurator) configureContainerLink(

// createContainerLink creates HNSEndpoint using the IP configuration in the IPAM result.
func (ic *ifConfigurator) createContainerLink(endpointName string, result *current.Result, containerID, podName, podNamespace string) (hostLink *hcsshim.HNSEndpoint, err error) {
// Create a new Endpoint if not found.
if err := ic.ensureHNSNetwork(); err != nil {
return nil, err
}
containerIP, err := findContainerIPConfig(result.IPs)
if err != nil {
return nil, err
Expand Down