Skip to content

Commit f6e105b

Browse files
authored
Validate machine limits before performing b/g deployment (#2817)
validate org limits before performing bluegreen deployment
1 parent f8e5ccc commit f6e105b

File tree

4 files changed

+60
-15
lines changed

4 files changed

+60
-15
lines changed

api/resource_deploy.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,22 @@ func (c *Client) GetReleaseCommand(ctx context.Context, id string) (*ReleaseComm
121121

122122
return data.ReleaseCommandNode, nil
123123
}
124+
125+
func (c *Client) CanPerformBluegreenDeployment(ctx context.Context, appName string) (bool, error) {
126+
query := `
127+
query ($appName: String!) {
128+
canPerformBluegreenDeployment(name: $appName)
129+
}
130+
`
131+
132+
req := c.NewRequest(query)
133+
134+
req.Var("appName", appName)
135+
136+
data, err := c.RunWithContext(ctx, req)
137+
if err != nil {
138+
return false, err
139+
}
140+
141+
return data.CanPerformBluegreenDeployment, nil
142+
}

api/types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ type Query struct {
215215
UpdateRemoteBuilder struct {
216216
Organization Organization
217217
}
218+
219+
CanPerformBluegreenDeployment bool
218220
}
219221

220222
type CreatedWireGuardPeer struct {

gql/schema.graphql

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6292,7 +6292,7 @@ input MigrateVolumeInput {
62926292
"""
62936293
The target Volume ID to be migrated
62946294
"""
6295-
targetVolumeId: Int!
6295+
targetVolumeId: String!
62966296

62976297
"""
62986298
Use the latest snapshot instead of creating a new one.
@@ -8222,6 +8222,16 @@ type Queries {
82228222
type: String @deprecated(reason: "will be removed")
82238223
): AppConnection!
82248224

8225+
"""
8226+
Verifies if an app can undergo a bluegreen deployment
8227+
"""
8228+
canPerformBluegreenDeployment(
8229+
"""
8230+
The name of the app
8231+
"""
8232+
name: String!
8233+
): Boolean!
8234+
82258235
"""
82268236
Find a certificate by ID
82278237
"""
@@ -8674,7 +8684,7 @@ input RegisterVolumeInput {
86748684
"""
86758685
The application to attach the new volume to
86768686
"""
8677-
appId: ID!
8687+
appId: Int!
86788688
autoBackupEnabled: Boolean!
86798689

86808690
"""
@@ -8702,7 +8712,7 @@ input RegisterVolumeInput {
87028712
Desired volume size, in GB
87038713
"""
87048714
sizeGb: Int!
8705-
snapshotId: ID
8715+
snapshot: ID
87068716
volumeId: String!
87078717
}
87088718

internal/command/deploy/strategy_bluegreen.go

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
"github.com/superfly/flyctl/api"
1515
"github.com/superfly/flyctl/flaps"
16+
"github.com/superfly/flyctl/internal/appconfig"
1617
"github.com/superfly/flyctl/internal/ctrlc"
1718
"github.com/superfly/flyctl/internal/machine"
1819
"github.com/superfly/flyctl/iostreams"
@@ -27,21 +28,23 @@ var (
2728
ErrMarkReadyForTraffic = errors.New("failed to mark green machines as ready")
2829
ErrDestroyBlueMachines = errors.New("failed to destroy previous deployment")
2930
ErrValidationError = errors.New("app not in valid state for bluegreen deployments")
31+
ErrOrgLimit = errors.New("app can't undergo bluegreen deployment due to org limits")
3032
)
3133

3234
type blueGreen struct {
33-
greenMachines []machine.LeasableMachine
34-
blueMachines []*machineUpdateEntry
35-
flaps *flaps.Client
36-
io *iostreams.IOStreams
37-
colorize *iostreams.ColorScheme
38-
clearLinesAbove func(count int)
39-
timeout time.Duration
40-
aborted atomic.Bool
41-
healthLock sync.RWMutex
42-
stateLock sync.RWMutex
43-
ctrlcHook ctrlc.Handle
44-
35+
greenMachines []machine.LeasableMachine
36+
blueMachines []*machineUpdateEntry
37+
flaps *flaps.Client
38+
apiClient *api.Client
39+
io *iostreams.IOStreams
40+
colorize *iostreams.ColorScheme
41+
clearLinesAbove func(count int)
42+
timeout time.Duration
43+
aborted atomic.Bool
44+
healthLock sync.RWMutex
45+
stateLock sync.RWMutex
46+
ctrlcHook ctrlc.Handle
47+
appConfig *appconfig.Config
4548
hangingBlueMachines []string
4649
}
4750

@@ -50,6 +53,8 @@ func BlueGreenStrategy(md *machineDeployment, blueMachines []*machineUpdateEntry
5053
greenMachines: []machine.LeasableMachine{},
5154
blueMachines: blueMachines,
5255
flaps: md.flapsClient,
56+
apiClient: md.apiClient,
57+
appConfig: md.appConfig,
5358
timeout: md.waitTimeout,
5459
io: md.io,
5560
colorize: md.colorize,
@@ -415,6 +420,15 @@ func (bg *blueGreen) Deploy(ctx context.Context) error {
415420
return ErrAborted
416421
}
417422

423+
canPerform, err := bg.apiClient.CanPerformBluegreenDeployment(ctx, bg.appConfig.AppName)
424+
if err != nil {
425+
return err
426+
}
427+
428+
if !canPerform {
429+
return ErrOrgLimit
430+
}
431+
418432
bg.attachCustomTopLevelChecks()
419433

420434
totalChecks := 0

0 commit comments

Comments
 (0)