Skip to content

Commit

Permalink
NO-ISSUE: agent: ensure os image exists in status
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Batschelet <[email protected]>
  • Loading branch information
hexfusion committed Jul 1, 2024
1 parent 475775d commit e8e7719
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
5 changes: 3 additions & 2 deletions internal/agent/device/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Bootstrap struct {
enrollmentClient *client.Enrollment
enrollmentUIEndpoint string
statusManager status.Manager
bootcClient *container.BootcCmd
backoff wait.Backoff

currentRenderedFile string
Expand Down Expand Up @@ -68,6 +69,7 @@ func NewBootstrap(
enrollmentClient: enrollmentClient,
enrollmentUIEndpoint: enrollmentUIEndpoint,
managementServiceConfig: managementServiceConfig,
bootcClient: container.NewBootcCmd(executer),
backoff: backoff,
currentRenderedFile: currentRenderedFile,
desiredRenderedFile: desiredRenderedFile,
Expand Down Expand Up @@ -143,8 +145,7 @@ func (b *Bootstrap) ensureCurrentRenderedSpecUpToDate(ctx context.Context) error
return nil
}

bootcCmd := container.NewBootcCmd(b.executer)
bootcHost, err := bootcCmd.Status(ctx)
bootcHost, err := b.bootcClient.Status(ctx)
if err != nil {
return fmt.Errorf("getting current bootc status: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/agent/device/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func NewManager(
exporters := []Exporter{
newSystemD(executer),
newContainer(executer),
newSystemInfo(),
newSystemInfo(executer),
newResources(log, resourceManager),
}
status := v1alpha1.NewDeviceStatus()
Expand Down
22 changes: 19 additions & 3 deletions internal/agent/device/status/systeminfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"runtime"

"github.com/flightctl/flightctl/api/v1alpha1"
"github.com/flightctl/flightctl/internal/container"
"github.com/flightctl/flightctl/pkg/executer"
"github.com/google/cadvisor/fs"
"github.com/google/cadvisor/machine"
"github.com/google/cadvisor/utils/sysfs"
Expand All @@ -15,12 +17,14 @@ var _ Exporter = (*SystemInfo)(nil)

// SystemInfo collects system information.
type SystemInfo struct {
sysFs sysfs.SysFs
sysFs sysfs.SysFs
bootcClient *container.BootcCmd
}

func newSystemInfo() *SystemInfo {
func newSystemInfo(exec executer.Executer) *SystemInfo {
return &SystemInfo{
sysFs: sysfs.NewRealSysFs(),
sysFs: sysfs.NewRealSysFs(),
bootcClient: container.NewBootcCmd(exec),
}
}

Expand All @@ -45,6 +49,18 @@ func (s *SystemInfo) Export(ctx context.Context, status *v1alpha1.DeviceStatus)
BootID: info.BootID,
}

bootcInfo, err := s.bootcClient.Status(ctx)
if err != nil {
return fmt.Errorf("getting bootc status: %w", err)
}

osImage := container.GetImage(bootcInfo)
if osImage == "" {
return fmt.Errorf("getting os image: %w", err)
}

status.Os.Image = osImage

return nil
}

Expand Down

0 comments on commit e8e7719

Please sign in to comment.