Skip to content

Commit bd75994

Browse files
Support vacate override failsafe (#82)
1 parent 73c0fac commit bd75994

File tree

5 files changed

+63
-0
lines changed

5 files changed

+63
-0
lines changed

cmd/platform/allocator/vacate.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package cmdallocator
2020
import (
2121
"errors"
2222
"fmt"
23+
"os"
2324
"strconv"
2425

2526
"github.com/elastic/cloud-sdk-go/pkg/util/ec"
@@ -90,6 +91,14 @@ var vacateAllocatorCmd = &cobra.Command{
9091
}
9192

9293
moveOnly, _ := cmd.Flags().GetBool("move-only")
94+
95+
overrideFailsafe, _ := cmd.Flags().GetBool("override-failsafe")
96+
force, _ := cmd.Flags().GetBool("force")
97+
var msg = "--override-failsafe has been flag specified. Are you sure you want to proceed? [y/N]: "
98+
if overrideFailsafe && !force && !cmdutil.ConfirmAction(msg, os.Stderr, os.Stdout) {
99+
return nil
100+
}
101+
93102
target, _ := cmd.Flags().GetStringSlice("target")
94103
kind, _ := cmd.Flags().GetString("kind")
95104

@@ -150,6 +159,7 @@ var vacateAllocatorCmd = &cobra.Command{
150159
PlanOverrides: allocator.PlanOverrides{
151160
SkipSnapshot: skipSnapshot,
152161
SkipDataMigration: skipDataMigration,
162+
OverrideFailsafe: ec.Bool(overrideFailsafe),
153163
},
154164
}
155165
if len(args) == 1 && allocatorDownRaw != "" {
@@ -178,6 +188,7 @@ func init() {
178188
vacateAllocatorCmd.Flags().Uint("concurrency", 8, "Maximum number of concurrent moves to perform at any time")
179189
vacateAllocatorCmd.Flags().String("allocator-down", "", "Disables the allocator health auto-discovery, setting the allocator-down to either [true|false]")
180190
vacateAllocatorCmd.Flags().Bool("move-only", true, "Keeps the cluster in its current -possibly broken- state and just does the bare minimum to move the requested instances across to another allocator. [true|false]")
191+
vacateAllocatorCmd.Flags().Bool("override-failsafe", false, "If false (the default) then the plan will fail out if it believes the requested sequence of operations can result in data loss - this flag will override some of these restraints. [true|false]")
181192
vacateAllocatorCmd.Flags().String("skip-snapshot", "", "Skips the snapshot operation on the specified cluster IDs. ONLY available when the cluster IDs are specified. [true|false]")
182193
vacateAllocatorCmd.Flags().String("skip-data-migration", "", "Skips the data-migration operation on the specified cluster IDs. ONLY available when the cluster IDs are specified and --move-only is true. [true|false]")
183194
}

docs/ecctl_platform_allocator_vacate.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ ecctl platform allocator vacate <source> [flags]
5454
-k, --kind string Kind of workload to vacate (elasticsearch|kibana)
5555
-m, --maintenance Whether to set the allocator(s) in maintenance before performing the vacate
5656
--move-only Keeps the cluster in its current -possibly broken- state and just does the bare minimum to move the requested instances across to another allocator. [true|false] (default true)
57+
--override-failsafe If false (the default) then the plan will fail out if it believes the requested sequence of operations can result in data loss - this flag will override some of these restraints. [true|false]
5758
--skip-data-migration string Skips the data-migration operation on the specified cluster IDs. ONLY available when the cluster IDs are specified and --move-only is true. [true|false]
5859
--skip-snapshot string Skips the snapshot operation on the specified cluster IDs. ONLY available when the cluster IDs are specified. [true|false]
5960
-t, --target stringArray Target allocator(s) on which to place the vacated workload

pkg/platform/allocator/vacate.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,10 @@ func ComputeVacateRequest(pr *models.MoveClustersDetails, clusters, to []string,
472472
c.CalculatedPlan.PlanConfiguration.SkipDataMigration = overrides.SkipDataMigration
473473
}
474474

475+
if overrides.OverrideFailsafe != nil {
476+
c.CalculatedPlan.PlanConfiguration.OverrideFailsafe = overrides.OverrideFailsafe
477+
}
478+
475479
c.CalculatedPlan.PlanConfiguration.PreferredAllocators = to
476480
req.ElasticsearchClusters = append(req.ElasticsearchClusters,
477481
&models.MoveElasticsearchClusterConfiguration{

pkg/platform/allocator/vacate_params.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,5 @@ type PlanOverrides struct {
193193
// SkipSnapshot overwrites the Transient part of an Elastisearch vacate.
194194
SkipSnapshot *bool
195195
SkipDataMigration *bool
196+
OverrideFailsafe *bool
196197
}

pkg/platform/allocator/vacate_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,52 @@ func TestComputeVacateRequest(t *testing.T) {
242242
},
243243
},
244244
},
245+
{
246+
name: "No filters with OverrideFailsafe override",
247+
args: args{
248+
pr: &models.MoveClustersDetails{
249+
ElasticsearchClusters: []*models.MoveElasticsearchClusterDetails{
250+
{
251+
ClusterID: ec.String("63d765d37613423e97b1040257cf20c8"),
252+
CalculatedPlan: &models.TransientElasticsearchPlanConfiguration{
253+
PlanConfiguration: &models.ElasticsearchPlanControlConfiguration{
254+
Timeout: 4096,
255+
ReallocateInstances: ec.Bool(false),
256+
ExtendedMaintenance: ec.Bool(false),
257+
OverrideFailsafe: ec.Bool(false),
258+
SkipDataMigration: ec.Bool(false),
259+
SkipPostUpgradeSteps: ec.Bool(false),
260+
SkipSnapshot: ec.Bool(false),
261+
},
262+
},
263+
},
264+
},
265+
},
266+
clusters: nil,
267+
to: nil,
268+
overrides: PlanOverrides{OverrideFailsafe: ec.Bool(true)},
269+
},
270+
want: &models.MoveClustersRequest{
271+
ElasticsearchClusters: []*models.MoveElasticsearchClusterConfiguration{
272+
{
273+
ClusterIds: []string{
274+
"63d765d37613423e97b1040257cf20c8",
275+
},
276+
PlanOverride: &models.TransientElasticsearchPlanConfiguration{
277+
PlanConfiguration: &models.ElasticsearchPlanControlConfiguration{
278+
Timeout: 4096,
279+
ReallocateInstances: ec.Bool(false),
280+
ExtendedMaintenance: ec.Bool(false),
281+
OverrideFailsafe: ec.Bool(true),
282+
SkipDataMigration: ec.Bool(false),
283+
SkipPostUpgradeSteps: ec.Bool(false),
284+
SkipSnapshot: ec.Bool(false),
285+
},
286+
},
287+
},
288+
},
289+
},
290+
},
245291
{
246292
name: "Set target allocator",
247293
args: args{

0 commit comments

Comments
 (0)