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

UDN LGW: ensure masq chain exists before adding rules #4697

Merged
merged 1 commit into from
Sep 6, 2024

Conversation

martinkennelly
Copy link
Member

@martinkennelly martinkennelly commented Sep 4, 2024

cc @tssurya

Fixes #4695

@martinkennelly martinkennelly added the feature/user-defined-network-segmentation All PRs related to User defined network segmentation label Sep 4, 2024
@martinkennelly martinkennelly requested a review from a team as a code owner September 4, 2024 12:49
Prior to this PR, we may try to insert a rule to jump
to a chain that doesn't exist.

Signed-off-by: Martin Kennelly <mkennell@redhat.com>
@@ -79,6 +79,18 @@ func deleteIptRules(rules []nodeipt.Rule) error {
return nodeipt.DelRules(rules)
}

// ensureChain ensures that a chain exists within a table
func ensureChain(table, chain string) error {
Copy link
Member

@tssurya tssurya Sep 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we already have a util for this somewhere no?
I thought insertIpt does chain creation automatically... that was why I didn't create the chain explicitly how is this crash transient and goes away eventually?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldnt find any.

If its a rule for a chain then itll auto create the chain, but if its a jump, it wont create the chain you jump to.
I assume it hit a rule during init startup that then created the chain but the error inserting the jump rule happened earlier and following reboot of the container, the new chain is there.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you use the IPTablesHelper function NewChain() similar to

if err = ipt.NewChain(r.Table, r.Chain); err != nil {
klog.V(5).Infof("Chain: \"%s\" in table: \"%s\" already exists, skipping creation: %v",
r.Chain, r.Table, err)
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If its a rule for a chain then itll auto create the chain, but if its a jump, it wont create the chain you jump to. I assume it hit a rule during init startup that then created the chain but the error inserting the jump rule happened earlier and following reboot of the container, the new chain is there.

yea that's it. thanks martin for rca

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JacobTanenbaum yea

func addChaintoTable(ipt util.IPTablesHelper, tableName, chain string) {
	if err := ipt.NewChain(tableName, chain); err != nil {
		klog.V(5).Infof("Chain: \"%s\" in table: \"%s\" already exists, skipping creation: %v", chain, tableName, err)
	}
}

he is indirectly using that

if err != nil {
return fmt.Errorf("failed to get IPTables helper to add UDN chain: %v", err)
}
addChaintoTable(ipt, table, chain)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah! I was talking about addChainToTable...OK looks like there isn't a wrapper for that and hence this happens..

Copy link
Contributor

@kyrtapz kyrtapz Sep 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it is unrelated to this change but addChaintoTable ignores all errors, not only the ones where the chain already exists. I feel like it would be best to introduce a new method to the helper, something like:

// EnsureChain creates a new chain if it doesn't already exist
func (ipt *IPTables) EnsureChain(table, chain string) error {
	exists, err := ipt.ChainExists(table, chain)
	if err != nil || exists {
		return err
	}
	return ipt.NewChain(table, chain)
}

Another option is to actually compare the error value in addChaintoTable.
This doesn't have to happen in this PR.

@tssurya
Copy link
Member

tssurya commented Sep 6, 2024

/assign @kyrtapz who takes the credit for spotting this.

@@ -26,6 +26,11 @@ func newLocalGateway(nodeName string, hostSubnets []*net.IPNet, gwNextHops []net
klog.Info("Creating new local gateway")
gw := &gateway{}

if util.IsNetworkSegmentationSupportEnabled() {
if err := ensureChain("nat", iptableUDNMasqueradeChain); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: Wouldn't it make more sense to move this to somewhere in

func initLocalGatewayNATRules(ifname string, cidr *net.IPNet) error {
?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think the purpose of that func was generate the rules and apply them, hence i put the creation of a chain outside it.

if err != nil {
return fmt.Errorf("failed to get IPTables helper to add UDN chain: %v", err)
}
addChaintoTable(ipt, table, chain)
Copy link
Contributor

@kyrtapz kyrtapz Sep 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it is unrelated to this change but addChaintoTable ignores all errors, not only the ones where the chain already exists. I feel like it would be best to introduce a new method to the helper, something like:

// EnsureChain creates a new chain if it doesn't already exist
func (ipt *IPTables) EnsureChain(table, chain string) error {
	exists, err := ipt.ChainExists(table, chain)
	if err != nil || exists {
		return err
	}
	return ipt.NewChain(table, chain)
}

Another option is to actually compare the error value in addChaintoTable.
This doesn't have to happen in this PR.

@martinkennelly
Copy link
Member Author

Ill follow up with another PR to address the issue pat brought up.

@tssurya tssurya merged commit a551930 into ovn-org:master Sep 6, 2024
39 checks passed
@tssurya tssurya added the kind/bug All issues that are bugs and PRs opened to fix bugs label Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/user-defined-network-segmentation All PRs related to User defined network segmentation kind/bug All issues that are bugs and PRs opened to fix bugs
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

UDN Panic: Chain 'OVN-KUBE-UDN-MASQUERADE' does not exist
4 participants