f-90: vm, vpc, watchdog: redirections en nft, retrait d'iptables #90
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
4f7d55a9ed
commit
682696214a
10 changed files with 31 additions and 173 deletions
|
|
@ -10,7 +10,6 @@ import (
|
|||
|
||||
configuration "git.g3e.fr/syonad/two/internal/config/agent"
|
||||
"git.g3e.fr/syonad/two/internal/dhcpbackend"
|
||||
"git.g3e.fr/syonad/two/internal/iptables"
|
||||
"git.g3e.fr/syonad/two/internal/l3vni"
|
||||
"git.g3e.fr/syonad/two/internal/metadata"
|
||||
"git.g3e.fr/syonad/two/internal/netif"
|
||||
|
|
@ -63,12 +62,7 @@ func StartVM(db *badger.DB, name string, cfg *configuration.Config) error {
|
|||
// métadonnées de l'interface primaire. Toutes les interfaces étant dans le
|
||||
// même VPC, donc le même netns, il est joignable depuis n'importe laquelle.
|
||||
if err := netns.Call(nic.vpcName, func() error {
|
||||
for _, n := range d.nics {
|
||||
if err := iptables.AddMetadataRedirect(n.ip, nic.interfaceIP, d.metadataPort); err != nil {
|
||||
return fmt.Errorf("interface %d: %w", n.index, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return nft.SetMetadataRedirect(name, nicIPs(d.nics), nic.interfaceIP+":"+d.metadataPort)
|
||||
}); err != nil {
|
||||
return fmt.Errorf("add metadata redirect: %w", err)
|
||||
}
|
||||
|
|
@ -186,6 +180,14 @@ func copyFile(src, dst string) error {
|
|||
return out.Sync()
|
||||
}
|
||||
|
||||
func nicIPs(nics []nicData) []string {
|
||||
ips := make([]string, len(nics))
|
||||
for i, n := range nics {
|
||||
ips[i] = n.ip
|
||||
}
|
||||
return ips
|
||||
}
|
||||
|
||||
func nicMACs(nics []nicData) []string {
|
||||
macs := make([]string, len(nics))
|
||||
for i, n := range nics {
|
||||
|
|
|
|||
|
|
@ -18,3 +18,17 @@ func TestNicMACs_KeepsTheOrderAndLowersTheCase(t *testing.T) {
|
|||
t.Errorf("nicMACs = %v, attendu %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNicIPs_EveryInterfaceGetsTheRedirect(t *testing.T) {
|
||||
nics := []nicData{
|
||||
{index: 0, ip: "10.49.1.10"},
|
||||
{index: 1, ip: "10.49.2.10", primary: true},
|
||||
}
|
||||
|
||||
got := nicIPs(nics)
|
||||
|
||||
want := []string{"10.49.1.10", "10.49.2.10"}
|
||||
if !reflect.DeepEqual(got, want) {
|
||||
t.Errorf("nicIPs = %v, attendu %v", got, want)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ import (
|
|||
|
||||
configuration "git.g3e.fr/syonad/two/internal/config/agent"
|
||||
"git.g3e.fr/syonad/two/internal/dhcpbackend"
|
||||
"git.g3e.fr/syonad/two/internal/iptables"
|
||||
"git.g3e.fr/syonad/two/internal/l3vni"
|
||||
"git.g3e.fr/syonad/two/internal/metadata"
|
||||
"git.g3e.fr/syonad/two/internal/netif"
|
||||
|
|
@ -60,12 +59,7 @@ func StopVM(db *badger.DB, name string, cfg *configuration.Config) error {
|
|||
}
|
||||
|
||||
if err := netns.Call(nic.vpcName, func() error {
|
||||
for _, n := range d.nics {
|
||||
if err := iptables.DeleteMetadataRedirect(n.ip, nic.interfaceIP, d.metadataPort); err != nil {
|
||||
return fmt.Errorf("interface %d: %w", n.index, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return nft.DeleteMetadataRedirect(name)
|
||||
}); err != nil {
|
||||
return fmt.Errorf("delete metadata redirect: %w", err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue