Refactoring
This commit is contained in:
75
pkg/cloudapi/k8s/create.go
Normal file
75
pkg/cloudapi/k8s/create.go
Normal file
@@ -0,0 +1,75 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type CreateRequest struct {
|
||||
Name string `url:"name"`
|
||||
RGID uint64 `url:"rgId"`
|
||||
K8SCIId uint64 `url:"k8ciId"`
|
||||
WorkerGroupName string `url:"workerGroupName"`
|
||||
Labels []string `url:"labels,omitempty"`
|
||||
Taints []string `url:"taints,omitempty"`
|
||||
Annotations []string `url:"annotations,omitempty"`
|
||||
MasterNum uint `url:"masterNum,omitempty"`
|
||||
MasterCPU uint `url:"masterCPU,omitempty"`
|
||||
MasterRAM uint `url:"masterRam,omitempty"`
|
||||
MasterDisk uint `url:"masterDisk,omitempty"`
|
||||
WorkerNum uint `url:"workerNum,omitempty"`
|
||||
WorkerCPU uint `url:"workerCPU,omitempty"`
|
||||
WorkerRAM uint `url:"workerRam,omitempty"`
|
||||
WorkerDisk uint `url:"workerDisk,omitempty"`
|
||||
ExtnetId uint64 `url:"extnetId,omitempty"`
|
||||
WithLB bool `url:"withLB,omitempty"`
|
||||
Description string `url:"desc, omitempty"`
|
||||
}
|
||||
|
||||
func (krq CreateRequest) Validate() error {
|
||||
if krq.Name == "" {
|
||||
return errors.New("validation-error: field Name can not be empty")
|
||||
}
|
||||
if krq.RGID == 0 {
|
||||
return errors.New("validation-error: field RgId can not be empty or equal to 0")
|
||||
}
|
||||
if krq.K8SCIId == 0 {
|
||||
return errors.New("validation-error: field K8SCIId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if krq.WorkerGroupName == "" {
|
||||
return errors.New("validation-error: field WorkerGroupName can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k8s K8S) Create(ctx context.Context, req CreateRequest, options ...opts.DecortOpts) (string, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
url := "/k8s/create"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := k8s.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return strings.ReplaceAll(string(res), "\"", ""), nil
|
||||
|
||||
}
|
||||
51
pkg/cloudapi/k8s/delete.go
Normal file
51
pkg/cloudapi/k8s/delete.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type DeleteRequest struct {
|
||||
K8SId uint64 `url:"k8sId"`
|
||||
Permanently bool `url:"permanently"`
|
||||
}
|
||||
|
||||
func (krq DeleteRequest) Validate() error {
|
||||
if krq.K8SId == 0 {
|
||||
return errors.New("validation-error: field K8SId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k8s K8S) Delete(ctx context.Context, req DeleteRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/k8s/delete"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := k8s.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
59
pkg/cloudapi/k8s/delete_master_from_group.go
Normal file
59
pkg/cloudapi/k8s/delete_master_from_group.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type DeleteMasterFromGroupRequest struct {
|
||||
K8SId uint64 `url:"k8sId"`
|
||||
MasterGroupId uint64 `url:"masterGroupId"`
|
||||
MasterIds []string `url:"masterIds"`
|
||||
}
|
||||
|
||||
func (krq DeleteMasterFromGroupRequest) Validate() error {
|
||||
if krq.K8SId == 0 {
|
||||
return errors.New("validation-error: field K8SId can not be empty or equal to 0")
|
||||
}
|
||||
if krq.MasterGroupId == 0 {
|
||||
return errors.New("validation-error: field MasterGroupId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if len(krq.MasterIds) == 0 {
|
||||
return errors.New("validation-error: field MasterIds can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k8s K8S) DeleteMasterFromGroup(ctx context.Context, req DeleteMasterFromGroupRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/k8s/deleteMasterFromGroup"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := k8s.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
59
pkg/cloudapi/k8s/delete_worker_from_group.go
Normal file
59
pkg/cloudapi/k8s/delete_worker_from_group.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type DeleteWorkerFromGroupRequest struct {
|
||||
K8SId uint64 `url:"k8sId"`
|
||||
WorkersGroupId uint64 `url:"workersGroupId"`
|
||||
WorkerId uint64 `url:"workerId"`
|
||||
}
|
||||
|
||||
func (krq DeleteWorkerFromGroupRequest) Validate() error {
|
||||
if krq.K8SId == 0 {
|
||||
return errors.New("validation-error: field K8SId can not be empty or equal to 0")
|
||||
}
|
||||
if krq.WorkersGroupId == 0 {
|
||||
return errors.New("validation-error: field WorkersGroupId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if krq.WorkerId == 0 {
|
||||
return errors.New("validation-error: field WorkerId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k8s K8S) DeleteWorkerFromGroup(ctx context.Context, req DeleteWorkerFromGroupRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/k8s/deleteWorkerFromGroup"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := k8s.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
78
pkg/cloudapi/k8s/disable_enable.go
Normal file
78
pkg/cloudapi/k8s/disable_enable.go
Normal file
@@ -0,0 +1,78 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type DisabelEnableRequest struct {
|
||||
K8SId uint64 `url:"k8sId"`
|
||||
}
|
||||
|
||||
func (krq DisabelEnableRequest) Validate() error {
|
||||
if krq.K8SId == 0 {
|
||||
return errors.New("validation-error: field K8SId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k8s K8S) Disable(ctx context.Context, req DisabelEnableRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/k8s/disable"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := k8s.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (k8s K8S) Enable(ctx context.Context, req DisabelEnableRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/k8s/enable"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := k8s.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
59
pkg/cloudapi/k8s/find_group_by_label.go
Normal file
59
pkg/cloudapi/k8s/find_group_by_label.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type FindGroupByLabelRequest struct {
|
||||
K8SId uint64 `url:"k8sId"`
|
||||
Labels []string `url:"labels"`
|
||||
Strict bool `url:"strict"`
|
||||
}
|
||||
|
||||
func (krq FindGroupByLabelRequest) Validate() error {
|
||||
if krq.K8SId == 0 {
|
||||
return errors.New("validation-error: field K8SId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if len(krq.Labels) == 0 {
|
||||
return errors.New("validation-error: field Labels can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k8s K8S) FindGroupByLabel(ctx context.Context, req FindGroupByLabelRequest, options ...opts.DecortOpts) (K8SGroupList, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/k8s/findGroupByLabel"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := k8s.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
k8sGroupList := K8SGroupList{}
|
||||
|
||||
err = json.Unmarshal(res, &k8sGroupList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return k8sGroupList, nil
|
||||
}
|
||||
53
pkg/cloudapi/k8s/get.go
Normal file
53
pkg/cloudapi/k8s/get.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type GetRequest struct {
|
||||
K8SId uint64 `url:"k8sId"`
|
||||
}
|
||||
|
||||
func (krq GetRequest) Validate() error {
|
||||
if krq.K8SId == 0 {
|
||||
return errors.New("validation-error: field K8SId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k8s K8S) Get(ctx context.Context, req GetRequest, options ...opts.DecortOpts) (*K8SRecord, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/k8s/get"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := k8s.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
k8sInfo := &K8SRecord{}
|
||||
|
||||
err = json.Unmarshal(res, k8sInfo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return k8sInfo, nil
|
||||
}
|
||||
45
pkg/cloudapi/k8s/get_config.go
Normal file
45
pkg/cloudapi/k8s/get_config.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type GetConfigRequest struct {
|
||||
K8SId uint64 `url:"k8sId"`
|
||||
}
|
||||
|
||||
func (krq GetConfigRequest) Validate() error {
|
||||
if krq.K8SId == 0 {
|
||||
return errors.New("validation-error: field K8SId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k8s K8S) GetConfig(ctx context.Context, req GetConfigRequest, options ...opts.DecortOpts) (string, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
url := "/k8s/getConfig"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := k8s.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return string(res), nil
|
||||
}
|
||||
49
pkg/cloudapi/k8s/get_node_annotations.go
Normal file
49
pkg/cloudapi/k8s/get_node_annotations.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type GetNodeAnnotationsRequest struct {
|
||||
K8SId uint64 `url:"k8sId"`
|
||||
NodeId uint64 `url:"nodeId"`
|
||||
}
|
||||
|
||||
func (krq GetNodeAnnotationsRequest) Validate() error {
|
||||
if krq.K8SId == 0 {
|
||||
return errors.New("validation-error: field K8SId can not be empty or equal to 0")
|
||||
}
|
||||
if krq.NodeId == 0 {
|
||||
return errors.New("validation-error: field NodeId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k8s K8S) GetNodeAnnotations(ctx context.Context, req GetNodeAnnotationsRequest, options ...opts.DecortOpts) (string, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
url := "/k8s/getNodeAnnotations"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := k8s.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return string(res), nil
|
||||
}
|
||||
49
pkg/cloudapi/k8s/get_node_taints.go
Normal file
49
pkg/cloudapi/k8s/get_node_taints.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type GetNodeTaintsRequest struct {
|
||||
K8SId uint64 `url:"k8sId"`
|
||||
NodeId uint64 `url:"nodeId"`
|
||||
}
|
||||
|
||||
func (krq GetNodeTaintsRequest) Validate() error {
|
||||
if krq.K8SId == 0 {
|
||||
return errors.New("validation-error: field K8SId can not be empty or equal to 0")
|
||||
}
|
||||
if krq.NodeId == 0 {
|
||||
return errors.New("validation-error: field NodeId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k8s K8S) GetNodeTaints(ctx context.Context, req GetNodeTaintsRequest, options ...opts.DecortOpts) (string, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
url := "/k8s/getNodeTaints"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := k8s.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return string(res), nil
|
||||
}
|
||||
15
pkg/cloudapi/k8s/k8s.go
Normal file
15
pkg/cloudapi/k8s/k8s.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/interfaces"
|
||||
)
|
||||
|
||||
type K8S struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
func New(client interfaces.Caller) *K8S {
|
||||
return &K8S{
|
||||
client,
|
||||
}
|
||||
}
|
||||
42
pkg/cloudapi/k8s/list.go
Normal file
42
pkg/cloudapi/k8s/list.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type ListRequest struct {
|
||||
IncludeDeleted bool `json:"includedeleted"`
|
||||
Page uint64 `json:"page"`
|
||||
Size uint64 `json:"size"`
|
||||
}
|
||||
|
||||
func (k8s K8S) List(ctx context.Context, req ListRequest, options ...opts.DecortOpts) (K8SList, error) {
|
||||
|
||||
url := "/k8s/list"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := k8s.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
k8sList := K8SList{}
|
||||
|
||||
err = json.Unmarshal(res, &k8sList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return k8sList, nil
|
||||
}
|
||||
41
pkg/cloudapi/k8s/list_deleted.go
Normal file
41
pkg/cloudapi/k8s/list_deleted.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type ListDeletedRequest struct {
|
||||
Page uint64 `json:"page"`
|
||||
Size uint64 `json:"size"`
|
||||
}
|
||||
|
||||
func (k8s K8S) ListDeleted(ctx context.Context, req ListDeletedRequest, options ...opts.DecortOpts) (K8SList, error) {
|
||||
|
||||
url := "/k8s/listDeleted"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := k8s.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
k8sList := K8SList{}
|
||||
|
||||
err = json.Unmarshal(res, &k8sList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return k8sList, nil
|
||||
}
|
||||
119
pkg/cloudapi/k8s/models.go
Normal file
119
pkg/cloudapi/k8s/models.go
Normal file
@@ -0,0 +1,119 @@
|
||||
package k8s
|
||||
|
||||
type K8SGroup struct {
|
||||
Annotations []string `json:"annotations"`
|
||||
CPU uint `json:"cpu"`
|
||||
DetailedInfo DetailedInfoList `json:"detailedInfo"`
|
||||
Disk uint `json:"disk"`
|
||||
GUID string `json:"guid"`
|
||||
ID uint64 `json:"id"`
|
||||
Labels []string `json:"labels"`
|
||||
Name string `json:"name"`
|
||||
Num uint `json:"num"`
|
||||
RAM uint `json:"ram"`
|
||||
Taints []string `json:"taints"`
|
||||
}
|
||||
|
||||
type K8SGroupList []K8SGroup
|
||||
|
||||
type DetailedInfo struct {
|
||||
ID uint64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Status string `json:"status"`
|
||||
TechStatus string `json:"techStatus"`
|
||||
}
|
||||
|
||||
type DetailedInfoList []DetailedInfo
|
||||
|
||||
type K8SRecord struct {
|
||||
ACL ACLGroup `json:"ACL"`
|
||||
AccountId uint64 `json:"accountId"`
|
||||
AccountName string `json:"accountName"`
|
||||
BServiceId uint64 `json:"bserviceId"`
|
||||
CIId uint64 `json:"ciId"`
|
||||
CreatedBy string `json:"createdBy"`
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
ID uint64 `json:"id"`
|
||||
K8CIName string `json:"k8ciName"`
|
||||
K8SGroups K8SGroups `json:"k8sGroups"`
|
||||
LBId uint64 `json:"lbId"`
|
||||
Name string `json:"name"`
|
||||
RGID uint64 `json:"rgId"`
|
||||
RGName string `json:"rgName"`
|
||||
Status string `json:"status"`
|
||||
TechStatus string `json:"techStatus"`
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
}
|
||||
|
||||
type K8SGroups struct {
|
||||
Masters MasterGroup `json:"masters"`
|
||||
Workers K8SGroupList `json:"workers"`
|
||||
}
|
||||
|
||||
type MasterGroup struct {
|
||||
CPU uint `json:"cpu"`
|
||||
DetailedInfo DetailedInfoList `json:"detailedInfo"`
|
||||
Disk uint `json:"disk"`
|
||||
ID uint64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Num uint `json:"num"`
|
||||
RAM uint `json:"ram"`
|
||||
}
|
||||
|
||||
type ACLGroup struct {
|
||||
AccountAcl AclList `json:"accountAcl"`
|
||||
K8SAcl AclList `json:"k8sAcl"`
|
||||
RGAcl AclList `json:"rgAcl"`
|
||||
}
|
||||
|
||||
type Acl struct {
|
||||
Explicit bool `json:"explicit"`
|
||||
GUID string `json:"guid"`
|
||||
Right string `json:"right"`
|
||||
Status string `json:"status"`
|
||||
Type string `json:"type"`
|
||||
UserGroupId string `json:"userGroupId"`
|
||||
}
|
||||
|
||||
type AclList []Acl
|
||||
|
||||
type K8SItem struct {
|
||||
AccountId uint64 `json:"accountId"`
|
||||
AccountName string `json:"accountName"`
|
||||
Acl string `json:"acl"`
|
||||
BServiceId uint64 `json:"bserviceId"`
|
||||
CIId uint64 `json:"ciId"`
|
||||
Config string `json:"config"`
|
||||
CreatedBy string `json:"createdBy"`
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
Description string `json:"desc"`
|
||||
ExtnetId uint64 `json:"extnetId"`
|
||||
GID uint64 `json:"gid"`
|
||||
GUID uint64 `json:"guid"`
|
||||
ID uint64 `json:"id"`
|
||||
LBId uint64 `json:"lbId"`
|
||||
Milestones uint64 `json:"milestones"`
|
||||
Name string `json:"name"`
|
||||
RGID uint64 `json:"rgId"`
|
||||
RGName string `json:"rgName"`
|
||||
ServiceAccount ServiceAccount `json:"serviceAccount"`
|
||||
Status string `json:"status"`
|
||||
TechStatus string `json:"techStatus"`
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
VinsId uint64 `json:"vinsId"`
|
||||
WorkersGroup K8SGroupList `json:"workersGroups"`
|
||||
}
|
||||
|
||||
type ServiceAccount struct {
|
||||
GUID string `json:"guid"`
|
||||
Password string `json:"password"`
|
||||
Username string `json:"username"`
|
||||
}
|
||||
|
||||
type K8SList []K8SItem
|
||||
50
pkg/cloudapi/k8s/restore.go
Normal file
50
pkg/cloudapi/k8s/restore.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type RestoreRequest struct {
|
||||
K8SId uint64 `url:"k8sId"`
|
||||
}
|
||||
|
||||
func (krq RestoreRequest) Validate() error {
|
||||
if krq.K8SId == 0 {
|
||||
return errors.New("validation-error: field K8SId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k8s K8S) Restore(ctx context.Context, req RestoreRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/k8s/restore"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := k8s.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
50
pkg/cloudapi/k8s/start.go
Normal file
50
pkg/cloudapi/k8s/start.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type StartRequest struct {
|
||||
K8SId uint64 `url:"k8sId"`
|
||||
}
|
||||
|
||||
func (krq StartRequest) Validate() error {
|
||||
if krq.K8SId == 0 {
|
||||
return errors.New("validation-error: field K8SId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k8s K8S) Start(ctx context.Context, req StartRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/k8s/start"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := k8s.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
50
pkg/cloudapi/k8s/stop.go
Normal file
50
pkg/cloudapi/k8s/stop.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type StopRequest struct {
|
||||
K8SId uint64 `url:"k8sId"`
|
||||
}
|
||||
|
||||
func (krq StopRequest) Validate() error {
|
||||
if krq.K8SId == 0 {
|
||||
return errors.New("validation-error: field K8SId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k8s K8S) Stop(ctx context.Context, req StopRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/k8s/stop"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := k8s.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
52
pkg/cloudapi/k8s/update.go
Normal file
52
pkg/cloudapi/k8s/update.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type UpdateRequest struct {
|
||||
K8SId uint64 `url:"k8sId"`
|
||||
Name string `url:"name,omitempty"`
|
||||
Description string `url:"desc,omitempty"`
|
||||
}
|
||||
|
||||
func (krq UpdateRequest) Validate() error {
|
||||
if krq.K8SId == 0 {
|
||||
return errors.New("validation-error: field K8SId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k8s K8S) Update(ctx context.Context, req UpdateRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/k8s/update"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := k8s.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
60
pkg/cloudapi/k8s/worker_add.go
Normal file
60
pkg/cloudapi/k8s/worker_add.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type WorkerAddRequest struct {
|
||||
K8SId uint64 `url:"k8sId"`
|
||||
WorkersGroupId uint64 `url:"workersGroupId"`
|
||||
Num uint `url:"num"`
|
||||
}
|
||||
|
||||
func (krq WorkerAddRequest) Validate() error {
|
||||
if krq.K8SId == 0 {
|
||||
return errors.New("validation-error: field K8SId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if krq.WorkersGroupId == 0 {
|
||||
return errors.New("validation-error: field WorkersGroupId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if krq.Num == 0 {
|
||||
return errors.New("validation-error: field Num can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k8s K8S) WorkerAdd(ctx context.Context, req WorkerAddRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/k8s/workerAdd"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := k8s.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
60
pkg/cloudapi/k8s/worker_reset.go
Normal file
60
pkg/cloudapi/k8s/worker_reset.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type WorkerResetRequest struct {
|
||||
K8SId uint64 `url:"k8sId"`
|
||||
WorkersGroupId uint64 `url:"workersGroupId"`
|
||||
WorkerId uint64 `url:"workerId"`
|
||||
}
|
||||
|
||||
func (krq WorkerResetRequest) Validate() error {
|
||||
if krq.K8SId == 0 {
|
||||
return errors.New("validation-error: field K8SId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if krq.WorkersGroupId == 0 {
|
||||
return errors.New("validation-error: field WorkersGroupId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if krq.WorkerId == 0 {
|
||||
return errors.New("validation-error: field WorkerId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k8s K8S) WorkerReset(ctx context.Context, req WorkerResetRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/k8s/workerReset"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := k8s.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
60
pkg/cloudapi/k8s/worker_restart.go
Normal file
60
pkg/cloudapi/k8s/worker_restart.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type WorkerRestartRequest struct {
|
||||
K8SId uint64 `url:"k8sId"`
|
||||
WorkersGroupId uint64 `url:"workersGroupId"`
|
||||
WorkerId uint64 `url:"workerId"`
|
||||
}
|
||||
|
||||
func (krq WorkerRestartRequest) Validate() error {
|
||||
if krq.K8SId == 0 {
|
||||
return errors.New("validation-error: field K8SId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if krq.WorkersGroupId == 0 {
|
||||
return errors.New("validation-error: field WorkersGroupId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if krq.WorkerId == 0 {
|
||||
return errors.New("validation-error: field WorkerId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k8s K8S) WorkerRestart(ctx context.Context, req WorkerRestartRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/k8s/workerRestart"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := k8s.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
74
pkg/cloudapi/k8s/workers_group_add.go
Normal file
74
pkg/cloudapi/k8s/workers_group_add.go
Normal file
@@ -0,0 +1,74 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type WorkersGroupAddRequest struct {
|
||||
K8SId uint64 `url:"k8sId"`
|
||||
Name string `url:"name"`
|
||||
Labels []string `url:"labels"`
|
||||
Taints []string `url:"taints"`
|
||||
Annotations []string `url:"annotations"`
|
||||
WorkerNum uint `url:"workerNum"`
|
||||
WorkerCpu uint `url:"workerCpu"`
|
||||
WorkerRam uint `url:"workerRam"`
|
||||
WorkerDisk uint `url:"workerDisk"`
|
||||
}
|
||||
|
||||
func (krq WorkersGroupAddRequest) Validate() error {
|
||||
if krq.K8SId == 0 {
|
||||
return errors.New("validation-error: field K8SId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if krq.Name == "" {
|
||||
return errors.New("validation-error: field Name can not be empty")
|
||||
}
|
||||
|
||||
if krq.WorkerNum == 0 {
|
||||
return errors.New("validation-error: field WorkerNum can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if krq.WorkerCpu == 0 {
|
||||
return errors.New("validation-error: field WorkerCpu can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if krq.WorkerRam < 1024 {
|
||||
return errors.New("validation-error: field WorkerRam must be greater or equal 1024")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k8s K8S) WorkersGroupAdd(ctx context.Context, req WorkersGroupAddRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/k8s/workersGroupAdd"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := k8s.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
55
pkg/cloudapi/k8s/workers_group_delete.go
Normal file
55
pkg/cloudapi/k8s/workers_group_delete.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type WorkersGroupDeleteRequest struct {
|
||||
K8SId uint64 `url:"k8sId"`
|
||||
WorkersGroupId uint64 `url:"workersGroupId"`
|
||||
}
|
||||
|
||||
func (krq WorkersGroupDeleteRequest) Validate() error {
|
||||
if krq.K8SId == 0 {
|
||||
return errors.New("validation-error: field K8SId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if krq.WorkersGroupId == 0 {
|
||||
return errors.New("validation-error: field WorkersGroupId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k8s K8S) WorkersGroupDelete(ctx context.Context, req WorkersGroupDeleteRequest, options ...opts.DecortOpts) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/k8s/workersGroupDelete"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := k8s.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
58
pkg/cloudapi/k8s/workers_group_get_by_name.go
Normal file
58
pkg/cloudapi/k8s/workers_group_get_by_name.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type WorkersGroupGetByNameRequest struct {
|
||||
K8SId uint64 `url:"k8sId"`
|
||||
GroupName string `url:"groupName "`
|
||||
}
|
||||
|
||||
func (krq WorkersGroupGetByNameRequest) Validate() error {
|
||||
if krq.K8SId == 0 {
|
||||
return errors.New("validation-error: field K8SId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
if krq.GroupName == "" {
|
||||
return errors.New("validation-error: field WorkersGroupId can not be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k8s K8S) WorkersGroupGetByName(ctx context.Context, req WorkersGroupGetByNameRequest, options ...opts.DecortOpts) (*K8SGroup, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/k8s/workersGroupGetByName"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := k8s.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
group := &K8SGroup{}
|
||||
|
||||
err = json.Unmarshal(res, group)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return group, nil
|
||||
}
|
||||
Reference in New Issue
Block a user