Skip to content

Commit 12e4524

Browse files
committed
Add min capi version check on instance steps commands
Signed-off-by: João Pereira <joao.pereira@broadcom.com>
1 parent 15e2367 commit 12e4524

11 files changed

Lines changed: 114 additions & 5 deletions

api/cloudcontroller/ccversion/minimum_version.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ const (
44
MinSupportedV2ClientVersion = "2.128.0"
55
MinSupportedClientVersionV9 = "3.160.0"
66

7-
MinVersionUpdateServiceNameWhenPlanNotVisibleV2 = "2.131.0"
8-
MinVersionUpdateServiceInstanceMaintenanceInfoV2 = "2.135.0"
9-
MinVersionMaintenanceInfoInSummaryV2 = "2.138.0"
10-
117
MinVersionCreateServiceBrokerV3 = "3.72.0"
128
MinVersionCreateSpaceScopedServiceBrokerV3 = "3.75.0"
139

@@ -16,4 +12,6 @@ const (
1612

1713
MinVersionLogRateLimitingV3 = "3.125.0"
1814
MinVersionPerRouteOpts = "3.183.0"
15+
16+
MinVersionCanarySteps = "3.254.0"
1917
)

command/v7/copy_source_command.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"code.cloudfoundry.org/cli/actor/v7action"
88
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant"
9+
"code.cloudfoundry.org/cli/api/cloudcontroller/ccversion"
910
"code.cloudfoundry.org/cli/api/logcache"
1011
"code.cloudfoundry.org/cli/command"
1112
"code.cloudfoundry.org/cli/command/flag"
@@ -70,6 +71,10 @@ func (cmd *CopySourceCommand) ValidateFlags() error {
7071
return translatableerror.ParseArgumentError{ArgumentName: "--instance-steps", ExpectedType: "list of weights"}
7172
}
7273

74+
if len(cmd.InstanceSteps) > 0 {
75+
return command.MinimumCCAPIVersionCheck(cmd.Config.APIVersion(), ccversion.MinVersionCanarySteps, "--instance-steps")
76+
}
77+
7378
return nil
7479
}
7580

command/v7/copy_source_command_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,5 +480,19 @@ var _ = Describe("copy-source Command", func() {
480480
ArgumentName: "--instance-steps",
481481
ExpectedType: "list of weights",
482482
}),
483+
484+
Entry("instance-steps used when CAPI does not support canary steps",
485+
func() {
486+
cmd.InstanceSteps = "1,2,3"
487+
cmd.Strategy.Name = constant.DeploymentStrategyCanary
488+
fakeConfig = &commandfakes.FakeConfig{}
489+
fakeConfig.APIVersionReturns("3.0.0")
490+
cmd.Config = fakeConfig
491+
},
492+
translatableerror.MinimumCFAPIVersionNotMetError{
493+
Command: "--instance-steps",
494+
CurrentVersion: "3.0.0",
495+
MinimumVersion: "3.254.0",
496+
}),
483497
)
484498
})

command/v7/push_command.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"strconv"
88
"strings"
99

10+
"code.cloudfoundry.org/cli/api/cloudcontroller/ccversion"
1011
"github.com/cloudfoundry/bosh-cli/director/template"
1112
log "github.com/sirupsen/logrus"
1213
"gopkg.in/yaml.v2"
@@ -578,6 +579,10 @@ func (cmd PushCommand) ValidateFlags() error {
578579
return translatableerror.ParseArgumentError{ArgumentName: "--instance-steps", ExpectedType: "list of weights"}
579580
}
580581

582+
if len(cmd.InstanceSteps) > 0 {
583+
return command.MinimumCCAPIVersionCheck(cmd.Config.APIVersion(), ccversion.MinVersionCanarySteps, "--instance-steps")
584+
}
585+
581586
return nil
582587
}
583588

command/v7/push_command_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,9 @@ var _ = Describe("push Command", func() {
628628
When("canary strategy is provided", func() {
629629
BeforeEach(func() {
630630
cmd.Strategy = flag.DeploymentStrategy{Name: "canary"}
631+
fakeConfig = &commandfakes.FakeConfig{}
632+
fakeConfig.APIVersionReturns("4.0.0")
633+
cmd.Config = fakeConfig
631634
})
632635

633636
It("should succeed", func() {
@@ -1440,5 +1443,19 @@ var _ = Describe("push Command", func() {
14401443
Args: []string{
14411444
"--instance-steps", "--strategy=rolling or --strategy not provided",
14421445
}}),
1446+
1447+
Entry("instance-steps used when CAPI does not support canary steps",
1448+
func() {
1449+
cmd.InstanceSteps = "1,2,3"
1450+
cmd.Strategy.Name = constant.DeploymentStrategyCanary
1451+
fakeConfig = &commandfakes.FakeConfig{}
1452+
fakeConfig.APIVersionReturns("3.0.0")
1453+
cmd.Config = fakeConfig
1454+
},
1455+
translatableerror.MinimumCFAPIVersionNotMetError{
1456+
Command: "--instance-steps",
1457+
CurrentVersion: "3.0.0",
1458+
MinimumVersion: "3.254.0",
1459+
}),
14431460
)
14441461
})

command/v7/restage_command.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"code.cloudfoundry.org/cli/actor/actionerror"
88
"code.cloudfoundry.org/cli/actor/v7action"
99
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant"
10+
"code.cloudfoundry.org/cli/api/cloudcontroller/ccversion"
1011
"code.cloudfoundry.org/cli/api/logcache"
1112
"code.cloudfoundry.org/cli/command"
1213
"code.cloudfoundry.org/cli/command/flag"
@@ -130,6 +131,10 @@ func (cmd RestageCommand) ValidateFlags() error {
130131
return translatableerror.ParseArgumentError{ArgumentName: "--instance-steps", ExpectedType: "list of weights"}
131132
}
132133

134+
if len(cmd.InstanceSteps) > 0 {
135+
return command.MinimumCCAPIVersionCheck(cmd.Config.APIVersion(), ccversion.MinVersionCanarySteps, "--instance-steps")
136+
}
137+
133138
return nil
134139
}
135140

command/v7/restage_command_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ var _ = Describe("restage Command", func() {
124124
BeforeEach(func() {
125125
cmd.Strategy = flag.DeploymentStrategy{Name: constant.DeploymentStrategyCanary}
126126
cmd.InstanceSteps = "1,2,4"
127+
fakeConfig = &commandfakes.FakeConfig{}
128+
fakeConfig.APIVersionReturns("4.0.0")
129+
cmd.Config = fakeConfig
127130
})
128131

129132
It("starts the app with the current droplet", func() {
@@ -276,5 +279,19 @@ var _ = Describe("restage Command", func() {
276279
ArgumentName: "--instance-steps",
277280
ExpectedType: "list of weights",
278281
}),
282+
283+
Entry("instance-steps used when CAPI does not support canary steps",
284+
func() {
285+
cmd.InstanceSteps = "1,2,3"
286+
cmd.Strategy.Name = constant.DeploymentStrategyCanary
287+
fakeConfig = &commandfakes.FakeConfig{}
288+
fakeConfig.APIVersionReturns("3.0.0")
289+
cmd.Config = fakeConfig
290+
},
291+
translatableerror.MinimumCFAPIVersionNotMetError{
292+
Command: "--instance-steps",
293+
CurrentVersion: "3.0.0",
294+
MinimumVersion: "3.254.0",
295+
}),
279296
)
280297
})

command/v7/restart_command.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"code.cloudfoundry.org/cli/actor/v7action"
88
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant"
9+
"code.cloudfoundry.org/cli/api/cloudcontroller/ccversion"
910
"code.cloudfoundry.org/cli/api/logcache"
1011
"code.cloudfoundry.org/cli/command"
1112
"code.cloudfoundry.org/cli/command/flag"
@@ -133,5 +134,9 @@ func (cmd RestartCommand) ValidateFlags() error {
133134
return translatableerror.ParseArgumentError{ArgumentName: "--instance-steps", ExpectedType: "list of weights"}
134135
}
135136

137+
if len(cmd.InstanceSteps) > 0 {
138+
return command.MinimumCCAPIVersionCheck(cmd.Config.APIVersion(), ccversion.MinVersionCanarySteps, "--instance-steps")
139+
}
140+
136141
return nil
137142
}

command/v7/restart_command_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ var _ = Describe("restart Command", func() {
154154
BeforeEach(func() {
155155
cmd.Strategy = flag.DeploymentStrategy{Name: constant.DeploymentStrategyCanary}
156156
cmd.InstanceSteps = "1,2,4"
157+
fakeConfig = &commandfakes.FakeConfig{}
158+
fakeConfig.APIVersionReturns("4.0.0")
159+
cmd.Config = fakeConfig
157160
})
158161

159162
It("starts the app with the current droplet", func() {
@@ -209,6 +212,10 @@ var _ = Describe("restart Command", func() {
209212
BeforeEach(func() {
210213
cmd.Strategy = flag.DeploymentStrategy{Name: constant.DeploymentStrategyCanary}
211214
cmd.InstanceSteps = "1,2,4"
215+
216+
fakeConfig = &commandfakes.FakeConfig{}
217+
fakeConfig.APIVersionReturns("4.0.0")
218+
cmd.Config = fakeConfig
212219
})
213220

214221
It("starts the app with the current droplet", func() {
@@ -297,5 +304,19 @@ var _ = Describe("restart Command", func() {
297304
ArgumentName: "--instance-steps",
298305
ExpectedType: "list of weights",
299306
}),
307+
308+
Entry("instance-steps used when CAPI does not support canary steps",
309+
func() {
310+
cmd.InstanceSteps = "1,2,3"
311+
cmd.Strategy.Name = constant.DeploymentStrategyCanary
312+
fakeConfig = &commandfakes.FakeConfig{}
313+
fakeConfig.APIVersionReturns("3.0.0")
314+
cmd.Config = fakeConfig
315+
},
316+
translatableerror.MinimumCFAPIVersionNotMetError{
317+
Command: "--instance-steps",
318+
CurrentVersion: "3.0.0",
319+
MinimumVersion: "3.254.0",
320+
}),
300321
)
301322
})

command/v7/rollback_command.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"code.cloudfoundry.org/cli/actor/sharedaction"
99
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant"
10+
"code.cloudfoundry.org/cli/api/cloudcontroller/ccversion"
1011
"code.cloudfoundry.org/cli/cf/errors"
1112
"code.cloudfoundry.org/cli/command"
1213
"code.cloudfoundry.org/cli/command/flag"
@@ -156,5 +157,9 @@ func (cmd RollbackCommand) ValidateFlags() error {
156157
return translatableerror.ParseArgumentError{ArgumentName: "--instance-steps", ExpectedType: "list of weights"}
157158
}
158159

160+
if len(cmd.InstanceSteps) > 0 {
161+
return command.MinimumCCAPIVersionCheck(cmd.Config.APIVersion(), ccversion.MinVersionCanarySteps, "--instance-steps")
162+
}
163+
159164
return nil
160165
}

0 commit comments

Comments
 (0)