v1.0.0
This commit is contained in:
141
pkg/cloudbroker/k8s/create.go
Normal file
141
pkg/cloudbroker/k8s/create.go
Normal file
@@ -0,0 +1,141 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Request struct for create K8S
|
||||
type CreateRequest struct {
|
||||
// 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 (K8CI) for cluster
|
||||
// Required: true
|
||||
K8CIID uint64 `url:"k8ciId"`
|
||||
|
||||
// Name for first worker group created with cluster
|
||||
// Required: true
|
||||
WorkerGroupName string `url:"workerGroupName"`
|
||||
|
||||
// ID of SEP to create boot disks for master nodes.
|
||||
// Uses images SEP ID if not set
|
||||
// Required: false
|
||||
MasterSEPID uint64 `url:"masterSepId,omitempty"`
|
||||
|
||||
// Pool to use if master SEP ID is set, can be also empty if needed to be chosen by system
|
||||
// Required: false
|
||||
MasterSEPPool string `url:"masterSepPool,omitempty"`
|
||||
|
||||
// ID of SEP to create boot disks for default worker nodes group.
|
||||
// Uses images SEP ID if not set
|
||||
// Required: false
|
||||
WorkerSEPID uint64 `url:"workerSepId,omitempty"`
|
||||
|
||||
// Pool to use if worker SEP ID is set, can be also empty if needed to be chosen by system
|
||||
// Required: false
|
||||
WorkerSEPPool string `url:"workerSepPool,omitempty"`
|
||||
|
||||
// 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 uint64 `url:"masterNum,omitempty"`
|
||||
|
||||
// Master node CPU count
|
||||
// Required: false
|
||||
MasterCPU uint64 `url:"masterCpu,omitempty"`
|
||||
|
||||
// Master node RAM volume in MB
|
||||
// Required: false
|
||||
MasterRAM uint64 `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 uint64 `url:"masterDisk,omitempty"`
|
||||
|
||||
// Number of worker nodes to create in default worker group
|
||||
// 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"`
|
||||
|
||||
// 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 external network
|
||||
// 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 {
|
||||
if krq.Name == "" {
|
||||
return errors.New("validation-error: field Name must be set")
|
||||
}
|
||||
if krq.RGID == 0 {
|
||||
return errors.New("validation-error: field RGID must be set")
|
||||
}
|
||||
if krq.K8CIID == 0 {
|
||||
return errors.New("validation-error: field K8CIID must be set")
|
||||
}
|
||||
if krq.WorkerGroupName == "" {
|
||||
return errors.New("validation-error: field WorkerGroupName must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Create creates a new kubernetes cluster in the specified resource group
|
||||
func (k K8S) Create(ctx context.Context, req CreateRequest) (string, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/k8s/create"
|
||||
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
result := strings.ReplaceAll(string(res), "\"", "")
|
||||
|
||||
return result, nil
|
||||
}
|
||||
50
pkg/cloudbroker/k8s/delete.go
Normal file
50
pkg/cloudbroker/k8s/delete.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for delete kubernetes cluster
|
||||
type DeleteRequest struct {
|
||||
// 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 {
|
||||
if krq.K8SID == 0 {
|
||||
return errors.New("validation-error: field K8SID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Delete deletes kubernetes cluster
|
||||
func (k K8S) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/k8s/delete"
|
||||
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, 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/cloudbroker/k8s/delete_master_from_group.go
Normal file
59
pkg/cloudbroker/k8s/delete_master_from_group.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for delete master from group
|
||||
type DeleteMasterFromGroupRequest struct {
|
||||
// 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 {
|
||||
if krq.K8SID == 0 {
|
||||
return errors.New("validation-error: field K8SID must be set")
|
||||
}
|
||||
if krq.MasterGroupID == 0 {
|
||||
return errors.New("validation-error: field MasterGroupID must be set")
|
||||
}
|
||||
if len(krq.MasterIDs) == 0 {
|
||||
return errors.New("validation-error: field MasterIDs must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteMasterFromGroup deletes compute from masters group in selected kubernetes cluster
|
||||
func (k K8S) DeleteMasterFromGroup(ctx context.Context, req DeleteMasterFromGroupRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/k8s/deleteMasterFromGroup"
|
||||
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, 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/cloudbroker/k8s/delete_worker_from_group.go
Normal file
59
pkg/cloudbroker/k8s/delete_worker_from_group.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for delete worker from group
|
||||
type DeleteWorkerFromGroupRequest struct {
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId"`
|
||||
|
||||
// ID of the workers compute group
|
||||
// Required: true
|
||||
WorkersGroupID uint64 `url:"workersGroupId"`
|
||||
|
||||
// Compute ID of worker node to delete
|
||||
// Required: true
|
||||
WorkerID uint64 `url:"workerId"`
|
||||
}
|
||||
|
||||
func (krq DeleteWorkerFromGroupRequest) validate() error {
|
||||
if krq.K8SID == 0 {
|
||||
return errors.New("validation-error: field K8SID must be set")
|
||||
}
|
||||
if krq.WorkersGroupID == 0 {
|
||||
return errors.New("validation-error: field WorkerGroupID must be set")
|
||||
}
|
||||
if krq.WorkerID == 0 {
|
||||
return errors.New("validation-error: field WorkerIDs must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteWorkerFromGroup deletes worker compute from workers group in selected kubernetes cluster
|
||||
func (k K8S) DeleteWorkerFromGroup(ctx context.Context, req DeleteWorkerFromGroupRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/k8s/deleteWorkerFromGroup"
|
||||
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
45
pkg/cloudbroker/k8s/disable.go
Normal file
45
pkg/cloudbroker/k8s/disable.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for disable kubernetes cluster
|
||||
type DisableRequest struct {
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId"`
|
||||
}
|
||||
|
||||
func (krq DisableRequest) validate() error {
|
||||
if krq.K8SID == 0 {
|
||||
return errors.New("validation-error: field K8SID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Disable disables kubernetes cluster by ID
|
||||
func (k K8S) Disable(ctx context.Context, req DisableRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/k8s/disable"
|
||||
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
45
pkg/cloudbroker/k8s/enable.go
Normal file
45
pkg/cloudbroker/k8s/enable.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for enable kubernetes cluster
|
||||
type EnableRequest struct {
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId"`
|
||||
}
|
||||
|
||||
func (krq EnableRequest) validate() error {
|
||||
if krq.K8SID == 0 {
|
||||
return errors.New("validation-error: field K8SID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Enable enables kubernetes cluster by ID
|
||||
func (k K8S) Enable(ctx context.Context, req EnableRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/k8s/enable"
|
||||
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, 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/cloudbroker/k8s/find_group_by_label.go
Normal file
59
pkg/cloudbroker/k8s/find_group_by_label.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get information about group of kubernetes cluster
|
||||
type FindGroupByLabelRequest struct {
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId"`
|
||||
|
||||
// List of labels to search
|
||||
// Required: true
|
||||
Labels []string `url:"labels"`
|
||||
|
||||
// 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 {
|
||||
if krq.K8SID == 0 {
|
||||
return errors.New("validation-error: field K8SID must be set")
|
||||
}
|
||||
if len(krq.Labels) == 0 {
|
||||
return errors.New("validation-error: field Labels must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// FindGroupByLabel find worker group information by one on more labels
|
||||
func (k K8S) FindGroupByLabel(ctx context.Context, req FindGroupByLabelRequest) (ListK8SGroup, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/k8s/findGroupByLabel"
|
||||
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListK8SGroup{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
47
pkg/cloudbroker/k8s/get.go
Normal file
47
pkg/cloudbroker/k8s/get.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"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 {
|
||||
if krq.K8SID == 0 {
|
||||
return errors.New("validation-error: field K8SID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get gets information about kubernetes cluster
|
||||
func (k K8S) Get(ctx context.Context, req GetRequest) (*RecordK8S, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/k8s/get"
|
||||
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := RecordK8S{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
42
pkg/cloudbroker/k8s/get_config.go
Normal file
42
pkg/cloudbroker/k8s/get_config.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// 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 {
|
||||
if krq.K8SID == 0 {
|
||||
return errors.New("validation-error: field K8SID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetConfig gets configuration data to access kubernetes cluster
|
||||
func (k K8S) GetConfig(ctx context.Context, req GetConfigRequest) (string, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/k8s/getConfig"
|
||||
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
result := strings.ReplaceAll(string(res), "\"", "")
|
||||
|
||||
return result, nil
|
||||
}
|
||||
49
pkg/cloudbroker/k8s/get_node_annotations.go
Normal file
49
pkg/cloudbroker/k8s/get_node_annotations.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Request struct for get node annotations
|
||||
type GetNodeAnnotationsRequest struct {
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId"`
|
||||
|
||||
// Node ID
|
||||
// Required: true
|
||||
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
|
||||
}
|
||||
|
||||
// GetNodeAnnotations gets kubernetes cluster worker node annotations
|
||||
func (k K8S) GetNodeAnnotations(ctx context.Context, req GetNodeAnnotationsRequest) (string, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/k8s/getNodeAnnotations"
|
||||
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
result := strings.ReplaceAll(string(res), "\"", "")
|
||||
|
||||
return result, nil
|
||||
}
|
||||
49
pkg/cloudbroker/k8s/get_node_labels.go
Normal file
49
pkg/cloudbroker/k8s/get_node_labels.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Request struct for get worker node labels
|
||||
type GetNodeLabelsRequest struct {
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId"`
|
||||
|
||||
// Compute ID of worker node
|
||||
// Required: true
|
||||
NodeID uint64 `url:"nodeId"`
|
||||
}
|
||||
|
||||
func (krq GetNodeLabelsRequest) 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
|
||||
}
|
||||
|
||||
// GetNodeLabels gets kubernetes cluster worker node labels
|
||||
func (k K8S) GetNodeLabels(ctx context.Context, req GetNodeLabelsRequest) (string, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/k8s/getNodeLabels"
|
||||
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
result := strings.ReplaceAll(string(res), "\"", "")
|
||||
|
||||
return result, nil
|
||||
}
|
||||
49
pkg/cloudbroker/k8s/get_node_taints.go
Normal file
49
pkg/cloudbroker/k8s/get_node_taints.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Request struct for get node taints
|
||||
type GetNodeTaintsRequest struct {
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId"`
|
||||
|
||||
// Node ID
|
||||
// Required: false
|
||||
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
|
||||
}
|
||||
|
||||
// GetNodeTaints gets kubernetes cluster worker node taints
|
||||
func (k K8S) GetNodeTaints(ctx context.Context, req GetNodeTaintsRequest) (string, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/k8s/getNodeTaints"
|
||||
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
result := strings.ReplaceAll(string(res), "\"", "")
|
||||
|
||||
return result, nil
|
||||
}
|
||||
18
pkg/cloudbroker/k8s/k8s.go
Normal file
18
pkg/cloudbroker/k8s/k8s.go
Normal file
@@ -0,0 +1,18 @@
|
||||
// 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: client,
|
||||
}
|
||||
}
|
||||
42
pkg/cloudbroker/k8s/list.go
Normal file
42
pkg/cloudbroker/k8s/list.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get list information K8S
|
||||
type ListRequest struct {
|
||||
// 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"`
|
||||
}
|
||||
|
||||
// List gets list all kubernetes clusters
|
||||
func (k K8S) List(ctx context.Context, req ListRequest) (ListK8S, error) {
|
||||
|
||||
url := "/cloudbroker/k8s/list"
|
||||
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListK8S{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
38
pkg/cloudbroker/k8s/list_deleted.go
Normal file
38
pkg/cloudbroker/k8s/list_deleted.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get list deleted kubernetes cluster
|
||||
type ListDeletedRequest struct {
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty"`
|
||||
|
||||
// Page size
|
||||
// Required: false
|
||||
Size uint64 `url:"size,omitempty"`
|
||||
}
|
||||
|
||||
// ListDeleted gets all deleted kubernetes clusters
|
||||
func (k K8S) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListK8S, error) {
|
||||
|
||||
url := "/cloudbroker/k8s/listDeleted"
|
||||
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListK8S{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
292
pkg/cloudbroker/k8s/models.go
Normal file
292
pkg/cloudbroker/k8s/models.go
Normal file
@@ -0,0 +1,292 @@
|
||||
package k8s
|
||||
|
||||
// Deteiled information
|
||||
type ItemDetailedInfo struct {
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
// Status
|
||||
TechStatus string `json:"techStatus"`
|
||||
}
|
||||
|
||||
// List detailed information
|
||||
type ListDetailedInfo []ItemDetailedInfo
|
||||
|
||||
// Detailed information about K8S group
|
||||
type RecordK8SGroup struct {
|
||||
// List annotations
|
||||
Annotations []string `json:"annotations"`
|
||||
|
||||
// Number of CPU
|
||||
CPU uint64 `json:"cpu"`
|
||||
|
||||
// List detailed information
|
||||
DetailedInfo ListDetailedInfo `json:"detailedInfo"`
|
||||
|
||||
// Disk
|
||||
Disk uint64 `json:"disk"`
|
||||
|
||||
// GUID
|
||||
GUID string `json:"guid"`
|
||||
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// List labels
|
||||
Labels []string `json:"labels"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Number
|
||||
Num uint64 `json:"num"`
|
||||
|
||||
// Number of RAM
|
||||
RAM uint64 `json:"ram"`
|
||||
|
||||
// List taints
|
||||
Taints []string `json:"taints"`
|
||||
}
|
||||
|
||||
// List K8S groups
|
||||
type ListK8SGroup []RecordK8SGroup
|
||||
|
||||
// Detailed information about K8S
|
||||
type RecordK8S struct {
|
||||
// Access Control List
|
||||
ACL RecordACLGroup `json:"ACL"`
|
||||
|
||||
// Account ID
|
||||
AccountID uint64 `json:"accountId"`
|
||||
|
||||
// Account name
|
||||
AccountName string `json:"accountName"`
|
||||
|
||||
// Basic service ID
|
||||
BServiceID uint64 `json:"bserviceId"`
|
||||
|
||||
// CI ID
|
||||
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"`
|
||||
|
||||
// Detailed information about K8S groups
|
||||
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"`
|
||||
}
|
||||
|
||||
// Detailed info about K8S groups
|
||||
type RecordK8SGroups struct {
|
||||
// Master group
|
||||
Masters MasterGroup `json:"masters"`
|
||||
|
||||
// Worker group
|
||||
Workers ListK8SGroup `json:"workers"`
|
||||
}
|
||||
|
||||
// Detailed information about master group
|
||||
type MasterGroup struct {
|
||||
// Number of CPU
|
||||
CPU uint64 `json:"cpu"`
|
||||
|
||||
// Detailed information
|
||||
DetailedInfo ListDetailedInfo `json:"detailedInfo"`
|
||||
|
||||
// Disk
|
||||
Disk uint64 `json:"disk"`
|
||||
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Number
|
||||
Num uint64 `json:"num"`
|
||||
|
||||
// Number of RAM
|
||||
RAM uint64 `json:"ram"`
|
||||
}
|
||||
|
||||
// Detailed information of access control
|
||||
type RecordACLGroup struct {
|
||||
// Account ACL
|
||||
AccountACL ListACL `json:"accountAcl"`
|
||||
|
||||
// K8S ACL
|
||||
K8SACL ListACL `json:"k8sAcl"`
|
||||
|
||||
// RG ACL
|
||||
RGACL ListACL `json:"rgAcl"`
|
||||
}
|
||||
|
||||
// Access Control List
|
||||
type ACL 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"`
|
||||
}
|
||||
|
||||
// List ACL
|
||||
type ListACL []ACL
|
||||
|
||||
// Main information about K8S
|
||||
type ItemK8S 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"`
|
||||
|
||||
// CI ID
|
||||
CIID uint64 `json:"ciId"`
|
||||
|
||||
// Config
|
||||
Config interface{} `json:"config"`
|
||||
|
||||
// Created 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"`
|
||||
|
||||
// Service account
|
||||
ServiceAccount ServiceAccount `json:"serviceAccount"`
|
||||
|
||||
// SSH key
|
||||
SSHKey string `json:"sshKey"`
|
||||
|
||||
// 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
|
||||
WorkersGroup ListK8SGroup `json:"workersGroups"`
|
||||
}
|
||||
|
||||
// Service account
|
||||
type ServiceAccount struct {
|
||||
// GUID
|
||||
GUID string `json:"guid"`
|
||||
|
||||
// Password
|
||||
Password string `json:"password"`
|
||||
|
||||
// Username
|
||||
Username string `json:"username"`
|
||||
}
|
||||
|
||||
// List K8S
|
||||
type ListK8S []ItemK8S
|
||||
45
pkg/cloudbroker/k8s/restore.go
Normal file
45
pkg/cloudbroker/k8s/restore.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for restore kubernetes cluster
|
||||
type RestoreRequest struct {
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId"`
|
||||
}
|
||||
|
||||
func (krq RestoreRequest) validate() error {
|
||||
if krq.K8SID == 0 {
|
||||
return errors.New("validation-error: field K8SID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Restore restore kubernetes cluster from recycle bin
|
||||
func (k K8S) Restore(ctx context.Context, req RestoreRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/k8s/restore"
|
||||
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
45
pkg/cloudbroker/k8s/start.go
Normal file
45
pkg/cloudbroker/k8s/start.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for start kubernetes cluster
|
||||
type StartRequest struct {
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId"`
|
||||
}
|
||||
|
||||
func (krq StartRequest) validate() error {
|
||||
if krq.K8SID == 0 {
|
||||
return errors.New("validation-error: field K8SID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Start starts kubernetes cluster by ID
|
||||
func (k K8S) Start(ctx context.Context, req StartRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/k8s/start"
|
||||
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
45
pkg/cloudbroker/k8s/stop.go
Normal file
45
pkg/cloudbroker/k8s/stop.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for stop kubernetes cluster
|
||||
type StopRequest struct {
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId"`
|
||||
}
|
||||
|
||||
func (krq StopRequest) validate() error {
|
||||
if krq.K8SID == 0 {
|
||||
return errors.New("validation-error: field K8SID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Stop stops kubernetes cluster by ID
|
||||
func (k K8S) Stop(ctx context.Context, req StopRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/k8s/stop"
|
||||
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, 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/cloudbroker/k8s/update.go
Normal file
55
pkg/cloudbroker/k8s/update.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for update kubernetes cluster
|
||||
type UpdateRequest struct {
|
||||
// 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 {
|
||||
if krq.K8SID == 0 {
|
||||
return errors.New("validation-error: field K8SID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Update updates name or description of kubernetes cluster
|
||||
func (k K8S) Update(ctx context.Context, req UpdateRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/k8s/update"
|
||||
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, 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/cloudbroker/k8s/worker_add.go
Normal file
58
pkg/cloudbroker/k8s/worker_add.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for add worker to a kubernetes cluster
|
||||
type WorkerAddRequest struct {
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId"`
|
||||
|
||||
// ID of the workers compute group
|
||||
// Required: true
|
||||
WorkersGroupID uint64 `url:"workersGroupId"`
|
||||
|
||||
// How many worker nodes to add
|
||||
// Required: true
|
||||
Num uint64 `url:"num"`
|
||||
}
|
||||
|
||||
func (krq WorkerAddRequest) validate() error {
|
||||
if krq.K8SID == 0 {
|
||||
return errors.New("validation-error: field K8SID must be set")
|
||||
}
|
||||
if krq.WorkersGroupID == 0 {
|
||||
return errors.New("validation-error: field WorkersGroupID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// WorkerAdd adds worker nodes to a kubernetes cluster
|
||||
func (k K8S) WorkerAdd(ctx context.Context, req WorkerAddRequest) ([]uint64, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/k8s/workerAdd"
|
||||
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := make([]uint64, 0)
|
||||
|
||||
err = json.Unmarshal(res, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
59
pkg/cloudbroker/k8s/worker_reset.go
Normal file
59
pkg/cloudbroker/k8s/worker_reset.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for hard reset kubernetes cluster
|
||||
type WorkerResetRequest struct {
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId"`
|
||||
|
||||
// ID of the workers compute group
|
||||
// Required: true
|
||||
WorkersGroupID uint64 `url:"workersGroupId"`
|
||||
|
||||
// Compute ID of worker node to reset
|
||||
// Required: true
|
||||
WorkerID uint64 `url:"workerId"`
|
||||
}
|
||||
|
||||
func (krq WorkerResetRequest) validate() error {
|
||||
if krq.K8SID == 0 {
|
||||
return errors.New("validation-error: field K8SID must be set")
|
||||
}
|
||||
if krq.WorkersGroupID == 0 {
|
||||
return errors.New("validation-error: field WorkersGroupID must be set")
|
||||
}
|
||||
if krq.WorkerID == 0 {
|
||||
return errors.New("validation-error: field WorkerID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// WorkerReset hard reset (compute start + stop) worker node of the kubernetes cluster
|
||||
func (k K8S) WorkerReset(ctx context.Context, req WorkerResetRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/k8s/workerReset"
|
||||
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, 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/cloudbroker/k8s/worker_restart.go
Normal file
58
pkg/cloudbroker/k8s/worker_restart.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for restart worker node
|
||||
type WorkerRestartRequest struct {
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId"`
|
||||
|
||||
// ID of the workers compute group
|
||||
// Required: true
|
||||
WorkersGroupID uint64 `url:"workersGroupId"`
|
||||
|
||||
// Compute ID of worker node to restart
|
||||
// Required: true
|
||||
WorkerID uint64 `url:"workerId"`
|
||||
}
|
||||
|
||||
func (krq WorkerRestartRequest) validate() error {
|
||||
if krq.K8SID == 0 {
|
||||
return errors.New("validation-error: field K8SID must be set")
|
||||
}
|
||||
if krq.WorkersGroupID == 0 {
|
||||
return errors.New("validation-error: field WorkersGroupID must be set")
|
||||
}
|
||||
if krq.WorkerID == 0 {
|
||||
return errors.New("validation-error: field WorkerID must be set")
|
||||
}
|
||||
|
||||
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()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/k8s/workerRestart"
|
||||
|
||||
res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
90
pkg/cloudbroker/k8s/workers_group_add.go
Normal file
90
pkg/cloudbroker/k8s/workers_group_add.go
Normal file
@@ -0,0 +1,90 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Request struct for add workers group
|
||||
type WorkersGroupAddRequest struct {
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId"`
|
||||
|
||||
// Worker group name
|
||||
// Required: true
|
||||
Name string `url:"name"`
|
||||
|
||||
// ID of SEP to create boot disks for default worker nodes group.
|
||||
// Uses images SEP ID if not set
|
||||
// Required: false
|
||||
WorkerSEPID uint64 `url:"workerSepId,omitempty"`
|
||||
|
||||
// Pool to use if worker SEP ID is set, can be also empty if
|
||||
// needed to be chosen by system
|
||||
// Required: false
|
||||
WorkerSEPPool string `url:"workerSepPool,omitempty"`
|
||||
|
||||
// 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 {
|
||||
if krq.K8SID == 0 {
|
||||
return errors.New("validation-error: field K8SID must be set")
|
||||
}
|
||||
if krq.Name == "" {
|
||||
return errors.New("validation-error: field Name must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// WorkersGroupAdd adds workers group to kubernetes cluster
|
||||
func (k K8S) WorkersGroupAdd(ctx context.Context, req WorkersGroupAddRequest) (string, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/k8s/workersGroupAdd"
|
||||
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
result := strings.ReplaceAll(string(res), "\"", "")
|
||||
|
||||
return result, nil
|
||||
}
|
||||
52
pkg/cloudbroker/k8s/workers_group_delete.go
Normal file
52
pkg/cloudbroker/k8s/workers_group_delete.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for delete workers group
|
||||
type WorkersGroupDeleteRequest struct {
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId"`
|
||||
|
||||
// Worker group ID
|
||||
// Required: true
|
||||
WorkersGroupID uint64 `url:"workersGroupId"`
|
||||
}
|
||||
|
||||
func (krq WorkersGroupDeleteRequest) validate() error {
|
||||
if krq.K8SID == 0 {
|
||||
return errors.New("validation-error: field K8SID must be set")
|
||||
}
|
||||
if krq.WorkersGroupID == 0 {
|
||||
return errors.New("validation-error: field WorkersGroupID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// WorkersGroupDelete deletes workers group from kubernetes cluster
|
||||
func (k K8S) WorkersGroupDelete(ctx context.Context, req WorkersGroupDeleteRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/k8s/workersGroupDelete"
|
||||
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
54
pkg/cloudbroker/k8s/workers_group_get_by_name.go
Normal file
54
pkg/cloudbroker/k8s/workers_group_get_by_name.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get information about worker group
|
||||
type WorkersGroupGetByNameRequest struct {
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId"`
|
||||
|
||||
// Worker group name
|
||||
// Required: true
|
||||
GroupName string `url:"groupName"`
|
||||
}
|
||||
|
||||
func (krq WorkersGroupGetByNameRequest) validate() error {
|
||||
if krq.K8SID == 0 {
|
||||
return errors.New("validation-error: field K8SID must be set")
|
||||
}
|
||||
if krq.GroupName == "" {
|
||||
return errors.New("validation-error: field WorkersGroupID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// WorkersGroupGetByName gets worker group metadata by name
|
||||
func (k K8S) WorkersGroupGetByName(ctx context.Context, req WorkersGroupGetByNameRequest) (*RecordK8SGroup, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/k8s/workersGroupGetByName"
|
||||
|
||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := RecordK8SGroup{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
Reference in New Issue
Block a user