Skip to content

Commit

Permalink
fix: improve container detection
Browse files Browse the repository at this point in the history
Instead of relying on cmdline (which will not work in case it's TinK on Talos, for example), add a file to container rootfs to signal the platform to machined.

Signed-off-by: Dmitry Sharshakov <[email protected]>
  • Loading branch information
dsseng committed Oct 7, 2024
1 parent b67bc73 commit 2362f6d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,7 @@ RUN <<END
END

FROM rootfs-base-${TARGETARCH} AS rootfs-base
RUN echo "true" > /rootfs/usr/etc/in-container
RUN find /rootfs -print0 \
| xargs -0r touch --no-dereference --date="@${SOURCE_DATE_EPOCH}"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ const (

// CurrentPlatform is a helper func for discovering the current platform.
func CurrentPlatform() (p runtime.Platform, err error) {
if _, err := os.Stat("/usr/etc/in-container"); err == nil {
return newPlatform("container")
}

var platform string

if p := procfs.ProcCmdline().Get(constants.KernelParamPlatform).First(); p != nil {
Expand Down

0 comments on commit 2362f6d

Please sign in to comment.