Skip to content

cf push to use deployment scale options for rolling and canary deployments #3535

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
19 changes: 12 additions & 7 deletions actor/v7pushaction/actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ type Actor struct {
SharedActor SharedActor
V7Actor V7Actor

PreparePushPlanSequence []UpdatePushPlanFunc
ChangeApplicationSequence func(plan PushPlan) []ChangeApplicationFunc
TransformManifestSequence []HandleFlagOverrideFunc

startWithProtocol *regexp.Regexp
urlValidator *regexp.Regexp
PreparePushPlanSequence []UpdatePushPlanFunc
ChangeApplicationSequence func(plan PushPlan) []ChangeApplicationFunc
TransformManifestSequence []HandleFlagOverrideFunc
TransformManifestSequenceForDeployment []HandleFlagOverrideFunc
startWithProtocol *regexp.Regexp
urlValidator *regexp.Regexp
}

const ProtocolRegexp = "^https?://|^tcp://"
Expand Down Expand Up @@ -69,7 +69,12 @@ func NewActor(v3Actor V7Actor, sharedActor SharedActor) *Actor {
HandleAppPathOverride,
HandleDropletPathOverride,
}

actor.TransformManifestSequenceForDeployment = []HandleFlagOverrideFunc{
HandleInstancesOverrideForDeployment,
HandleMemoryOverrideForDeployment,
HandleDiskOverrideForDeployment,
HandleLogRateLimitOverrideForDeployment,
}
actor.PreparePushPlanSequence = []UpdatePushPlanFunc{
SetDefaultBitsPathForPushPlan,
SetupDropletPathForPushPlan,
Expand Down
11 changes: 11 additions & 0 deletions actor/v7pushaction/actor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,15 @@ var _ = Describe("Actor", func() {
))
})
})

Describe("TransformManifestSequenceForDeployment", func() {
It("is a list of functions for preparing the push plan", func() {
Expect(actor.TransformManifestSequenceForDeployment).To(matchers.MatchFuncsByName(
HandleInstancesOverrideForDeployment,
HandleMemoryOverrideForDeployment,
HandleDiskOverrideForDeployment,
HandleLogRateLimitOverrideForDeployment,
))
})
})
})
5 changes: 5 additions & 0 deletions actor/v7pushaction/create_deployment_for_push_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ func (actor Actor) CreateDeploymentForApplication(pushPlan PushPlan, eventStream
}
}

dep.Options.Instances = pushPlan.Instances
dep.Options.MemoryInMB = pushPlan.MemoryInMB
dep.Options.DiskInMB = pushPlan.DiskInMB
dep.Options.LogRateLimitInBPS = pushPlan.LogRateLimitInBPS

deploymentGUID, warnings, err := actor.V7Actor.CreateDeployment(dep)

if err != nil {
Expand Down
12 changes: 11 additions & 1 deletion actor/v7pushaction/create_deployment_for_push_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"code.cloudfoundry.org/cli/actor/v7pushaction/v7pushactionfakes"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant"
"code.cloudfoundry.org/cli/resources"
"code.cloudfoundry.org/cli/types"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
Expand Down Expand Up @@ -122,6 +123,10 @@ var _ = Describe("CreateDeploymentForApplication()", func() {
)
paramPlan.Strategy = "rolling"
paramPlan.MaxInFlight = 10
paramPlan.Instances = types.NullInt{IsSet: true, Value: 3}
paramPlan.MemoryInMB = types.NullUint64{IsSet: true, Value: 10}
paramPlan.DiskInMB = types.NullUint64{IsSet: true, Value: 20}
paramPlan.LogRateLimitInBPS = types.NullInt{IsSet: true, Value: 30}
})

It("waits for the app to start", func() {
Expand All @@ -135,7 +140,12 @@ var _ = Describe("CreateDeploymentForApplication()", func() {
dep := fakeV7Actor.CreateDeploymentArgsForCall(0)
Expect(dep).To(Equal(resources.Deployment{
Strategy: "rolling",
Options: resources.DeploymentOpts{MaxInFlight: 10},
Options: resources.DeploymentOpts{MaxInFlight: 10,
Instances: types.NullInt{IsSet: true, Value: 3},
MemoryInMB: types.NullUint64{IsSet: true, Value: 10},
DiskInMB: types.NullUint64{IsSet: true, Value: 20},
LogRateLimitInBPS: types.NullInt{IsSet: true, Value: 30},
},
Relationships: resources.Relationships{
constant.RelationshipTypeApplication: resources.Relationship{GUID: "some-app-guid"},
},
Expand Down
22 changes: 22 additions & 0 deletions actor/v7pushaction/handle_deployment_scale_flag_overrides.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package v7pushaction

import (
"code.cloudfoundry.org/cli/util/manifestparser"
)

func (actor Actor) HandleDeploymentScaleFlagOverrides(
baseManifest manifestparser.Manifest,
flagOverrides FlagOverrides,
) (manifestparser.Manifest, error) {
newManifest := baseManifest

for _, transformPlan := range actor.TransformManifestSequenceForDeployment {
var err error
newManifest, err = transformPlan(newManifest, flagOverrides)
if err != nil {
return manifestparser.Manifest{}, err
}
}

return newManifest, nil
}
46 changes: 46 additions & 0 deletions actor/v7pushaction/handle_deployment_scale_flag_overrides_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package v7pushaction_test

import (
. "code.cloudfoundry.org/cli/actor/v7pushaction"
"code.cloudfoundry.org/cli/util/manifestparser"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

var _ = Describe("HandleDeploymentScaleFlagOverrides", func() {
var (
pushActor *Actor
baseManifest manifestparser.Manifest
flagOverrides FlagOverrides
transformedManifest manifestparser.Manifest
executeErr error

testFuncCallCount int
)

testTransformManifestFunc := func(manifest manifestparser.Manifest, overrides FlagOverrides) (manifestparser.Manifest, error) {
testFuncCallCount += 1
return manifest, nil
}

BeforeEach(func() {
baseManifest = manifestparser.Manifest{}
flagOverrides = FlagOverrides{}
testFuncCallCount = 0

pushActor, _, _ = getTestPushActor()
pushActor.TransformManifestSequenceForDeployment = []HandleFlagOverrideFunc{
testTransformManifestFunc,
}
})

JustBeforeEach(func() {
transformedManifest, executeErr = pushActor.HandleDeploymentScaleFlagOverrides(baseManifest, flagOverrides)
})

It("calls each transform-manifest-for-deployment function", func() {
Expect(testFuncCallCount).To(Equal(1))
Expect(executeErr).NotTo(HaveOccurred())
Expect(transformedManifest).To(Equal(baseManifest))
})
})
27 changes: 27 additions & 0 deletions actor/v7pushaction/handle_disk_override.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,38 @@
package v7pushaction

import (
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant"
"code.cloudfoundry.org/cli/command/translatableerror"
"code.cloudfoundry.org/cli/util/manifestparser"
)

func HandleDiskOverride(manifest manifestparser.Manifest, overrides FlagOverrides) (manifestparser.Manifest, error) {
if overrides.Strategy != "" {
return manifest, nil
}

if overrides.Disk != "" {
if manifest.ContainsMultipleApps() {
return manifest, translatableerror.CommandLineArgsWithMultipleAppsError{}
}

webProcess := manifest.GetFirstAppWebProcess()
if webProcess != nil {
webProcess.DiskQuota = overrides.Disk
} else {
app := manifest.GetFirstApp()
app.DiskQuota = overrides.Disk
}
}

return manifest, nil
}

func HandleDiskOverrideForDeployment(manifest manifestparser.Manifest, overrides FlagOverrides) (manifestparser.Manifest, error) {
if overrides.Strategy != constant.DeploymentStrategyRolling && overrides.Strategy != constant.DeploymentStrategyCanary {
return manifest, nil
}

if overrides.Disk != "" {
if manifest.ContainsMultipleApps() {
return manifest, translatableerror.CommandLineArgsWithMultipleAppsError{}
Expand Down
Loading
Loading