This commit is contained in:
asteam
2025-09-23 14:34:24 +03:00
parent b924e85e49
commit f1ffb4c0fd
1108 changed files with 72020 additions and 0 deletions

View File

@@ -0,0 +1,202 @@
package k8s
import (
"context"
"net/http"
"strings"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// CreateRequest struct to create K8S
type CreateRequest struct {
// Name of kubernetes cluster
// Required: true
Name string `url:"name" json:"name" validate:"required"`
// Resource group ID for cluster placement
// Required: true
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
// ID of kubernetes catalog item (K8CI) for cluster
// Required: true
K8CIID uint64 `url:"k8ciId" json:"k8ciId" validate:"required"`
// Name for first worker group created with cluster
// Required: true
WorkerGroupName string `url:"workerGroupName" json:"workerGroupName" validate:"required,workerGroupName"`
// Network plugin
// Must be one of these values: flannel, weavenet, calico
// Required: true
NetworkPlugin string `url:"networkPlugin" json:"networkPlugin" validate:"required,networkPlugin"`
// ID of SEP to create boot disks for master nodes.
// Uses images SEP ID if not set
// Required: false
MasterSEPID uint64 `url:"masterSepId,omitempty" json:"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" json:"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" json:"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" json:"workerSepPool,omitempty"`
// List of strings with labels for default worker group
// i.e: ["label1=value1", "label2=value2"]
// Required: false
Labels []string `url:"labels,omitempty" json:"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" json:"taints,omitempty"`
// List of strings with annotations for worker group
// i.e: ["key1=value1", "key2=value2"]
// Required: false
Annotations []string `url:"annotations,omitempty" json:"annotations,omitempty"`
// Number of master nodes to create
// Required: false
MasterNum uint64 `url:"masterNum,omitempty" json:"masterNum,omitempty"`
// Master node CPU count
// Required: false
MasterCPU uint64 `url:"masterCpu,omitempty" json:"masterCpu,omitempty"`
// Master node RAM volume in MB
// Required: false
MasterRAM uint64 `url:"masterRam,omitempty" json:"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" json:"masterDisk,omitempty"`
// Number of worker nodes to create in default worker group
// Required: false
WorkerNum uint64 `url:"workerNum,omitempty" json:"workerNum,omitempty"`
// Worker node CPU count
// Required: false
WorkerCPU uint64 `url:"workerCpu,omitempty" json:"workerCpu,omitempty"`
// Worker node RAM volume in MB
// Required: false
WorkerRAM uint64 `url:"workerRam,omitempty" json:"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" json:"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" json:"extnetId,omitempty"`
// ID of the ViNS to connect k8s cluster. If nothing is specified, ViNS will be created automatically
// Required: false
VinsId uint64 `url:"vinsId,omitempty" json:"vinsId,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" json:"withLB"`
// Custom sysctl values for Load Balancer instance. Applied on boot
// Required: false
LbSysctlParams []map[string]interface{} `url:"lbSysctlParams,omitempty" json:"lbSysctlParams,omitempty"`
// Use Highly Available schema for LB deploy
// Required: false
HighlyAvailable bool `url:"highlyAvailableLB,omitempty" json:"highlyAvailableLB,omitempty"`
// Optional extra Subject Alternative Names (SANs) to use for the API Server serving certificate. Can be both IP addresses and DNS names
// Required: false
AdditionalSANs []string `url:"additionalSANs,omitempty" json:"additionalSANs,omitempty"`
// Is used to define settings and actions that should be performed before any other component in the cluster starts.
// It allows you to configure things like node registration, network setup, and other initialization tasks. insert a valid JSON string with all levels of nesting
// Required: false
InitConfiguration string `url:"initConfiguration,omitempty" json:"initConfiguration,omitempty"`
// Is used to define global settings and configurations for the entire cluster.
// It includes parameters such as cluster name, DNS settings, authentication methods, and other cluster-wide configurations.
// Insert a valid JSON string with all levels of nesting
// Required: false
ClusterConfiguration string `url:"clusterConfiguration,omitempty" json:"clusterConfiguration,omitempty"`
// Is used to configure the behavior and settings of the Kubelet, which is the primary node agent that runs on each node in the cluster.
// It includes parameters such as node IP address, resource allocation, pod eviction policies, and other Kubelet-specific configurations.
// Insert a valid JSON string with all levels of nesting
// Required: false
KubeletConfiguration string `url:"kubeletConfiguration,omitempty" json:"kubeletConfiguration,omitempty"`
// Is used to configure the behavior and settings of the Kube-proxy, which is responsible for network proxying and load balancing within the cluster.
// It includes parameters such as proxy mode, cluster IP ranges, and other Kube-proxy specific configurations.
// Insert a valid JSON string with all levels of nesting
// Required: false
KubeProxyConfiguration string `url:"kubeProxyConfiguration,omitempty" json:"kubeProxyConfiguration,omitempty"`
// Is used to configure the behavior and settings for joining a node to a cluster.
// It includes parameters such as the cluster's control plane endpoint, token, and certificate key. insert a valid JSON string with all levels of nesting
// Required: false
JoinConfiguration string `url:"joinConfiguration,omitempty" json:"joinConfiguration,omitempty"`
// Text description of this kubernetes cluster
// Required: false
Description string `url:"desc,omitempty" json:"desc,omitempty"`
// Meta data for working group computes, format YAML "user_data": 1111
// Required: false
UserData string `url:"userData,omitempty" json:"userData,omitempty"`
// Use only selected ExtNet for infrastructure connections
// Required: false
ExtNetOnly bool `url:"extnetOnly,omitempty" json:"extnetOnly,omitempty"`
// Insert ssl certificate in x509 pem format
// Required: false
OidcCertificate string `url:"oidcCertificate,omitempty" json:"oidcCertificate,omitempty"`
// Type of the emulated system, Q35 or i440fx
// Required: false
Chipset string `url:"chipset,omitempty" json:"chipset,omitempty" validate:"omitempty,chipset"`
}
// GetRAM returns RAM values
func (r CreateRequest) GetRAM() map[string]uint64 {
res := make(map[string]uint64, 2)
res["MasterRAM"] = r.MasterRAM
res["WorkerRAM"] = r.WorkerRAM
return res
}
// Create creates a new kubernetes cluster in the specified resource group
func (k K8S) Create(ctx context.Context, req CreateRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/k8s/create"
res, err := k.client.DecortApiCallMP(ctx, http.MethodPost, url, req)
if err != nil {
return "", err
}
result := strings.ReplaceAll(string(res), "\"", "")
return result, nil
}

View File

@@ -0,0 +1,43 @@
package k8s
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// DeleteRequest struct to delete kubernetes cluster
type DeleteRequest struct {
// Kubernetes cluster ID
// Required: true
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
// True if cluster is destroyed permanently.
// Otherwise it can be restored from recycle bin
// Required: false
Permanently bool `url:"permanently" json:"permanently"`
}
// Delete deletes kubernetes cluster
func (k K8S) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(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
}

View File

@@ -0,0 +1,46 @@
package k8s
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// DeleteMasterFromGroupRequest struct to delete master from group
type DeleteMasterFromGroupRequest struct {
// Kubernetes cluster ID
// Required: true
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
// ID of the masters compute group
// Required: true
MasterGroupID uint64 `url:"masterGroupId" json:"masterGroupId" validate:"required"`
// List of Compute IDs of master nodes to delete
// Required: true
MasterIDs []uint64 `url:"masterIds" json:"masterIds" validate:"min=1"`
}
// DeleteMasterFromGroup deletes compute from masters group in selected kubernetes cluster
func (k K8S) DeleteMasterFromGroup(ctx context.Context, req DeleteMasterFromGroupRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(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
}

View File

@@ -0,0 +1,46 @@
package k8s
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// DeleteWorkerFromGroupRequest struct to delete worker from group
type DeleteWorkerFromGroupRequest struct {
// Kubernetes cluster ID
// Required: true
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
// ID of the workers compute group
// Required: true
WorkersGroupID uint64 `url:"workersGroupId" json:"workersGroupId" validate:"required"`
// Compute ID of worker node to delete
// Required: true
WorkerID uint64 `url:"workerId" json:"workerId" validate:"required"`
}
// DeleteWorkerFromGroup deletes worker compute from workers group in selected kubernetes cluster
func (k K8S) DeleteWorkerFromGroup(ctx context.Context, req DeleteWorkerFromGroupRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(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
}

View File

@@ -0,0 +1,38 @@
package k8s
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// DisableRequest struct to disable kubernetes cluster
type DisableRequest struct {
// Kubernetes cluster ID
// Required: true
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
}
// Disable disables kubernetes cluster by ID
func (k K8S) Disable(ctx context.Context, req DisableRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(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
}

View File

@@ -0,0 +1,38 @@
package k8s
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// EnableRequest struct to enable kubernetes cluster
type EnableRequest struct {
// Kubernetes cluster ID
// Required: true
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
}
// Enable enables kubernetes cluster by ID
func (k K8S) Enable(ctx context.Context, req EnableRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(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
}

View File

@@ -0,0 +1,98 @@
package k8s
// FilterByID returns ListK8S with specified ID.
func (lkc ListK8S) FilterByID(id uint64) ListK8S {
predicate := func(ikc ItemK8S) bool {
return ikc.ID == id
}
return lkc.FilterFunc(predicate)
}
// FilterByName returns ListK8S with specified Name.
func (lkc ListK8S) FilterByName(name string) ListK8S {
predicate := func(ikc ItemK8S) bool {
return ikc.Name == name
}
return lkc.FilterFunc(predicate)
}
// FilterByAccountID returns ListK8S with specified AccountID.
func (lkc ListK8S) FilterByAccountID(accountID uint64) ListK8S {
predicate := func(ikc ItemK8S) bool {
return ikc.AccountID == accountID
}
return lkc.FilterFunc(predicate)
}
// FilterByRGID returns ListK8S with specified RGID.
func (lkc ListK8S) FilterByRGID(rgID uint64) ListK8S {
predicate := func(ikc ItemK8S) bool {
return ikc.RGID == rgID
}
return lkc.FilterFunc(predicate)
}
// FilterByStatus returns ListK8S with specified Status.
func (lkc ListK8S) FilterByStatus(status string) ListK8S {
predicate := func(ikc ItemK8S) bool {
return ikc.Status == status
}
return lkc.FilterFunc(predicate)
}
// FilterByTechStatus returns ListK8S with specified TechStatus.
func (lkc ListK8S) FilterByTechStatus(techStatus string) ListK8S {
predicate := func(ikc ItemK8S) bool {
return ikc.TechStatus == techStatus
}
return lkc.FilterFunc(predicate)
}
// FilterByCreatedBy returns ListK8S created by specified user.
func (lkc ListK8S) FilterByCreatedBy(createdBy string) ListK8S {
predicate := func(ikc ItemK8S) bool {
return ikc.CreatedBy == createdBy
}
return lkc.FilterFunc(predicate)
}
// FilterByDeletedBy returns ListK8S deleted by specified user.
func (lkc ListK8S) FilterByDeletedBy(deletedBy string) ListK8S {
predicate := func(ikc ItemK8S) bool {
return ikc.DeletedBy == deletedBy
}
return lkc.FilterFunc(predicate)
}
// FilterFunc allows filtering ListK8S based on a user-specified predicate.
func (lkc ListK8S) FilterFunc(predicate func(ItemK8S) bool) ListK8S {
var result ListK8S
for _, item := range lkc.Data {
if predicate(item) {
result.Data = append(result.Data, item)
}
}
result.EntryCount = uint64(len(result.Data))
return result
}
// FindOne returns first found ItemK8S
// If none was found, returns an empty struct.
func (lkc ListK8S) FindOne() ItemK8S {
if len(lkc.Data) == 0 {
return ItemK8S{}
}
return lkc.Data[0]
}

View File

@@ -0,0 +1,200 @@
package k8s
import "testing"
var k8sItems = ListK8S{
Data: []ItemK8S{
{
AccountID: 1,
AccountName: "test_1",
ACL: []interface{}{},
BServiceID: 1,
CIID: 1,
Config: nil,
CreatedBy: "test_user",
CreatedTime: 132454563,
DeletedBy: "",
DeletedTime: 0,
Description: "",
ExtNetID: 1,
GID: 0,
GUID: 1,
ID: 1,
LBID: 1,
Milestones: 999999,
Name: "k8s_1",
RGID: 1,
RGName: "rg_1",
ServiceAccount: ServiceAccount{},
SSHKey: "sample_key",
Status: "ENABLED",
TechStatus: "STARTED",
UpdatedBy: "",
UpdatedTime: 0,
VINSID: 0,
WorkersGroup: []RecordK8SGroup{},
},
{
AccountID: 2,
AccountName: "test_2",
ACL: []interface{}{},
BServiceID: 2,
CIID: 2,
Config: nil,
CreatedBy: "test_user",
CreatedTime: 132454638,
DeletedBy: "",
DeletedTime: 0,
Description: "",
ExtNetID: 2,
GID: 0,
GUID: 2,
ID: 2,
LBID: 2,
Milestones: 999999,
Name: "k8s_2",
RGID: 2,
RGName: "rg_2",
ServiceAccount: ServiceAccount{},
SSHKey: "sample_key",
Status: "ENABLED",
TechStatus: "STARTED",
UpdatedBy: "",
UpdatedTime: 0,
VINSID: 0,
WorkersGroup: []RecordK8SGroup{},
},
{
AccountID: 3,
AccountName: "test_3",
ACL: []interface{}{},
BServiceID: 3,
CIID: 3,
Config: nil,
CreatedBy: "test_user",
CreatedTime: 132454682,
DeletedBy: "",
DeletedTime: 0,
Description: "",
ExtNetID: 3,
GID: 0,
GUID: 3,
ID: 3,
LBID: 3,
Milestones: 999999,
Name: "k8s_3",
RGID: 3,
RGName: "rg_3",
ServiceAccount: ServiceAccount{},
SSHKey: "sample_key",
Status: "DISABLED",
TechStatus: "STOPPED",
UpdatedBy: "",
UpdatedTime: 0,
VINSID: 0,
WorkersGroup: []RecordK8SGroup{},
},
},
EntryCount: 3,
}
func TestFilterByID(t *testing.T) {
actual := k8sItems.FilterByID(1).FindOne()
if actual.ID != 1 {
t.Fatal("expected 1 ID, found: ", actual.ID)
}
}
func TestFilterByName(t *testing.T) {
actual := k8sItems.FilterByName("k8s_3").FindOne()
if actual.Name != "k8s_3" {
t.Fatal("expected Name 'k8s_3', found: ", actual.Name)
}
}
func TestFilterByAccountID(t *testing.T) {
actual := k8sItems.FilterByAccountID(2).FindOne()
if actual.AccountID != 2 {
t.Fatal("expected AccountID 2, found: ", actual.AccountID)
}
}
func TestFilterByRGID(t *testing.T) {
actual := k8sItems.FilterByRGID(3).FindOne()
if actual.RGID != 3 {
t.Fatal("expected RGID 3, found: ", actual.RGID)
}
}
func TestFilterByStatus(t *testing.T) {
actual := k8sItems.FilterByStatus("ENABLED")
if len(actual.Data) != 2 {
t.Fatal("expected 2 found, actual: ", len(actual.Data))
}
for _, item := range actual.Data {
if item.Status != "ENABLED" {
t.Fatal("expected Status 'ENABLED', found: ", item.Status)
}
}
}
func TestFilterByTechStatus(t *testing.T) {
actual := k8sItems.FilterByTechStatus("STARTED")
if len(actual.Data) != 2 {
t.Fatal("expected 2 found, actual: ", len(actual.Data))
}
for _, item := range actual.Data {
if item.TechStatus != "STARTED" {
t.Fatal("expected TechStatus 'STARTED', found: ", item.TechStatus)
}
}
}
func TestFilterByCreatedBy(t *testing.T) {
actual := k8sItems.FilterByCreatedBy("test_user")
if len(actual.Data) != 3 {
t.Fatal("expected 3 found, actual: ", len(actual.Data))
}
for _, item := range actual.Data {
if item.CreatedBy != "test_user" {
t.Fatal("expected CreatedBy 'test_user', found: ", item.CreatedBy)
}
}
}
func TestFilterByDeletedBy(t *testing.T) {
actual := k8sItems.FilterByDeletedBy("test_user")
if len(actual.Data) != 0 {
t.Fatal("expected 0 found, actual: ", len(actual.Data))
}
}
func TestFilterFunc(t *testing.T) {
actual := k8sItems.FilterFunc(func(iks ItemK8S) bool {
return iks.AccountName == "test_2"
}).
FindOne()
if actual.AccountName != "test_2" {
t.Fatal("expected AccountName 'test_2', found: ", actual.AccountName)
}
}
func TestSortByCreatedTime(t *testing.T) {
actual := k8sItems.SortByCreatedTime(false)
if actual.Data[0].CreatedTime != 132454563 || actual.Data[2].CreatedTime != 132454682 {
t.Fatal("expected ascending sort, seems to be inversed")
}
}

View File

@@ -0,0 +1,49 @@
package k8s
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// FindGroupByLabelRequest struct for get information about group of kubernetes cluster
type FindGroupByLabelRequest struct {
// Kubernetes cluster ID
// Required: true
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
// List of labels to search
// Required: true
Labels []string `url:"labels" json:"labels" validate:"min=1"`
// 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: false
Strict bool `url:"strict,omitempty" json:"strict,omitempty"`
}
// FindGroupByLabel finds worker group information by one on more labels
func (k K8S) FindGroupByLabel(ctx context.Context, req FindGroupByLabelRequest) (ListK8SGroup, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(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
}

View File

@@ -0,0 +1,46 @@
package k8s
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// GetRequest struct to get detailed information about kubernetes cluster
type GetRequest struct {
// Kubernetes cluster ID
// Required: true
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
}
// Get gets information about kubernetes cluster as a RecordK8S struct
func (k K8S) Get(ctx context.Context, req GetRequest) (*RecordK8S, error) {
res, err := k.GetRaw(ctx, req)
if err != nil {
return nil, err
}
info := RecordK8S{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}
// GetRaw gets information about kubernetes cluster as an array of bytes
func (k K8S) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/k8s/get"
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -0,0 +1,35 @@
package k8s
import (
"context"
"net/http"
"strings"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// GetConfigRequest struct to get configuration of kubernetes cluster
type GetConfigRequest struct {
// Kubernetes cluster ID
// Required: true
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
}
// GetConfig gets configuration data to access kubernetes cluster
func (k K8S) GetConfig(ctx context.Context, req GetConfigRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(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
}

View File

@@ -0,0 +1,39 @@
package k8s
import (
"context"
"net/http"
"strings"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// GetNodeAnnotationsRequest struct to get node annotations
type GetNodeAnnotationsRequest struct {
// Kubernetes cluster ID
// Required: true
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
// Node ID
// Required: true
NodeID uint64 `url:"nodeId" json:"nodeId" validate:"required"`
}
// GetNodeAnnotations gets kubernetes cluster worker node annotations
func (k K8S) GetNodeAnnotations(ctx context.Context, req GetNodeAnnotationsRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(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
}

View File

@@ -0,0 +1,39 @@
package k8s
import (
"context"
"net/http"
"strings"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// GetNodeLabelsRequest struct to get worker node labels
type GetNodeLabelsRequest struct {
// Kubernetes cluster ID
// Required: true
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
// Compute ID of worker node
// Required: true
NodeID uint64 `url:"nodeId" json:"nodeId" validate:"required"`
}
// GetNodeLabels gets kubernetes cluster worker node labels
func (k K8S) GetNodeLabels(ctx context.Context, req GetNodeLabelsRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(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
}

View File

@@ -0,0 +1,39 @@
package k8s
import (
"context"
"net/http"
"strings"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// GetNodeTaintsRequest struct to get node taints
type GetNodeTaintsRequest struct {
// Kubernetes cluster ID
// Required: true
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
// Node ID
// Required: true
NodeID uint64 `url:"nodeId" json:"nodeId" validate:"required"`
}
// GetNodeTaints gets kubernetes cluster worker node taints
func (k K8S) GetNodeTaints(ctx context.Context, req GetNodeTaintsRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(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
}

View File

@@ -0,0 +1,36 @@
package k8s
import (
"context"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// GetWorkerNodesMetaDataRequest struct to get worker group metadata by ID
type GetWorkerNodesMetaDataRequest struct {
// Kubernetes cluster ID
// Required: true
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
// ID of the workers compute group
// Required: true
WorkersGroupID uint64 `url:"workersGroupId" json:"workersGroupId" validate:"required"`
}
// GetWorkerNodesMetaData gets worker group metadata by ID
func (k K8S) GetWorkerNodesMetaData(ctx context.Context, req GetWorkerNodesMetaDataRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/k8s/getWorkerNodesMetaData"
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return "", err
}
return string(res), nil
}

View File

@@ -0,0 +1,30 @@
package k8s
// IDs gets array of K8SIDs from ListK8S struct
func (lk ListK8S) IDs() []uint64 {
res := make([]uint64, 0, len(lk.Data))
for _, k := range lk.Data {
res = append(res, k.ID)
}
return res
}
// IDs gets array of K8SWorkerGroupIDs from ListK8SGroups struct
func (lwg ListK8SGroup) IDs() []uint64 {
res := make([]uint64, 0, len(lwg))
for _, wg := range lwg {
res = append(res, wg.ID)
}
return res
}
// IDs gets array of Worker or Master ComputesIDs from ListDetailedInfo struct
func (ldi ListDetailedInfo) IDs() []uint64 {
res := make([]uint64, 0, len(ldi))
for _, di := range ldi {
res = append(res, di.ID)
}
return res
}

View File

@@ -0,0 +1,18 @@
// API for kubernetes clusters management
package k8s
import (
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/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,
}
}

View File

@@ -0,0 +1,92 @@
package k8s
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// ListRequest struct to get list information K8S
type ListRequest struct {
// Find by ID
// Required: false
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
// Find by name
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// Find by IP address
// Required: false
IPAddress string `url:"ipAddress,omitempty" json:"ipAddress,omitempty"`
// Find by resource group ID
// Required: false
RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"`
// Find by lbId
// Required: false
LBID uint64 `url:"lbId,omitempty" json:"lbId,omitempty"`
// Find by basicServiceId
// Required: false
BasicServiceID uint64 `url:"basicServiceId,omitempty" json:"basicServiceId,omitempty"`
// Find by status
// Required: false
Status string `url:"status,omitempty" json:"status,omitempty"`
// Find by techStatus
// Required: false
TechStatus string `url:"techStatus,omitempty" json:"techStatus,omitempty"`
// Include deleted clusters in result
// Required: false
IncludeDeleted bool `url:"includedeleted,omitempty" json:"includedeleted,omitempty"`
// Sort by one of supported fields, format +|-(field)
// Required: false
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
// Page number
// Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
// Page size
// Required: false
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
}
// List gets list of all kubernetes clusters as a ListK8S struct
func (k K8S) List(ctx context.Context, req ListRequest) (*ListK8S, error) {
res, err := k.ListRaw(ctx, req)
if err != nil {
return nil, err
}
list := ListK8S{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return &list, nil
}
// ListRaw gets list of all kubernetes clusters as an array of bytes
func (k K8S) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/k8s/list"
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -0,0 +1,77 @@
package k8s
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// ListDeletedRequest struct to get list of deleted kubernetes cluster
type ListDeletedRequest struct {
// Find by ID
// Required: false
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
// Find by name
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// Find by IP address
// Required: false
IPAddress string `url:"ipAddress,omitempty" json:"ipAddress,omitempty"`
// Find by resource group ID
// Required: false
RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"`
// Find by lbId
// Required: false
LBID uint64 `url:"lbId,omitempty" json:"lbId,omitempty"`
// Find by basicServiceId
// Required: false
BasicServiceID uint64 `url:"basicServiceId,omitempty" json:"basicServiceId,omitempty"`
// Find by techStatus
// Required: false
TechStatus string `url:"techStatus,omitempty" json:"techStatus,omitempty"`
// Sort by one of supported fields, format +|-(field)
// Required: false
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
// Page number
// Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
// Page size
// Required: false
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
}
// ListDeleted gets all deleted kubernetes clusters
func (k K8S) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListK8S, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
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
}

View File

@@ -0,0 +1,328 @@
package k8s
// Deteiled information
type ItemDetailedInfo struct {
// External Ip
ExternalIp string `json:"externalip"`
// ID
ID uint64 `json:"id"`
// Name
Name string `json:"name"`
// Status
Status string `json:"status"`
// Tech 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"`
// Only external network
ExtnetOnly bool `json:"extnetOnly"`
// Highly available LB
HighlyAvailableLB bool `json:"highlyAvailableLB"`
// Address Virtual Internet Protocol
AddressVIP K8SAddressVIP `json:"addressVip"`
// 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"`
// Network plugin
NetworkPlugin string `json:"networkPlugin"`
// 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"`
// With LB
WithLB bool `json:"withLB"`
}
// Detailed info about address of the Virtual Internet Protocol
type K8SAddressVIP struct {
// Backend IP
BackendIP string `json:"backendIp"`
// Frontend IP
FrontendIP string `json:"frontendIp"`
}
// 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"`
// Network plugin
NetworkPlugin string `json:"networkPlugin"`
// 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 struct {
// Data
Data []ItemK8S `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}

View File

@@ -0,0 +1,38 @@
package k8s
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// RestoreRequest struct to restore kubernetes cluster
type RestoreRequest struct {
// Kubernetes cluster ID
// Required: true
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
}
// Restore restores kubernetes cluster from recycle bin
func (k K8S) Restore(ctx context.Context, req RestoreRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(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
}

View File

@@ -0,0 +1,43 @@
package k8s
import (
"encoding/json"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/serialization"
)
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
//
// In order to serialize with indent make sure to follow these guidelines:
// - First argument -> prefix
// - Second argument -> indent
func (lkc ListK8S) Serialize(params ...string) (serialization.Serialized, error) {
if len(lkc.Data) == 0 {
return []byte{}, nil
}
if len(params) > 1 {
prefix := params[0]
indent := params[1]
return json.MarshalIndent(lkc, prefix, indent)
}
return json.Marshal(lkc)
}
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
//
// In order to serialize with indent make sure to follow these guidelines:
// - First argument -> prefix
// - Second argument -> indent
func (ikc ItemK8S) Serialize(params ...string) (serialization.Serialized, error) {
if len(params) > 1 {
prefix := params[0]
indent := params[1]
return json.MarshalIndent(ikc, prefix, indent)
}
return json.Marshal(ikc)
}

View File

@@ -0,0 +1,60 @@
package k8s
import "sort"
// SortByCreatedTime sorts ListK8S by the CreatedTime field in ascending order.
//
// If inverse param is set to true, the order is reversed.
func (lkc ListK8S) SortByCreatedTime(inverse bool) ListK8S {
if len(lkc.Data) < 2 {
return lkc
}
sort.Slice(lkc.Data, func(i, j int) bool {
if inverse {
return lkc.Data[i].CreatedTime > lkc.Data[j].CreatedTime
}
return lkc.Data[i].CreatedTime < lkc.Data[j].CreatedTime
})
return lkc
}
// SortByUpdatedTime sorts ListK8S by the UpdatedTime field in ascending order.
//
// If inverse param is set to true, the order is reversed.
func (lkc ListK8S) SortByUpdatedTime(inverse bool) ListK8S {
if len(lkc.Data) < 2 {
return lkc
}
sort.Slice(lkc.Data, func(i, j int) bool {
if inverse {
return lkc.Data[i].UpdatedTime > lkc.Data[j].UpdatedTime
}
return lkc.Data[i].UpdatedTime < lkc.Data[j].UpdatedTime
})
return lkc
}
// SortByDeletedTime sorts ListK8S by the DeletedTime field in ascending order.
//
// If inverse param is set to true, the order is reversed.
func (lkc ListK8S) SortByDeletedTime(inverse bool) ListK8S {
if len(lkc.Data) < 2 {
return lkc
}
sort.Slice(lkc.Data, func(i, j int) bool {
if inverse {
return lkc.Data[i].DeletedTime > lkc.Data[j].DeletedTime
}
return lkc.Data[i].DeletedTime < lkc.Data[j].DeletedTime
})
return lkc
}

View File

@@ -0,0 +1,38 @@
package k8s
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// StartRequest struct to start kubernetes cluster
type StartRequest struct {
// Kubernetes cluster ID
// Required: true
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
}
// Start starts kubernetes cluster by ID
func (k K8S) Start(ctx context.Context, req StartRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(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
}

View File

@@ -0,0 +1,38 @@
package k8s
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// StopRequest struct to stop kubernetes cluster
type StopRequest struct {
// Kubernetes cluster ID
// Required: true
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
}
// Stop stops kubernetes cluster by ID
func (k K8S) Stop(ctx context.Context, req StopRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(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
}

View File

@@ -0,0 +1,48 @@
package k8s
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// UpdateRequest struct to update kubernetes cluster
type UpdateRequest struct {
// Kubernetes cluster ID
// Required: true
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
// New name to set.
// If empty string is passed, name is not updated
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// New description to set.
// If empty string is passed, description is not updated
// Required: false
Description string `url:"desc,omitempty" json:"desc,omitempty"`
}
// Update updates name or description of kubernetes cluster
func (k K8S) Update(ctx context.Context, req UpdateRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(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
}

View File

@@ -0,0 +1,46 @@
package k8s
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// UpdateWorkerNodesMetaDataRequest struct to add worker to a kubernetes cluster
type UpdateWorkerNodesMetaDataRequest struct {
// Kubernetes cluster ID
// Required: true
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
// ID of the workers compute group
// Required: true
WorkersGroupID uint64 `url:"workersGroupId" json:"workersGroupId" validate:"required"`
// Meta data for working group computes, format YAML "user_data": 1111
// Required: true
UserData string `url:"userData" json:"userData" validate:"required"`
}
// UpdateWorkerNodesMetaData adds worker nodes to a kubernetes cluster
func (k K8S) UpdateWorkerNodesMetaData(ctx context.Context, req UpdateWorkerNodesMetaDataRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/k8s/updateWorkerNodesMetaData"
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
}

View File

@@ -0,0 +1,52 @@
package k8s
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// WorkerAddRequest struct to add worker to a kubernetes cluster
type WorkerAddRequest struct {
// Kubernetes cluster ID
// Required: true
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
// ID of the workers compute group
// Required: true
WorkersGroupID uint64 `url:"workersGroupId" json:"workersGroupId" validate:"required"`
// How many worker nodes to add
// Required: false
Num uint64 `url:"num,omitempty" json:"num,omitempty"`
// Type of the emulated system, Q35 or i440fx
// Required: false
Chipset string `url:"chipset,omitempty" json:"chipset,omitempty" validate:"omitempty,chipset"`
}
// WorkerAdd adds worker nodes to a kubernetes cluster
func (k K8S) WorkerAdd(ctx context.Context, req WorkerAddRequest) ([]uint64, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(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
}

View File

@@ -0,0 +1,46 @@
package k8s
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// WorkerResetRequest struct for hard reset kubernetes cluster
type WorkerResetRequest struct {
// Kubernetes cluster ID
// Required: true
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
// ID of the workers compute group
// Required: true
WorkersGroupID uint64 `url:"workersGroupId" json:"workersGroupId" validate:"required"`
// Compute ID of worker node to reset
// Required: true
WorkerID uint64 `url:"workerId" json:"workerId" validate:"required"`
}
// WorkerReset hard reset (compute start + stop) worker node of the kubernetes cluster
func (k K8S) WorkerReset(ctx context.Context, req WorkerResetRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(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
}

View File

@@ -0,0 +1,45 @@
package k8s
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// WorkerRestartRequest struct to restart worker node
type WorkerRestartRequest struct {
// Kubernetes cluster ID
// Required: true
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
// ID of the workers compute group
// Required: true
WorkersGroupID uint64 `url:"workersGroupId" json:"workersGroupId" validate:"required"`
// Compute ID of worker node to restart
// Required: true
WorkerID uint64 `url:"workerId" json:"workerId" validate:"required"`
}
// WorkerRestart soft restart (reboot OS) worker node of the kubernetes cluster
func (k8s K8S) WorkerRestart(ctx context.Context, req WorkerRestartRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(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
}

View File

@@ -0,0 +1,98 @@
package k8s
import (
"context"
"net/http"
"strings"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// WorkersGroupAddRequest struct to add workers group
type WorkersGroupAddRequest struct {
// Kubernetes cluster ID
// Required: true
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
// Worker group name
// Required: true
Name string `url:"name" json:"name" validate:"required"`
// 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" json:"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" json:"workerSepPool,omitempty"`
// List of strings with labels for worker group
// i.e: ["label1=value1", "label2=value2"]
// Required: false
Labels []string `url:"labels,omitempty" json:"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" json:"taints,omitempty"`
// List of strings with annotations for worker group
// i.e: ["key1=value1", "key2=value2"]
// Required: false
Annotations []string `url:"annotations,omitempty" json:"annotations,omitempty"`
// Number of worker nodes to create
// Required: false
WorkerNum uint64 `url:"workerNum,omitempty" json:"workerNum,omitempty"`
// Worker node CPU count
// Required: false
WorkerCPU uint64 `url:"workerCpu,omitempty" json:"workerCpu,omitempty"`
// Worker node RAM volume in MB
// Required: false
WorkerRAM uint64 `url:"workerRam,omitempty" json:"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" json:"workerDisk,omitempty"`
// Meta data for working group computes, format YAML "user_data": 1111
// Required: false
UserData string `url:"userData,omitempty" json:"userData,omitempty"`
// Type of the emulated system, Q35 or i440fx
// Required: false
Chipset string `url:"chipset,omitempty" json:"chipset,omitempty" validate:"omitempty,chipset"`
}
// GetRAM returns RAM field values
func (r WorkersGroupAddRequest) GetRAM() map[string]uint64 {
res := make(map[string]uint64, 1)
res["WorkerRAM"] = r.WorkerRAM
return res
}
// WorkersGroupAdd adds workers group to kubernetes cluster
func (k K8S) WorkersGroupAdd(ctx context.Context, req WorkersGroupAddRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(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
}

View File

@@ -0,0 +1,42 @@
package k8s
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// WorkersGroupDeleteRequest struct to delete workers group
type WorkersGroupDeleteRequest struct {
// Kubernetes cluster ID
// Required: true
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
// Worker group ID
// Required: true
WorkersGroupID uint64 `url:"workersGroupId" json:"workersGroupId" validate:"required"`
}
// WorkersGroupDelete deletes workers group from kubernetes cluster
func (k K8S) WorkersGroupDelete(ctx context.Context, req WorkersGroupDeleteRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(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
}

View File

@@ -0,0 +1,44 @@
package k8s
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// WorkersGroupGetByNameRequest struct to get information about worker group
type WorkersGroupGetByNameRequest struct {
// Kubernetes cluster ID
// Required: true
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
// Worker group name
// Required: true
GroupName string `url:"groupName" json:"groupName" validate:"required"`
}
// WorkersGroupGetByName gets worker group metadata by name
func (k K8S) WorkersGroupGetByName(ctx context.Context, req WorkersGroupGetByNameRequest) (*RecordK8SGroup, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(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
}