diff options
author | Zhaoxing Meng <meng.zhaoxing1@zte.com.cn> | 2018-08-07 01:27:11 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-08-07 01:27:11 +0000 |
commit | b46341305cafc13f0c367be775dc3cc6ddc01bc1 (patch) | |
tree | cd16f000099e98e45b3aefbfaeb8f223c81604f7 | |
parent | 3e9c64fd1cbc70e3239c7ad2b6ea2fa456588ad3 (diff) | |
parent | 38447771f156197521f34f2c89f6b4fb4c42b28c (diff) |
Merge "delete all rules"
-rw-r--r-- | msb2pilot/src/msb2pilot/pilot/msb.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/msb2pilot/src/msb2pilot/pilot/msb.go b/msb2pilot/src/msb2pilot/pilot/msb.go index a1b5b5f..d81b2f1 100644 --- a/msb2pilot/src/msb2pilot/pilot/msb.go +++ b/msb2pilot/src/msb2pilot/pilot/msb.go @@ -32,6 +32,9 @@ const ( ) func SyncMsbData(newServices []*models.MsbService) { + if len(cachedServices) == 0 { + deleteAllMsbRules() + } log.Log.Debug("sync msb rewrite rule to pilot") createServices, updateServices, deleteServices := compareServices(cachedServices, newServices) @@ -55,6 +58,31 @@ func saveService(operation Operation, services []*models.MsbService) { log.Log.Debug("%d services need to %s, %d fails. \n", len(services), operation, len(fails)) } +func deleteAllMsbRules() { + log.Log.Informational("delete all msb rules") + configs, err := List("route-rule", "") + + if err != nil { + return + } + + deleteList := msbRuleFilter(configs) + + Save(OperationDelete, deleteList) +} + +func msbRuleFilter(configs []istioModel.Config) []istioModel.Config { + res := make([]istioModel.Config, 0, len(configs)) + + for _, config := range configs { + if strings.HasPrefix(config.Name, routerulePrefix) { + res = append(res, config) + } + } + + return res +} + func compareServices(oldServices, newServices []*models.MsbService) (createServices, updateServices, deleteServices []*models.MsbService) { oldServiceMap := toServiceMap(oldServices) newServiceMap := toServiceMap(newServices) |