Skip to content

Commit 1414b7c

Browse files
authored
cf push to use deployment scale options for rolling and canary deployments (cloudfoundry#3535)
1 parent ffc2ab9 commit 1414b7c

23 files changed

+1645
-76
lines changed

actor/v7pushaction/actor.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ type Actor struct {
1414
SharedActor SharedActor
1515
V7Actor V7Actor
1616

17-
PreparePushPlanSequence []UpdatePushPlanFunc
18-
ChangeApplicationSequence func(plan PushPlan) []ChangeApplicationFunc
19-
TransformManifestSequence []HandleFlagOverrideFunc
20-
21-
startWithProtocol *regexp.Regexp
22-
urlValidator *regexp.Regexp
17+
PreparePushPlanSequence []UpdatePushPlanFunc
18+
ChangeApplicationSequence func(plan PushPlan) []ChangeApplicationFunc
19+
TransformManifestSequence []HandleFlagOverrideFunc
20+
TransformManifestSequenceForDeployment []HandleFlagOverrideFunc
21+
startWithProtocol *regexp.Regexp
22+
urlValidator *regexp.Regexp
2323
}
2424

2525
const ProtocolRegexp = "^https?://|^tcp://"
@@ -69,7 +69,12 @@ func NewActor(v3Actor V7Actor, sharedActor SharedActor) *Actor {
6969
HandleAppPathOverride,
7070
HandleDropletPathOverride,
7171
}
72-
72+
actor.TransformManifestSequenceForDeployment = []HandleFlagOverrideFunc{
73+
HandleInstancesOverrideForDeployment,
74+
HandleMemoryOverrideForDeployment,
75+
HandleDiskOverrideForDeployment,
76+
HandleLogRateLimitOverrideForDeployment,
77+
}
7378
actor.PreparePushPlanSequence = []UpdatePushPlanFunc{
7479
SetDefaultBitsPathForPushPlan,
7580
SetupDropletPathForPushPlan,

actor/v7pushaction/actor_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,15 @@ var _ = Describe("Actor", func() {
2929
))
3030
})
3131
})
32+
33+
Describe("TransformManifestSequenceForDeployment", func() {
34+
It("is a list of functions for preparing the push plan", func() {
35+
Expect(actor.TransformManifestSequenceForDeployment).To(matchers.MatchFuncsByName(
36+
HandleInstancesOverrideForDeployment,
37+
HandleMemoryOverrideForDeployment,
38+
HandleDiskOverrideForDeployment,
39+
HandleLogRateLimitOverrideForDeployment,
40+
))
41+
})
42+
})
3243
})

actor/v7pushaction/create_deployment_for_push_plan.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ func (actor Actor) CreateDeploymentForApplication(pushPlan PushPlan, eventStream
2525
}
2626
}
2727

28+
dep.Options.Instances = pushPlan.Instances
29+
dep.Options.MemoryInMB = pushPlan.MemoryInMB
30+
dep.Options.DiskInMB = pushPlan.DiskInMB
31+
dep.Options.LogRateLimitInBPS = pushPlan.LogRateLimitInBPS
32+
2833
deploymentGUID, warnings, err := actor.V7Actor.CreateDeployment(dep)
2934

3035
if err != nil {

actor/v7pushaction/create_deployment_for_push_plan_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"code.cloudfoundry.org/cli/actor/v7pushaction/v7pushactionfakes"
99
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant"
1010
"code.cloudfoundry.org/cli/resources"
11+
"code.cloudfoundry.org/cli/types"
1112
. "github.com/onsi/ginkgo/v2"
1213
. "github.com/onsi/gomega"
1314
)
@@ -122,6 +123,10 @@ var _ = Describe("CreateDeploymentForApplication()", func() {
122123
)
123124
paramPlan.Strategy = "rolling"
124125
paramPlan.MaxInFlight = 10
126+
paramPlan.Instances = types.NullInt{IsSet: true, Value: 3}
127+
paramPlan.MemoryInMB = types.NullUint64{IsSet: true, Value: 10}
128+
paramPlan.DiskInMB = types.NullUint64{IsSet: true, Value: 20}
129+
paramPlan.LogRateLimitInBPS = types.NullInt{IsSet: true, Value: 30}
125130
})
126131

127132
It("waits for the app to start", func() {
@@ -135,7 +140,12 @@ var _ = Describe("CreateDeploymentForApplication()", func() {
135140
dep := fakeV7Actor.CreateDeploymentArgsForCall(0)
136141
Expect(dep).To(Equal(resources.Deployment{
137142
Strategy: "rolling",
138-
Options: resources.DeploymentOpts{MaxInFlight: 10},
143+
Options: resources.DeploymentOpts{MaxInFlight: 10,
144+
Instances: types.NullInt{IsSet: true, Value: 3},
145+
MemoryInMB: types.NullUint64{IsSet: true, Value: 10},
146+
DiskInMB: types.NullUint64{IsSet: true, Value: 20},
147+
LogRateLimitInBPS: types.NullInt{IsSet: true, Value: 30},
148+
},
139149
Relationships: resources.Relationships{
140150
constant.RelationshipTypeApplication: resources.Relationship{GUID: "some-app-guid"},
141151
},
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package v7pushaction
2+
3+
import (
4+
"code.cloudfoundry.org/cli/util/manifestparser"
5+
)
6+
7+
func (actor Actor) HandleDeploymentScaleFlagOverrides(
8+
baseManifest manifestparser.Manifest,
9+
flagOverrides FlagOverrides,
10+
) (manifestparser.Manifest, error) {
11+
newManifest := baseManifest
12+
13+
for _, transformPlan := range actor.TransformManifestSequenceForDeployment {
14+
var err error
15+
newManifest, err = transformPlan(newManifest, flagOverrides)
16+
if err != nil {
17+
return manifestparser.Manifest{}, err
18+
}
19+
}
20+
21+
return newManifest, nil
22+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package v7pushaction_test
2+
3+
import (
4+
. "code.cloudfoundry.org/cli/actor/v7pushaction"
5+
"code.cloudfoundry.org/cli/util/manifestparser"
6+
. "github.com/onsi/ginkgo/v2"
7+
. "github.com/onsi/gomega"
8+
)
9+
10+
var _ = Describe("HandleDeploymentScaleFlagOverrides", func() {
11+
var (
12+
pushActor *Actor
13+
baseManifest manifestparser.Manifest
14+
flagOverrides FlagOverrides
15+
transformedManifest manifestparser.Manifest
16+
executeErr error
17+
18+
testFuncCallCount int
19+
)
20+
21+
testTransformManifestFunc := func(manifest manifestparser.Manifest, overrides FlagOverrides) (manifestparser.Manifest, error) {
22+
testFuncCallCount += 1
23+
return manifest, nil
24+
}
25+
26+
BeforeEach(func() {
27+
baseManifest = manifestparser.Manifest{}
28+
flagOverrides = FlagOverrides{}
29+
testFuncCallCount = 0
30+
31+
pushActor, _, _ = getTestPushActor()
32+
pushActor.TransformManifestSequenceForDeployment = []HandleFlagOverrideFunc{
33+
testTransformManifestFunc,
34+
}
35+
})
36+
37+
JustBeforeEach(func() {
38+
transformedManifest, executeErr = pushActor.HandleDeploymentScaleFlagOverrides(baseManifest, flagOverrides)
39+
})
40+
41+
It("calls each transform-manifest-for-deployment function", func() {
42+
Expect(testFuncCallCount).To(Equal(1))
43+
Expect(executeErr).NotTo(HaveOccurred())
44+
Expect(transformedManifest).To(Equal(baseManifest))
45+
})
46+
})

actor/v7pushaction/handle_disk_override.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,38 @@
11
package v7pushaction
22

33
import (
4+
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant"
45
"code.cloudfoundry.org/cli/command/translatableerror"
56
"code.cloudfoundry.org/cli/util/manifestparser"
67
)
78

89
func HandleDiskOverride(manifest manifestparser.Manifest, overrides FlagOverrides) (manifestparser.Manifest, error) {
10+
if overrides.Strategy != "" {
11+
return manifest, nil
12+
}
13+
14+
if overrides.Disk != "" {
15+
if manifest.ContainsMultipleApps() {
16+
return manifest, translatableerror.CommandLineArgsWithMultipleAppsError{}
17+
}
18+
19+
webProcess := manifest.GetFirstAppWebProcess()
20+
if webProcess != nil {
21+
webProcess.DiskQuota = overrides.Disk
22+
} else {
23+
app := manifest.GetFirstApp()
24+
app.DiskQuota = overrides.Disk
25+
}
26+
}
27+
28+
return manifest, nil
29+
}
30+
31+
func HandleDiskOverrideForDeployment(manifest manifestparser.Manifest, overrides FlagOverrides) (manifestparser.Manifest, error) {
32+
if overrides.Strategy != constant.DeploymentStrategyRolling && overrides.Strategy != constant.DeploymentStrategyCanary {
33+
return manifest, nil
34+
}
35+
936
if overrides.Disk != "" {
1037
if manifest.ContainsMultipleApps() {
1138
return manifest, translatableerror.CommandLineArgsWithMultipleAppsError{}

0 commit comments

Comments
 (0)