Skip to content

Commit cf22c32

Browse files
authored
cmd: Add --skip-tracking flag to allocator vacate (#119)
Adds a --skip-tracking flag which will make the whole operation async and not wait for the deployments to complete moving nodes. Adds an interactive warning which can be skipped with the `--force` flag. Signed-off-by: Marc Lopez <marc5.12@outlook.com>
1 parent 4eeb7a2 commit cf22c32

File tree

5 files changed

+75
-13
lines changed

5 files changed

+75
-13
lines changed

cmd/platform/allocator/vacate.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,18 @@ const vacateExamples = ` ecctl [globalFlags] allocator vacate i-05e245252362f7f
6060
6161
# Override the skip_data_migration setting
6262
ecctl [globalFlags] allocator vacate --skip-data-migration=true i-05e245252362f7f1d -c f521dedb07194c478fbbc6624f3bbf8f
63-
`
63+
64+
# Skips tracking the vacate progress which will cause the command to return almost immediately.
65+
# Not recommended since it can lead to failed vacates without the operator knowing about them.
66+
ecctl [globalFlags] allocator vacate --skip-tracking i-05e245252362f7f1d
67+
`
6468

6569
var vacateAllocatorCmd = &cobra.Command{
6670
Use: "vacate <source>",
6771
Short: "Moves all the clusters from the specified allocator",
6872
Example: vacateExamples,
6973
PreRunE: cobra.MinimumNArgs(1),
7074
Aliases: []string{"move-nodes"},
71-
7275
RunE: func(cmd *cobra.Command, args []string) error {
7376
concurrency, err := strconv.ParseUint(cmd.Flag("concurrency").Value.String(), 10, 64)
7477
if err != nil {
@@ -127,6 +130,11 @@ var vacateAllocatorCmd = &cobra.Command{
127130
return err
128131
}
129132

133+
skipTracking, _ := cmd.Flags().GetBool("skip-tracking")
134+
if !force && skipTracking && !cmdutil.ConfirmAction("--skip-tracking flag specified. Are you sure you want to proceed? [y/N]: ", os.Stdin, os.Stderr) {
135+
return nil
136+
}
137+
130138
setAllocatorMaintenance, _ := cmd.Flags().GetBool("maintenance")
131139

132140
var merr error
@@ -156,6 +164,7 @@ var vacateAllocatorCmd = &cobra.Command{
156164
Concurrency: uint16(concurrency),
157165
Output: ecctl.Get().Config.OutputDevice,
158166
MoveOnly: ec.Bool(moveOnly),
167+
SkipTracking: skipTracking,
159168
PlanOverrides: allocator.PlanOverrides{
160169
SkipSnapshot: skipSnapshot,
161170
SkipDataMigration: skipDataMigration,
@@ -180,7 +189,7 @@ func validateSkipDataMigration(clusters []string, moveOnly bool) error {
180189

181190
func init() {
182191
Command.AddCommand(vacateAllocatorCmd)
183-
192+
vacateAllocatorCmd.Flags().Bool("skip-tracking", false, "Skips tracking the vacate progress causing the command to return after the move operation has been executed. Not recommended.")
184193
vacateAllocatorCmd.Flags().StringP("kind", "k", "", "Kind of workload to vacate (elasticsearch|kibana)")
185194
vacateAllocatorCmd.Flags().StringArrayP("cluster", "c", nil, "Cluster IDs to include in the vacate")
186195
vacateAllocatorCmd.Flags().StringArrayP("target", "t", nil, "Target allocator(s) on which to place the vacated workload")

docs/ecctl_platform_allocator_vacate.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ ecctl platform allocator vacate <source> [flags]
4242
# Override the skip_data_migration setting
4343
ecctl [globalFlags] allocator vacate --skip-data-migration=true i-05e245252362f7f1d -c f521dedb07194c478fbbc6624f3bbf8f
4444
45+
# Skips tracking the vacate progress which will cause the command to return almost immediately.
46+
# Not recommended since it can lead to failed vacates without the operator knowing about them.
47+
ecctl [globalFlags] allocator vacate --skip-tracking i-05e245252362f7f1d
48+
4549
```
4650

4751
### Options
@@ -57,6 +61,7 @@ ecctl platform allocator vacate <source> [flags]
5761
--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]
5862
--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]
5963
--skip-snapshot string Skips the snapshot operation on the specified cluster IDs. ONLY available when the cluster IDs are specified. [true|false]
64+
--skip-tracking Skips tracking the vacate progress causing the command to return after the move operation has been executed. Not recommended.
6065
-t, --target stringArray Target allocator(s) on which to place the vacated workload
6166
```
6267

pkg/platform/allocator/vacate.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ func newVacateClusterParams(params addAllocatorMovesToPoolParams, id, kind strin
237237
ID: params.ID,
238238
Kind: kind,
239239
ClusterID: id,
240+
SkipTracking: params.VacateParams.SkipTracking,
240241
ClusterFilter: params.VacateParams.ClusterFilter,
241242
PreferredAllocators: params.VacateParams.PreferredAllocators,
242243
MaxPollRetries: params.VacateParams.MaxPollRetries,
@@ -272,6 +273,10 @@ func VacateCluster(params *VacateClusterParams) error {
272273
return err
273274
}
274275

276+
if params.SkipTracking {
277+
return nil
278+
}
279+
275280
return trackMovedCluster(params)
276281
}
277282

pkg/platform/allocator/vacate_params.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ type VacateParams struct {
8686
// bare minimum to move the requested instances across to another allocator.
8787
MoveOnly *bool
8888

89+
// SkipTracking skips displaying and waiting for the individual vacates to complete.
90+
// Setting it to true will render the concurrency flag pretty much ineffective since
91+
// the vacate action is asynchronous and the only thing keeping the working items in
92+
// the pool is the tracking function call which synchronously waits until the vacate
93+
// has effectively finished.
94+
SkipTracking bool
95+
8996
// Plan body overrides to place in all of the vacate clusters.
9097
PlanOverrides
9198
}
@@ -132,20 +139,20 @@ func (params VacateParams) Validate() error {
132139
// VacateClusterParams is used by VacateCluster to move a cluster node
133140
// from an allocator.
134141
type VacateClusterParams struct {
135-
*api.API
136-
ID string
137-
ClusterID string
138-
Kind string
139142
PreferredAllocators []string
140143
ClusterFilter []string
141-
MaxPollRetries uint8
142-
TrackFrequency time.Duration
143-
AllocatorDown *bool
144-
MoveOnly *bool
145-
Output *output.Device
146-
147144
// Plan body overrides to place in all of the vacate clusters.
148145
PlanOverrides
146+
ID string
147+
ClusterID string
148+
Kind string
149+
*api.API
150+
TrackFrequency time.Duration
151+
AllocatorDown *bool
152+
MoveOnly *bool
153+
Output *output.Device
154+
MaxPollRetries uint8
155+
SkipTracking bool
149156
}
150157

151158
// Validate validates the parameters

pkg/platform/allocator/vacate_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,24 @@ func TestVacateCluster(t *testing.T) {
749749
"\x1b[92;mCluster [3ee11eb40eda22cac0cce259625c6734][Elasticsearch]: finished running all the plan steps\x1b[0m (Total plan duration )",
750750
),
751751
},
752+
{
753+
name: "Succeeds with an elasticsearch cluster with no tracking",
754+
args: args{
755+
buf: new(bytes.Buffer),
756+
params: &VacateClusterParams{
757+
ID: "someID",
758+
ClusterID: "3ee11eb40eda22cac0cce259625c6734",
759+
Kind: "elasticsearch",
760+
Output: new(output.Device),
761+
TrackFrequency: time.Nanosecond,
762+
SkipTracking: true,
763+
MaxPollRetries: 1,
764+
API: discardResponses(
765+
newElasticsearchVacateMove(t, "someID", vacateCaseClusterConfig{}),
766+
),
767+
},
768+
},
769+
},
752770
{
753771
name: "Succeeds with a kibana instance",
754772
args: args{
@@ -787,6 +805,24 @@ func TestVacateCluster(t *testing.T) {
787805
"\x1b[92;mCluster [2ee11eb40eda22cac0cce259625c6734][Kibana]: finished running all the plan steps\x1b[0m (Total plan duration )",
788806
),
789807
},
808+
{
809+
name: "Succeeds with a kibana instance with no tracking",
810+
args: args{
811+
buf: new(bytes.Buffer),
812+
params: &VacateClusterParams{
813+
ID: "someID",
814+
ClusterID: "2ee11eb40eda22cac0cce259625c6734",
815+
Kind: "kibana",
816+
Output: new(output.Device),
817+
TrackFrequency: time.Nanosecond,
818+
SkipTracking: true,
819+
MaxPollRetries: 1,
820+
API: discardResponses(
821+
newKibanaVacateMove(t, "someID", vacateCaseClusterConfig{}),
822+
),
823+
},
824+
},
825+
},
790826
{
791827
name: "Moving kibana instance fails",
792828
args: args{

0 commit comments

Comments
 (0)