-
Notifications
You must be signed in to change notification settings - Fork 516
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement D-Bus systemd-compatible shutdown for kubelet
Add a mock D-Bus daemon and a mock logind implementation over D-Bus. Kubelet gets a handle to the D-Bus socket, connects over it to our logind mock and negotiates shutdown activities. Signed-off-by: Andrey Smirnov <[email protected]>
- Loading branch information
Showing
17 changed files
with
858 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
internal/app/machined/pkg/runtime/v1alpha1/v1alpha1_dbus.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
package v1alpha1 | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"time" | ||
|
||
"github.com/talos-systems/talos/internal/pkg/logind" | ||
"github.com/talos-systems/talos/pkg/machinery/constants" | ||
) | ||
|
||
// DBusState implements the logind mock. | ||
type DBusState struct { | ||
broker *logind.DBusBroker | ||
logindMock *logind.ServiceMock | ||
errCh chan error | ||
cancel context.CancelFunc | ||
} | ||
|
||
// Start the D-Bus broker and logind mock. | ||
func (dbus *DBusState) Start() error { | ||
for _, path := range []string{constants.DBusServiceSocketPath, constants.DBusClientSocketPath} { | ||
if err := os.MkdirAll(filepath.Dir(path), 0o700); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
var err error | ||
|
||
dbus.broker, err = logind.NewBroker(constants.DBusServiceSocketPath, constants.DBusClientSocketPath) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var ctx context.Context | ||
|
||
ctx, dbus.cancel = context.WithCancel(context.Background()) | ||
|
||
dbus.errCh = make(chan error) | ||
|
||
go func() { | ||
dbus.errCh <- dbus.broker.Run(ctx) | ||
}() | ||
|
||
dbus.logindMock, err = logind.NewServiceMock(constants.DBusServiceSocketPath) | ||
|
||
return err | ||
} | ||
|
||
// Stop the D-Bus broker and logind mock. | ||
func (dbus *DBusState) Stop() error { | ||
dbus.cancel() | ||
|
||
if err := dbus.logindMock.Close(); err != nil { | ||
return err | ||
} | ||
|
||
if err := dbus.broker.Close(); err != nil { | ||
return err | ||
} | ||
|
||
select { | ||
case <-time.After(time.Second): | ||
return fmt.Errorf("timed out stopping D-Bus broker") | ||
case err := <-dbus.errCh: | ||
return err | ||
} | ||
} | ||
|
||
// WaitShutdown signals the shutdown over the D-Bus and waits for the inhibit lock to be released. | ||
func (dbus *DBusState) WaitShutdown(ctx context.Context) error { | ||
if err := dbus.logindMock.EmitShutdown(); err != nil { | ||
return err | ||
} | ||
|
||
return dbus.logindMock.WaitLockRelease(ctx) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.