From c1839fbdf49d4539da37f70cc7d220bbd32b3d3f Mon Sep 17 00:00:00 2001 From: Yunkon Kim Date: Mon, 18 Nov 2024 20:50:16 +0900 Subject: [PATCH] Refactor label removal to use DeleteLabelObject function --- src/core/common/label/label.go | 6 ++++++ src/core/resource/sqlDb.go | 4 ++-- src/core/resource/vnet.go | 14 +++++++------- src/core/resource/vpn.go | 4 ++-- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/core/common/label/label.go b/src/core/common/label/label.go index d54bcb861..a261c48a9 100644 --- a/src/core/common/label/label.go +++ b/src/core/common/label/label.go @@ -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 { diff --git a/src/core/resource/sqlDb.go b/src/core/resource/sqlDb.go index b299afc23..db4cb0002 100644 --- a/src/core/resource/sqlDb.go +++ b/src/core/resource/sqlDb.go @@ -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 diff --git a/src/core/resource/vnet.go b/src/core/resource/vnet.go index d9c392541..bfdf38f3c 100644 --- a/src/core/resource/vnet.go +++ b/src/core/resource/vnet.go @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/src/core/resource/vpn.go b/src/core/resource/vpn.go index 2bb2609ad..231e5b6b0 100644 --- a/src/core/resource/vpn.go +++ b/src/core/resource/vpn.go @@ -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