Files
decort-golang-sdk/pkg/cloudapi/k8s/worker_add.go

54 lines
1.3 KiB
Go
Raw Normal View History

2022-10-03 16:56:47 +03:00
package k8s
import (
"context"
2023-05-04 16:15:35 +03:00
"encoding/json"
2022-10-03 16:56:47 +03:00
"net/http"
2023-07-07 12:40:03 +03:00
2023-03-24 17:09:30 +03:00
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
2022-10-03 16:56:47 +03:00
)
2023-10-25 17:37:18 +03:00
// WorkerAddRequest struct to add worker to a kubernetes cluster
2022-10-03 16:56:47 +03:00
type WorkerAddRequest struct {
2022-12-22 17:56:47 +03:00
// Kubernetes cluster ID
// Required: true
2023-03-24 17:09:30 +03:00
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
2022-12-22 17:56:47 +03:00
// ID of the workers compute group
// Required: true
2023-03-24 17:09:30 +03:00
WorkersGroupID uint64 `url:"workersGroupId" json:"workersGroupId" validate:"required"`
2022-12-22 17:56:47 +03:00
// How many worker nodes to add
2023-07-07 12:40:03 +03:00
// Required: false
Num uint64 `url:"num,omitempty" json:"num,omitempty"`
2024-11-12 12:51:21 +03:00
// Type of the emulated system, Q35 or i440fx
// Required: false
2025-12-08 16:16:35 +03:00
// Default: Q35
2024-11-22 12:09:50 +03:00
Chipset string `url:"chipset,omitempty" json:"chipset,omitempty" validate:"omitempty,chipset"`
2022-10-03 16:56:47 +03:00
}
2023-10-25 17:37:18 +03:00
// WorkerAdd adds worker nodes to a Kubernetes cluster
2023-05-04 16:15:35 +03:00
func (k8s K8S) WorkerAdd(ctx context.Context, req WorkerAddRequest) ([]uint64, error) {
2023-03-24 17:09:30 +03:00
err := validators.ValidateRequest(req)
2022-10-03 16:56:47 +03:00
if err != nil {
2023-10-25 17:37:18 +03:00
return nil, validators.ValidationErrors(validators.GetErrors(err))
2022-10-03 16:56:47 +03:00
}
url := "/cloudapi/k8s/workerAdd"
res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
2023-05-04 16:15:35 +03:00
return nil, err
2022-10-03 16:56:47 +03:00
}
2023-05-04 16:15:35 +03:00
result := make([]uint64, 0)
err = json.Unmarshal(res, &result)
2022-10-03 16:56:47 +03:00
if err != nil {
2023-05-04 16:15:35 +03:00
return nil, err
2022-10-03 16:56:47 +03:00
}
2022-12-22 17:56:47 +03:00
2022-10-03 16:56:47 +03:00
return result, nil
}