v1.5.0-gamma2

This commit is contained in:
2023-07-07 12:40:03 +03:00
parent 20fd7ab50c
commit 7c787f6fce
111 changed files with 2905 additions and 1505 deletions

View File

@@ -76,21 +76,23 @@ func (lkc ListK8SClusters) FilterByDeletedBy(deletedBy string) ListK8SClusters {
func (lkc ListK8SClusters) FilterFunc(predicate func(ItemK8SCluster) bool) ListK8SClusters {
var result ListK8SClusters
for _, item := range lkc {
for _, item := range lkc.Data {
if predicate(item) {
result = append(result, item)
result.Data = append(result.Data, item)
}
}
result.EntryCount = uint64(len(result.Data))
return result
}
// FindOne returns first found ItemK8SCluster
// If none was found, returns an empty struct.
func (lkc ListK8SClusters) FindOne() ItemK8SCluster {
if len(lkc) == 0 {
if len(lkc.Data) == 0 {
return ItemK8SCluster{}
}
return lkc[0]
return lkc.Data[0]
}

View File

@@ -3,86 +3,88 @@ package k8s
import "testing"
var k8sItems = ListK8SClusters{
ItemK8SCluster{
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",
Status: "ENABLED",
TechStatus: "STARTED",
UpdatedBy: "",
UpdatedTime: 0,
VINSID: 0,
},
ItemK8SCluster{
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",
Status: "ENABLED",
TechStatus: "STARTED",
UpdatedBy: "",
UpdatedTime: 0,
VINSID: 0,
},
ItemK8SCluster{
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",
Status: "DISABLED",
TechStatus: "STOPPED",
UpdatedBy: "",
UpdatedTime: 0,
VINSID: 0,
Data: []ItemK8SCluster{
{
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",
Status: "ENABLED",
TechStatus: "STARTED",
UpdatedBy: "",
UpdatedTime: 0,
VINSID: 0,
},
{
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",
Status: "ENABLED",
TechStatus: "STARTED",
UpdatedBy: "",
UpdatedTime: 0,
VINSID: 0,
},
{
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",
Status: "DISABLED",
TechStatus: "STOPPED",
UpdatedBy: "",
UpdatedTime: 0,
VINSID: 0,
},
},
}
@@ -121,11 +123,11 @@ func TestFilterByRGID(t *testing.T) {
func TestFilterByStatus(t *testing.T) {
actual := k8sItems.FilterByStatus("ENABLED")
if len(actual) != 2 {
t.Fatal("expected 2 found, actual: ", len(actual))
if len(actual.Data) != 2 {
t.Fatal("expected 2 found, actual: ", len(actual.Data))
}
for _, item := range actual {
for _, item := range actual.Data {
if item.Status != "ENABLED" {
t.Fatal("expected Status 'ENABLED', found: ", item.Status)
}
@@ -135,11 +137,11 @@ func TestFilterByStatus(t *testing.T) {
func TestFilterByTechStatus(t *testing.T) {
actual := k8sItems.FilterByTechStatus("STARTED")
if len(actual) != 2 {
t.Fatal("expected 2 found, actual: ", len(actual))
if len(actual.Data) != 2 {
t.Fatal("expected 2 found, actual: ", len(actual.Data))
}
for _, item := range actual {
for _, item := range actual.Data {
if item.TechStatus != "STARTED" {
t.Fatal("expected TechStatus 'STARTED', found: ", item.TechStatus)
}
@@ -149,11 +151,11 @@ func TestFilterByTechStatus(t *testing.T) {
func TestFilterByCreatedBy(t *testing.T) {
actual := k8sItems.FilterByCreatedBy("test_user")
if len(actual) != 3 {
t.Fatal("expected 3 found, actual: ", len(actual))
if len(actual.Data) != 3 {
t.Fatal("expected 3 found, actual: ", len(actual.Data))
}
for _, item := range actual {
for _, item := range actual.Data {
if item.CreatedBy != "test_user" {
t.Fatal("expected CreatedBy 'test_user', found: ", item.CreatedBy)
}
@@ -163,8 +165,8 @@ func TestFilterByCreatedBy(t *testing.T) {
func TestFilterByDeletedBy(t *testing.T) {
actual := k8sItems.FilterByDeletedBy("test_user")
if len(actual) != 0 {
t.Fatal("expected 0 found, actual: ", len(actual))
if len(actual.Data) != 0 {
t.Fatal("expected 0 found, actual: ", len(actual.Data))
}
}
@@ -182,7 +184,7 @@ func TestFilterFunc(t *testing.T) {
func TestSortByCreatedTime(t *testing.T) {
actual := k8sItems.SortByCreatedTime(false)
if actual[0].CreatedTime != 132454563 || actual[2].CreatedTime != 132454682 {
if actual.Data[0].CreatedTime != 132454563 || actual.Data[2].CreatedTime != 132454682 {
t.Fatal("expected ascending sort, seems to be inversed")
}
}

View File

@@ -8,6 +8,38 @@ import (
// Request struct for 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"`
@@ -22,7 +54,7 @@ type ListRequest struct {
}
// List gets list all kubernetes clusters the user has access to
func (k8s K8S) List(ctx context.Context, req ListRequest) (ListK8SClusters, error) {
func (k8s K8S) List(ctx context.Context, req ListRequest) (*ListK8SClusters, error) {
url := "/cloudapi/k8s/list"
res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req)
@@ -37,5 +69,5 @@ func (k8s K8S) List(ctx context.Context, req ListRequest) (ListK8SClusters, erro
return nil, err
}
return list, nil
return &list, nil
}

View File

@@ -8,6 +8,38 @@ import (
// Request struct for get list 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 status
// Required: false
Status string `url:"status,omitempty" json:"status,omitempty"`
// Find by techStatus
// Required: false
TechStatus string `url:"techStatus,omitempty" json:"techStatus,omitempty"`
// Page number
// Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
@@ -18,7 +50,7 @@ type ListDeletedRequest struct {
}
// ListDeleted gets all deleted kubernetes clusters the user has access to
func (k8s K8S) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListK8SClusters, error) {
func (k8s K8S) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListK8SClusters, error) {
url := "/cloudapi/k8s/listDeleted"
res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req)
@@ -33,5 +65,5 @@ func (k8s K8S) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListK8S
return nil, err
}
return list, nil
return &list, nil
}

View File

@@ -293,4 +293,10 @@ type RecordServiceAccount struct {
}
// List of kubernetes clusters
type ListK8SClusters []ItemK8SCluster
type ListK8SClusters struct {
// Data
Data []ItemK8SCluster `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}

View File

@@ -12,7 +12,7 @@ import (
// - First argument -> prefix
// - Second argument -> indent
func (lkc ListK8SClusters) Serialize(params ...string) (serialization.Serialized, error) {
if len(lkc) == 0 {
if len(lkc.Data) == 0 {
return []byte{}, nil
}

View File

@@ -6,16 +6,16 @@ import "sort"
//
// If inverse param is set to true, the order is reversed.
func (lkc ListK8SClusters) SortByCreatedTime(inverse bool) ListK8SClusters {
if len(lkc) < 2 {
if len(lkc.Data) < 2 {
return lkc
}
sort.Slice(lkc, func(i, j int) bool {
sort.Slice(lkc.Data, func(i, j int) bool {
if inverse {
return lkc[i].CreatedTime > lkc[j].CreatedTime
return lkc.Data[i].CreatedTime > lkc.Data[j].CreatedTime
}
return lkc[i].CreatedTime < lkc[j].CreatedTime
return lkc.Data[i].CreatedTime < lkc.Data[j].CreatedTime
})
return lkc
@@ -25,16 +25,16 @@ func (lkc ListK8SClusters) SortByCreatedTime(inverse bool) ListK8SClusters {
//
// If inverse param is set to true, the order is reversed.
func (lkc ListK8SClusters) SortByUpdatedTime(inverse bool) ListK8SClusters {
if len(lkc) < 2 {
if len(lkc.Data) < 2 {
return lkc
}
sort.Slice(lkc, func(i, j int) bool {
sort.Slice(lkc.Data, func(i, j int) bool {
if inverse {
return lkc[i].UpdatedTime > lkc[j].UpdatedTime
return lkc.Data[i].UpdatedTime > lkc.Data[j].UpdatedTime
}
return lkc[i].UpdatedTime < lkc[j].UpdatedTime
return lkc.Data[i].UpdatedTime < lkc.Data[j].UpdatedTime
})
return lkc
@@ -44,16 +44,16 @@ func (lkc ListK8SClusters) SortByUpdatedTime(inverse bool) ListK8SClusters {
//
// If inverse param is set to true, the order is reversed.
func (lkc ListK8SClusters) SortByDeletedTime(inverse bool) ListK8SClusters {
if len(lkc) < 2 {
if len(lkc.Data) < 2 {
return lkc
}
sort.Slice(lkc, func(i, j int) bool {
sort.Slice(lkc.Data, func(i, j int) bool {
if inverse {
return lkc[i].DeletedTime > lkc[j].DeletedTime
return lkc.Data[i].DeletedTime > lkc.Data[j].DeletedTime
}
return lkc[i].DeletedTime < lkc[j].DeletedTime
return lkc.Data[i].DeletedTime < lkc.Data[j].DeletedTime
})
return lkc

View File

@@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
@@ -18,8 +19,8 @@ type WorkerAddRequest struct {
WorkersGroupID uint64 `url:"workersGroupId" json:"workersGroupId" validate:"required"`
// How many worker nodes to add
// Required: true
Num uint64 `url:"num" json:"num" validate:"required"`
// Required: false
Num uint64 `url:"num,omitempty" json:"num,omitempty"`
}
// WorkerAdd add worker nodes to a Kubernetes cluster

View File

@@ -20,7 +20,7 @@ type WorkersGroupGetByNameRequest struct {
}
// WorkersGroupGetByName gets worker group metadata by name
func (k8s K8S) WorkersGroupGetByName(ctx context.Context, req WorkersGroupGetByNameRequest) (*RecordK8SGroups, error) {
func (k8s K8S) WorkersGroupGetByName(ctx context.Context, req WorkersGroupGetByNameRequest) (*ItemK8SGroup, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
@@ -35,7 +35,7 @@ func (k8s K8S) WorkersGroupGetByName(ctx context.Context, req WorkersGroupGetByN
return nil, err
}
info := RecordK8SGroups{}
info := ItemK8SGroup{}
err = json.Unmarshal(res, &info)
if err != nil {