Skip to content

Commit

Permalink
RFC0027 CLI Support for Generic Per-Route Options [v8] (#3366)
Browse files Browse the repository at this point in the history
* Add MinVersionPerRouteOpts check for create and update route commands
* Route command in the v7/commands
* Changed typed route options to an untyped map
* Change DisplayText to DisplayWarning for flag spec err
* Output an error if at least one option is specified incorrectly
* New integration test and adjustments of other tests
* Consistent naming: per-route options vs route specific options
* Rename least-connections to least-connection

---------

Co-authored-by: Clemens Hoffmann <[email protected]>
  • Loading branch information
Dariquest and hoffmaen authored Feb 5, 2025
1 parent 8e76f4d commit f2fda72
Show file tree
Hide file tree
Showing 38 changed files with 1,401 additions and 115 deletions.
22 changes: 22 additions & 0 deletions actor/actionerror/route_option_error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package actionerror

import "fmt"

// RouteOptionError is returned when a route option was specified in the wrong format
type RouteOptionError struct {
Name string
Host string
DomainName string
Path string
}

func (e RouteOptionError) Error() string {
return fmt.Sprintf("Route option '%s' for route with host '%s', domain '%s', and path '%s' was specified incorrectly. Please use key-value pair format key=value.", e.Name, e.Host, e.DomainName, e.path())
}

func (e RouteOptionError) path() string {
if e.Path == "" {
return "/"
}
return e.Path
}
12 changes: 12 additions & 0 deletions actor/actionerror/route_option_support_error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package actionerror

import "fmt"

// RouteOptionSupportError is returned when route options are not supported
type RouteOptionSupportError struct {
ErrorText string
}

func (e RouteOptionSupportError) Error() string {
return fmt.Sprintf("Route option support: '%s'", e.ErrorText)
}
1 change: 1 addition & 0 deletions actor/v7action/cloud_controller_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ type CloudControllerClient interface {
UpdateOrganizationQuota(orgQuota resources.OrganizationQuota) (resources.OrganizationQuota, ccv3.Warnings, error)
UpdateProcess(process resources.Process) (resources.Process, ccv3.Warnings, error)
UpdateResourceMetadata(resource string, resourceGUID string, metadata resources.Metadata) (ccv3.JobURL, ccv3.Warnings, error)
UpdateRoute(routeGUID string, options map[string]*string) (resources.Route, ccv3.Warnings, error)
UpdateSecurityGroupRunningSpace(securityGroupGUID string, spaceGUIDs []string) (ccv3.Warnings, error)
UpdateSecurityGroupStagingSpace(securityGroupGUID string, spaceGUIDs []string) (ccv3.Warnings, error)
UpdateSecurityGroup(securityGroup resources.SecurityGroup) (resources.SecurityGroup, ccv3.Warnings, error)
Expand Down
8 changes: 7 additions & 1 deletion actor/v7action/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type RouteSummary struct {
ServiceInstanceName string
}

func (actor Actor) CreateRoute(spaceGUID, domainName, hostname, path string, port int) (resources.Route, Warnings, error) {
func (actor Actor) CreateRoute(spaceGUID, domainName, hostname, path string, port int, options map[string]*string) (resources.Route, Warnings, error) {
allWarnings := Warnings{}
domain, warnings, err := actor.GetDomainByName(domainName)
allWarnings = append(allWarnings, warnings...)
Expand All @@ -41,6 +41,7 @@ func (actor Actor) CreateRoute(spaceGUID, domainName, hostname, path string, por
Host: hostname,
Path: path,
Port: port,
Options: options,
})

actorWarnings := Warnings(apiWarnings)
Expand Down Expand Up @@ -401,6 +402,11 @@ func (actor Actor) MapRoute(routeGUID string, appGUID string, destinationProtoco
return Warnings(warnings), err
}

func (actor Actor) UpdateRoute(routeGUID string, options map[string]*string) (resources.Route, Warnings, error) {
route, warnings, err := actor.CloudControllerClient.UpdateRoute(routeGUID, options)
return route, Warnings(warnings), err
}

func (actor Actor) UpdateDestination(routeGUID string, destinationGUID string, protocol string) (Warnings, error) {
warnings, err := actor.CloudControllerClient.UpdateDestination(routeGUID, destinationGUID, protocol)
return Warnings(warnings), err
Expand Down
10 changes: 8 additions & 2 deletions actor/v7action/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,20 @@ var _ = Describe("Route Actions", func() {
hostname string
path string
port int
options map[string]*string
)

BeforeEach(func() {
hostname = ""
path = ""
port = 0
lbLCVal := "least-connection"
lbLeastConnections := &lbLCVal
options = map[string]*string{"loadbalancing": lbLeastConnections}
})

JustBeforeEach(func() {
_, warnings, executeErr = actor.CreateRoute("space-guid", "domain-name", hostname, path, port)
_, warnings, executeErr = actor.CreateRoute("space-guid", "domain-name", hostname, path, port, options)
})

When("the API layer calls are successful", func() {
Expand All @@ -56,7 +60,7 @@ var _ = Describe("Route Actions", func() {
)

fakeCloudControllerClient.CreateRouteReturns(
resources.Route{GUID: "route-guid", SpaceGUID: "space-guid", DomainGUID: "domain-guid", Host: "hostname", Path: "path-name"},
resources.Route{GUID: "route-guid", SpaceGUID: "space-guid", DomainGUID: "domain-guid", Host: "hostname", Path: "path-name", Options: options},
ccv3.Warnings{"create-warning-1", "create-warning-2"},
nil)
})
Expand All @@ -80,6 +84,7 @@ var _ = Describe("Route Actions", func() {
DomainGUID: "domain-guid",
Host: hostname,
Path: path,
Options: options,
},
))
})
Expand All @@ -102,6 +107,7 @@ var _ = Describe("Route Actions", func() {
SpaceGUID: "space-guid",
DomainGUID: "domain-guid",
Port: 1234,
Options: options,
},
))
})
Expand Down
86 changes: 86 additions & 0 deletions actor/v7action/v7actionfakes/fake_cloud_controller_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion actor/v7pushaction/v7_actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type V7Actor interface {
CreateBitsPackageByApplication(appGUID string) (resources.Package, v7action.Warnings, error)
CreateDeployment(dep resources.Deployment) (string, v7action.Warnings, error)
CreateDockerPackageByApplication(appGUID string, dockerImageCredentials v7action.DockerImageCredentials) (resources.Package, v7action.Warnings, error)
CreateRoute(spaceGUID, domainName, hostname, path string, port int) (resources.Route, v7action.Warnings, error)
CreateRoute(spaceGUID, domainName, hostname, path string, port int, options map[string]*string) (resources.Route, v7action.Warnings, error)
GetApplicationByNameAndSpace(appName string, spaceGUID string) (resources.Application, v7action.Warnings, error)
GetApplicationDroplets(appName string, spaceGUID string) ([]resources.Droplet, v7action.Warnings, error)
GetApplicationRoutes(appGUID string) ([]resources.Route, v7action.Warnings, error)
Expand All @@ -41,6 +41,7 @@ type V7Actor interface {
UnmapRoute(routeGUID string, destinationGUID string) (v7action.Warnings, error)
UpdateApplication(app resources.Application) (resources.Application, v7action.Warnings, error)
UpdateProcessByTypeAndApplication(processType string, appGUID string, updatedProcess resources.Process) (v7action.Warnings, error)
UpdateRoute(routeGUID string, options map[string]*string) (resources.Route, v7action.Warnings, error)
UploadBitsPackage(pkg resources.Package, matchedResources []sharedaction.V3Resource, newResources io.Reader, newResourcesLength int64) (resources.Package, v7action.Warnings, error)
UploadDroplet(dropletGUID string, dropletPath string, progressReader io.Reader, fileSize int64) (v7action.Warnings, error)
}
Loading

0 comments on commit f2fda72

Please sign in to comment.