summaryrefslogtreecommitdiffstats
path: root/msb2pilot/src
diff options
context:
space:
mode:
authorLvbo163 <lv.bo163@zte.com.cn>2018-08-06 17:14:07 +0800
committerLvbo163 <lv.bo163@zte.com.cn>2018-08-06 17:14:07 +0800
commit38447771f156197521f34f2c89f6b4fb4c42b28c (patch)
tree7ba1eae152a2d6ea424a8e7e513003b7357a2efd /msb2pilot/src
parentf003bbb0f7609d793ea08781cefb49adce1b3ed1 (diff)
delete all rules
delete all routerules if the service array from consul is empty Issue-ID: MSB-261 Change-Id: I6c8b31e42d5c7d0d4403fb2851f9f7bd00707925 Signed-off-by: Lvbo163 <lv.bo163@zte.com.cn>
Diffstat (limited to 'msb2pilot/src')
-rw-r--r--msb2pilot/src/msb2pilot/pilot/msb.go28
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)