Skip to content

Commit 394c793

Browse files
Merge pull request #17087 from danwinship/fix-cross-build
Automatic merge from submit-queue. Fix cross build #17043 broke the cross build by depending on netlink from pkg/network/common. This fixes that (by just moving the new function since it wasn't needed outside of pkg/network/node anyway).
2 parents c4d53a2 + 6e33e20 commit 394c793

File tree

4 files changed

+47
-36
lines changed

4 files changed

+47
-36
lines changed

hack/import-restrictions.json

+13
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,19 @@
188188
]
189189
},
190190

191+
{
192+
"checkedPackages": [
193+
"github.com/openshift/origin/pkg/network/master",
194+
"github.com/openshift/origin/pkg/network/common"
195+
],
196+
"forbiddenImportPackageRoots": [
197+
"vendor/github.com/vishvananda/netlink"
198+
],
199+
"allowedImportPackageRoots": [
200+
""
201+
]
202+
},
203+
191204
{
192205
"checkedPackages": [
193206
"github.com/openshift/origin/pkg/network/apis/network",

pkg/network/common/common.go

-33
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ import (
2222
kapi "k8s.io/kubernetes/pkg/api"
2323
"k8s.io/kubernetes/pkg/apis/extensions"
2424
kinternalinformers "k8s.io/kubernetes/pkg/client/informers/informers_generated/internalversion"
25-
26-
"github.com/vishvananda/netlink"
2725
)
2826

2927
func HostSubnetToString(subnet *networkapi.HostSubnet) string {
@@ -280,34 +278,3 @@ func RegisterSharedInformerEventHandlers(kubeInformers kinternalinformers.Shared
280278
},
281279
})
282280
}
283-
284-
var (
285-
ErrorNetworkInterfaceNotFound = fmt.Errorf("could not find network interface")
286-
)
287-
288-
func GetLinkDetails(ip string) (netlink.Link, *net.IPNet, error) {
289-
links, err := netlink.LinkList()
290-
if err != nil {
291-
return nil, nil, err
292-
}
293-
294-
for _, link := range links {
295-
addrs, err := netlink.AddrList(link, netlink.FAMILY_V4)
296-
if err != nil {
297-
glog.Warningf("Could not get addresses of interface %q: %v", link.Attrs().Name, err)
298-
continue
299-
}
300-
301-
for _, addr := range addrs {
302-
if addr.IP.String() == ip {
303-
_, ipNet, err := net.ParseCIDR(addr.IPNet.String())
304-
if err != nil {
305-
return nil, nil, fmt.Errorf("could not parse CIDR network from address %q: %v", ip, err)
306-
}
307-
return link, ipNet, nil
308-
}
309-
}
310-
}
311-
312-
return nil, nil, ErrorNetworkInterfaceNotFound
313-
}

pkg/network/node/egressip.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func newEgressIPWatcher(localIP string, oc *ovsController) *egressIPWatcher {
7272

7373
func (eip *egressIPWatcher) Start(networkClient networkclient.Interface, iptables *NodeIPTables) error {
7474
var err error
75-
if eip.localEgressLink, eip.localEgressNet, err = common.GetLinkDetails(eip.localIP); err != nil {
75+
if eip.localEgressLink, eip.localEgressNet, err = GetLinkDetails(eip.localIP); err != nil {
7676
// Not expected, should already be caught by node.New()
7777
return err
7878
}

pkg/network/node/node.go

+33-2
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ func (c *OsdnNodeConfig) setNodeIP() error {
222222
}
223223
}
224224

225-
if _, _, err := common.GetLinkDetails(c.SelfIP); err != nil {
226-
if err == common.ErrorNetworkInterfaceNotFound {
225+
if _, _, err := GetLinkDetails(c.SelfIP); err != nil {
226+
if err == ErrorNetworkInterfaceNotFound {
227227
return fmt.Errorf("node IP %q is not a local/private address (hostname %q)", c.SelfIP, c.Hostname)
228228
} else {
229229
return err
@@ -233,6 +233,37 @@ func (c *OsdnNodeConfig) setNodeIP() error {
233233
return nil
234234
}
235235

236+
var (
237+
ErrorNetworkInterfaceNotFound = fmt.Errorf("could not find network interface")
238+
)
239+
240+
func GetLinkDetails(ip string) (netlink.Link, *net.IPNet, error) {
241+
links, err := netlink.LinkList()
242+
if err != nil {
243+
return nil, nil, err
244+
}
245+
246+
for _, link := range links {
247+
addrs, err := netlink.AddrList(link, netlink.FAMILY_V4)
248+
if err != nil {
249+
glog.Warningf("Could not get addresses of interface %q: %v", link.Attrs().Name, err)
250+
continue
251+
}
252+
253+
for _, addr := range addrs {
254+
if addr.IP.String() == ip {
255+
_, ipNet, err := net.ParseCIDR(addr.IPNet.String())
256+
if err != nil {
257+
return nil, nil, fmt.Errorf("could not parse CIDR network from address %q: %v", ip, err)
258+
}
259+
return link, ipNet, nil
260+
}
261+
}
262+
}
263+
264+
return nil, nil, ErrorNetworkInterfaceNotFound
265+
}
266+
236267
// Detect whether we are upgrading from a pre-CNI openshift and clean up
237268
// interfaces and iptables rules that are no longer required
238269
func (node *OsdnNode) dockerPreCNICleanup() error {

0 commit comments

Comments
 (0)