Skip to content

Commit

Permalink
Fix broken calico support
Browse files Browse the repository at this point in the history
  • Loading branch information
jellonek committed Nov 17, 2017
1 parent af56429 commit 434387f
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions pkg/tapmanager/tapfdsource.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,27 @@ func (s *TapFDSource) GetFDs(key string, data []byte) ([]int, []byte, error) {
if netConfig == nil {
netConfig = &cnicurrent.Result{}
}
// Calico needs network config to be adjusted for DHCP compatibility
if s.dummyGateway != nil {
if len(netConfig.IPs) != 1 {
return nil, nil, errors.New("didn't expect more than one IP config")
}
if netConfig.IPs[0].Version != "4" {
return nil, nil, errors.New("IPv4 config was expected")
}
netConfig.IPs[0].Address.Mask = netmaskForCalico()
netConfig.IPs[0].Gateway = s.dummyGateway
netConfig.Routes = []*cnitypes.Route{
{
Dst: net.IPNet{
IP: net.IP{0, 0, 0, 0},
Mask: net.IPMask{0, 0, 0, 0},
},
GW: s.dummyGateway,
},
}
}

if err := nettools.ValidateAndfixCNIResult(netConfig, pnd.PodNs); err != nil {
return nil, nil, fmt.Errorf("error in fixing cni configuration: %v", err)
}
Expand All @@ -172,27 +193,6 @@ func (s *TapFDSource) GetFDs(key string, data []byte) ([]int, []byte, error) {

netConfig := payload.CNIConfig

// Calico needs network config to be adjusted for DHCP compatibility
if s.dummyGateway != nil {
if len(netConfig.IPs) != 1 {
return nil, nil, errors.New("didn't expect more than one IP config")
}
if netConfig.IPs[0].Version != "4" {
return nil, nil, errors.New("IPv4 config was expected")
}
netConfig.IPs[0].Address.Mask = netmaskForCalico()
netConfig.IPs[0].Gateway = s.dummyGateway
netConfig.Routes = []*cnitypes.Route{
{
Dst: net.IPNet{
IP: net.IP{0, 0, 0, 0},
Mask: net.IPMask{0, 0, 0, 0},
},
GW: s.dummyGateway,
},
}
}

netNSPath := cni.PodNetNSPath(pnd.PodId)
vmNS, err := ns.GetNS(netNSPath)
if err != nil {
Expand Down

0 comments on commit 434387f

Please sign in to comment.