diff --git a/pkg/interfaces/nftman.go b/pkg/interfaces/nftman.go index 73c3dcc..4f0e6ad 100644 --- a/pkg/interfaces/nftman.go +++ b/pkg/interfaces/nftman.go @@ -12,6 +12,7 @@ type NFTManager interface { AddChainAndRulesForTProxy(*config.TProxy) error AddRoutes([]types.Route) error Clear() error + InitStructure() error Release() error RemoveCgroups([]string) error } diff --git a/pkg/nftman/new.go b/pkg/nftman/new.go index fdfc74b..d144f01 100644 --- a/pkg/nftman/new.go +++ b/pkg/nftman/new.go @@ -73,11 +73,6 @@ func New(opts ...Opt) (ret *NFTManager, err error) { t.log = zap.NewNop().Sugar() } - err = t.initStructure() - if err != nil { - return - } - ret = t t.log.Debugw("NFTManager created.") @@ -151,7 +146,7 @@ func WithConnFactory(f interfaces.NetlinkConnector) Opt { } } -func (nft *NFTManager) initStructure() (err error) { +func (nft *NFTManager) InitStructure() (err error) { defer Wrap(&err, "flush initial content") nft.log.Debug("Initialing nft table structure.") diff --git a/pkg/nftman/nftman_test.go b/pkg/nftman/nftman_test.go index 47d6549..4640f34 100644 --- a/pkg/nftman/nftman_test.go +++ b/pkg/nftman/nftman_test.go @@ -44,9 +44,11 @@ var _ = Describe("Netfliter table", Ordered, func() { ContextTableEntry(injectedNFTManagerWithConnector).WithFmt("connector"), func(injectedNFTManager func(cGroupRoot config.CGroupRoot) (*NFTManager, error)) { BeforeEach(func() { - By("Create a Table object.", func() { + By("Create a Table object and initialize structure", func() { nft, err = injectedNFTManager(config.CGroupRoot(cgroupRoot)) Expect(err).To(Succeed()) + err = nft.InitStructure() + Expect(err).To(Succeed()) }) }) diff --git a/pkg/routeman/public.go b/pkg/routeman/public.go index f6fa0f5..9a216de 100644 --- a/pkg/routeman/public.go +++ b/pkg/routeman/public.go @@ -12,6 +12,12 @@ func (m *RouteManager) RunRouteManager(ctx context.Context) (err error) { defer Wrap(&err, "running route manager") defer m.removeRoute() + + err = m.nft.InitStructure() + if err != nil { + return + } + err = m.addRoute() if err != nil { return