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

Fix Provisioning Global L4 NLB faces runtime error #1364

Merged
merged 1 commit into from
Oct 12, 2023
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/rest/server/mcis/remoteCommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func RestSetBastionNodes(c echo.Context) error {
// @Param nsId path string true "Namespace ID" default(ns01)
// @Param mcisId path string true "MCIS ID" default(mcis01)
// @Param targetVmId path string true "Target VM ID" default(vm01)
// @Success 200 {object} mcis.BastionInfo
// @Success 200 {object} []mcir.BastionNode
// @Failure 404 {object} common.SimpleMsg
// @Failure 500 {object} common.SimpleMsg
// @Router /ns/{nsId}/mcis/{mcisId}/vm/{targetVmId}/bastion [get]
Expand Down
18 changes: 12 additions & 6 deletions src/core/mcir/vnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,18 @@ func TbSubnetReqStructLevelValidation(sl validator.StructLevel) {

// TbSubnetInfo is a struct that represents TB subnet object.
type TbSubnetInfo struct { // Tumblebug
Id string
Name string `validate:"required"`
IPv4_CIDR string `validate:"required"`
BastionNodeIds []string
KeyValueList []common.KeyValue
Description string
Id string
Name string `validate:"required"`
IPv4_CIDR string `validate:"required"`
BastionNodes []BastionNode
KeyValueList []common.KeyValue
Description string
}

// BastionNode is a struct that represents TB BastionNode object.
type BastionNode struct {
McisId string `json:"mcisId"`
VmId string `json:"vmId"`
}

// CreateVNet accepts vNet creation request, creates and returns an TB vNet object
Expand Down
23 changes: 12 additions & 11 deletions src/core/mcis/remoteCommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ func RunRemoteCommand(nsId string, mcisId string, vmId string, givenUserName str
common.CBLog.Error(err)
return map[int]string{}, map[int]string{}, err
}
bastionNode := bastionNodes.VmId[0]
bastionNode := bastionNodes[0]
// use public IP of the bastion VM
bastionIp, _, bastionSshPort := GetVmIp(nsId, mcisId, bastionNode)
bastionUserName, bastionSshKey, err := VerifySshUserName(nsId, mcisId, bastionNode, bastionIp, bastionSshPort, givenUserName)
bastionIp, _, bastionSshPort := GetVmIp(nsId, bastionNode.McisId, bastionNode.VmId)
bastionUserName, bastionSshKey, err := VerifySshUserName(nsId, bastionNode.McisId, bastionNode.VmId, bastionIp, bastionSshPort, givenUserName)
bastionEndpoint := fmt.Sprintf("%s:%s", bastionIp, bastionSshPort)

bastionSshInfo := sshInfo{
Expand Down Expand Up @@ -536,7 +536,7 @@ func SetBastionNodes(nsId string, mcisId string, targetVmId string, bastionVmId
common.CBLog.Error(err)
return "", err
}
if len(currentBastion.VmId) > 0 && bastionVmId == "" {
if len(currentBastion) > 0 && bastionVmId == "" {
return "", fmt.Errorf("bastion node already exists for VM (ID: %s) in MCIS (ID: %s) under namespace (ID: %s)",
targetVmId, mcisId, nsId)
}
Expand Down Expand Up @@ -576,16 +576,17 @@ func SetBastionNodes(nsId string, mcisId string, targetVmId string, bastionVmId
}
}
} else {
for _, existingId := range subnetInfo.BastionNodeIds {
if existingId == bastionVmId {
for _, existingId := range subnetInfo.BastionNodes {
if existingId.VmId == bastionVmId {
return fmt.Sprintf("Bastion (ID: %s) already exists in subnet (ID: %s) in VNet (ID: %s).",
bastionVmId, subnetInfo.Id, vmObj.VNetId), nil
}
}
}

bastionCandidate := mcir.BastionNode{McisId: mcisId, VmId: bastionVmId}
// Append bastionVmId only if it doesn't already exist.
subnetInfo.BastionNodeIds = append(subnetInfo.BastionNodeIds, bastionVmId)
subnetInfo.BastionNodes = append(subnetInfo.BastionNodes, bastionCandidate)
tempVNetInfo.SubnetInfoList[i] = subnetInfo
mcir.UpdateResourceObject(nsId, common.StrVNet, tempVNetInfo)

Expand All @@ -598,8 +599,8 @@ func SetBastionNodes(nsId string, mcisId string, targetVmId string, bastionVmId
}

// GetBastionNodes func retrieves bastion nodes for a given VM
func GetBastionNodes(nsId string, mcisId string, targetVmId string) (BastionInfo, error) {
returnValue := BastionInfo{}
func GetBastionNodes(nsId string, mcisId string, targetVmId string) ([]mcir.BastionNode, error) {
returnValue := []mcir.BastionNode{}
// Fetch VM object based on nsId, mcisId, and targetVmId
vmObj, err := GetVmObject(nsId, mcisId, targetVmId)
if err != nil {
Expand All @@ -624,10 +625,10 @@ func GetBastionNodes(nsId string, mcisId string, targetVmId string) (BastionInfo
// Find the subnet corresponding to the VM and return the BastionNodeIds
for _, subnetInfo := range tempVNetInfo.SubnetInfoList {
if subnetInfo.Id == vmObj.SubnetId {
if subnetInfo.BastionNodeIds == nil {
if subnetInfo.BastionNodes == nil {
return returnValue, nil
}
returnValue.VmId = subnetInfo.BastionNodeIds
returnValue = subnetInfo.BastionNodes
return returnValue, nil
}
}
Expand Down