Skip to content

Commit

Permalink
Refactor Cloudprovider routes so providerID is useable
Browse files Browse the repository at this point in the history
  • Loading branch information
Keith Byrne authored and timbyr committed Jul 20, 2016
1 parent ecebdb5 commit 06f3f80
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
10 changes: 9 additions & 1 deletion pkg/cloudprovider/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,22 @@ type Instances interface {
CurrentNodeName(hostname string) (string, error)
}

type Instance struct {
// Name is the name of the instance as Kubernetes understands it. Usually the hostname
Name string

// ID is the instance ID. To be used for clouds that don't have a mapping of hostname to instance
ID string
}

// Route is a representation of an advanced routing rule.
type Route struct {
// Name is the name of the routing rule in the cloud-provider.
// It will be ignored in a Create (although nameHint may influence it)
Name string
// TargetInstance is the name of the instance as specified in routing rules
// for the cloud-provider (in gce: the Instance Name).
TargetInstance string
TargetInstance Instance
// DestinationCIDR is the CIDR format IP range that this routing rule
// applies to.
DestinationCIDR string
Expand Down
4 changes: 2 additions & 2 deletions pkg/cloudprovider/providers/aws/aws_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (c *Cloud) ListRoutes(clusterName string) ([]*cloudprovider.Route, error) {
}
instanceName := orEmpty(instance.PrivateDnsName)
routeName := clusterName + "-" + destinationCIDR
routes = append(routes, &cloudprovider.Route{Name: routeName, TargetInstance: instanceName, DestinationCIDR: destinationCIDR})
routes = append(routes, &cloudprovider.Route{Name: routeName, TargetInstance: cloudprovider.Instance{Name: instanceName}, DestinationCIDR: destinationCIDR})
}

return routes, nil
Expand All @@ -110,7 +110,7 @@ func (c *Cloud) configureInstanceSourceDestCheck(instanceID string, sourceDestCh
// CreateRoute implements Routes.CreateRoute
// Create the described route
func (c *Cloud) CreateRoute(clusterName string, nameHint string, route *cloudprovider.Route) error {
instance, err := c.getInstanceByNodeName(route.TargetInstance)
instance, err := c.getInstanceByNodeName(route.TargetInstance.Name)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cloudprovider/providers/gce/gce.go
Original file line number Diff line number Diff line change
Expand Up @@ -2193,7 +2193,7 @@ func (gce *GCECloud) ListRoutes(clusterName string) ([]*cloudprovider.Route, err
}

target := path.Base(r.NextHopInstance)
routes = append(routes, &cloudprovider.Route{Name: r.Name, TargetInstance: target, DestinationCIDR: r.DestRange})
routes = append(routes, &cloudprovider.Route{Name: r.Name, TargetInstance: cloudprovider.Instance{Name: target}, DestinationCIDR: r.DestRange})
}
}
if page >= maxPages {
Expand All @@ -2209,7 +2209,7 @@ func gceNetworkURL(project, network string) string {
func (gce *GCECloud) CreateRoute(clusterName string, nameHint string, route *cloudprovider.Route) error {
routeName := truncateClusterName(clusterName) + "-" + nameHint

targetInstance, err := gce.getInstanceByName(route.TargetInstance)
targetInstance, err := gce.getInstanceByName(route.TargetInstance.Name)
if err != nil {
return err
}
Expand Down
9 changes: 6 additions & 3 deletions pkg/controller/route/routecontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (rc *RouteController) reconcile(nodes []api.Node, routes []*cloudprovider.R
// routeMap maps routeTargetInstance->route
routeMap := make(map[string]*cloudprovider.Route)
for _, route := range routes {
routeMap[route.TargetInstance] = route
routeMap[route.TargetInstance.Name] = route
}

wg := sync.WaitGroup{}
Expand All @@ -111,7 +111,10 @@ func (rc *RouteController) reconcile(nodes []api.Node, routes []*cloudprovider.R
if r == nil || r.DestinationCIDR != node.Spec.PodCIDR {
// If not, create the route.
route := &cloudprovider.Route{
TargetInstance: node.Name,
TargetInstance: cloudprovider.Instance{
Name: node.Name,
ID: node.Spec.ProviderID,
},
DestinationCIDR: node.Spec.PodCIDR,
}
nameHint := string(node.UID)
Expand Down Expand Up @@ -144,7 +147,7 @@ func (rc *RouteController) reconcile(nodes []api.Node, routes []*cloudprovider.R
for _, route := range routes {
if rc.isResponsibleForRoute(route) {
// Check if this route applies to a node we know about & has correct CIDR.
if nodeCIDRs[route.TargetInstance] != route.DestinationCIDR {
if nodeCIDRs[route.TargetInstance.Name] != route.DestinationCIDR {
wg.Add(1)
// Delete the route.
go func(route *cloudprovider.Route, startTime time.Time) {
Expand Down

0 comments on commit 06f3f80

Please sign in to comment.