mirror of
https://github.com/siderolabs/talos.git
synced 2025-09-15 19:01:12 +02:00
This concludes basic KubeSpan implementation. Most of the code is from #3577 with some fixes and refactoring. Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com> Signed-off-by: Seán C McCord <ulexus@gmail.com> Co-authored-by: Seán C McCord <ulexus@gmail.com>
45 lines
1.3 KiB
Go
45 lines
1.3 KiB
Go
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
package kubespan_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"inet.af/netaddr"
|
|
|
|
"github.com/talos-systems/talos/internal/app/machined/pkg/controllers/kubespan"
|
|
"github.com/talos-systems/talos/pkg/machinery/constants"
|
|
)
|
|
|
|
func TestNfTables(t *testing.T) {
|
|
// use a different mark to avoid conflicts with running kubespan
|
|
mgr := kubespan.NewNfTablesManager(constants.KubeSpanDefaultFirewallMark+10, constants.KubeSpanDefaultForceFirewallMark+10)
|
|
|
|
// cleanup should be fine if nothing is installed
|
|
assert.NoError(t, mgr.Cleanup())
|
|
|
|
defer mgr.Cleanup() //nolint:errcheck
|
|
|
|
var builder netaddr.IPSetBuilder
|
|
|
|
builder.AddPrefix(netaddr.MustParseIPPrefix("172.20.0.0/24"))
|
|
builder.AddPrefix(netaddr.MustParseIPPrefix("10.0.0.0/16"))
|
|
|
|
ipSet, err := builder.IPSet()
|
|
require.NoError(t, err)
|
|
|
|
assert.NoError(t, mgr.Update(ipSet))
|
|
|
|
builder.AddPrefix(netaddr.MustParseIPPrefix("10.0.0.0/8"))
|
|
|
|
ipSet, err = builder.IPSet()
|
|
require.NoError(t, err)
|
|
|
|
assert.NoError(t, mgr.Update(ipSet))
|
|
|
|
assert.NoError(t, mgr.Cleanup())
|
|
}
|