Skip to content

Commit d7c576b

Browse files
author
Ravi Sankar Penta
committed
Allow egress-router to connect to cluster service network for DNS, etc.
#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.
1 parent d7c2dc7 commit d7c576b

File tree

6 files changed

+24
-10
lines changed

6 files changed

+24
-10
lines changed

pkg/network/node/cniserver/cniserver.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,14 @@ const CNIServerRunDir string = "/var/run/openshift-sdn"
5151
const CNIServerSocketName string = "cni-server.sock"
5252
const CNIServerSocketPath string = CNIServerRunDir + "/" + CNIServerSocketName
5353

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

5858
// Server-to-plugin config data
5959
type Config struct {
60-
MTU uint32 `json:"mtu"`
60+
MTU uint32 `json:"mtu"`
61+
ServiceNetworkCIDR string `json:"serviceNetworkCIDR"`
6162
}
6263

6364
// Explicit type for CNI commands the server handles

pkg/network/node/cniserver/cniserver_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func TestCNIServer(t *testing.T) {
6262
defer os.RemoveAll(tmpDir)
6363
socketPath := filepath.Join(tmpDir, CNIServerSocketName)
6464

65-
s := NewCNIServer(tmpDir, &Config{MTU: 1500})
65+
s := NewCNIServer(tmpDir, &Config{MTU: 1500, ServiceNetworkCIDR: "172.30.0.0/16"})
6666
if err := s.Start(serverHandleCNI); err != nil {
6767
t.Fatalf("error starting CNI server: %v", err)
6868
}

pkg/network/node/node.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,8 @@ func (node *OsdnNode) Start() error {
349349
}
350350

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

pkg/network/node/pod.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ func getIPAMConfig(clusterNetworks []common.ClusterNetwork, localSubnet string)
168168
}
169169

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

182182
go m.processCNIRequests()
183183

184-
m.cniServer = cniserver.NewCNIServer(rundir, &cniserver.Config{MTU: m.mtu})
184+
m.cniServer = cniserver.NewCNIServer(rundir, &cniserver.Config{MTU: m.mtu, ServiceNetworkCIDR: serviceNetworkCIDR})
185185
return m.cniServer.Start(m.handleCNIRequest)
186186
}
187187

pkg/network/sdn-cni-plugin/openshift-sdn.go

+15-3
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,23 @@ func (p *cniPlugin) CmdAdd(args *skel.CmdArgs) error {
213213
},
214214
Gw: defaultGW,
215215
}
216-
err = netlink.RouteAdd(route)
217-
if err != nil {
218-
return fmt.Errorf("failed to configure macvlan device: %v", err)
216+
if err := netlink.RouteAdd(route); err != nil {
217+
return fmt.Errorf("failed to add route to node IP: %v", err)
219218
}
220219
}
220+
221+
// Add a route to service network via SDN
222+
_, serviceIPNet, err := net.ParseCIDR(config.ServiceNetworkCIDR)
223+
if err != nil {
224+
return fmt.Errorf("failed to parse ServiceNetworkCIDR: %v", err)
225+
}
226+
route := &netlink.Route{
227+
Dst: serviceIPNet,
228+
Gw: defaultGW,
229+
}
230+
if err := netlink.RouteAdd(route); err != nil {
231+
return fmt.Errorf("failed to add route to service network: %v", err)
232+
}
221233
}
222234

223235
return nil

pkg/network/sdn-cni-plugin/sdn_cni_plugin_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func TestOpenshiftSdnCNIPlugin(t *testing.T) {
8383
defer os.RemoveAll(tmpDir)
8484

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

0 commit comments

Comments
 (0)