mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-15 14:14:39 +00:00
Address a TODO, move to lazy initialization of the firewallD signal handler.
This commit is contained in:
@@ -137,6 +137,7 @@ type runner struct {
|
|||||||
dbus utildbus.Interface
|
dbus utildbus.Interface
|
||||||
protocol Protocol
|
protocol Protocol
|
||||||
hasCheck bool
|
hasCheck bool
|
||||||
|
hasListener bool
|
||||||
waitFlag []string
|
waitFlag []string
|
||||||
restoreWaitFlag []string
|
restoreWaitFlag []string
|
||||||
lockfilePath string
|
lockfilePath string
|
||||||
@@ -163,13 +164,11 @@ func newInternal(exec utilexec.Interface, dbus utildbus.Interface, protocol Prot
|
|||||||
dbus: dbus,
|
dbus: dbus,
|
||||||
protocol: protocol,
|
protocol: protocol,
|
||||||
hasCheck: getIPTablesHasCheckCommand(vstring),
|
hasCheck: getIPTablesHasCheckCommand(vstring),
|
||||||
|
hasListener: false,
|
||||||
waitFlag: getIPTablesWaitFlag(vstring),
|
waitFlag: getIPTablesWaitFlag(vstring),
|
||||||
restoreWaitFlag: getIPTablesRestoreWaitFlag(exec, protocol),
|
restoreWaitFlag: getIPTablesRestoreWaitFlag(exec, protocol),
|
||||||
lockfilePath: lockfilePath,
|
lockfilePath: lockfilePath,
|
||||||
}
|
}
|
||||||
// TODO this needs to be moved to a separate Start() or Run() function so that New() has zero side
|
|
||||||
// effects.
|
|
||||||
runner.connectToFirewallD()
|
|
||||||
return runner
|
return runner
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,6 +199,7 @@ func (runner *runner) connectToFirewallD() {
|
|||||||
glog.V(1).Infof("Could not connect to D-Bus system bus: %s", err)
|
glog.V(1).Infof("Could not connect to D-Bus system bus: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
runner.hasListener = true
|
||||||
|
|
||||||
rule := fmt.Sprintf("type='signal',sender='%s',path='%s',interface='%s',member='Reloaded'", firewalldName, firewalldPath, firewalldInterface)
|
rule := fmt.Sprintf("type='signal',sender='%s',path='%s',interface='%s',member='Reloaded'", firewalldName, firewalldPath, firewalldInterface)
|
||||||
bus.BusObject().Call("org.freedesktop.DBus.AddMatch", 0, rule)
|
bus.BusObject().Call("org.freedesktop.DBus.AddMatch", 0, rule)
|
||||||
@@ -669,6 +669,15 @@ func (runner *runner) dbusSignalHandler(bus utildbus.Connection) {
|
|||||||
|
|
||||||
// AddReloadFunc is part of Interface
|
// AddReloadFunc is part of Interface
|
||||||
func (runner *runner) AddReloadFunc(reloadFunc func()) {
|
func (runner *runner) AddReloadFunc(reloadFunc func()) {
|
||||||
|
runner.mu.Lock()
|
||||||
|
defer runner.mu.Unlock()
|
||||||
|
|
||||||
|
// We only need to listen to firewalld if there are Reload functions, so lazy
|
||||||
|
// initialize the listener.
|
||||||
|
if !runner.hasListener {
|
||||||
|
runner.connectToFirewallD()
|
||||||
|
}
|
||||||
|
|
||||||
runner.reloadFuncs = append(runner.reloadFuncs, reloadFunc)
|
runner.reloadFuncs = append(runner.reloadFuncs, reloadFunc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user