func newMoveClusterParams()

in pkg/api/platformapi/allocatorapi/vacate.go [385:443]


func newMoveClusterParams(params *VacateClusterParams) (*platform_infrastructure.MoveClustersByTypeParams, error) {
	// By setting the ClusterID in the request body, the API will only return the matched cluster's plan information.
	// This greatly reduces the amount of work that the API has to perform to return the calculated plan.
	req := getVacateRequestByClusterID(params.ClusterID, params.Kind)

	res, err := params.API.V1API.PlatformInfrastructure.MoveClusters(
		platform_infrastructure.NewMoveClustersParams().
			WithAllocatorDown(params.AllocatorDown).
			WithMoveOnly(params.MoveOnly).
			WithAllocatorID(params.ID).
			WithContext(api.WithRegion(context.Background(), params.Region)).
			WithValidateOnly(ec.Bool(true)).
			WithBody(req),
		params.AuthWriter,
	)
	if err != nil {
		return nil, VacateError{
			AllocatorID: params.ID,
			ResourceID:  params.ClusterID,
			Kind:        params.Kind,
			Ctx:         "failed obtaining default vacate parameters",
			Err:         apierror.Wrap(err),
		}
	}

	req = ComputeVacateRequest(res.Payload.Moves,
		[]string{params.ClusterID},
		params.PreferredAllocators,
		params.PlanOverrides,
	)

	var moveParams = platform_infrastructure.NewMoveClustersByTypeParams().
		WithAllocatorID(params.ID).
		WithAllocatorDown(params.AllocatorDown).
		WithContext(api.WithRegion(context.Background(), params.Region)).
		WithBody(req)

	if len(req.ElasticsearchClusters) > 0 {
		moveParams.SetClusterType(util.Elasticsearch)
	}

	if len(req.KibanaClusters) > 0 {
		moveParams.SetClusterType(util.Kibana)
	}

	if len(req.ApmClusters) > 0 {
		moveParams.SetClusterType(util.Apm)
	}

	if len(req.AppsearchClusters) > 0 {
		moveParams.SetClusterType(util.Appsearch)
	}

	if len(req.EnterpriseSearchClusters) > 0 {
		moveParams.SetClusterType(util.EnterpriseSearch)
	}

	return moveParams, nil
}