v1.0.0
This commit is contained in:
@@ -7,28 +7,86 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Request struct for create kubernetes cluster
|
||||
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"`
|
||||
// Name of Kubernetes cluster
|
||||
// Required: true
|
||||
Name string `url:"name"`
|
||||
|
||||
// Resource Group ID for cluster placement
|
||||
// Required: true
|
||||
RGID uint64 `url:"rgId"`
|
||||
|
||||
// ID of Kubernetes catalog item (k8sci) for cluster
|
||||
// Required: true
|
||||
K8SCIID uint64 `url:"k8ciId"`
|
||||
|
||||
// Name for first worker group created with cluster
|
||||
// Required: true
|
||||
WorkerGroupName string `url:"workerGroupName"`
|
||||
|
||||
// List of strings with labels for default worker group
|
||||
// i.e: ["label1=value1", "label2=value2"]
|
||||
// Required: false
|
||||
Labels []string `url:"labels,omitempty"`
|
||||
|
||||
// List of strings with taints for default worker group
|
||||
// i.e: ["key1=value1:NoSchedule", "key2=value2:NoExecute"]
|
||||
// Required: false
|
||||
Taints []string `url:"taints,omitempty"`
|
||||
|
||||
// List of strings with annotations for worker group
|
||||
// i.e: ["key1=value1", "key2=value2"]
|
||||
// Required: false
|
||||
Annotations []string `url:"annotations,omitempty"`
|
||||
|
||||
// Number of master nodes to create
|
||||
// Required: false
|
||||
MasterNum uint `url:"masterNum,omitempty"`
|
||||
|
||||
// Master node CPU count
|
||||
// Required: false
|
||||
MasterCPU uint `url:"masterCPU,omitempty"`
|
||||
|
||||
// Master node RAM volume in MB
|
||||
// Required: false
|
||||
MasterRAM uint `url:"masterRam,omitempty"`
|
||||
|
||||
// Master node boot disk size in GB If 0 is specified, size is defined by the OS image size
|
||||
// Required: false
|
||||
MasterDisk uint `url:"masterDisk,omitempty"`
|
||||
|
||||
// Number of worker nodes to create in default worker group
|
||||
// Required: false
|
||||
WorkerNum uint `url:"workerNum,omitempty"`
|
||||
|
||||
// Worker node CPU count
|
||||
// Required: false
|
||||
WorkerCPU uint `url:"workerCPU,omitempty"`
|
||||
|
||||
// Worker node RAM volume in MB
|
||||
// Required: false
|
||||
WorkerRAM uint `url:"workerRam,omitempty"`
|
||||
|
||||
// Worker node boot disk size in GB. If 0 is specified, size is defined by the OS image size
|
||||
// Required: false
|
||||
WorkerDisk uint `url:"workerDisk,omitempty"`
|
||||
|
||||
// ID of the external network to connect load balancer and cluster ViNS. If 0 is specified, external network selects automatically to
|
||||
// Required: false
|
||||
ExtNetID uint64 `url:"extnetId,omitempty"`
|
||||
|
||||
// Create Kubernetes cluster with masters nodes behind load balancer if true.
|
||||
// Otherwise give all cluster nodes direct external addresses from selected ExtNet
|
||||
// Required: false
|
||||
WithLB bool `url:"withLB,omitempty"`
|
||||
|
||||
// Text description of this Kubernetes cluster
|
||||
// Required: false
|
||||
Description string `url:"desc, omitempty"`
|
||||
}
|
||||
|
||||
func (krq CreateRequest) Validate() error {
|
||||
func (krq CreateRequest) validate() error {
|
||||
if krq.Name == "" {
|
||||
return errors.New("validation-error: field Name can not be empty")
|
||||
}
|
||||
@@ -38,7 +96,6 @@ func (krq CreateRequest) Validate() error {
|
||||
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")
|
||||
}
|
||||
@@ -46,8 +103,9 @@ func (krq CreateRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Create creates a new Kubernetes cluster in the specified Resource Group
|
||||
func (k8s K8S) Create(ctx context.Context, req CreateRequest) (string, error) {
|
||||
err := req.Validate()
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -59,6 +117,7 @@ func (k8s K8S) Create(ctx context.Context, req CreateRequest) (string, error) {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return strings.ReplaceAll(string(res), "\"", ""), nil
|
||||
result := strings.ReplaceAll(string(res), "\"", "")
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -7,12 +7,19 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for delete kubernetes cluster
|
||||
type DeleteRequest struct {
|
||||
K8SID uint64 `url:"k8sId"`
|
||||
Permanently bool `url:"permanently"`
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId"`
|
||||
|
||||
// True if cluster is destroyed permanently.
|
||||
// Otherwise it can be restored from Recycle Bin
|
||||
// Required: true
|
||||
Permanently bool `url:"permanently"`
|
||||
}
|
||||
|
||||
func (krq DeleteRequest) Validate() error {
|
||||
func (krq DeleteRequest) validate() error {
|
||||
if krq.K8SID == 0 {
|
||||
return errors.New("validation-error: field K8SID can not be empty or equal to 0")
|
||||
}
|
||||
@@ -20,8 +27,9 @@ func (krq DeleteRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Delete deletes kubernetes cluster
|
||||
func (k8s K8S) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -37,5 +45,6 @@ func (k8s K8S) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -7,20 +7,28 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for delete master from group
|
||||
type DeleteMasterFromGroupRequest struct {
|
||||
K8SID uint64 `url:"k8sId"`
|
||||
MasterGroupID uint64 `url:"masterGroupId"`
|
||||
MasterIDs []string `url:"masterIds"`
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId"`
|
||||
|
||||
// ID of the masters compute group
|
||||
// Required: true
|
||||
MasterGroupID uint64 `url:"masterGroupId"`
|
||||
|
||||
// List of Compute IDs of master nodes to delete
|
||||
// Required: true
|
||||
MasterIDs []string `url:"masterIds"`
|
||||
}
|
||||
|
||||
func (krq DeleteMasterFromGroupRequest) Validate() error {
|
||||
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")
|
||||
}
|
||||
@@ -28,8 +36,9 @@ func (krq DeleteMasterFromGroupRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteMasterFromGroup deletes compute from masters group in selected Kubernetes cluster
|
||||
func (k8s K8S) DeleteMasterFromGroup(ctx context.Context, req DeleteMasterFromGroupRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -45,5 +54,6 @@ func (k8s K8S) DeleteMasterFromGroup(ctx context.Context, req DeleteMasterFromGr
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -7,20 +7,28 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for delete worker from group
|
||||
type DeleteWorkerFromGroupRequest struct {
|
||||
K8SID uint64 `url:"k8sId"`
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId"`
|
||||
|
||||
// ID of the workers compute group
|
||||
// Required: true
|
||||
WorkersGroupID uint64 `url:"workersGroupId"`
|
||||
WorkerID uint64 `url:"workerId"`
|
||||
|
||||
// Compute ID of worker node to delete
|
||||
// Required: true
|
||||
WorkerID uint64 `url:"workerId"`
|
||||
}
|
||||
|
||||
func (krq DeleteWorkerFromGroupRequest) Validate() error {
|
||||
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")
|
||||
}
|
||||
@@ -28,8 +36,9 @@ func (krq DeleteWorkerFromGroupRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteWorkerFromGroup deletes worker compute from workers group in selected Kubernetes cluster
|
||||
func (k8s K8S) DeleteWorkerFromGroup(ctx context.Context, req DeleteWorkerFromGroupRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -45,5 +54,6 @@ func (k8s K8S) DeleteWorkerFromGroup(ctx context.Context, req DeleteWorkerFromGr
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -7,11 +7,14 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for disable/enable kubernetes cluster
|
||||
type DisabelEnableRequest struct {
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId"`
|
||||
}
|
||||
|
||||
func (krq DisabelEnableRequest) Validate() error {
|
||||
func (krq DisabelEnableRequest) validate() error {
|
||||
if krq.K8SID == 0 {
|
||||
return errors.New("validation-error: field K8SID can not be empty or equal to 0")
|
||||
}
|
||||
@@ -19,8 +22,9 @@ func (krq DisabelEnableRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Disable disables kubernetes cluster by ID
|
||||
func (k8s K8S) Disable(ctx context.Context, req DisabelEnableRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -36,11 +40,13 @@ func (k8s K8S) Disable(ctx context.Context, req DisabelEnableRequest) (bool, err
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// Enable enables kubernetes cluster by ID
|
||||
func (k8s K8S) Enable(ctx context.Context, req DisabelEnableRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -56,5 +62,6 @@ func (k8s K8S) Enable(ctx context.Context, req DisabelEnableRequest) (bool, erro
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -7,17 +7,26 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get information about group of kubernetes cluster
|
||||
type FindGroupByLabelRequest struct {
|
||||
K8SID uint64 `url:"k8sId"`
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId"`
|
||||
|
||||
// List of labels to search
|
||||
// Required: true
|
||||
Labels []string `url:"labels"`
|
||||
Strict bool `url:"strict"`
|
||||
|
||||
// If true and more than one label provided, select only groups that have all provided labels.
|
||||
// If false - groups that have at least one label
|
||||
// Required: true
|
||||
Strict bool `url:"strict"`
|
||||
}
|
||||
|
||||
func (krq FindGroupByLabelRequest) Validate() error {
|
||||
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")
|
||||
}
|
||||
@@ -25,8 +34,9 @@ func (krq FindGroupByLabelRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k8s K8S) FindGroupByLabel(ctx context.Context, req FindGroupByLabelRequest) (K8SGroupList, error) {
|
||||
err := req.Validate()
|
||||
// FindGroupByLabel find worker group information by one on more labels
|
||||
func (k8s K8S) FindGroupByLabel(ctx context.Context, req FindGroupByLabelRequest) (ListK8SGroups, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -38,12 +48,12 @@ func (k8s K8S) FindGroupByLabel(ctx context.Context, req FindGroupByLabelRequest
|
||||
return nil, err
|
||||
}
|
||||
|
||||
k8sGroupList := K8SGroupList{}
|
||||
list := ListK8SGroups{}
|
||||
|
||||
err = json.Unmarshal(res, &k8sGroupList)
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return k8sGroupList, nil
|
||||
return list, nil
|
||||
}
|
||||
|
||||
@@ -7,11 +7,14 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get detailed information about kubernetes cluster
|
||||
type GetRequest struct {
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId"`
|
||||
}
|
||||
|
||||
func (krq GetRequest) Validate() error {
|
||||
func (krq GetRequest) validate() error {
|
||||
if krq.K8SID == 0 {
|
||||
return errors.New("validation-error: field K8SID can not be empty or equal to 0")
|
||||
}
|
||||
@@ -19,8 +22,9 @@ func (krq GetRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k8s K8S) Get(ctx context.Context, req GetRequest) (*K8SRecord, error) {
|
||||
err := req.Validate()
|
||||
// Get gets information about Kubernetes cluster
|
||||
func (k8s K8S) Get(ctx context.Context, req GetRequest) (*RecordK8S, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -32,12 +36,12 @@ func (k8s K8S) Get(ctx context.Context, req GetRequest) (*K8SRecord, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
k8sInfo := &K8SRecord{}
|
||||
info := RecordK8S{}
|
||||
|
||||
err = json.Unmarshal(res, k8sInfo)
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return k8sInfo, nil
|
||||
return &info, nil
|
||||
}
|
||||
|
||||
@@ -6,11 +6,14 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get configuration of kubernetes cluster
|
||||
type GetConfigRequest struct {
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId"`
|
||||
}
|
||||
|
||||
func (krq GetConfigRequest) Validate() error {
|
||||
func (krq GetConfigRequest) validate() error {
|
||||
if krq.K8SID == 0 {
|
||||
return errors.New("validation-error: field K8SID can not be empty or equal to 0")
|
||||
}
|
||||
@@ -18,8 +21,9 @@ func (krq GetConfigRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetConfig gets configuration data to access Kubernetes cluster
|
||||
func (k8s K8S) GetConfig(ctx context.Context, req GetConfigRequest) (string, error) {
|
||||
err := req.Validate()
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -6,12 +6,18 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get node annotations
|
||||
type GetNodeAnnotationsRequest struct {
|
||||
K8SID uint64 `url:"k8sId"`
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId"`
|
||||
|
||||
// Node ID
|
||||
// Required: true
|
||||
NodeID uint64 `url:"nodeId"`
|
||||
}
|
||||
|
||||
func (krq GetNodeAnnotationsRequest) Validate() error {
|
||||
func (krq GetNodeAnnotationsRequest) validate() error {
|
||||
if krq.K8SID == 0 {
|
||||
return errors.New("validation-error: field K8SID can not be empty or equal to 0")
|
||||
}
|
||||
@@ -22,8 +28,9 @@ func (krq GetNodeAnnotationsRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetNodeAnnotations gets kubernetes cluster worker node annotations
|
||||
func (k8s K8S) GetNodeAnnotations(ctx context.Context, req GetNodeAnnotationsRequest) (string, error) {
|
||||
err := req.Validate()
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -6,12 +6,18 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get node taints
|
||||
type GetNodeTaintsRequest struct {
|
||||
K8SID uint64 `url:"k8sId"`
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId"`
|
||||
|
||||
// Node ID
|
||||
// Required: false
|
||||
NodeID uint64 `url:"nodeId"`
|
||||
}
|
||||
|
||||
func (krq GetNodeTaintsRequest) Validate() error {
|
||||
func (krq GetNodeTaintsRequest) validate() error {
|
||||
if krq.K8SID == 0 {
|
||||
return errors.New("validation-error: field K8SID can not be empty or equal to 0")
|
||||
}
|
||||
@@ -22,8 +28,9 @@ func (krq GetNodeTaintsRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetNodeTaints gets kubernetes cluster worker node taints
|
||||
func (k8s K8S) GetNodeTaints(ctx context.Context, req GetNodeTaintsRequest) (string, error) {
|
||||
err := req.Validate()
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
// API for Kubernetes clusters management
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/interfaces"
|
||||
)
|
||||
|
||||
// Structure for creating request to K8S
|
||||
type K8S struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
// Builder for K8S endpoints
|
||||
func New(client interfaces.Caller) *K8S {
|
||||
return &K8S{
|
||||
client,
|
||||
|
||||
@@ -6,14 +6,23 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get list information K8S
|
||||
type ListRequest struct {
|
||||
IncludeDeleted bool `url:"includedeleted"`
|
||||
Page uint64 `url:"page"`
|
||||
Size uint64 `url:"size"`
|
||||
// Include deleted clusters in result
|
||||
// Required: false
|
||||
IncludeDeleted bool `url:"includedeleted,omitempty"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty"`
|
||||
|
||||
// Page size
|
||||
// Required: false
|
||||
Size uint64 `url:"size,omitempty"`
|
||||
}
|
||||
|
||||
func (k8s K8S) List(ctx context.Context, req ListRequest) (K8SList, error) {
|
||||
|
||||
// List gets list all kubernetes clusters the user has access to
|
||||
func (k8s K8S) List(ctx context.Context, req ListRequest) (ListK8SClusters, error) {
|
||||
url := "/cloudapi/k8s/list"
|
||||
|
||||
res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
@@ -21,12 +30,12 @@ func (k8s K8S) List(ctx context.Context, req ListRequest) (K8SList, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
k8sList := K8SList{}
|
||||
list := ListK8SClusters{}
|
||||
|
||||
err = json.Unmarshal(res, &k8sList)
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return k8sList, nil
|
||||
return list, nil
|
||||
}
|
||||
|
||||
@@ -6,13 +6,19 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get list deleted kubernetes cluster
|
||||
type ListDeletedRequest struct {
|
||||
Page uint64 `url:"page"`
|
||||
Size uint64 `url:"size"`
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty"`
|
||||
|
||||
// Page size
|
||||
// Required: false
|
||||
Size uint64 `url:"size,omitempty"`
|
||||
}
|
||||
|
||||
func (k8s K8S) ListDeleted(ctx context.Context, req ListDeletedRequest) (K8SList, error) {
|
||||
|
||||
// ListDeleted gets all deleted kubernetes clusters the user has access to
|
||||
func (k8s K8S) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListK8SClusters, error) {
|
||||
url := "/cloudapi/k8s/listDeleted"
|
||||
|
||||
res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
@@ -20,12 +26,12 @@ func (k8s K8S) ListDeleted(ctx context.Context, req ListDeletedRequest) (K8SList
|
||||
return nil, err
|
||||
}
|
||||
|
||||
k8sList := K8SList{}
|
||||
list := ListK8SClusters{}
|
||||
|
||||
err = json.Unmarshal(res, &k8sList)
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return k8sList, nil
|
||||
return list, nil
|
||||
}
|
||||
|
||||
@@ -1,119 +1,290 @@
|
||||
package k8s
|
||||
|
||||
type K8SGroup struct {
|
||||
Annotations []string `json:"annotations"`
|
||||
CPU uint64 `json:"cpu"`
|
||||
DetailedInfo DetailedInfoList `json:"detailedInfo"`
|
||||
Disk uint64 `json:"disk"`
|
||||
GUID string `json:"guid"`
|
||||
ID uint64 `json:"id"`
|
||||
Labels []string `json:"labels"`
|
||||
Name string `json:"name"`
|
||||
Num uint64 `json:"num"`
|
||||
RAM uint64 `json:"ram"`
|
||||
Taints []string `json:"taints"`
|
||||
// Main information about kubernetes cluster
|
||||
type ItemK8SGroup struct {
|
||||
// List of Annotations
|
||||
Annotations []string `json:"annotations"`
|
||||
|
||||
// Number of CPU
|
||||
CPU uint64 `json:"cpu"`
|
||||
|
||||
// List detailed information
|
||||
DetailedInfo ListDetailedInfo `json:"detailedInfo"`
|
||||
|
||||
// Disk ID
|
||||
Disk uint64 `json:"disk"`
|
||||
|
||||
// GUID
|
||||
GUID string `json:"guid"`
|
||||
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// List of Labels
|
||||
Labels []string `json:"labels"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Num
|
||||
Num uint64 `json:"num"`
|
||||
|
||||
// Number of RAM
|
||||
RAM uint64 `json:"ram"`
|
||||
|
||||
// List of taints
|
||||
Taints []string `json:"taints"`
|
||||
}
|
||||
|
||||
type K8SGroupList []K8SGroup
|
||||
// List kubernetes cluster groups
|
||||
type ListK8SGroups []ItemK8SGroup
|
||||
|
||||
type DetailedInfo struct {
|
||||
ID uint64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Status string `json:"status"`
|
||||
// Detailed information
|
||||
type ItemDetailedInfo struct {
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
// Tech status
|
||||
TechStatus string `json:"techStatus"`
|
||||
}
|
||||
|
||||
type DetailedInfoList []DetailedInfo
|
||||
// List detailed information
|
||||
type ListDetailedInfo []ItemDetailedInfo
|
||||
|
||||
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"`
|
||||
// Deteal information about kubernetes cluster
|
||||
type RecordK8S struct {
|
||||
// Access Control List
|
||||
ACL RecordACL `json:"ACL"`
|
||||
|
||||
// Account ID
|
||||
AccountID uint64 `json:"accountId"`
|
||||
|
||||
// Account name
|
||||
AccountName string `json:"accountName"`
|
||||
|
||||
// Basic Service ID
|
||||
BServiceID uint64 `json:"bserviceId"`
|
||||
|
||||
// CIID
|
||||
CIID uint64 `json:"ciId"`
|
||||
|
||||
// Created by
|
||||
CreatedBy string `json:"createdBy"`
|
||||
|
||||
// Created time
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
|
||||
// Deleted by
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
|
||||
// Deleted time
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// K8CI name
|
||||
K8CIName string `json:"k8ciName"`
|
||||
|
||||
// Kubernetes cluster groups information
|
||||
K8SGroups RecordK8SGroups `json:"k8sGroups"`
|
||||
|
||||
// Load balancer ID
|
||||
LBID uint64 `json:"lbId"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Resource group ID
|
||||
RGID uint64 `json:"rgId"`
|
||||
|
||||
// Resource group name
|
||||
RGName string `json:"rgName"`
|
||||
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
// Tech status
|
||||
TechStatus string `json:"techStatus"`
|
||||
|
||||
// Updated by
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
|
||||
// Updated time
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
}
|
||||
|
||||
type K8SGroups struct {
|
||||
Masters MasterGroup `json:"masters"`
|
||||
Workers K8SGroupList `json:"workers"`
|
||||
// Detailed information about kubernetes cluster groups
|
||||
type RecordK8SGroups struct {
|
||||
|
||||
// Master information
|
||||
Masters MasterGroup `json:"masters"`
|
||||
|
||||
// Worker information
|
||||
Workers ListK8SGroups `json:"workers"`
|
||||
}
|
||||
|
||||
// Master group information
|
||||
type MasterGroup struct {
|
||||
CPU uint64 `json:"cpu"`
|
||||
DetailedInfo DetailedInfoList `json:"detailedInfo"`
|
||||
Disk uint64 `json:"disk"`
|
||||
ID uint64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Num uint64 `json:"num"`
|
||||
RAM uint64 `json:"ram"`
|
||||
// Number of CPU
|
||||
CPU uint64 `json:"cpu"`
|
||||
|
||||
// Detailed information
|
||||
DetailedInfo ListDetailedInfo `json:"detailedInfo"`
|
||||
|
||||
// Disk ID
|
||||
Disk uint64 `json:"disk"`
|
||||
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Num
|
||||
Num uint64 `json:"num"`
|
||||
|
||||
// Number of RAM
|
||||
RAM uint64 `json:"ram"`
|
||||
}
|
||||
|
||||
type ACLGroup struct {
|
||||
AccountACL ACLList `json:"accountAcl"`
|
||||
K8SACL ACLList `json:"k8sAcl"`
|
||||
RGACL ACLList `json:"rgAcl"`
|
||||
// Access Control List
|
||||
type RecordACL struct {
|
||||
// Account ACL
|
||||
AccountACL ListACL `json:"accountAcl"`
|
||||
|
||||
// K8S ACL
|
||||
K8SACL ListACL `json:"k8sAcl"`
|
||||
|
||||
// RG ACL
|
||||
RGACL ListACL `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"`
|
||||
// Main information of Access Control List
|
||||
type ItemACL struct {
|
||||
// Explicit
|
||||
Explicit bool `json:"explicit"`
|
||||
|
||||
// GUID
|
||||
GUID string `json:"guid"`
|
||||
|
||||
// Right
|
||||
Right string `json:"right"`
|
||||
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
// Type
|
||||
Type string `json:"type"`
|
||||
|
||||
// User group ID
|
||||
UserGroupID string `json:"userGroupId"`
|
||||
}
|
||||
|
||||
type ACLList []ACL
|
||||
// List of ACL
|
||||
type ListACL []ItemACL
|
||||
|
||||
type K8SItem struct {
|
||||
AccountID uint64 `json:"accountId"`
|
||||
AccountName string `json:"accountName"`
|
||||
ACL []interface{} `json:"acl"`
|
||||
BServiceID uint64 `json:"bserviceId"`
|
||||
CIID uint64 `json:"ciId"`
|
||||
Config interface{} `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"`
|
||||
// Main information about kubernetes cluster
|
||||
type ItemK8SCluster struct {
|
||||
// Account ID
|
||||
AccountID uint64 `json:"accountId"`
|
||||
|
||||
// Account name
|
||||
AccountName string `json:"accountName"`
|
||||
|
||||
// Access Control List
|
||||
ACL []interface{} `json:"acl"`
|
||||
|
||||
// Basic Service ID
|
||||
BServiceID uint64 `json:"bserviceId"`
|
||||
|
||||
// CIID
|
||||
CIID uint64 `json:"ciId"`
|
||||
|
||||
// Config
|
||||
Config interface{} `json:"config"`
|
||||
|
||||
// Create by
|
||||
CreatedBy string `json:"createdBy"`
|
||||
|
||||
// Created time
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
|
||||
// Deleted by
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
|
||||
// Deleted time
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
|
||||
// Description
|
||||
Description string `json:"desc"`
|
||||
|
||||
// External network ID
|
||||
ExtNetID uint64 `json:"extnetId"`
|
||||
|
||||
// Grid ID
|
||||
GID uint64 `json:"gid"`
|
||||
|
||||
// GUID
|
||||
GUID uint64 `json:"guid"`
|
||||
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// Load balancer ID
|
||||
LBID uint64 `json:"lbId"`
|
||||
|
||||
// Milestones
|
||||
Milestones uint64 `json:"milestones"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Resource group ID
|
||||
RGID uint64 `json:"rgId"`
|
||||
|
||||
// Resource group name
|
||||
RGName string `json:"rgName"`
|
||||
|
||||
// Information about service account
|
||||
ServiceAccount RecordServiceAccount `json:"serviceAccount"`
|
||||
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
// Tech status
|
||||
TechStatus string `json:"techStatus"`
|
||||
|
||||
// Updated by
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
|
||||
// Updated time
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
|
||||
// VINS ID
|
||||
VINSID uint64 `json:"vinsId"`
|
||||
|
||||
// List workers group
|
||||
WorkersGroup ListK8SGroups `json:"workersGroups"`
|
||||
}
|
||||
|
||||
type ServiceAccount struct {
|
||||
GUID string `json:"guid"`
|
||||
// Information about service account
|
||||
type RecordServiceAccount struct {
|
||||
// GUID
|
||||
GUID string `json:"guid"`
|
||||
|
||||
// Password
|
||||
Password string `json:"password"`
|
||||
|
||||
// Username
|
||||
Username string `json:"username"`
|
||||
}
|
||||
|
||||
type K8SList []K8SItem
|
||||
// List of kubernetes clusters
|
||||
type ListK8SClusters []ItemK8SCluster
|
||||
|
||||
@@ -7,11 +7,14 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for restore kubernetes cluster
|
||||
type RestoreRequest struct {
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId"`
|
||||
}
|
||||
|
||||
func (krq RestoreRequest) Validate() error {
|
||||
func (krq RestoreRequest) validate() error {
|
||||
if krq.K8SID == 0 {
|
||||
return errors.New("validation-error: field K8SID can not be empty or equal to 0")
|
||||
}
|
||||
@@ -19,8 +22,9 @@ func (krq RestoreRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Restore restore kubernetes cluster from Recycle Bin
|
||||
func (k8s K8S) Restore(ctx context.Context, req RestoreRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -36,5 +40,6 @@ func (k8s K8S) Restore(ctx context.Context, req RestoreRequest) (bool, error) {
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -7,11 +7,14 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for start kubernetes cluster
|
||||
type StartRequest struct {
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId"`
|
||||
}
|
||||
|
||||
func (krq StartRequest) Validate() error {
|
||||
func (krq StartRequest) validate() error {
|
||||
if krq.K8SID == 0 {
|
||||
return errors.New("validation-error: field K8SID can not be empty or equal to 0")
|
||||
}
|
||||
@@ -19,8 +22,9 @@ func (krq StartRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Start starts kubernetes cluster by ID
|
||||
func (k8s K8S) Start(ctx context.Context, req StartRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -36,5 +40,6 @@ func (k8s K8S) Start(ctx context.Context, req StartRequest) (bool, error) {
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -7,11 +7,14 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for stop kubernetes cluster
|
||||
type StopRequest struct {
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId"`
|
||||
}
|
||||
|
||||
func (krq StopRequest) Validate() error {
|
||||
func (krq StopRequest) validate() error {
|
||||
if krq.K8SID == 0 {
|
||||
return errors.New("validation-error: field K8SID can not be empty or equal to 0")
|
||||
}
|
||||
@@ -19,8 +22,9 @@ func (krq StopRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Stop stops kubernetes cluster by ID
|
||||
func (k8s K8S) Stop(ctx context.Context, req StopRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -36,5 +40,6 @@ func (k8s K8S) Stop(ctx context.Context, req StopRequest) (bool, error) {
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -7,13 +7,24 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for update kubernetes cluster
|
||||
type UpdateRequest struct {
|
||||
K8SID uint64 `url:"k8sId"`
|
||||
Name string `url:"name,omitempty"`
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId"`
|
||||
|
||||
// New name to set.
|
||||
// If empty string is passed, name is not updated
|
||||
// Required: false
|
||||
Name string `url:"name,omitempty"`
|
||||
|
||||
// New description to set.
|
||||
// If empty string is passed, description is not updated
|
||||
// Required: false
|
||||
Description string `url:"desc,omitempty"`
|
||||
}
|
||||
|
||||
func (krq UpdateRequest) Validate() error {
|
||||
func (krq UpdateRequest) validate() error {
|
||||
if krq.K8SID == 0 {
|
||||
return errors.New("validation-error: field K8SID can not be empty or equal to 0")
|
||||
}
|
||||
@@ -21,8 +32,9 @@ func (krq UpdateRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Update updates name or description of Kubernetes cluster
|
||||
func (k8s K8S) Update(ctx context.Context, req UpdateRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -38,5 +50,6 @@ func (k8s K8S) Update(ctx context.Context, req UpdateRequest) (bool, error) {
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -7,21 +7,28 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for add worker to a kubernetes cluster
|
||||
type WorkerAddRequest struct {
|
||||
K8SID uint64 `url:"k8sId"`
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId"`
|
||||
|
||||
// ID of the workers compute group
|
||||
// Required: true
|
||||
WorkersGroupID uint64 `url:"workersGroupId"`
|
||||
Num uint `url:"num"`
|
||||
|
||||
// How many worker nodes to add
|
||||
// Required: true
|
||||
Num uint64 `url:"num"`
|
||||
}
|
||||
|
||||
func (krq WorkerAddRequest) Validate() error {
|
||||
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")
|
||||
}
|
||||
@@ -29,8 +36,9 @@ func (krq WorkerAddRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// WorkerAdd add worker nodes to a Kubernetes cluster
|
||||
func (k8s K8S) WorkerAdd(ctx context.Context, req WorkerAddRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -46,5 +54,6 @@ func (k8s K8S) WorkerAdd(ctx context.Context, req WorkerAddRequest) (bool, error
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -7,21 +7,28 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for hard reset kubernetes cluster
|
||||
type WorkerResetRequest struct {
|
||||
K8SID uint64 `url:"k8sId"`
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId"`
|
||||
|
||||
// ID of the workers compute group
|
||||
// Required: true
|
||||
WorkersGroupID uint64 `url:"workersGroupId"`
|
||||
WorkerID uint64 `url:"workerId"`
|
||||
|
||||
// Compute ID of worker node to reset
|
||||
// Required: true
|
||||
WorkerID uint64 `url:"workerId"`
|
||||
}
|
||||
|
||||
func (krq WorkerResetRequest) Validate() error {
|
||||
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")
|
||||
}
|
||||
@@ -29,8 +36,9 @@ func (krq WorkerResetRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// WorkerReset hard reset (compute start + stop) worker node of the Kubernetes cluster
|
||||
func (k8s K8S) WorkerReset(ctx context.Context, req WorkerResetRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -46,5 +54,6 @@ func (k8s K8S) WorkerReset(ctx context.Context, req WorkerResetRequest) (bool, e
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -7,21 +7,28 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for restart worker node
|
||||
type WorkerRestartRequest struct {
|
||||
K8SID uint64 `url:"k8sId"`
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId"`
|
||||
|
||||
// ID of the workers compute group
|
||||
// Required: true
|
||||
WorkersGroupID uint64 `url:"workersGroupId"`
|
||||
WorkerID uint64 `url:"workerId"`
|
||||
|
||||
// Compute ID of worker node to restart
|
||||
// Required: true
|
||||
WorkerID uint64 `url:"workerId"`
|
||||
}
|
||||
|
||||
func (krq WorkerRestartRequest) Validate() error {
|
||||
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")
|
||||
}
|
||||
@@ -29,8 +36,9 @@ func (krq WorkerRestartRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// WorkerRestart soft restart (reboot OS) worker node of the Kubernetes cluster
|
||||
func (k8s K8S) WorkerRestart(ctx context.Context, req WorkerRestartRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -46,5 +54,6 @@ func (k8s K8S) WorkerRestart(ctx context.Context, req WorkerRestartRequest) (boo
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -7,44 +7,61 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for add workers group
|
||||
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"`
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId"`
|
||||
|
||||
// Worker group name
|
||||
// Required: true
|
||||
Name string `url:"name"`
|
||||
|
||||
// List of strings with labels for worker group
|
||||
// i.e: ["label1=value1", "label2=value2"]
|
||||
// Required: false
|
||||
Labels []string `url:"labels,omitempty"`
|
||||
|
||||
// List of strings with taints for worker group
|
||||
// i.e: ["key1=value1:NoSchedule", "key2=value2:NoExecute"]
|
||||
// Required: false
|
||||
Taints []string `url:"taints,omitempty"`
|
||||
|
||||
// List of strings with annotations for worker group
|
||||
// i.e: ["key1=value1", "key2=value2"]
|
||||
// Required: false
|
||||
Annotations []string `url:"annotations,omitempty"`
|
||||
|
||||
// Number of worker nodes to create
|
||||
// Required: false
|
||||
WorkerNum uint64 `url:"workerNum,omitempty"`
|
||||
|
||||
// Worker node CPU count
|
||||
// Required: false
|
||||
WorkerCPU uint64 `url:"workerCpu,omitempty"`
|
||||
|
||||
// Worker node RAM volume in MB
|
||||
// Required: false
|
||||
WorkerRAM uint64 `url:"workerRam,omitempty"`
|
||||
|
||||
// Worker node boot disk size in GB If 0 is specified, size is defined by the OS image size
|
||||
// Required: false
|
||||
WorkerDisk uint64 `url:"workerDisk,omitempty"`
|
||||
}
|
||||
|
||||
func (krq WorkersGroupAddRequest) Validate() error {
|
||||
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")
|
||||
return errors.New("validation-error: field Name must be set")
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
// WorkersGroupAdd adds workers group to Kubernetes cluster
|
||||
func (k8s K8S) WorkersGroupAdd(ctx context.Context, req WorkersGroupAddRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -60,5 +77,6 @@ func (k8s K8S) WorkersGroupAdd(ctx context.Context, req WorkersGroupAddRequest)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -7,16 +7,21 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for delete workers group
|
||||
type WorkersGroupDeleteRequest struct {
|
||||
K8SID uint64 `url:"k8sId"`
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId"`
|
||||
|
||||
// Worker group ID
|
||||
// Required: true
|
||||
WorkersGroupID uint64 `url:"workersGroupId"`
|
||||
}
|
||||
|
||||
func (krq WorkersGroupDeleteRequest) Validate() error {
|
||||
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")
|
||||
}
|
||||
@@ -24,8 +29,9 @@ func (krq WorkersGroupDeleteRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// WorkersGroupDelete deletes workers group from Kubernetes cluster
|
||||
func (k8s K8S) WorkersGroupDelete(ctx context.Context, req WorkersGroupDeleteRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -41,5 +47,6 @@ func (k8s K8S) WorkersGroupDelete(ctx context.Context, req WorkersGroupDeleteReq
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -7,16 +7,21 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get information about worker group
|
||||
type WorkersGroupGetByNameRequest struct {
|
||||
K8SID uint64 `url:"k8sId"`
|
||||
GroupName string `url:"groupName "`
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId"`
|
||||
|
||||
// Worker group name
|
||||
// Required: true
|
||||
GroupName string `url:"groupName"`
|
||||
}
|
||||
|
||||
func (krq WorkersGroupGetByNameRequest) Validate() error {
|
||||
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")
|
||||
}
|
||||
@@ -24,8 +29,9 @@ func (krq WorkersGroupGetByNameRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k8s K8S) WorkersGroupGetByName(ctx context.Context, req WorkersGroupGetByNameRequest) (*K8SGroup, error) {
|
||||
err := req.Validate()
|
||||
// WorkersGroupGetByName gets worker group metadata by name
|
||||
func (k8s K8S) WorkersGroupGetByName(ctx context.Context, req WorkersGroupGetByNameRequest) (*RecordK8SGroups, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -37,12 +43,12 @@ func (k8s K8S) WorkersGroupGetByName(ctx context.Context, req WorkersGroupGetByN
|
||||
return nil, err
|
||||
}
|
||||
|
||||
group := &K8SGroup{}
|
||||
info := RecordK8SGroups{}
|
||||
|
||||
err = json.Unmarshal(res, group)
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return group, nil
|
||||
return &info, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user