From ed41512bfe11fdaf3cd35915ecdebea3a130dc88 Mon Sep 17 00:00:00 2001 From: Jorres Tarasov Date: Wed, 20 Nov 2024 13:04:42 +0100 Subject: [PATCH] wip --- cmd/maintenance/create/options.go | 3 ++ pkg/maintenance/host.go | 63 ------------------------------- 2 files changed, 3 insertions(+), 63 deletions(-) delete mode 100644 pkg/maintenance/host.go diff --git a/cmd/maintenance/create/options.go b/cmd/maintenance/create/options.go index 86d67e9..451018a 100644 --- a/cmd/maintenance/create/options.go +++ b/cmd/maintenance/create/options.go @@ -14,6 +14,7 @@ import ( "github.com/ydb-platform/ydbops/pkg/client/cms" "github.com/ydb-platform/ydbops/pkg/cmdutil" "github.com/ydb-platform/ydbops/pkg/options" + "github.com/ydb-platform/ydbops/pkg/prettyprint" "github.com/ydb-platform/ydbops/pkg/rolling/restarters" "github.com/ydb-platform/ydbops/pkg/utils" ) @@ -131,5 +132,7 @@ func (o *Options) Run(f cmdutil.Factory) error { task.GetTaskUid(), ) + fmt.Println(prettyprint.TaskToString(task)) + return nil } diff --git a/pkg/maintenance/host.go b/pkg/maintenance/host.go deleted file mode 100644 index 255536e..0000000 --- a/pkg/maintenance/host.go +++ /dev/null @@ -1,63 +0,0 @@ -package maintenance - -import ( - "fmt" - - "github.com/google/uuid" - "github.com/ydb-platform/ydb-go-genproto/draft/protos/Ydb_Maintenance" - "google.golang.org/protobuf/types/known/durationpb" - - "github.com/ydb-platform/ydbops/pkg/client/cms" -) - -const ( - MaintenanceTaskPrefix = "maintenance-" -) - -func getNodesOnHost(cmsClient cms.Client, hostFQDN string) ([]*Ydb_Maintenance.Node, error) { - nodes, err := cmsClient.Nodes() - if err != nil { - return nil, err - } - - res := []*Ydb_Maintenance.Node{} - - for _, node := range nodes { - // TODO here is the non-trivial part with Kubernetes, surgically create a shared logic - // with Kubernetes restarters - if node.Host == hostFQDN { - res = append(res, node) - } - } - - return res, nil -} - -type RequestHostParams struct { - AvailabilityMode Ydb_Maintenance.AvailabilityMode - HostFQDN string - MaintenanceDuration *durationpb.Duration -} - -func RequestHost(cmsClient cms.Client, params *RequestHostParams) (string, error) { - taskUID := MaintenanceTaskPrefix + uuid.New().String() - - nodes, err := getNodesOnHost(cmsClient, params.HostFQDN) - if err != nil { - return "", err - } - - taskParams := cms.MaintenanceTaskParams{ - TaskUID: taskUID, - AvailabilityMode: params.AvailabilityMode, - Duration: params.MaintenanceDuration, - Nodes: nodes, - } - - task, err := cmsClient.CreateMaintenanceTask(taskParams) - if err != nil { - return "", fmt.Errorf("failed to create maintenance task: %w", err) - } - - return task.GetTaskUid(), nil -}