From 434387fd088a2083678580a8ec71cb6e4109b07e Mon Sep 17 00:00:00 2001 From: Piotr Skamruk Date: Fri, 17 Nov 2017 12:38:13 +0100 Subject: [PATCH] Fix broken calico support --- pkg/tapmanager/tapfdsource.go | 42 +++++++++++++++++------------------ 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/pkg/tapmanager/tapfdsource.go b/pkg/tapmanager/tapfdsource.go index 4df606495..4d4aeaa9b 100644 --- a/pkg/tapmanager/tapfdsource.go +++ b/pkg/tapmanager/tapfdsource.go @@ -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) } @@ -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 {