Skip to content

Commit ac78c23

Browse files
Cleanup post rebase to remove redundant methods and install D-Bus
Signed-off-by: Kate Goldenring <kate.goldenring@fermyon.com>
1 parent 4ddb0a1 commit ac78c23

File tree

4 files changed

+15
-22
lines changed

4 files changed

+15
-22
lines changed

cmd/node-installer/install.go

+8
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,14 @@ func RunInstall(config Config, rootFs, hostFs afero.Fs, restarter containerd.Res
116116
return nil
117117
}
118118

119+
// Ensure D-Bus is installed and running if using systemd
120+
if _, err := containerd.ListSystemdUnits(); err == nil {
121+
err = containerd.InstallDbus()
122+
if err != nil {
123+
return fmt.Errorf("failed to install D-Bus: %w", err)
124+
}
125+
}
126+
119127
slog.Info("restarting containerd")
120128
err = containerdConfig.RestartRuntime()
121129
if err != nil {

internal/containerd/install_dbus.go

-17
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,8 @@ package containerd
33
import (
44
"fmt"
55
"log/slog"
6-
"os"
7-
"os/exec"
86
)
97

10-
// UsesSystemd checks if the system is using systemd.
11-
func UsesSystemd() bool {
12-
cmd := nsenterCmd("systemctl", "list-units", "|", "grep", "-q", "containerd.service")
13-
if err := cmd.Run(); err != nil {
14-
slog.Info("Error with systemctl: %w\n", "error", err)
15-
return false
16-
}
17-
return true
18-
}
19-
208
// InstallDbus checks if D-Bus service is installed and active. If not, installs D-Bus
219
// and starts the service.
2210
// NOTE: this limits support to systems using systemctl to manage systemd.
@@ -63,8 +51,3 @@ func InstallDbus() error {
6351

6452
return nil
6553
}
66-
67-
func nsenterCmd(cmd ...string) *exec.Cmd {
68-
return exec.Command("nsenter",
69-
append([]string{fmt.Sprintf("-m/%s/proc/1/ns/mnt", os.Getenv("HOST_ROOT")), "--"}, cmd...)...) // #nosec G204
70-
}

internal/containerd/restart_unix.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func NewDefaultRestarter() Restarter {
4040

4141
func (c defaultRestarter) Restart() error {
4242
// If listing systemd units succeeds, prefer systemctl restart; otherwise kill pid
43-
if _, err := listSystemdUnits(); err == nil {
43+
if _, err := ListSystemdUnits(); err == nil {
4444
out, err := nsenterCmd("systemctl", "restart", "containerd").CombinedOutput()
4545
slog.Debug(string(out))
4646
if err != nil {
@@ -67,7 +67,7 @@ type K0sRestarter struct{}
6767
func (c K0sRestarter) Restart() error {
6868
// First, collect systemd units to determine which mode k0s is running in, eg
6969
// k0sworker or k0scontroller
70-
units, err := listSystemdUnits()
70+
units, err := ListSystemdUnits()
7171
if err != nil {
7272
return fmt.Errorf("unable to list systemd units: %w", err)
7373
}
@@ -88,7 +88,7 @@ func (c K3sRestarter) Restart() error {
8888
// This restarter will be used both for stock K3s distros, which use systemd as well as K3d, which does not.
8989

9090
// If listing systemd units succeeds, prefer systemctl restart; otherwise kill pid
91-
if _, err := listSystemdUnits(); err == nil {
91+
if _, err := ListSystemdUnits(); err == nil {
9292
out, err := nsenterCmd("systemctl", "restart", "k3s").CombinedOutput()
9393
slog.Debug(string(out))
9494
if err != nil {
@@ -130,7 +130,7 @@ type RKE2Restarter struct{}
130130
func (c RKE2Restarter) Restart() error {
131131
// First, collect systemd units to determine which mode rke2 is running in, eg
132132
// rke2-agent or rke2-server
133-
units, err := listSystemdUnits()
133+
units, err := ListSystemdUnits()
134134
if err != nil {
135135
return fmt.Errorf("unable to list systemd units: %w", err)
136136
}
@@ -145,7 +145,7 @@ func (c RKE2Restarter) Restart() error {
145145
return nil
146146
}
147147

148-
func listSystemdUnits() ([]byte, error) {
148+
func ListSystemdUnits() ([]byte, error) {
149149
return nsenterCmd("systemctl", "list-units", "--type", "service").CombinedOutput()
150150
}
151151

internal/controller/shim_controller.go

+2
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,8 @@ func (sr *ShimReconciler) setOperationConfiguration(shim *rcmv1.Shim, opConfig *
380380
}
381381

382382
// createJobManifest creates a Job manifest for a Shim.
383+
//
384+
//nolint:funlen // function is longer due to scaffolding an entire K8s Job manifest
383385
func (sr *ShimReconciler) createJobManifest(shim *rcmv1.Shim, node *corev1.Node, operation string) (*batchv1.Job, error) {
384386
opConfig := opConfig{
385387
operation: operation,

0 commit comments

Comments
 (0)