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

utils(iptables): Factor out a common function for executing commands #1277

Closed

Conversation

vadorovsky
Copy link
Contributor

SaveInto and Restore were almost the same aside from what was executed.

Signed-off-by: Michal Rostecki [email protected]

Copy link
Collaborator

@aauren aauren left a comment

Choose a reason for hiding this comment

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

Thanks for the submission @vadorovsky.

It looks like it needs a small tweak in order to work. When I tested it in my cluster it threw an error:

2022-04-05T22:04:36.594653566Z E0405 22:04:36.594568   14423 network_policy_controller.go:253] Aborting sync. Failed to run iptables-save: %!v(MISSING)failed to call iptables-save [-t filter]: exit status 1, (ERROR: No valid subcommand given.                                
2022-04-05T22:04:36.594671003Z Valid subcommands:                                                                                                                                                                                                                                 
2022-04-05T22:04:36.594674132Z  * iptables                                                                                                                                                                                                                                        
2022-04-05T22:04:36.594676686Z  * main4                                                                                                                                                                                                                                           
2022-04-05T22:04:36.594679175Z  * iptables-save                                                                                                                                                                                                                                   
2022-04-05T22:04:36.594681693Z  * save4                                                                                                                                                                                                                                           
2022-04-05T22:04:36.594684203Z  * iptables-restore                                                                                                                                                                                                                                
2022-04-05T22:04:36.594686723Z  * restore4                                                                                                                                                                                                                                        
2022-04-05T22:04:36.594694755Z  * iptables-legacy                                                                                                                                                                                                                                 
2022-04-05T22:04:36.594697534Z  * iptables-legacy-save                                                                                                                                                                                                                            
2022-04-05T22:04:36.594700027Z  * iptables-legacy-restore                                                                                                                                                                                                                         
2022-04-05T22:04:36.594702516Z  * iptables-xml                                                                                                                                                                                                                                    
2022-04-05T22:04:36.594705010Z  * xml                                                                                                                                                                                                                                             
2022-04-05T22:04:36.594707616Z  * ip6tables                                                                                                                                                                                                                                       
2022-04-05T22:04:36.594710110Z  * main6                                                                                                                                                                                                                                           
2022-04-05T22:04:36.594712637Z  * ip6tables-save                                                                                                                                                                                                                                  
2022-04-05T22:04:36.594715142Z  * save6                                                                                                                                                                                                                                           
2022-04-05T22:04:36.594717642Z  * ip6tables-restore                                                                                                                                                                                                                               
2022-04-05T22:04:36.594720150Z  * restore6                                                                                                                                                                                                                                        
2022-04-05T22:04:36.594722634Z  * ip6tables-legacy                                                                                                                                                                                                                                
2022-04-05T22:04:36.594725121Z  * ip6tables-legacy-save                                                                                                                                                                                                                           
2022-04-05T22:04:36.594727598Z  * ip6tables-legacy-restore                                                                                                                                                                                                                        
2022-04-05T22:04:36.594730080Z )

Other than that, I'm always in favor of consolidation.

cmd := exec.Cmd{
Path: path,
Args: args,
Stdout: buffer,
Copy link
Collaborator

Choose a reason for hiding this comment

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

The args here needs to contain the command name here as well.

So you'll need to do some work like the following in order for it to work:

trueArgs := append([]string{cmdName}, args...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops, sorry for that!. Should be fixed now.

SaveInto and Restore were almost the same aside from what was executed.

Signed-off-by: Michal Rostecki <[email protected]>
@vadorovsky vadorovsky force-pushed the iptables-save-restore branch from 53fae19 to d912e6b Compare April 5, 2022 22:42
@vadorovsky
Copy link
Contributor Author

Actually it's irrelevant now, #1280 completely changes the iptables code.

@vadorovsky vadorovsky closed this Apr 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants