Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/api/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
_ "github.com/openshift/origin/pkg/deploy/api"
_ "github.com/openshift/origin/pkg/image/api"
_ "github.com/openshift/origin/pkg/template/api"
_ "github.com/openshift/origin/pkg/route/api"
)

// Codec is the identity codec for this package - it can only convert itself
Expand Down
1 change: 1 addition & 0 deletions pkg/api/v1beta1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
_ "github.com/openshift/origin/pkg/deploy/api/v1beta1"
_ "github.com/openshift/origin/pkg/image/api/v1beta1"
_ "github.com/openshift/origin/pkg/template/api/v1beta1"
_ "github.com/openshift/origin/pkg/route/api/v1beta1"
)

// Codec encodes internal objects to the v1beta1 scheme
Expand Down
52 changes: 52 additions & 0 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
buildapi "github.com/openshift/origin/pkg/build/api"
deployapi "github.com/openshift/origin/pkg/deploy/api"
imageapi "github.com/openshift/origin/pkg/image/api"
routeapi "github.com/openshift/origin/pkg/route/api"
)

// Interface exposes methods on OpenShift resources.
Expand All @@ -23,6 +24,7 @@ type Interface interface {
ImageRepositoryMappingInterface
DeploymentInterface
DeploymentConfigInterface
RouteInterface
}

// BuildInterface exposes methods on Build resources.
Expand Down Expand Up @@ -81,6 +83,16 @@ type DeploymentInterface interface {
DeleteDeployment(string) error
}

// RouteInterface exposes methods on Route resources
type RouteInterface interface {
ListRoutes(selector labels.Selector) (*routeapi.RouteList, error)
GetRoute(routeID string) (*routeapi.Route, error)
CreateRoute(route *routeapi.Route) (*routeapi.Route, error)
UpdateRoute(route *routeapi.Route) (*routeapi.Route, error)
DeleteRoute(routeID string) error
WatchRoutes(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error)
}

// Client is an OpenShift client object
type Client struct {
*kubeclient.RESTClient
Expand Down Expand Up @@ -295,3 +307,43 @@ func (c *Client) UpdateDeployment(deployment *deployapi.Deployment) (result *dep
func (c *Client) DeleteDeployment(id string) error {
return c.Delete().Path("deployments").Path(id).Do().Error()
}

// ListRoutes takes a selector, and returns the list of routes that match that selector
func (c *Client) ListRoutes(selector labels.Selector) (result *routeapi.RouteList, err error) {
err = c.Get().Path("routes").SelectorParam("labels", selector).Do().Into(result)
return
}

// GetRoute takes the name of the route, and returns the corresponding Route object, and an error if it occurs
func (c *Client) GetRoute(name string) (result *routeapi.Route, err error) {
err = c.Get().Path("routes").Path(name).Do().Into(result)
return
}

// DeleteRoute takes the name of the route, and returns an error if one occurs
func (c *Client) DeleteRoute(name string) error {
return c.Delete().Path("routes").Path(name).Do().Error()
}

// CreateRoute takes the representation of a route. Returns the server's representation of the route, and an error, if it occurs
func (c *Client) CreateRoute(route *routeapi.Route) (result *routeapi.Route, err error) {
err = c.Post().Path("routes").Body(route).Do().Into(result)
return
}

// UpdateRoute takes the representation of a route to update. Returns the server's representation of the route, and an error, if it occurs
func (c *Client) UpdateRoute(route *routeapi.Route) (result *routeapi.Route, err error) {
err = c.Put().Path("routes").Path(route.ID).Body(route).Do().Into(result)
return
}

// WatchRoutes returns a watch.Interface that watches the requested routes.
func (c *Client) WatchRoutes(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) {
return c.Get().
Path("watch").
Path("routes").
UintParam("resourceVersion", resourceVersion).
SelectorParam("labels", label).
SelectorParam("fields", field).
Watch()
}
31 changes: 31 additions & 0 deletions pkg/client/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
buildapi "github.com/openshift/origin/pkg/build/api"
deployapi "github.com/openshift/origin/pkg/deploy/api"
imageapi "github.com/openshift/origin/pkg/image/api"
routeapi "github.com/openshift/origin/pkg/route/api"
)

type FakeAction struct {
Expand Down Expand Up @@ -160,3 +161,33 @@ func (c *Fake) DeleteDeployment(id string) error {
c.Actions = append(c.Actions, FakeAction{Action: "delete-deployment"})
return nil
}

func (c *Fake) ListRoutes(selector labels.Selector) (*routeapi.RouteList, error) {
c.Actions = append(c.Actions, FakeAction{Action: "list-routes"})
return &routeapi.RouteList{}, nil
}

func (c *Fake) GetRoute(id string) (*routeapi.Route, error) {
c.Actions = append(c.Actions, FakeAction{Action: "get-route"})
return &routeapi.Route{}, nil
}

func (c *Fake) CreateRoute(route *routeapi.Route) (*routeapi.Route, error) {
c.Actions = append(c.Actions, FakeAction{Action: "create-route"})
return &routeapi.Route{}, nil
}

func (c *Fake) UpdateRoute(route *routeapi.Route) (*routeapi.Route, error) {
c.Actions = append(c.Actions, FakeAction{Action: "update-route"})
return &routeapi.Route{}, nil
}

func (c *Fake) DeleteRoute(id string) error {
c.Actions = append(c.Actions, FakeAction{Action: "delete-route"})
return nil
}

func (c *Fake) WatchRoutes(field, label labels.Selector, resourceVersion uint64) (watch.Interface, error) {
c.Actions = append(c.Actions, FakeAction{Action: "watch-routes"})
return nil, nil
}
5 changes: 5 additions & 0 deletions pkg/cmd/client/kubecfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ import (
. "github.com/openshift/origin/pkg/cmd/client/api"
"github.com/openshift/origin/pkg/cmd/client/build"
"github.com/openshift/origin/pkg/cmd/client/image"
"github.com/openshift/origin/pkg/cmd/client/route"
"github.com/openshift/origin/pkg/config"
configapi "github.com/openshift/origin/pkg/config/api"
deployapi "github.com/openshift/origin/pkg/deploy/api"
deployclient "github.com/openshift/origin/pkg/deploy/client"
imageapi "github.com/openshift/origin/pkg/image/api"
routeapi "github.com/openshift/origin/pkg/route/api"
)

type KubeConfig struct {
Expand Down Expand Up @@ -126,6 +128,7 @@ var parser = kubecfg.NewParser(map[string]runtime.Object{
"config": &configapi.Config{},
"deployments": &deployapi.Deployment{},
"deploymentConfigs": &deployapi.DeploymentConfig{},
"routes": &routeapi.Route{},
})

func prettyWireStorage() string {
Expand Down Expand Up @@ -275,6 +278,7 @@ func (c *KubeConfig) Run() {
"imageRepositoryMappings": {"ImageRepositoryMapping", client.RESTClient, latest.Codec},
"deployments": {"Deployment", client.RESTClient, latest.Codec},
"deploymentConfigs": {"DeploymentConfig", client.RESTClient, latest.Codec},
"routes": {"Route", client.RESTClient, latest.Codec},
}

matchFound := c.executeConfigRequest(method, clients) || c.executeTemplateRequest(method, client) || c.executeControllerRequest(method, kubeClient) || c.executeAPIRequest(method, clients)
Expand Down Expand Up @@ -520,6 +524,7 @@ func humanReadablePrinter() *kubecfg.HumanReadablePrinter {
build.RegisterPrintHandlers(printer)
image.RegisterPrintHandlers(printer)
deployclient.RegisterPrintHandlers(printer)
route.RegisterPrintHandlers(printer)

return printer
}
33 changes: 33 additions & 0 deletions pkg/cmd/client/route/printer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package route

import (
"fmt"
"io"

"github.com/GoogleCloudPlatform/kubernetes/pkg/kubecfg"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"

"github.com/openshift/origin/pkg/route/api"
)

var routeColumns = []string{"ID", "Host/Port", "Path", "Service", "Labels"}

// RegisterPrintHandlers registers HumanReadablePrinter handlers
func RegisterPrintHandlers(printer *kubecfg.HumanReadablePrinter) {
printer.Handler(routeColumns, printRoute)
printer.Handler(routeColumns, printRouteList)
}

func printRoute(route *api.Route, w io.Writer) error {
_, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", route.ID, route.Host, route.Path, route.ServiceName, labels.Set(route.Labels))
return err
}

func printRouteList(routeList *api.RouteList, w io.Writer) error {
for _, route := range routeList.Items {
if err := printRoute(&route, w); err != nil {
return err
}
}
return nil
}
5 changes: 5 additions & 0 deletions pkg/cmd/master/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,16 @@ import (
"github.com/openshift/origin/pkg/image/registry/image"
"github.com/openshift/origin/pkg/image/registry/imagerepository"
"github.com/openshift/origin/pkg/image/registry/imagerepositorymapping"
routeregistry "github.com/openshift/origin/pkg/route/registry/route"
routeetcd "github.com/openshift/origin/pkg/route/registry/etcd"
"github.com/openshift/origin/pkg/template"
"github.com/openshift/origin/pkg/version"

// Register versioned api types
_ "github.com/openshift/origin/pkg/config/api/v1beta1"
_ "github.com/openshift/origin/pkg/image/api/v1beta1"
_ "github.com/openshift/origin/pkg/template/api/v1beta1"
_ "github.com/openshift/origin/pkg/route/api/v1beta1"
)

func NewCommandStartAllInOne(name string) *cobra.Command {
Expand Down Expand Up @@ -214,6 +217,7 @@ func (c *config) runApiserver() {
buildRegistry := buildetcd.New(etcdHelper)
imageRegistry := imageetcd.New(etcdHelper)
deployEtcd := deployetcd.New(etcdHelper)
routeEtcd := routeetcd.New(etcdHelper)

// initialize OpenShift API
storage := map[string]apiserver.RESTStorage{
Expand All @@ -225,6 +229,7 @@ func (c *config) runApiserver() {
"deployments": deployregistry.NewREST(deployEtcd),
"deploymentConfigs": deployconfigregistry.NewREST(deployEtcd),
"templateConfigs": template.NewStorage(),
"routes": routeregistry.NewREST(routeEtcd),
}

osMux := http.NewServeMux()
Expand Down
15 changes: 15 additions & 0 deletions pkg/route/api/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package api

import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
)

func init() {
api.Scheme.AddKnownTypes("",
&Route{},
&RouteList{},
)
}

func (*Route) IsAnAPIObject() {}
func (*RouteList) IsAnAPIObject() {}
27 changes: 27 additions & 0 deletions pkg/route/api/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package api

import (
kubeapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
)

// Route encapsulates the inputs needed to connect a DNS/alias to a service proxy.
type Route struct {
kubeapi.JSONBase `json:",inline" yaml:",inline"`

// Required: Alias/DNS that points to the service
// Can be host or host:port
// host and port are combined to follow the net/url URL struct
Host string `json:"host" yaml:"host"`
// Optional: Path that the router watches for, to route traffic for to the service
Path string `json:"path,omitempty" yaml:"path,omitempty"`

// the name of the service that this route points to
ServiceName string `json:"serviceName" yaml:"serviceName"`
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
}

// RouteList is a collection of Routes.
type RouteList struct {
kubeapi.JSONBase `json:",inline" yaml:",inline"`
Items []Route `json:"items,omitempty" yaml:"items,omitempty"`
}
15 changes: 15 additions & 0 deletions pkg/route/api/v1beta1/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package v1beta1

import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
)

func init() {
api.Scheme.AddKnownTypes("v1beta1",
&Route{},
&RouteList{},
)
}

func (*Route) IsAnAPIObject() {}
func (*RouteList) IsAnAPIObject() {}
27 changes: 27 additions & 0 deletions pkg/route/api/v1beta1/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package v1beta1

import (
v1beta1 "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta1"
)

// Route encapsulates the inputs needed to connect a DNS/alias to a service proxy.
type Route struct {
v1beta1.JSONBase `json:",inline" yaml:",inline"`

// Required: Alias/DNS that points to the service
// Can be host or host:port
// host and port are combined to follow the net/url URL struct
Host string `json:"host" yaml:"host"`
// Optional: Path that the router watches for, to route traffic for to the service
Path string `json:"path,omitempty" yaml:"path,omitempty"`

// the name of the service that this route points to
ServiceName string `json:"serviceName" yaml:"serviceName"`
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
}

// RouteList is a collection of Routes.
type RouteList struct {
v1beta1.JSONBase `json:",inline" yaml:",inline"`
Items []Route `json:"items,omitempty" yaml:"items,omitempty"`
}
19 changes: 19 additions & 0 deletions pkg/route/api/validation/validation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package validation

import (
errs "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
routeapi "github.com/openshift/origin/pkg/route/api"
)

// ValidateRoute tests if required fields in the route are set.
func ValidateRoute(route *routeapi.Route) errs.ErrorList {
result := errs.ErrorList{}

if len(route.Host) == 0 {
result = append(result, errs.NewFieldRequired("host", ""))
}
if len(route.ServiceName) == 0 {
result = append(result, errs.NewFieldRequired("serviceName", ""))
}
return result
}
22 changes: 22 additions & 0 deletions pkg/route/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
Package route provides support for managing and watching routes.
It defines a Route resource type, along with associated storage.

A Route object allows the user to specify a DNS / alias for a Kubernetes service.
It stores the ID of the Service (ServiceName) and the DNS/alias (Name).
The Route can be used to specify just the DNS/alias or it could also include
port and/or the path.

The Route model includes the following attributes to specify the frontend URL:
- Host: Alias/DNS that points to the service. Can be host or host:port
- Path: Path allows the router to perform fine-grained routing

The Route resources can be used by routers and load balancers to route external inbound
traffic. The proxy is expected to have frontend mappings for the Route.Name in its
configuration. For its endpoints, a proxy could either forward the traffic to the
Kubernetes Service port and let it do the load balancing and routing. Alternately,
a more meaningful implementation of a router could take the endpoints for the service
and route/load balance the incoming requests to the corresponding service endpoints.
*/

package route
Loading