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

Remove associated NLBs with MCIS del #1201

Merged
merged 1 commit into from
Oct 13, 2022
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 src/api/grpc/server/mcis/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func (s *MCISService) DeleteMcis(ctx context.Context, req *pb.TbMcisQryRequest)

logger.Debug("calling MCISService.DeleteMcis()")

err := mcis.DelMcis(req.NsId, req.McisId, req.Option)
_, err := mcis.DelMcis(req.NsId, req.McisId, req.Option)
if err != nil {
return nil, gc.ConvGrpcStatusErr(err, "", "MCISService.DeleteMcis()")
}
Expand Down
2 changes: 1 addition & 1 deletion src/api/rest/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1880,7 +1880,7 @@ var doc = `{
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/common.SimpleMsg"
"$ref": "#/definitions/common.IdList"
}
},
"404": {
Expand Down
2 changes: 1 addition & 1 deletion src/api/rest/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1865,7 +1865,7 @@
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/common.SimpleMsg"
"$ref": "#/definitions/common.IdList"
}
},
"404": {
Expand Down
2 changes: 1 addition & 1 deletion src/api/rest/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3472,7 +3472,7 @@ paths:
"200":
description: OK
schema:
$ref: '#/definitions/common.SimpleMsg'
$ref: '#/definitions/common.IdList'
"404":
description: Not Found
schema:
Expand Down
7 changes: 3 additions & 4 deletions src/api/rest/server/mcis/manageInfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func RestPutMcis(c echo.Context) error {
// @Param nsId path string true "Namespace ID" default(ns01)
// @Param mcisId path string true "MCIS ID" default(mcis01)
// @Param option query string false "Option for delete MCIS (support force delete)" Enums(terminate,force)
// @Success 200 {object} common.SimpleMsg
// @Success 200 {object} common.IdList
// @Failure 404 {object} common.SimpleMsg
// @Router /ns/{nsId}/mcis/{mcisId} [delete]
func RestDelMcis(c echo.Context) error {
Expand All @@ -203,15 +203,14 @@ func RestDelMcis(c echo.Context) error {
mcisId := c.Param("mcisId")
option := c.QueryParam("option")

err := mcis.DelMcis(nsId, mcisId, option)
output, err := mcis.DelMcis(nsId, mcisId, option)
if err != nil {
common.CBLog.Error(err)
mapA := map[string]string{"message": err.Error()}
return c.JSON(http.StatusInternalServerError, &mapA)
}

mapA := map[string]string{"message": "Deleted the MCIS " + mcisId}
return c.JSON(http.StatusOK, &mapA)
return c.JSON(http.StatusOK, output)
}

// RestDelAllMcis godoc
Expand Down
49 changes: 33 additions & 16 deletions src/core/mcis/manageInfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -1655,26 +1655,28 @@ func AttachDetachDataDisk(nsId string, mcisId string, vmId string, command strin
// [Delete MCIS and VM object]

// DelMcis is func to delete MCIS object
func DelMcis(nsId string, mcisId string, option string) error {
func DelMcis(nsId string, mcisId string, option string) (common.IdList, error) {

option = common.ToLower(option)
deletedResources := common.IdList{}
deleteStatus := " [Done]"

err := common.CheckString(nsId)
if err != nil {
common.CBLog.Error(err)
return err
return deletedResources, err
}

err = common.CheckString(mcisId)
if err != nil {
common.CBLog.Error(err)
return err
return deletedResources, err
}
check, _ := CheckMcis(nsId, mcisId)

if !check {
err := fmt.Errorf("The mcis " + mcisId + " does not exist.")
return err
return deletedResources, err
}

fmt.Println("[Delete MCIS] " + mcisId)
Expand All @@ -1685,7 +1687,7 @@ func DelMcis(nsId string, mcisId string, option string) error {
err := fmt.Errorf("MCIS " + mcisId + " status nil, Deletion is not allowed (use option=force for force deletion)")
common.CBLog.Error(err)
if option != "force" {
return err
return deletedResources, err
}
}

Expand All @@ -1698,14 +1700,14 @@ func DelMcis(nsId string, mcisId string, option string) error {
_, err := HandleMcisAction(nsId, mcisId, ActionRefine, true)
if err != nil {
common.CBLog.Error(err)
return err
return deletedResources, err
}

// ActionTerminate
_, err = HandleMcisAction(nsId, mcisId, ActionTerminate, true)
if err != nil {
common.CBLog.Error(err)
return err
return deletedResources, err
}
// for deletion, need to wait until termination is finished
// Sleep for 5 seconds
Expand All @@ -1721,7 +1723,7 @@ func DelMcis(nsId string, mcisId string, option string) error {
err := fmt.Errorf("MCIS " + mcisId + " is " + mcisStatus.Status + " and not " + StatusTerminated + "/" + StatusUndefined + "/" + StatusFailed + ", Deletion is not allowed (use option=force for force deletion)")
common.CBLog.Error(err)
if option != "force" {
return err
return deletedResources, err
}
}

Expand All @@ -1731,7 +1733,7 @@ func DelMcis(nsId string, mcisId string, option string) error {
vmList, err := ListVmId(nsId, mcisId)
if err != nil {
common.CBLog.Error(err)
return err
return deletedResources, err
}

// delete vms info
Expand All @@ -1743,13 +1745,13 @@ func DelMcis(nsId string, mcisId string, option string) error {
vmInfo, err := GetVmObject(nsId, mcisId, v)
if err != nil {
common.CBLog.Error(err)
return err
return deletedResources, err
}

err = common.CBStore.Delete(vmKey)
if err != nil {
common.CBLog.Error(err)
return err
return deletedResources, err
}
Comment on lines 1751 to 1755
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'vmList 의 vm들을 하나씩 지우는 for 문' 을 돌다가
특정 vm 삭제에 실패하면
return deletedResources, err 하는 것이 아니라
deletedResources.IdList = append(deletedResources.IdList, "VM: "+v+" [Failed]") 하는 것이 어떨까 싶기도 했었는데

(option=force 경우가 아닌 일반적인 경우에는)
DelMcis 함수는 Running VM이 있는 경우에는 삭제를 수행하지 않고
Terminated / Failed 등의 VM이 있는 경우에만 삭제를 수행하며
이 삭제 동작이 내부적으로 수행하는 것은 CBStore.Delete 인데
이전 코드들을 고려하면 이 동작이 실패할 확률은 거의 없어서
현재 로직도 괜찮을 것 같습니다. 😊


_, err = mcir.UpdateAssociatedObjectList(nsId, common.StrImage, vmInfo.ImageId, common.StrDelete, vmKey)
Expand All @@ -1768,32 +1770,47 @@ func DelMcis(nsId string, mcisId string, option string) error {
for _, v2 := range vmInfo.DataDiskIds {
mcir.UpdateAssociatedObjectList(nsId, common.StrDataDisk, v2, common.StrDelete, vmKey)
}
deletedResources.IdList = append(deletedResources.IdList, "VM: "+v+deleteStatus)
}

// delete vm group info
vmGroupList, err := ListVmGroupId(nsId, mcisId)
if err != nil {
common.CBLog.Error(err)
return err
return deletedResources, err
}
for _, v := range vmGroupList {
vmGroupKey := common.GenMcisVmGroupKey(nsId, mcisId, v)
fmt.Println(vmGroupKey)
err := common.CBStore.Delete(vmGroupKey)
if err != nil {
common.CBLog.Error(err)
return err
return deletedResources, err
}
deletedResources.IdList = append(deletedResources.IdList, "vmGroup: "+v+deleteStatus)
}

// delete associated CSP NLBs
forceFlag := "false"
if option == "force" {
forceFlag = "true"
}
output, err := DelAllNLB(nsId, mcisId, "", forceFlag)
if err != nil {
common.CBLog.Error(err)
return deletedResources, err
}
Comment on lines +1798 to 1802
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분에서, 예를 들어 MCIS 내에 3개의 NLB가 있었는데
DelAllNLB 실행 결과 2개는 삭제 성공, 1개는 삭제 실패 이면
DelAllNLB의 리턴값인 output, err

output:

[
"NLB: nlb01 [Done]",
"NLB: nlb02 [Done]",
"NLB: nlb03 <Some error>"
]

err: nil
로 오며

이후 L1803부터 다시 진행되어
K-V store에서 MCIS 객체를 삭제합니다.
(즉, MCIS 내에 있었던 3개의 NLB 중 하나는 삭제되지 않은 상태로 MCIS가 삭제됨)

저는 이것(↑)도 괜찮은 것 같습니다.. ㅎㅎ
(NLB 삭제를 시도했지만 실패한 것이니.. 사용자에게 출력해주고, proceed하여 나머지 object 삭제)

deletedResources.IdList = append(deletedResources.IdList, output.IdList...)

// delete mcis info
err = common.CBStore.Delete(key)
if err != nil {
common.CBLog.Error(err)
return err
return deletedResources, err
}
deletedResources.IdList = append(deletedResources.IdList, "MCIS: "+mcisId+deleteStatus)

return nil
return deletedResources, nil
}

// DelMcisVm is func to delete VM object
Expand Down Expand Up @@ -1890,7 +1907,7 @@ func CoreDelAllMcis(nsId string, option string) (string, error) {
}

for _, v := range mcisList {
err := DelMcis(nsId, v, option)
_, err := DelMcis(nsId, v, option)
if err != nil {
common.CBLog.Error(err)
return "", fmt.Errorf("Failed to delete All MCISs")
Expand Down