mirror of
https://github.com/gravitl/netmaker.git
synced 2025-09-13 16:44:52 +08:00
fix egress HA migration (#3555)
This commit is contained in:
parent
f4e6cc94d4
commit
e517a0ac66
2 changed files with 16 additions and 6 deletions
|
@ -536,21 +536,27 @@ func migrateToEgressV1() {
|
||||||
}
|
}
|
||||||
for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
if node.IsEgressGateway {
|
if node.IsEgressGateway {
|
||||||
egressHost, err := logic.GetHost(node.HostID.String())
|
_, err := logic.GetHost(node.HostID.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for _, rangeI := range node.EgressGatewayRequest.Ranges {
|
for _, rangeMetric := range node.EgressGatewayRequest.RangesWithMetric {
|
||||||
e := schema.Egress{
|
e := &schema.Egress{Range: rangeMetric.Network}
|
||||||
|
if err := e.DoesEgressRouteExists(db.WithContext(context.TODO())); err == nil {
|
||||||
|
e.Nodes[node.ID.String()] = rangeMetric.RouteMetric
|
||||||
|
e.Update(db.WithContext(context.TODO()))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
e = &schema.Egress{
|
||||||
ID: uuid.New().String(),
|
ID: uuid.New().String(),
|
||||||
Name: fmt.Sprintf("%s egress", egressHost.Name),
|
Name: fmt.Sprintf("%s egress", rangeMetric.Network),
|
||||||
Description: "",
|
Description: "",
|
||||||
Network: node.Network,
|
Network: node.Network,
|
||||||
Nodes: datatypes.JSONMap{
|
Nodes: datatypes.JSONMap{
|
||||||
node.ID.String(): 256,
|
node.ID.String(): rangeMetric.RouteMetric,
|
||||||
},
|
},
|
||||||
Tags: make(datatypes.JSONMap),
|
Tags: make(datatypes.JSONMap),
|
||||||
Range: rangeI,
|
Range: rangeMetric.Network,
|
||||||
Nat: node.EgressGatewayRequest.NatEnabled == "yes",
|
Nat: node.EgressGatewayRequest.NatEnabled == "yes",
|
||||||
Status: true,
|
Status: true,
|
||||||
CreatedBy: user.UserName,
|
CreatedBy: user.UserName,
|
||||||
|
|
|
@ -50,6 +50,10 @@ func (e *Egress) UpdateEgressStatus(ctx context.Context) error {
|
||||||
}).Error
|
}).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (e *Egress) DoesEgressRouteExists(ctx context.Context) error {
|
||||||
|
return db.FromContext(ctx).Table(e.Table()).Where("range = ?", e.Range).First(&e).Error
|
||||||
|
}
|
||||||
|
|
||||||
func (e *Egress) Create(ctx context.Context) error {
|
func (e *Egress) Create(ctx context.Context) error {
|
||||||
return db.FromContext(ctx).Table(e.Table()).Create(&e).Error
|
return db.FromContext(ctx).Table(e.Table()).Create(&e).Error
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue