reference node name when needed

Signed-off-by: Brian Downs <brian.downs@gmail.com>
This commit is contained in:
Brian Downs 2021-05-04 10:03:28 -07:00
parent 64577a070d
commit beb0d8397a

View File

@ -72,7 +72,6 @@ type ETCD struct {
address string address string
cron *cron.Cron cron *cron.Cron
s3 *s3 s3 *s3
nodeName string
} }
type learnerProgress struct { type learnerProgress struct {
@ -93,7 +92,6 @@ type Members struct {
func NewETCD() *ETCD { func NewETCD() *ETCD {
return &ETCD{ return &ETCD{
cron: cron.New(), cron: cron.New(),
nodeName: os.Getenv("NODE_NAME"),
} }
} }
@ -948,11 +946,13 @@ func (e *ETCD) listSnapshots(ctx context.Context, snapshotDir string) ([]snapsho
return nil, err return nil, err
} }
nodeName := os.Getenv("NODE_NAME")
for _, f := range files { for _, f := range files {
snapshots = append(snapshots, snapshotFile{ snapshots = append(snapshots, snapshotFile{
Name: f.Name(), Name: f.Name(),
Location: "file://" + filepath.Join(snapshotDir, f.Name()), Location: "file://" + filepath.Join(snapshotDir, f.Name()),
NodeName: e.nodeName, NodeName: nodeName,
CreatedAt: &metav1.Time{ CreatedAt: &metav1.Time{
Time: f.ModTime(), Time: f.ModTime(),
}, },
@ -1022,18 +1022,20 @@ func (e *ETCD) StoreSnapshotData(ctx context.Context) error {
snapshotConfigMap.Data = make(map[string]string, 0) snapshotConfigMap.Data = make(map[string]string, 0)
} }
nodeName := os.Getenv("NODE_NAME")
// remove entries for this node only // remove entries for this node only
for k, v := range snapshotConfigMap.Data { for k, v := range snapshotConfigMap.Data {
var sf snapshotFile var sf snapshotFile
if err := json.Unmarshal([]byte(v), &sf); err != nil { if err := json.Unmarshal([]byte(v), &sf); err != nil {
return err return err
} }
if sf.NodeName == e.nodeName || sf.NodeName == "s3" { if sf.NodeName == nodeName || sf.NodeName == "s3" {
delete(snapshotConfigMap.Data, k) delete(snapshotConfigMap.Data, k)
} }
} }
// this node's entries to the ConfigMap // save this node's entries to the ConfigMap
for k, v := range data { for k, v := range data {
snapshotConfigMap.Data[k] = v snapshotConfigMap.Data[k] = v
} }