func()

in cmd/node-cache/app/cache_app.go [166:198]


func (c *CacheApp) TeardownNetworking() error {
	clog.Infof("Tearing down")
	if c.exitChan != nil {
		// Stop the goroutine that periodically checks for iptables rules/dummy interface
		// exitChan is a buffered channel of size 1, so this will not block
		c.exitChan <- struct{}{}
	}
	var err error
	if c.params.SetupInterface {
		err = c.netifHandle.RemoveDummyDevice(c.params.InterfaceName)
	}
	if c.params.SetupIptables {
		for _, rule := range c.iptablesRules {
			exists := true
			for exists == true {
				// check in a loop in case the same rule got added multiple times.
				err = c.iptables.DeleteRule(rule.table, rule.chain, rule.args...)
				if err != nil {
					clog.Errorf("Failed deleting iptables rule %v, error - %v", rule, err)
					handleIPTablesError(err)
				}
				exists, err = c.iptables.EnsureRule(utiliptables.Prepend, rule.table, rule.chain, rule.args...)
				if err != nil {
					clog.Errorf("Failed checking iptables rule after deletion, rule - %v, error - %v", rule, err)
					handleIPTablesError(err)
				}
			}
			// Delete the rule one last time since EnsureRule creates the rule if it doesn't exist
			err = c.iptables.DeleteRule(rule.table, rule.chain, rule.args...)
		}
	}
	return err
}