v1.5.0-delta

This commit is contained in:
Никита Сорокин
2023-07-13 15:28:07 +03:00
parent 7c787f6fce
commit 5025a17ea4
71 changed files with 1602 additions and 936 deletions

View File

@@ -103,7 +103,7 @@ type CreateRequest struct {
// 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" json:"withLB,omitempty"`
WithLB bool `url:"withLB" json:"withLB"`
// Text description of this kubernetes cluster
// Required: false

View File

@@ -76,21 +76,23 @@ func (lkc ListK8S) FilterByDeletedBy(deletedBy string) ListK8S {
func (lkc ListK8S) FilterFunc(predicate func(ItemK8S) bool) ListK8S {
var result ListK8S
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 ItemK8S
// If none was found, returns an empty struct.
func (lkc ListK8S) FindOne() ItemK8S {
if len(lkc) == 0 {
if len(lkc.Data) == 0 {
return ItemK8S{}
}
return lkc[0]
return lkc.Data[0]
}

View File

@@ -3,96 +3,99 @@ package k8s
import "testing"
var k8sItems = ListK8S{
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{},
},
ItemK8S{
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{},
},
ItemK8S{
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{},
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) {
@@ -130,11 +133,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)
}
@@ -144,11 +147,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)
}
@@ -158,11 +161,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)
}
@@ -172,8 +175,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))
}
}
@@ -191,7 +194,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
func (k K8S) List(ctx context.Context, req ListRequest) (ListK8S, error) {
func (k K8S) List(ctx context.Context, req ListRequest) (*ListK8S, error) {
url := "/cloudbroker/k8s/list"
@@ -38,5 +70,5 @@ func (k K8S) List(ctx context.Context, req ListRequest) (ListK8S, error) {
return nil, err
}
return list, nil
return &list, nil
}

View File

@@ -8,6 +8,34 @@ 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 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 +46,7 @@ type ListDeletedRequest struct {
}
// ListDeleted gets all deleted kubernetes clusters
func (k K8S) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListK8S, error) {
func (k K8S) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListK8S, error) {
url := "/cloudbroker/k8s/listDeleted"
@@ -34,5 +62,5 @@ func (k K8S) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListK8S,
return nil, err
}
return list, nil
return &list, nil
}

View File

@@ -295,4 +295,10 @@ type ServiceAccount struct {
}
// List K8S
type ListK8S []ItemK8S
type ListK8S struct {
// Data
Data []ItemK8S `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}

View File

@@ -12,7 +12,7 @@ import (
// - First argument -> prefix
// - Second argument -> indent
func (lkc ListK8S) 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 ListK8S) SortByCreatedTime(inverse bool) ListK8S {
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 ListK8S) SortByCreatedTime(inverse bool) ListK8S {
//
// If inverse param is set to true, the order is reversed.
func (lkc ListK8S) SortByUpdatedTime(inverse bool) ListK8S {
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 ListK8S) SortByUpdatedTime(inverse bool) ListK8S {
//
// If inverse param is set to true, the order is reversed.
func (lkc ListK8S) SortByDeletedTime(inverse bool) ListK8S {
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