Skip to content

Commit

Permalink
One can now allocate hostsubnets for hosts that are not part of the c…
Browse files Browse the repository at this point in the history
…luster. This is useful when a host wants to be part of the SDN, but not part of the cluster (e.g. F5)
  • Loading branch information
Rajat Chopra committed Aug 24, 2016
1 parent 9d1e0b4 commit 1dcd79f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/sdn/api/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ func ValidateHostSubnet(hs *sdnapi.HostSubnet) field.ErrorList {

_, _, err := net.ParseCIDR(hs.Subnet)
if err != nil {
allErrs = append(allErrs, field.Invalid(field.NewPath("subnet"), hs.Subnet, err.Error()))
// check if annotation exists, then let the Subnet field be empty
if _, ok := hs.Annotations["hostsubnet.sdn.openshift.io/autocreate"]; !ok {
allErrs = append(allErrs, field.Invalid(field.NewPath("subnet"), hs.Subnet, err.Error()))
}
}
if net.ParseIP(hs.HostIP) == nil {
allErrs = append(allErrs, field.Invalid(field.NewPath("hostIP"), hs.HostIP, "invalid IP address"))
Expand Down
42 changes: 42 additions & 0 deletions pkg/sdn/plugin/subnets.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func (master *OsdnMaster) SubnetStartMaster(clusterNetwork *net.IPNet, hostSubne
}

go utilwait.Forever(master.watchNodes, 0)
go utilwait.Forever(master.watchSubnetsOnMaster, 0)
return nil
}

Expand Down Expand Up @@ -205,6 +206,47 @@ func (node *OsdnNode) initSelfSubnet() error {
return nil
}

// Only run on the master
// Watch for all hostsubnet events and if one is found with the right annotation, use the IPAM to dole a real subnet
func (master *OsdnMaster) watchSubnetsOnMaster() {
eventQueue := master.registry.RunEventQueue(HostSubnets)

for {
eventType, obj, err := eventQueue.Pop()
if err != nil {
utilruntime.HandleError(fmt.Errorf("EventQueue failed for subnets: %v", err))
return
}
hs := obj.(*osapi.HostSubnet)
name := hs.ObjectMeta.Name
hostIP := hs.HostIP

log.V(5).Infof("Watch %s event for HostSubnet %q", strings.Title(string(eventType)), name)
switch eventType {
case watch.Added, watch.Modified:
if err = master.registry.ValidateNodeIP(hostIP); err != nil {
log.Errorf("Ignoring invalid subnet for node %s: %v", hostIP, err)
continue
}

if _, ok := hs.Annotations["hostsubnet.sdn.openshift.io/autocreate"]; ok {
err = master.registry.DeleteSubnet(name)
if err != nil {
log.Errorf("Error in recreating annotated subnet from master, name: %s, ip %s: %v", name, hostIP, err)
continue
}
err = master.addNode(name, hostIP)
if err != nil {
log.Errorf("Error creating subnet for node %s, ip %s: %v", name, hostIP, err)
continue
}
}
case watch.Deleted:
// ignore all deleted hostsubnets
}
}
}

// Only run on the nodes
func (node *OsdnNode) watchSubnets() {
subnets := make(map[string]*osapi.HostSubnet)
Expand Down

0 comments on commit 1dcd79f

Please sign in to comment.