From ba19c5ba30789b14db68605e6d2c73402bc579d4 Mon Sep 17 00:00:00 2001 From: riccardomarinelli Date: Thu, 10 Oct 2024 13:41:59 +0800 Subject: [PATCH 1/6] Add ForceMove option on vacate parameters --- pkg/api/platformapi/allocatorapi/vacate.go | 3 +++ pkg/api/platformapi/allocatorapi/vacate_params.go | 6 +++++- pkg/api/platformapi/allocatorapi/vacate_params_test.go | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/api/platformapi/allocatorapi/vacate.go b/pkg/api/platformapi/allocatorapi/vacate.go index ceacb394..2b8e8d4b 100644 --- a/pkg/api/platformapi/allocatorapi/vacate.go +++ b/pkg/api/platformapi/allocatorapi/vacate.go @@ -126,6 +126,7 @@ func moveNodes(id string, params *VacateParams, p *pool.Pool) ([]pool.Validator, platform_infrastructure.NewMoveClustersParams(). WithAllocatorID(id). WithMoveOnly(params.MoveOnly). + WithForceMove(params.ForceMove). WithContext(api.WithRegion(context.Background(), params.Region)). WithValidateOnly(ec.Bool(true)), params.AuthWriter, @@ -282,6 +283,7 @@ func newVacateClusterParams(params addAllocatorMovesToPoolParams, id, kind strin Output: params.VacateParams.Output, OutputFormat: params.VacateParams.OutputFormat, MoveOnly: params.VacateParams.MoveOnly, + ForceMove: params.VacateParams.ForceMove, PlanOverrides: params.VacateParams.PlanOverrides, } @@ -391,6 +393,7 @@ func newMoveClusterParams(params *VacateClusterParams) (*platform_infrastructure platform_infrastructure.NewMoveClustersParams(). WithAllocatorDown(params.AllocatorDown). WithMoveOnly(params.MoveOnly). + WithForceMove(params.ForceMove). WithAllocatorID(params.ID). WithContext(api.WithRegion(context.Background(), params.Region)). WithValidateOnly(ec.Bool(true)). diff --git a/pkg/api/platformapi/allocatorapi/vacate_params.go b/pkg/api/platformapi/allocatorapi/vacate_params.go index 23f4168d..78e2dce1 100644 --- a/pkg/api/platformapi/allocatorapi/vacate_params.go +++ b/pkg/api/platformapi/allocatorapi/vacate_params.go @@ -51,7 +51,7 @@ var ( ) // VacateParams used to vacate N allocators or clusters. -//nolint +// nolint type VacateParams struct { *api.API @@ -98,6 +98,9 @@ type VacateParams struct { // bare minimum to move the requested instances across to another allocator. MoveOnly *bool + // Optional value to be set to force_move to true for primitive vacate or false for standard. + ForceMove *bool + // SkipTracking skips displaying and waiting for the individual vacates to complete. // Setting it to true will render the concurrency flag pretty much ineffective since // the vacate action is asynchronous and the only thing keeping the working items in @@ -166,6 +169,7 @@ type VacateClusterParams struct { TrackFrequency time.Duration AllocatorDown *bool MoveOnly *bool + ForceMove *bool Output *output.Device OutputFormat string MaxPollRetries uint8 diff --git a/pkg/api/platformapi/allocatorapi/vacate_params_test.go b/pkg/api/platformapi/allocatorapi/vacate_params_test.go index 11dde5eb..5d06e921 100644 --- a/pkg/api/platformapi/allocatorapi/vacate_params_test.go +++ b/pkg/api/platformapi/allocatorapi/vacate_params_test.go @@ -211,6 +211,7 @@ func TestVacateClusterParamsValidate(t *testing.T) { TrackFrequency time.Duration AllocatorDown *bool MoveOnly *bool + ForceMove *bool Output *output.Device OutputFormat string MaxPollRetries uint8 From 5ea6794c3206d49a561c80e5ae981100df1ff249 Mon Sep 17 00:00:00 2001 From: riccardomarinelli Date: Mon, 14 Oct 2024 10:10:48 +0800 Subject: [PATCH 2/6] Update moveParams to add ForceMove --- pkg/api/platformapi/allocatorapi/vacate.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/api/platformapi/allocatorapi/vacate.go b/pkg/api/platformapi/allocatorapi/vacate.go index 2b8e8d4b..53fe61e0 100644 --- a/pkg/api/platformapi/allocatorapi/vacate.go +++ b/pkg/api/platformapi/allocatorapi/vacate.go @@ -420,6 +420,7 @@ func newMoveClusterParams(params *VacateClusterParams) (*platform_infrastructure WithAllocatorID(params.ID). WithAllocatorDown(params.AllocatorDown). WithContext(api.WithRegion(context.Background(), params.Region)). + WithForceMove(params.ForceMove). WithBody(req) if len(req.ElasticsearchClusters) > 0 { From 799ce06f885b41e2348ef087dccf2bb5f670a2a9 Mon Sep 17 00:00:00 2001 From: riccardomarinelli Date: Mon, 14 Oct 2024 13:20:29 +0800 Subject: [PATCH 3/6] Remove uneeded entries and Update vacate Tests --- pkg/api/platformapi/allocatorapi/vacate.go | 3 --- pkg/api/platformapi/allocatorapi/vacate_test.go | 2 ++ 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/pkg/api/platformapi/allocatorapi/vacate.go b/pkg/api/platformapi/allocatorapi/vacate.go index 53fe61e0..2af7283b 100644 --- a/pkg/api/platformapi/allocatorapi/vacate.go +++ b/pkg/api/platformapi/allocatorapi/vacate.go @@ -126,7 +126,6 @@ func moveNodes(id string, params *VacateParams, p *pool.Pool) ([]pool.Validator, platform_infrastructure.NewMoveClustersParams(). WithAllocatorID(id). WithMoveOnly(params.MoveOnly). - WithForceMove(params.ForceMove). WithContext(api.WithRegion(context.Background(), params.Region)). WithValidateOnly(ec.Bool(true)), params.AuthWriter, @@ -283,7 +282,6 @@ func newVacateClusterParams(params addAllocatorMovesToPoolParams, id, kind strin Output: params.VacateParams.Output, OutputFormat: params.VacateParams.OutputFormat, MoveOnly: params.VacateParams.MoveOnly, - ForceMove: params.VacateParams.ForceMove, PlanOverrides: params.VacateParams.PlanOverrides, } @@ -393,7 +391,6 @@ func newMoveClusterParams(params *VacateClusterParams) (*platform_infrastructure platform_infrastructure.NewMoveClustersParams(). WithAllocatorDown(params.AllocatorDown). WithMoveOnly(params.MoveOnly). - WithForceMove(params.ForceMove). WithAllocatorID(params.ID). WithContext(api.WithRegion(context.Background(), params.Region)). WithValidateOnly(ec.Bool(true)). diff --git a/pkg/api/platformapi/allocatorapi/vacate_test.go b/pkg/api/platformapi/allocatorapi/vacate_test.go index 50a1a3c8..a966becc 100644 --- a/pkg/api/platformapi/allocatorapi/vacate_test.go +++ b/pkg/api/platformapi/allocatorapi/vacate_test.go @@ -1295,11 +1295,13 @@ func Test_newMoveClusterParams(t *testing.T) { Kind: "elasticsearch", Output: output.NewDevice(new(bytes.Buffer)), AllocatorDown: ec.Bool(false), + ForceMove: ec.Bool(true), }}, want: platform_infrastructure.NewMoveClustersByTypeParams(). WithAllocatorID("allocator-1"). WithClusterType(util.Elasticsearch). WithAllocatorDown(ec.Bool(false)). + WithForceMove(ec.Bool(true)). WithContext(api.WithRegion(context.Background(), "us-east-1")). WithBody(&models.MoveClustersRequest{ ElasticsearchClusters: []*models.MoveElasticsearchClusterConfiguration{ From 7d3cc6748f7f9030b12dd54f517568e88f115f80 Mon Sep 17 00:00:00 2001 From: riccardomarinelli Date: Mon, 14 Oct 2024 13:46:52 +0800 Subject: [PATCH 4/6] Add previously removed force-move entries --- pkg/api/platformapi/allocatorapi/vacate.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/api/platformapi/allocatorapi/vacate.go b/pkg/api/platformapi/allocatorapi/vacate.go index 2af7283b..491b8ce9 100644 --- a/pkg/api/platformapi/allocatorapi/vacate.go +++ b/pkg/api/platformapi/allocatorapi/vacate.go @@ -127,6 +127,7 @@ func moveNodes(id string, params *VacateParams, p *pool.Pool) ([]pool.Validator, WithAllocatorID(id). WithMoveOnly(params.MoveOnly). WithContext(api.WithRegion(context.Background(), params.Region)). + WithForceMove(params.ForceMove). WithValidateOnly(ec.Bool(true)), params.AuthWriter, ) @@ -282,6 +283,7 @@ func newVacateClusterParams(params addAllocatorMovesToPoolParams, id, kind strin Output: params.VacateParams.Output, OutputFormat: params.VacateParams.OutputFormat, MoveOnly: params.VacateParams.MoveOnly, + ForceMove: params.VacateParams.ForceMove, PlanOverrides: params.VacateParams.PlanOverrides, } @@ -391,6 +393,7 @@ func newMoveClusterParams(params *VacateClusterParams) (*platform_infrastructure platform_infrastructure.NewMoveClustersParams(). WithAllocatorDown(params.AllocatorDown). WithMoveOnly(params.MoveOnly). + WithForceMove(params.ForceMove). WithAllocatorID(params.ID). WithContext(api.WithRegion(context.Background(), params.Region)). WithValidateOnly(ec.Bool(true)). From 9a535963539f58168fe9ef07b4ac1acf5b63aa54 Mon Sep 17 00:00:00 2001 From: riccardomarinelli Date: Mon, 14 Oct 2024 14:17:31 +0800 Subject: [PATCH 5/6] Remove platform_infrastructure.NewMoveClustersByTypeParams entry --- pkg/api/platformapi/allocatorapi/vacate.go | 1 - pkg/api/platformapi/allocatorapi/vacate_test.go | 2 -- 2 files changed, 3 deletions(-) diff --git a/pkg/api/platformapi/allocatorapi/vacate.go b/pkg/api/platformapi/allocatorapi/vacate.go index 491b8ce9..fb4c04ef 100644 --- a/pkg/api/platformapi/allocatorapi/vacate.go +++ b/pkg/api/platformapi/allocatorapi/vacate.go @@ -420,7 +420,6 @@ func newMoveClusterParams(params *VacateClusterParams) (*platform_infrastructure WithAllocatorID(params.ID). WithAllocatorDown(params.AllocatorDown). WithContext(api.WithRegion(context.Background(), params.Region)). - WithForceMove(params.ForceMove). WithBody(req) if len(req.ElasticsearchClusters) > 0 { diff --git a/pkg/api/platformapi/allocatorapi/vacate_test.go b/pkg/api/platformapi/allocatorapi/vacate_test.go index a966becc..50a1a3c8 100644 --- a/pkg/api/platformapi/allocatorapi/vacate_test.go +++ b/pkg/api/platformapi/allocatorapi/vacate_test.go @@ -1295,13 +1295,11 @@ func Test_newMoveClusterParams(t *testing.T) { Kind: "elasticsearch", Output: output.NewDevice(new(bytes.Buffer)), AllocatorDown: ec.Bool(false), - ForceMove: ec.Bool(true), }}, want: platform_infrastructure.NewMoveClustersByTypeParams(). WithAllocatorID("allocator-1"). WithClusterType(util.Elasticsearch). WithAllocatorDown(ec.Bool(false)). - WithForceMove(ec.Bool(true)). WithContext(api.WithRegion(context.Background(), "us-east-1")). WithBody(&models.MoveClustersRequest{ ElasticsearchClusters: []*models.MoveElasticsearchClusterConfiguration{ From d8b9dc86aaba376b4affd5e95c0ed9f2315fe1e0 Mon Sep 17 00:00:00 2001 From: riccardomarinelli Date: Mon, 14 Oct 2024 18:35:15 +0800 Subject: [PATCH 6/6] Add FroceMove as PlanOverride --- pkg/api/platformapi/allocatorapi/vacate.go | 7 ++++++- pkg/api/platformapi/allocatorapi/vacate_params.go | 1 + pkg/models/elasticsearch_plan_control_configuration.go | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/api/platformapi/allocatorapi/vacate.go b/pkg/api/platformapi/allocatorapi/vacate.go index fb4c04ef..df2686cb 100644 --- a/pkg/api/platformapi/allocatorapi/vacate.go +++ b/pkg/api/platformapi/allocatorapi/vacate.go @@ -127,7 +127,7 @@ func moveNodes(id string, params *VacateParams, p *pool.Pool) ([]pool.Validator, WithAllocatorID(id). WithMoveOnly(params.MoveOnly). WithContext(api.WithRegion(context.Background(), params.Region)). - WithForceMove(params.ForceMove). + //WithForceMove(params.ForceMove). WithValidateOnly(ec.Bool(true)), params.AuthWriter, ) @@ -419,6 +419,7 @@ func newMoveClusterParams(params *VacateClusterParams) (*platform_infrastructure var moveParams = platform_infrastructure.NewMoveClustersByTypeParams(). WithAllocatorID(params.ID). WithAllocatorDown(params.AllocatorDown). + WithForceMove(params.ForceMove). WithContext(api.WithRegion(context.Background(), params.Region)). WithBody(req) @@ -658,6 +659,10 @@ func ComputeVacateRequest(pr *models.MoveClustersDetails, resources, to []string c.CalculatedPlan.PlanConfiguration.OverrideFailsafe = overrides.OverrideFailsafe } + if overrides.ForceMove != nil { + c.CalculatedPlan.PlanConfiguration.ForceMove = overrides.ForceMove + } + c.CalculatedPlan.PlanConfiguration.PreferredAllocators = to req.ElasticsearchClusters = append(req.ElasticsearchClusters, &models.MoveElasticsearchClusterConfiguration{ diff --git a/pkg/api/platformapi/allocatorapi/vacate_params.go b/pkg/api/platformapi/allocatorapi/vacate_params.go index 78e2dce1..0df2a93a 100644 --- a/pkg/api/platformapi/allocatorapi/vacate_params.go +++ b/pkg/api/platformapi/allocatorapi/vacate_params.go @@ -226,4 +226,5 @@ type PlanOverrides struct { SkipSnapshot *bool SkipDataMigration *bool OverrideFailsafe *bool + ForceMove *bool } diff --git a/pkg/models/elasticsearch_plan_control_configuration.go b/pkg/models/elasticsearch_plan_control_configuration.go index 2a25a031..3cea3d9a 100644 --- a/pkg/models/elasticsearch_plan_control_configuration.go +++ b/pkg/models/elasticsearch_plan_control_configuration.go @@ -84,6 +84,9 @@ type ElasticsearchPlanControlConfiguration struct { // If true (default: false), does not take (or require) a successful snapshot to be taken before performing any potentially destructive changes to this cluster SkipSnapshot *bool `json:"skip_snapshot,omitempty"` + // If false (default: true), will run standard vacate + ForceMove *bool `json:"force_move,omitempty"` + // If false (the default), the cluster will perform a snapshot after a major version upgrade takes place SkipSnapshotPostMajorUpgrade *bool `json:"skip_snapshot_post_major_upgrade,omitempty"`