Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify ID system using GenUid and no Transform #1748

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ services:
# - API_PASSWORD=
- SPIDER_LOG_LEVEL=error
- SPIDER_HISCALL_LOG_LEVEL=error
- ID_TRANSFORM_MODE=ON
- ID_TRANSFORM_MODE=OFF
healthcheck: # for CB-Spider
test: [ "CMD", "curl", "-f", "http://localhost:1024/spider/readyz" ]
interval: 1m
Expand Down
48 changes: 25 additions & 23 deletions src/api/rest/server/mcir/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,31 +73,33 @@ func RestDelResource(c echo.Context) error {
return common.EndRequestWithLog(c, reqID, err, content)
}

// Todo: need to reimplment the following invalid function

// RestDelChildResource is a common function to handle 'DelChildResource' REST API requests.
// Dummy functions for Swagger exist in [mcir/*.go]
func RestDelChildResource(c echo.Context) error {
reqID, idErr := common.StartRequestWithLog(c)
if idErr != nil {
return c.JSON(http.StatusBadRequest, map[string]string{"message": idErr.Error()})
}
nsId := c.Param("nsId")

childResourceType := strings.Split(c.Path(), "/")[7]
// c.Path(): /tumblebug/ns/:nsId/resources/vNet/:vNetId/subnet/:subnetId

parentResourceId := c.Param("parentResourceId")
childResourceId := c.Param("childResourceId")
parentResourceId = strings.ReplaceAll(parentResourceId, " ", "+")
parentResourceId = strings.ReplaceAll(parentResourceId, "%2B", "+")
childResourceId = strings.ReplaceAll(childResourceId, " ", "+")
childResourceId = strings.ReplaceAll(childResourceId, "%2B", "+")

forceFlag := c.QueryParam("force")

err := mcir.DelChildResource(nsId, childResourceType, parentResourceId, childResourceId, forceFlag)
content := map[string]string{"message": "The " + childResourceType + " " + childResourceId + " has been deleted"}
return common.EndRequestWithLog(c, reqID, err, content)
}
// func RestDelChildResource(c echo.Context) error {
// reqID, idErr := common.StartRequestWithLog(c)
// if idErr != nil {
// return c.JSON(http.StatusBadRequest, map[string]string{"message": idErr.Error()})
// }
// nsId := c.Param("nsId")

// childResourceType := strings.Split(c.Path(), "/")[7]
// // c.Path(): /tumblebug/ns/:nsId/resources/vNet/:vNetId/subnet/:subnetId

// parentResourceId := c.Param("parentResourceId")
// childResourceId := c.Param("childResourceId")
// parentResourceId = strings.ReplaceAll(parentResourceId, " ", "+")
// parentResourceId = strings.ReplaceAll(parentResourceId, "%2B", "+")
// childResourceId = strings.ReplaceAll(childResourceId, " ", "+")
// childResourceId = strings.ReplaceAll(childResourceId, "%2B", "+")

// forceFlag := c.QueryParam("force")

// err := mcir.DelChildResource(nsId, childResourceType, parentResourceId, childResourceId, forceFlag)
// content := map[string]string{"message": "The " + childResourceType + " " + childResourceId + " has been deleted"}
// return common.EndRequestWithLog(c, reqID, err, content)
// }

// RestGetAllResources is a common function to handle 'GetAllResources' REST API requests.
// Dummy functions for Swagger exist in [mcir/*.go]
Expand Down
2 changes: 1 addition & 1 deletion src/api/rest/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ func RunServer(port string) {
// g.GET("/:nsId/resources/vNet/:vNetId/subnet/:subnetId", rest_mcir.RestGetSubnet)
// g.GET("/:nsId/resources/vNet/:vNetId/subnet", rest_mcir.RestGetAllSubnet)
// g.PUT("/:nsId/resources/vNet/:vNetId/subnet/:subnetId", rest_mcir.RestPutSubnet)
g.DELETE("/:nsId/resources/vNet/:parentResourceId/subnet/:childResourceId", rest_mcir.RestDelChildResource)
// g.DELETE("/:nsId/resources/vNet/:parentResourceId/subnet/:childResourceId", rest_mcir.RestDelChildResource)
// g.DELETE("/:nsId/resources/vNet/:vNetId/subnet", rest_mcir.RestDelAllSubnet)

/*
Expand Down
8 changes: 3 additions & 5 deletions src/core/mci/k8scluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,6 @@ func CreateK8sCluster(nsId string, u *TbK8sClusterReq, option string) (TbK8sClus
* Build RequestBody for SpiderClusterReq{}
*/

spName := fmt.Sprintf("%s-%s", nsId, u.Id)

// Validate
err = validateAtCreateK8sCluster(u)
if err != nil {
Expand Down Expand Up @@ -605,7 +603,7 @@ func CreateK8sCluster(nsId string, u *TbK8sClusterReq, option string) (TbK8sClus
}

spNodeGroupList = append(spNodeGroupList, SpiderNodeGroupReqInfo{
Name: v.Name,
Name: common.GenUid(),
ImageName: spImgName,
VMSpecName: spSpecName,
RootDiskType: v.RootDiskType,
Expand All @@ -622,7 +620,7 @@ func CreateK8sCluster(nsId string, u *TbK8sClusterReq, option string) (TbK8sClus
NameSpace: "", // should be empty string from Tumblebug
ConnectionName: u.ConnectionName,
ReqInfo: SpiderClusterReqInfo{
Name: spName,
Name: common.GenUid(),
Version: spVersion,
VPCName: spVPCName,
SubnetNames: spSubnetNames,
Expand Down Expand Up @@ -1210,7 +1208,7 @@ func GetK8sCluster(nsId string, k8sClusterId string) (TbK8sClusterInfo, error) {

client := resty.New()
client.SetTimeout(10 * time.Minute)
url := common.SpiderRestUrl + "/cluster/" + nsId + "-" + k8sClusterId
url := common.SpiderRestUrl + "/cluster/" + storedTbK8sCInfo.CspK8sClusterName
method := "GET"

// Create Request body for GetK8sCluster of CB-Spider
Expand Down
6 changes: 4 additions & 2 deletions src/core/mci/provisioning.go
Original file line number Diff line number Diff line change
Expand Up @@ -1657,8 +1657,7 @@ func CreateVm(nsId string, mciId string, vmInfoData *TbVmInfo, option string) er
requestBody.ConnectionName = vmInfoData.ConnectionName

//generate VM ID(Name) to request to CSP(Spider)
//combination of nsId, mcidId, and vmName reqested from user
requestBody.ReqInfo.Name = fmt.Sprintf("%s-%s-%s", nsId, mciId, vmInfoData.Name)
requestBody.ReqInfo.Name = common.GenUid()

customImageFlag := false

Expand Down Expand Up @@ -1771,6 +1770,9 @@ func CreateVm(nsId string, mciId string, vmInfoData *TbVmInfo, option string) er
}
}

log.Info().Msg("VM request body to CB-Spider")
common.PrintJsonPretty(requestBody)

// Randomly sleep within 20 Secs to avoid rateLimit from CSP
common.RandomSleep(0, 20)
client := resty.New()
Expand Down
2 changes: 1 addition & 1 deletion src/core/mci/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func CreateVmSnapshot(nsId string, mciId string, vmId string, snapshotName strin
json.Unmarshal([]byte(keyValue.Value), &vm)

if snapshotName == "" {
snapshotName = fmt.Sprintf("%s-%s", vm.Name, common.GenerateNewRandomString(5))
snapshotName = common.GenUid()
}

requestBody := mcir.SpiderMyImageReq{
Expand Down
Loading