Skip to content

Commit

Permalink
Add infraType field to TbSpecInfo/TbImageInfo and assets
Browse files Browse the repository at this point in the history
ref #1665

- Update alibaba ubuntu 22.04 image info
- Update NHNCloud ubuntu 20.04 and ubuntu 22.04 image info for vm/k8s
- Update TbImageInfo with description from assets
- Remove nodeImage in k8sclusterinfo.yaml
- Comment out deprecated DB access and test filterSpecsByRange() with InfraType
  • Loading branch information
Sooyoung Kim committed Jul 11, 2024
1 parent 70b65fb commit 48f66c4
Show file tree
Hide file tree
Showing 10 changed files with 972 additions and 902 deletions.
264 changes: 134 additions & 130 deletions assets/cloudimage.csv

Large diffs are not rendered by default.

Empty file modified assets/cloudlatencymap.csv
100755 → 100644
Empty file.
1,245 changes: 627 additions & 618 deletions assets/cloudspec.csv

Large diffs are not rendered by default.

40 changes: 0 additions & 40 deletions assets/k8sclusterinfo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@ k8scluster:
id: 1.28.9-aliyun.1
- name: 1.26
id: 1.26.15-aliyun.1
nodeImage:
- region: [all]
available:
- name: default
id: default
- name: Alibaba Cloud Linux 3.2104 LTS 64 bit
id: aliyun_3_x64_20G_alibase_20240528.vhd
rootDisk:
- region: [all]
type:
Expand All @@ -48,21 +41,6 @@ k8scluster:
id: v1.27.3
- name: 1.26
id: v1.26.3
nodeImage:
- region: [kr1,kr2]
available:
- name: default
id: default
- name: Ubuntu Server 22.04.4 LTS - Container (2024.05.21)
id: b70fe2c9-ce55-448b-8e42-bb8f4c862391
- name: Ubuntu Server 20.04.6 LTS - Container (2024.05.21)
id: 4c02a2f3-e9db-49b9-abeb-7ae7c604f24d
- name: CentOS 7.9 - Container (2024.05.21)
id: d95aeef9-3cd0-4288-8370-b874d64884e7
- name: Debian 11.9 Bullseye - Container (2024.05.21)
id: 8f4c0ded-501d-410a-a362-a5edd8730e3a
- name: Rocky Linux 8.9 - Container (2024.05.21)
id: 7bbeb38a-7398-4188-8ccf-1c0ce1776d02
rootDisk:
- region: [all]
type:
Expand All @@ -82,24 +60,6 @@ k8scluster:
id: 1.26.1
- name: 1.24
id: 1.24.4
nodeImage:
# https://www.tencentcloud.com/document/product/457/46750
- region: [all]
available:
- name: default
id: default
- name: TencentOS Server 2.4(TK4)
id: img-9axl1k53
- name: CentOS 7.8
id: img-3la7wgnt
- name: TencentOS Server 3.1(TK4)
id: img-eb30mz89
- name: TencentOS Server 2.4
id: img-hdt9xxkt
- name: Ubuntu 18.04 LTS 64bit
id: img-pi0ii46r
- name: Ubuntu Server 20.04.1 LTS 64bit(beta)
id: img-22trbn9x
rootDisk:
- region: [all]
type:
Expand Down
3 changes: 3 additions & 0 deletions src/core/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ const (
StrNLB string = "nlb"
StrVM string = "vm"
StrMCIS string = "mcis"
StrK8s string = "k8s"
StrKubernetes string = "kubernetes"
StrContainer string = "container"
StrDefaultResourceName string = "-systemdefault-"
// StrFirewallRule string = "firewallRule"

Expand Down
35 changes: 34 additions & 1 deletion src/core/mcir/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -1574,6 +1574,7 @@ func LoadCommonResource() (common.IdList, error) {
// 18 acceleratorCount
// 19 acceleratorMemoryGB
// 20 acceleratorDetails
// 21 infraType

providerName := strings.ToLower(row[0])
regionName := strings.ToLower(row[1])
Expand All @@ -1591,6 +1592,7 @@ func LoadCommonResource() (common.IdList, error) {
acceleratorMemoryGB = s
}
description := row[20]
infraType := strings.ToLower(row[21])

specReqTmp.Name = GetProviderRegionZoneResourceKey(providerName, regionName, "", specReqTmp.CspSpecName)

Expand Down Expand Up @@ -1659,6 +1661,7 @@ func LoadCommonResource() (common.IdList, error) {
log.Error().Msgf("Not valid evaluationScore01 value in the asset: %s", specInfoId)
evaluationScore01 = -99.9
}
expandedInfraType := expandInfraType(infraType)
specUpdateRequest :=
TbSpecInfo{
ProviderName: providerName,
Expand All @@ -1672,6 +1675,7 @@ func LoadCommonResource() (common.IdList, error) {
AcceleratorMemoryGB: float32(acceleratorMemoryGB),
Description: description,
EvaluationScore01: float32(evaluationScore01),
InfraType: expandedInfraType,
}

_, err3 := UpdateSpec(common.SystemCommonNs, specInfoId, specUpdateRequest)
Expand Down Expand Up @@ -1707,10 +1711,16 @@ func LoadCommonResource() (common.IdList, error) {
// row1: regionName
// row2: cspImageId
// row3: OsType
// row4: description
// row5: supportedInstance
// row6: infraType
providerName := strings.ToLower(row[0])
regionName := strings.ToLower(row[1])
imageReqTmp.CspImageId = row[2]
osType := strings.ReplaceAll(row[3], " ", "")
description := row[4]
infraType := strings.ToLower(row[6])

// Give a name for spec object by combining ConnectionName and OsType
imageReqTmp.Name = GetProviderRegionZoneResourceKey(providerName, regionName, "", osType)

Expand Down Expand Up @@ -1742,7 +1752,12 @@ func LoadCommonResource() (common.IdList, error) {
regiesteredStatus += " [Failed] " + err1.Error()
} else {
// Update registered image object with OsType info
imageUpdateRequest := TbImageInfo{GuestOS: osType}
expandedInfraType := expandInfraType(infraType)
imageUpdateRequest := TbImageInfo{
GuestOS: osType,
Description: description,
InfraType: expandedInfraType,
}
_, err2 := UpdateImage(common.SystemCommonNs, imageInfoId, imageUpdateRequest)
if err2 != nil {
log.Error().Err(err2).Msg("UpdateImage failed")
Expand Down Expand Up @@ -2032,6 +2047,24 @@ func UpdateResourceObject(nsId string, resourceType string, resourceObject inter

}

func expandInfraType(infraType string) string {
expInfraTypeList := []string{}
lowerInfraType := strings.ToLower(infraType)

if strings.Contains(lowerInfraType, common.StrVM) {
expInfraTypeList = append(expInfraTypeList, common.StrVM)
}
if strings.Contains(lowerInfraType, common.StrK8s) ||
strings.Contains(lowerInfraType, common.StrKubernetes) ||
strings.Contains(lowerInfraType, common.StrContainer) {
expInfraTypeList = append(expInfraTypeList, common.StrK8s)
expInfraTypeList = append(expInfraTypeList, common.StrKubernetes)
expInfraTypeList = append(expInfraTypeList, common.StrContainer)
}

return strings.Join(expInfraTypeList, "|")
}

/*
func AreEqualJSON(s1, s2 string) (bool, error) {
var o1 interface{}
Expand Down
1 change: 1 addition & 0 deletions src/core/mcir/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ type TbImageInfo struct {
ConnectionName string `json:"connectionName,omitempty"`
CspImageId string `json:"cspImageId,omitempty"`
CspImageName string `json:"cspImageName,omitempty"`
InfraType string `json:"infraType,omitempty"` // vm|k8s|kubernetes|container, etc.
Description string `json:"description,omitempty"`
CreationDate string `json:"creationDate,omitempty"`
GuestOS string `json:"guestOS,omitempty"` // Windows7, Ubuntu etc.
Expand Down
130 changes: 63 additions & 67 deletions src/core/mcir/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,82 +15,78 @@ limitations under the License.
package mcir

import (
"encoding/json"
"fmt"
"testing"

"github.com/cloud-barista/cb-tumblebug/src/core/common"
_ "github.com/mattn/go-sqlite3"
"github.com/rs/zerolog/log"
"github.com/stretchr/testify/assert"
)

func TestImage(t *testing.T) {
/*
expected := 1
actual := 0
assert.Equal(t, expected, actual, "기대값과 결과값이 다릅니다.")
assert.Equal(t, expected, actual, "expected value and actual value are different")
*/

nsName := "tb-unit-test"

nsReq := common.NsReq{}
nsReq.Name = nsName

_, err := common.CreateNs(&nsReq)
if err != nil {
fmt.Println(err.Error())
} else {
log.Debug().Msg("Namespace created successfully")
}

err = common.OpenSQL("../../../meta_db/dat/tb-unit-test.s3db")
if err != nil {
fmt.Println(err.Error())
} else {
log.Debug().Msg("Database access info set successfully")
}

err = common.SelectDatabase("tb-unit-test")
if err != nil {
fmt.Println(err.Error())
} else {
log.Debug().Msg("DB selected successfully..")
}

// err = common.CreateImageTable()
// if err != nil {
// fmt.Println(err.Error())
// } else {
// log.Debug().Msg("Table image created successfully..")
// }

imageName := "tb-unit-test"

imageReq := TbImageInfo{}
imageReq.Name = imageName

result, _ := RegisterImageWithInfo(nsName, &imageReq, false)
resultJSON, _ := json.MarshalIndent(result, "", " ")
log.Debug().Msg("result: " + string(resultJSON))
assert.Equal(t, imageName, result.Name, "CreateImage 기대값과 결과값이 다릅니다.")

resultInterface, _ := GetResource(nsName, common.StrImage, imageName)
result = resultInterface.(TbImageInfo) // type assertion
assert.Equal(t, imageName, result.Name, "GetImage 기대값과 결과값이 다릅니다.")

//result, _ := ListImage()

//result, _ := ListImageId()

resultErr := DelResource(nsName, common.StrImage, imageName, "false")
assert.Nil(t, resultErr)

err = common.DelNs(nsName)
if err != nil {
fmt.Println(err.Error())
} else {
log.Debug().Msg("Namespace deleted successfully")
}

/*
nsName := "tb-unit-test"
nsReq := common.NsReq{}
nsReq.Name = nsName
_, err := common.CreateNs(&nsReq)
if err != nil {
fmt.Println(err.Error())
} else {
log.Debug().Msg("Namespace created successfully")
}
err = common.OpenSQL("../../../meta_db/dat/tb-unit-test.s3db")
if err != nil {
fmt.Println(err.Error())
} else {
log.Debug().Msg("Database access info set successfully")
}
err = common.SelectDatabase("tb-unit-test")
if err != nil {
fmt.Println(err.Error())
} else {
log.Debug().Msg("DB selected successfully..")
}
// err = common.CreateImageTable()
// if err != nil {
// fmt.Println(err.Error())
// } else {
// log.Debug().Msg("Table image created successfully..")
// }
imageName := "tb-unit-test"
imageReq := TbImageInfo{}
imageReq.Name = imageName
result, _ := RegisterImageWithInfo(nsName, &imageReq, false)
resultJSON, _ := json.MarshalIndent(result, "", " ")
log.Debug().Msg("result: " + string(resultJSON))
assert.Equal(t, imageName, result.Name, "CreateImage: expected value and actual value are different.")
resultInterface, _ := GetResource(nsName, common.StrImage, imageName)
result = resultInterface.(TbImageInfo) // type assertion
assert.Equal(t, imageName, result.Name, "GetImage: expected value and actual value are different.")
//result, _ := ListImage()
//result, _ := ListImageId()
resultErr := DelResource(nsName, common.StrImage, imageName, "false")
assert.Nil(t, resultErr)
err = common.DelNs(nsName)
if err != nil {
fmt.Println(err.Error())
} else {
log.Debug().Msg("Namespace deleted successfully")
}
*/
}
2 changes: 2 additions & 0 deletions src/core/mcir/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ type TbSpecInfo struct { // Tumblebug
ProviderName string `json:"providerName,omitempty"`
RegionName string `json:"regionName,omitempty"`
CspSpecName string `json:"cspSpecName,omitempty"`
InfraType string `json:"infraType,omitempty"` // vm|k8s|kubernetes|container, etc.
OsType string `json:"osType,omitempty"`
VCPU uint16 `json:"vCPU,omitempty"`
MemoryGiB float32 `json:"memoryGiB,omitempty"`
Expand Down Expand Up @@ -130,6 +131,7 @@ type FilterSpecsByRangeRequest struct {
ProviderName string `json:"providerName"`
RegionName string `json:"regionName"`
CspSpecName string `json:"cspSpecName"`
InfraType string `json:"infraType"`
OsType string `json:"osType"`
VCPU Range `json:"vCPU"`
MemoryGiB Range `json:"memoryGiB"`
Expand Down
Loading

0 comments on commit 48f66c4

Please sign in to comment.