Skip to content

Commit f2fda72

Browse files
Dariquesthoffmaen
andauthored
RFC0027 CLI Support for Generic Per-Route Options [v8] (#3366)
* 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]>
1 parent 8e76f4d commit f2fda72

38 files changed

+1401
-115
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package actionerror
2+
3+
import "fmt"
4+
5+
// RouteOptionError is returned when a route option was specified in the wrong format
6+
type RouteOptionError struct {
7+
Name string
8+
Host string
9+
DomainName string
10+
Path string
11+
}
12+
13+
func (e RouteOptionError) Error() string {
14+
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())
15+
}
16+
17+
func (e RouteOptionError) path() string {
18+
if e.Path == "" {
19+
return "/"
20+
}
21+
return e.Path
22+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package actionerror
2+
3+
import "fmt"
4+
5+
// RouteOptionSupportError is returned when route options are not supported
6+
type RouteOptionSupportError struct {
7+
ErrorText string
8+
}
9+
10+
func (e RouteOptionSupportError) Error() string {
11+
return fmt.Sprintf("Route option support: '%s'", e.ErrorText)
12+
}

actor/v7action/cloud_controller_client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ type CloudControllerClient interface {
177177
UpdateOrganizationQuota(orgQuota resources.OrganizationQuota) (resources.OrganizationQuota, ccv3.Warnings, error)
178178
UpdateProcess(process resources.Process) (resources.Process, ccv3.Warnings, error)
179179
UpdateResourceMetadata(resource string, resourceGUID string, metadata resources.Metadata) (ccv3.JobURL, ccv3.Warnings, error)
180+
UpdateRoute(routeGUID string, options map[string]*string) (resources.Route, ccv3.Warnings, error)
180181
UpdateSecurityGroupRunningSpace(securityGroupGUID string, spaceGUIDs []string) (ccv3.Warnings, error)
181182
UpdateSecurityGroupStagingSpace(securityGroupGUID string, spaceGUIDs []string) (ccv3.Warnings, error)
182183
UpdateSecurityGroup(securityGroup resources.SecurityGroup) (resources.SecurityGroup, ccv3.Warnings, error)

actor/v7action/route.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type RouteSummary struct {
2626
ServiceInstanceName string
2727
}
2828

29-
func (actor Actor) CreateRoute(spaceGUID, domainName, hostname, path string, port int) (resources.Route, Warnings, error) {
29+
func (actor Actor) CreateRoute(spaceGUID, domainName, hostname, path string, port int, options map[string]*string) (resources.Route, Warnings, error) {
3030
allWarnings := Warnings{}
3131
domain, warnings, err := actor.GetDomainByName(domainName)
3232
allWarnings = append(allWarnings, warnings...)
@@ -41,6 +41,7 @@ func (actor Actor) CreateRoute(spaceGUID, domainName, hostname, path string, por
4141
Host: hostname,
4242
Path: path,
4343
Port: port,
44+
Options: options,
4445
})
4546

4647
actorWarnings := Warnings(apiWarnings)
@@ -401,6 +402,11 @@ func (actor Actor) MapRoute(routeGUID string, appGUID string, destinationProtoco
401402
return Warnings(warnings), err
402403
}
403404

405+
func (actor Actor) UpdateRoute(routeGUID string, options map[string]*string) (resources.Route, Warnings, error) {
406+
route, warnings, err := actor.CloudControllerClient.UpdateRoute(routeGUID, options)
407+
return route, Warnings(warnings), err
408+
}
409+
404410
func (actor Actor) UpdateDestination(routeGUID string, destinationGUID string, protocol string) (Warnings, error) {
405411
warnings, err := actor.CloudControllerClient.UpdateDestination(routeGUID, destinationGUID, protocol)
406412
return Warnings(warnings), err

actor/v7action/route_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,20 @@ var _ = Describe("Route Actions", func() {
3333
hostname string
3434
path string
3535
port int
36+
options map[string]*string
3637
)
3738

3839
BeforeEach(func() {
3940
hostname = ""
4041
path = ""
4142
port = 0
43+
lbLCVal := "least-connection"
44+
lbLeastConnections := &lbLCVal
45+
options = map[string]*string{"loadbalancing": lbLeastConnections}
4246
})
4347

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

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

5862
fakeCloudControllerClient.CreateRouteReturns(
59-
resources.Route{GUID: "route-guid", SpaceGUID: "space-guid", DomainGUID: "domain-guid", Host: "hostname", Path: "path-name"},
63+
resources.Route{GUID: "route-guid", SpaceGUID: "space-guid", DomainGUID: "domain-guid", Host: "hostname", Path: "path-name", Options: options},
6064
ccv3.Warnings{"create-warning-1", "create-warning-2"},
6165
nil)
6266
})
@@ -80,6 +84,7 @@ var _ = Describe("Route Actions", func() {
8084
DomainGUID: "domain-guid",
8185
Host: hostname,
8286
Path: path,
87+
Options: options,
8388
},
8489
))
8590
})
@@ -102,6 +107,7 @@ var _ = Describe("Route Actions", func() {
102107
SpaceGUID: "space-guid",
103108
DomainGUID: "domain-guid",
104109
Port: 1234,
110+
Options: options,
105111
},
106112
))
107113
})

actor/v7action/v7actionfakes/fake_cloud_controller_client.go

Lines changed: 86 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

actor/v7pushaction/v7_actor.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type V7Actor interface {
1616
CreateBitsPackageByApplication(appGUID string) (resources.Package, v7action.Warnings, error)
1717
CreateDeployment(dep resources.Deployment) (string, v7action.Warnings, error)
1818
CreateDockerPackageByApplication(appGUID string, dockerImageCredentials v7action.DockerImageCredentials) (resources.Package, v7action.Warnings, error)
19-
CreateRoute(spaceGUID, domainName, hostname, path string, port int) (resources.Route, v7action.Warnings, error)
19+
CreateRoute(spaceGUID, domainName, hostname, path string, port int, options map[string]*string) (resources.Route, v7action.Warnings, error)
2020
GetApplicationByNameAndSpace(appName string, spaceGUID string) (resources.Application, v7action.Warnings, error)
2121
GetApplicationDroplets(appName string, spaceGUID string) ([]resources.Droplet, v7action.Warnings, error)
2222
GetApplicationRoutes(appGUID string) ([]resources.Route, v7action.Warnings, error)
@@ -41,6 +41,7 @@ type V7Actor interface {
4141
UnmapRoute(routeGUID string, destinationGUID string) (v7action.Warnings, error)
4242
UpdateApplication(app resources.Application) (resources.Application, v7action.Warnings, error)
4343
UpdateProcessByTypeAndApplication(processType string, appGUID string, updatedProcess resources.Process) (v7action.Warnings, error)
44+
UpdateRoute(routeGUID string, options map[string]*string) (resources.Route, v7action.Warnings, error)
4445
UploadBitsPackage(pkg resources.Package, matchedResources []sharedaction.V3Resource, newResources io.Reader, newResourcesLength int64) (resources.Package, v7action.Warnings, error)
4546
UploadDroplet(dropletGUID string, dropletPath string, progressReader io.Reader, fileSize int64) (v7action.Warnings, error)
4647
}

0 commit comments

Comments
 (0)