Skip to content

Commit efaa9b9

Browse files
author
Rajat Chopra
committed
Merge pull request #2 from rajatchopra/master
Sync mode for running independently of PaaS to register nodes
2 parents 066d0a1 + e6a694b commit efaa9b9

File tree

4 files changed

+52
-14
lines changed

4 files changed

+52
-14
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Steps to create manually create an OpenShift cluster with openshift-sdn. This re
3131

3232
On OpenShift master,
3333

34-
$ openshift start master # start the master openshift server (also starts the etcd server by default)
34+
$ openshift start master [--nodes=node1] # start the master openshift server (also starts the etcd server by default) with an optional list of nodes
3535
$ openshift-sdn # assumes etcd is running at localhost:4001
3636

3737
To add a node to the cluster, do the following on the node:
@@ -59,6 +59,8 @@ Back on the master, to finally register the node:
5959

6060
Done. Repeat last two pieces to add more nodes. Create new pods from the master (or just docker containers on the minions), and see that the pods are indeed reachable from each other.
6161

62+
##### OpenShift? PaaS? Can I create a plain one just for Docker?
63+
6264
#### Performance Note
6365

6466
The current design has a long path for packets directed for the overlay network.

main.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os"
77
"os/exec"
88
"os/signal"
9+
"path"
910
"strings"
1011
"syscall"
1112
"time"
@@ -26,6 +27,7 @@ type CmdLineOpts struct {
2627
master bool
2728
minion bool
2829
skipsetup bool
30+
sync bool
2931
help bool
3032
}
3133

@@ -44,6 +46,7 @@ func init() {
4446
flag.BoolVar(&opts.master, "master", true, "Run in master mode")
4547
flag.BoolVar(&opts.minion, "minion", false, "Run in minion mode")
4648
flag.BoolVar(&opts.skipsetup, "skip-setup", false, "Skip the setup when in minion mode")
49+
flag.BoolVar(&opts.sync, "sync", false, "Sync the minions directly to etcd-path (Do not wait for PaaS to do so!)")
4750

4851
flag.BoolVar(&opts.help, "help", false, "print this message")
4952
}
@@ -61,13 +64,19 @@ func newNetworkManager() controller.Controller {
6164
func newSubnetRegistry() registry.SubnetRegistry {
6265
peers := strings.Split(opts.etcdEndpoints, ",")
6366

67+
subnetPath := path.Join(opts.etcdPath + "subnets")
68+
minionPath := "/registry/minions/"
69+
if opts.sync {
70+
minionPath = path.Join(opts.etcdPath + "minions")
71+
}
72+
6473
cfg := &registry.EtcdConfig{
6574
Endpoints: peers,
6675
Keyfile: opts.etcdKeyfile,
6776
Certfile: opts.etcdCertfile,
6877
CAFile: opts.etcdCAFile,
69-
SubnetPath: opts.etcdPath,
70-
MinionPath: "/registry/minions/",
78+
SubnetPath: subnetPath,
79+
MinionPath: minionPath,
7180
}
7281

7382
for {
@@ -102,7 +111,7 @@ func main() {
102111

103112
be := newNetworkManager()
104113
if opts.minion {
105-
err := be.StartNode(opts.skipsetup)
114+
err := be.StartNode(opts.sync, opts.skipsetup)
106115
if err != nil {
107116
return
108117
}

ovs-simple/controller/controller.go

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const (
2020

2121
type Controller interface {
2222
StartMaster() error
23-
StartNode(skipsetup bool) error
23+
StartNode(sync, skipsetup bool) error
2424
AddNode(minionIP string) error
2525
DeleteNode(minionIP string) error
2626
Stop()
@@ -142,7 +142,18 @@ func (oc *OvsController) DeleteNode(minion string) error {
142142
return oc.sm.DeleteSubnet(minion)
143143
}
144144

145-
func (oc *OvsController) StartNode(skipsetup bool) error {
145+
func (oc *OvsController) syncWithMaster() error {
146+
return oc.sm.CreateMinion(oc.hostName, oc.localIP)
147+
}
148+
149+
func (oc *OvsController) StartNode(sync, skipsetup bool) error {
150+
if sync {
151+
err := oc.syncWithMaster()
152+
if err != nil {
153+
log.Errorf("Failed to register with master. (%s)", err.Error())
154+
return err
155+
}
156+
}
146157
err := oc.initSelfSubnet()
147158
if err != nil {
148159
log.Errorf("Failed to get subnet for this host. (%v)", err)
@@ -239,15 +250,15 @@ func (oc *OvsController) AddOFRules(minionip, subnet string) {
239250
cookie := generateCookie(minionip)
240251
if minionip == oc.localIP {
241252
// self, so add the input rules
242-
iprule := fmt.Sprintf("table=0,cookie=%s,priority=200,ip,in_port=10,nw_dst=%s,actions=output:9", cookie, subnet)
243-
arprule := fmt.Sprintf("table=0,cookie=%s,priority=200,arp,in_port=10,nw_dst=%s,actions=output:9", cookie, subnet)
253+
iprule := fmt.Sprintf("table=0,cookie=0x%s,priority=200,ip,in_port=10,nw_dst=%s,actions=output:9", cookie, subnet)
254+
arprule := fmt.Sprintf("table=0,cookie=0x%s,priority=200,arp,in_port=10,nw_dst=%s,actions=output:9", cookie, subnet)
244255
o, e := exec.Command("ovs-ofctl", "-O", "OpenFlow13", "add-flow", "br0", iprule).CombinedOutput()
245256
log.Infof("Output of adding %s: %s (%v)", iprule, o, e)
246257
o, e = exec.Command("ovs-ofctl", "-O", "OpenFlow13", "add-flow", "br0", arprule).CombinedOutput()
247258
log.Infof("Output of adding %s: %s (%v)", arprule, o, e)
248259
} else {
249-
iprule := fmt.Sprintf("table=0,cookie=%s,priority=200,ip,in_port=9,nw_dst=%s,actions=set_field:%s->tun_dst,output:10", cookie, subnet, minionip)
250-
arprule := fmt.Sprintf("table=0,cookie=%s,priority=200,arp,in_port=9,nw_dst=%s,actions=set_field:%s->tun_dst,output:10", cookie, subnet, minionip)
260+
iprule := fmt.Sprintf("table=0,cookie=0x%s,priority=200,ip,in_port=9,nw_dst=%s,actions=set_field:%s->tun_dst,output:10", cookie, subnet, minionip)
261+
arprule := fmt.Sprintf("table=0,cookie=0x%s,priority=200,arp,in_port=9,nw_dst=%s,actions=set_field:%s->tun_dst,output:10", cookie, subnet, minionip)
251262
o, e := exec.Command("ovs-ofctl", "-O", "OpenFlow13", "add-flow", "br0", iprule).CombinedOutput()
252263
log.Infof("Output of adding %s: %s (%v)", iprule, o, e)
253264
o, e = exec.Command("ovs-ofctl", "-O", "OpenFlow13", "add-flow", "br0", arprule).CombinedOutput()
@@ -259,15 +270,15 @@ func (oc *OvsController) DelOFRules(minion string) {
259270
log.Infof("Calling del rules for %s", minion)
260271
cookie := generateCookie(minion)
261272
if minion == oc.localIP {
262-
iprule := fmt.Sprintf("table=0,cookie=%s,ip,in_port=10", cookie)
263-
arprule := fmt.Sprintf("table=0,cookie=%s,arp,in_port=10", cookie)
273+
iprule := fmt.Sprintf("table=0,cookie=0x%s/0xffffffff,ip,in_port=10", cookie)
274+
arprule := fmt.Sprintf("table=0,cookie=0x%s/0xffffffff,arp,in_port=10", cookie)
264275
o, e := exec.Command("ovs-ofctl", "-O", "OpenFlow13", "del-flows", "br0", iprule).CombinedOutput()
265276
log.Infof("Output of deleting local ip rules %s (%v)", o, e)
266277
o, e = exec.Command("ovs-ofctl", "-O", "OpenFlow13", "del-flows", "br0", arprule).CombinedOutput()
267278
log.Infof("Output of deleting local ip rules %s (%v)", o, e)
268279
} else {
269-
iprule := fmt.Sprintf("table=0,cookie=%s/0xffffffff,ip,in_port=9", cookie)
270-
arprule := fmt.Sprintf("table=0,cookie=%s/0xffffffff,arp,in_port=9", cookie)
280+
iprule := fmt.Sprintf("table=0,cookie=0x%s/0xffffffff,ip,in_port=9", cookie)
281+
arprule := fmt.Sprintf("table=0,cookie=0x%s/0xffffffff,arp,in_port=9", cookie)
271282
o, e := exec.Command("ovs-ofctl", "-O", "OpenFlow13", "del-flows", "br0", iprule).CombinedOutput()
272283
log.Infof("Output of deleting %s: %s (%v)", iprule, o, e)
273284
o, e = exec.Command("ovs-ofctl", "-O", "OpenFlow13", "del-flows", "br0", arprule).CombinedOutput()

pkg/registry/registry.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type SubnetRegistry interface {
2525
GetSubnet(minion string) (*Subnet, error)
2626
DeleteSubnet(minion string) error
2727
CreateSubnet(sn string, sub *Subnet) (*etcd.Response, error)
28+
CreateMinion(minion string, data string) error
2829
WatchSubnets(rev uint64, receiver chan *SubnetEvent, stop chan bool) error
2930
GetMinions() (*[]string, error)
3031
WatchMinions(rev uint64, receiver chan *MinionEvent, stop chan bool) error
@@ -200,6 +201,21 @@ func (sub *EtcdSubnetRegistry) DeleteSubnet(minion string) error {
200201
return err
201202
}
202203

204+
func (sub *EtcdSubnetRegistry) CreateMinion(minion string, data string) error {
205+
key := path.Join(sub.etcdCfg.MinionPath, minion)
206+
_, err := sub.client().Get(key, false, false)
207+
if err != nil {
208+
// good, it does not exist, write it
209+
_, err = sub.client().Create(key, data, 0)
210+
if err != nil {
211+
log.Errorf("Failed to write new subnet to etcd - %v", err)
212+
return err
213+
}
214+
}
215+
216+
return nil
217+
}
218+
203219
func (sub *EtcdSubnetRegistry) CreateSubnet(minion string, subnet *Subnet) (*etcd.Response, error) {
204220
subbytes, _ := json.Marshal(subnet)
205221
data := string(subbytes)

0 commit comments

Comments
 (0)