Skip to content

Commit

Permalink
refact: Initialize the nft structure after starting the service
Browse files Browse the repository at this point in the history
Signed-off-by: ComixHe <[email protected]>
  • Loading branch information
ComixHe committed Nov 17, 2023
1 parent 1c23345 commit 4e7e5f7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions pkg/interfaces/nftman.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 1 addition & 6 deletions pkg/nftman/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down Expand Up @@ -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.")
Expand Down
4 changes: 3 additions & 1 deletion pkg/nftman/nftman_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
})
})

Expand Down
6 changes: 6 additions & 0 deletions pkg/routeman/public.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4e7e5f7

Please sign in to comment.