Skip to content

Commit

Permalink
Allow egress-router to connect to cluster service network for DNS, etc.
Browse files Browse the repository at this point in the history
openshift#19885 allows egress routers to
connect to the node IP but when openshift node is configured to use
service network IP as DNS IP then egress router pod will not be able
to resolve DNS requests. This change will address this issue.
  • Loading branch information
Ravi Sankar Penta committed Jun 25, 2018
1 parent d7c2dc7 commit d7c576b
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 10 deletions.
5 changes: 3 additions & 2 deletions pkg/network/node/cniserver/cniserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,14 @@ const CNIServerRunDir string = "/var/run/openshift-sdn"
const CNIServerSocketName string = "cni-server.sock"
const CNIServerSocketPath string = CNIServerRunDir + "/" + CNIServerSocketName

// Config file containing MTU, and default full path
// Config file contains server to plugin config data
const CNIServerConfigFileName string = "config.json"
const CNIServerConfigFilePath string = CNIServerRunDir + "/" + CNIServerConfigFileName

// Server-to-plugin config data
type Config struct {
MTU uint32 `json:"mtu"`
MTU uint32 `json:"mtu"`
ServiceNetworkCIDR string `json:"serviceNetworkCIDR"`
}

// Explicit type for CNI commands the server handles
Expand Down
2 changes: 1 addition & 1 deletion pkg/network/node/cniserver/cniserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestCNIServer(t *testing.T) {
defer os.RemoveAll(tmpDir)
socketPath := filepath.Join(tmpDir, CNIServerSocketName)

s := NewCNIServer(tmpDir, &Config{MTU: 1500})
s := NewCNIServer(tmpDir, &Config{MTU: 1500, ServiceNetworkCIDR: "172.30.0.0/16"})
if err := s.Start(serverHandleCNI); err != nil {
t.Fatalf("error starting CNI server: %v", err)
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/network/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,8 @@ func (node *OsdnNode) Start() error {
}

glog.V(2).Infof("Starting openshift-sdn pod manager")
if err := node.podManager.Start(cniserver.CNIServerRunDir, node.localSubnetCIDR, node.networkInfo.ClusterNetworks); err != nil {
if err := node.podManager.Start(cniserver.CNIServerRunDir, node.localSubnetCIDR,
node.networkInfo.ClusterNetworks, node.networkInfo.ServiceNetwork.String()); err != nil {
return err
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/network/node/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func getIPAMConfig(clusterNetworks []common.ClusterNetwork, localSubnet string)
}

// Start the CNI server and start processing requests from it
func (m *podManager) Start(rundir string, localSubnetCIDR string, clusterNetworks []common.ClusterNetwork) error {
func (m *podManager) Start(rundir string, localSubnetCIDR string, clusterNetworks []common.ClusterNetwork, serviceNetworkCIDR string) error {
if m.enableHostports {
iptInterface := utiliptables.New(utilexec.New(), utildbus.New(), utiliptables.ProtocolIpv4)
m.hostportSyncer = kubehostport.NewHostportSyncer(iptInterface)
Expand All @@ -181,7 +181,7 @@ func (m *podManager) Start(rundir string, localSubnetCIDR string, clusterNetwork

go m.processCNIRequests()

m.cniServer = cniserver.NewCNIServer(rundir, &cniserver.Config{MTU: m.mtu})
m.cniServer = cniserver.NewCNIServer(rundir, &cniserver.Config{MTU: m.mtu, ServiceNetworkCIDR: serviceNetworkCIDR})
return m.cniServer.Start(m.handleCNIRequest)
}

Expand Down
18 changes: 15 additions & 3 deletions pkg/network/sdn-cni-plugin/openshift-sdn.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,23 @@ func (p *cniPlugin) CmdAdd(args *skel.CmdArgs) error {
},
Gw: defaultGW,
}
err = netlink.RouteAdd(route)
if err != nil {
return fmt.Errorf("failed to configure macvlan device: %v", err)
if err := netlink.RouteAdd(route); err != nil {
return fmt.Errorf("failed to add route to node IP: %v", err)
}
}

// Add a route to service network via SDN
_, serviceIPNet, err := net.ParseCIDR(config.ServiceNetworkCIDR)
if err != nil {
return fmt.Errorf("failed to parse ServiceNetworkCIDR: %v", err)
}
route := &netlink.Route{
Dst: serviceIPNet,
Gw: defaultGW,
}
if err := netlink.RouteAdd(route); err != nil {
return fmt.Errorf("failed to add route to service network: %v", err)
}
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/network/sdn-cni-plugin/sdn_cni_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func TestOpenshiftSdnCNIPlugin(t *testing.T) {
defer os.RemoveAll(tmpDir)

path := filepath.Join(tmpDir, cniserver.CNIServerSocketName)
server := cniserver.NewCNIServer(tmpDir, &cniserver.Config{MTU: 1500})
server := cniserver.NewCNIServer(tmpDir, &cniserver.Config{MTU: 1500, ServiceNetworkCIDR: "172.30.0.0/16"})
if err := server.Start(serverHandleCNI); err != nil {
t.Fatalf("error starting CNI server: %v", err)
}
Expand Down

0 comments on commit d7c576b

Please sign in to comment.