Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refact: Initialize the nft structure after starting the service #106

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading