Skip to content

Commit

Permalink
Refactor label removal to use DeleteLabelObject function
Browse files Browse the repository at this point in the history
  • Loading branch information
yunkon-kim committed Nov 18, 2024
1 parent c3c5e4c commit c1839fb
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
6 changes: 6 additions & 0 deletions src/core/common/label/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ func RemoveLabel(labelType, uid, key string) error {
return err
}

if labelData == "" {
err = fmt.Errorf("does not exist, label object for %s", labelKey)
log.Warn().Msg(err.Error())
return err
}

var labelInfo model.LabelInfo
err = json.Unmarshal([]byte(labelData), &labelInfo)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions src/core/resource/sqlDb.go
Original file line number Diff line number Diff line change
Expand Up @@ -942,8 +942,8 @@ func DeleteSqlDb(nsId string, sqlDbId string) (model.SimpleMsg, error) {
return emptyRet, err
}

// Remove label info using RemoveLabel
err = label.RemoveLabel(model.StrSqlDB, sqlDBInfo.Uid, sqlDbKey)
// Remove label info using DeleteLabelObject
err = label.DeleteLabelObject(model.StrSqlDB, sqlDBInfo.Uid)
if err != nil {
log.Error().Err(err).Msg("")
return emptyRet, err
Expand Down
14 changes: 7 additions & 7 deletions src/core/resource/vnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -908,12 +908,12 @@ func DeleteVNet(nsId string, vNetId string, actionParam string) (model.SimpleMsg
return emptyRet, err
}

// Remove label info using RemoveLabel
// Remove label info using DeleteLabelObject
// labels := map[string]string{
// model.LabelManager: model.StrManager,
// "namespace": nsId,
// }
err = label.RemoveLabel(model.StrVNet, vNetInfo.Uid, vNetKey)
err = label.DeleteLabelObject(model.StrVNet, vNetInfo.Uid)
if err != nil {
log.Error().Err(err).Msg("")
return emptyRet, err
Expand Down Expand Up @@ -1066,7 +1066,7 @@ func RefineVNet(nsId string, vNetId string) (model.SimpleMsg, error) {
// return emptyRet, err
}

err = label.RemoveLabel(model.StrSubnet, vNetInfo.Uid, subnetKv.Key)
err = label.DeleteLabelObject(model.StrSubnet, vNetInfo.Uid)
if err != nil {
log.Warn().Err(err).Msg("")
// return emptyRet, err
Expand All @@ -1080,12 +1080,12 @@ func RefineVNet(nsId string, vNetId string) (model.SimpleMsg, error) {
// return emptyRet, err
}

// Remove label info using RemoveLabel
// Remove label info using DeleteLabelObject
// labels := map[string]string{
// "sys.manager": model.StrManager,
// "namespace": nsId,
// }
err = label.RemoveLabel(model.StrVNet, vNetInfo.Uid, vNetKey)
err = label.DeleteLabelObject(model.StrVNet, vNetInfo.Uid)
if err != nil {
log.Warn().Err(err).Msg("")
// return emptyRet, err
Expand Down Expand Up @@ -1536,12 +1536,12 @@ func DeregisterVNet(nsId string, vNetId string, withSubnets string) (model.Simpl
return emptyRet, err
}

// Remove label info using RemoveLabel
// Remove label info using DeleteLabelObject
// labels := map[string]string{
// model.LabelManager: model.StrManager,
// "namespace": nsId,
// }
err = label.RemoveLabel(model.StrVNet, vNetInfo.Uid, vNetKey)
err = label.DeleteLabelObject(model.StrVNet, vNetInfo.Uid)
if err != nil {
log.Error().Err(err).Msg("")
return emptyRet, err
Expand Down
4 changes: 2 additions & 2 deletions src/core/resource/vpn.go
Original file line number Diff line number Diff line change
Expand Up @@ -1178,8 +1178,8 @@ func DeleteSiteToSiteVPN(nsId string, mciId string, vpnId string) (model.SimpleM
return emptyRet, err
}

// Remove label info using RemoveLabel
err = label.RemoveLabel(model.StrVPN, vpnInfo.Uid, vpnKey)
// Remove label info using DeleteLabelObject
err = label.DeleteLabelObject(model.StrVPN, vpnInfo.Uid)
if err != nil {
log.Error().Err(err).Msg("")
return emptyRet, err
Expand Down

0 comments on commit c1839fb

Please sign in to comment.