Skip to content

Commit

Permalink
make sure taps are cleaned correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
muhamadazmy committed Jan 30, 2024
1 parent b8f1c38 commit a6935e7
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
17 changes: 15 additions & 2 deletions pkg/gridtypes/zos/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,19 @@ func (c *Mycelium) Challenge(b io.Writer) error {
return nil
}

func (c *Mycelium) Valid() error {
if len(c.Key) != MyceliumKeyLen {
return fmt.Errorf("invalid mycelium key length, expected %d", MyceliumKeyLen)
}

// TODO:
// we are not supporting extra peers right now until
if len(c.Peers) != 0 {
return fmt.Errorf("user defined peers list is not supported right now")
}
return nil
}

// Valid checks if the network resource is valid.
func (n Network) Valid(getter gridtypes.WorkloadGetter) error {

Expand All @@ -136,8 +149,8 @@ func (n Network) Valid(getter gridtypes.WorkloadGetter) error {
}

if n.Mycelium != nil {
if len(n.Mycelium.Key) != MyceliumKeyLen {
return fmt.Errorf("invalid mycelium key length, expected %d", MyceliumKeyLen)
if err := n.Mycelium.Valid(); err != nil {
return err
}
}

Expand Down
21 changes: 20 additions & 1 deletion pkg/network/nr/net_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,14 @@ func (nr *NetResource) SetMycelium() (err error) {
"--peers",
}

// append global peers.
// first append peers from user input.
// right now this is shadowed by Mycelium config validation
// which does not allow custom peer list.
args = AppendFunc(args, config.Peers, func(mp zos.MyceliumPeer) string {
return string(mp)
})

// global peers list
args = append(args, peers.Mycelium.Peers...)

// todo: add custom peers requested by the user
Expand Down Expand Up @@ -863,3 +870,15 @@ func Convert4to6(netID string, ip net.IP) net.IP {

return net.ParseIP(ipv6)
}

// AppendFunc appends arrays with automatic map
func AppendFunc[A any, B any, S []A, D []B](d D, s S, f func(A) B) D {
d = slices.Grow(d, len(s))

for _, e := range s {
d = append(d, f(e))
}

return d

}
9 changes: 8 additions & 1 deletion pkg/primitives/vm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,14 @@ func (p *Manager) Deprovision(ctx context.Context, wl *gridtypes.WorkloadWithID)
}

if cfg.Network.Planetary {
tapName := wl.ID.Unique("ygg")
var tapName string
if cfg.Network.Mycelium == nil {
// yggdrasil network
tapName = wl.ID.Unique("ygg")
} else {
tapName = wl.ID.Unique("mycelium")
}

if err := network.RemoveTap(ctx, tapName); err != nil {
return errors.Wrap(err, "could not clean up tap device")
}
Expand Down

0 comments on commit a6935e7

Please sign in to comment.