/
reconcile.go
91 lines (71 loc) · 3.09 KB
/
reconcile.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright (c) 2017 Cisco and/or its affiliates.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Package core: The reconcile process "resyncs" the configuration stored in
// the database, and the provided config yaml file (if there is one). It is
// possible to start with an empty database if desired by providing the -clean
// command line arg. The resync procedure loads the configuration into a
// reconcile "before" resync data structure then applies the configuration
// which causes new ETCD entries to be made, however, these will be put into
// the "after" resync data structure during reconcile. Once all config has
// been processed, the before and after data structures are post-processed.
// This module drives the resync for the plugins.
package core
import (
"github.com/ligato/sfc-controller/controller/utils"
)
// ReconcileVppLabelsMapType: track all the vpp agents in etcd
type ReconcileVppLabelsMapType map[string]struct{}
// ReconcileInit: initialize the map of all etcd vpp/agent labels
func (sfcCtrlPlugin *SfcControllerPluginHandler) ReconcileInit() error {
sfcCtrlPlugin.ReconcileVppLabelsMap = make(ReconcileVppLabelsMapType)
return nil
}
// ReconcileStart: init the reconcile procedure for all plguins
func (sfcCtrlPlugin *SfcControllerPluginHandler) ReconcileStart() error {
log.Info("ReconcileStart: enter ...")
defer log.Info("ReconcileStart: exit ...")
for k, _ := range sfcCtrlPlugin.ReconcileVppLabelsMap {
delete(sfcCtrlPlugin.ReconcileVppLabelsMap, k)
}
sfcCtrlPlugin.ReconcileLoadAllVppLabels()
sfcCtrlPlugin.cnpDriverPlugin.ReconcileStart(sfcCtrlPlugin.ReconcileVppLabelsMap)
return nil
}
// ReconcileEnd: perform post processing of the reconcile procedure
func (sfcCtrlPlugin *SfcControllerPluginHandler) ReconcileEnd() error {
log.Info("ReconcileEnd: begin ...")
defer log.Info("ReconcileEnd: exit ...")
sfcCtrlPlugin.cnpDriverPlugin.ReconcileEnd()
return nil
}
// ReconcileLoadAllVppLabels: retrieve all vpp lavels from the etcd datastore
func (sfcCtrlPlugin *SfcControllerPluginHandler) ReconcileLoadAllVppLabels() {
log.Info("ReconcileLoadAllVppLabels: begin ...")
defer log.Info("ReconcileLoadAllVppLabels: exit ...")
keyIter, err := sfcCtrlPlugin.db.ListKeys(utils.GetVppAgentPrefix())
if err == nil {
for {
if key, _, done := keyIter.GetNext(); !done {
label := utils.GetVppEtcdlabel(key)
_, exists := sfcCtrlPlugin.ReconcileVppLabelsMap[label]
if !exists {
log.Info("ReconcileLoadAllVppLabels: adding label to reconcile label map: ", label)
sfcCtrlPlugin.ReconcileVppLabelsMap[label] = struct{}{}
}
continue
}
break
}
}
}