Merge pull request #986 from jimmidyson/machine-id-docker
Fix machine ID file path when running in container
This commit is contained in:
commit
017b8b2b57
@ -18,6 +18,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"flag"
|
"flag"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
@ -50,8 +51,13 @@ func getInfoFromFiles(filePaths string) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMachineInfo(sysFs sysfs.SysFs, fsInfo fs.FsInfo) (*info.MachineInfo, error) {
|
func getMachineInfo(sysFs sysfs.SysFs, fsInfo fs.FsInfo, inHostNamespace bool) (*info.MachineInfo, error) {
|
||||||
cpuinfo, err := ioutil.ReadFile("/proc/cpuinfo")
|
rootFs := "/"
|
||||||
|
if !inHostNamespace {
|
||||||
|
rootFs = "/rootfs"
|
||||||
|
}
|
||||||
|
|
||||||
|
cpuinfo, err := ioutil.ReadFile(filepath.Join(rootFs, "/proc/cpuinfo"))
|
||||||
clockSpeed, err := machine.GetClockSpeed(cpuinfo)
|
clockSpeed, err := machine.GetClockSpeed(cpuinfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -98,9 +104,9 @@ func getMachineInfo(sysFs sysfs.SysFs, fsInfo fs.FsInfo) (*info.MachineInfo, err
|
|||||||
DiskMap: diskMap,
|
DiskMap: diskMap,
|
||||||
NetworkDevices: netDevices,
|
NetworkDevices: netDevices,
|
||||||
Topology: topology,
|
Topology: topology,
|
||||||
MachineID: getInfoFromFiles(*machineIdFilePath),
|
MachineID: getInfoFromFiles(filepath.Join(rootFs, *machineIdFilePath)),
|
||||||
SystemUUID: systemUUID,
|
SystemUUID: systemUUID,
|
||||||
BootID: getInfoFromFiles(*bootIdFilePath),
|
BootID: getInfoFromFiles(filepath.Join(rootFs, *bootIdFilePath)),
|
||||||
CloudProvider: cloudProvider,
|
CloudProvider: cloudProvider,
|
||||||
InstanceType: instanceType,
|
InstanceType: instanceType,
|
||||||
}
|
}
|
||||||
|
@ -155,7 +155,7 @@ func New(memoryCache *memory.InMemoryCache, sysfs sysfs.SysFs, maxHousekeepingIn
|
|||||||
allowDynamicHousekeeping: allowDynamicHousekeeping,
|
allowDynamicHousekeeping: allowDynamicHousekeeping,
|
||||||
}
|
}
|
||||||
|
|
||||||
machineInfo, err := getMachineInfo(sysfs, fsInfo)
|
machineInfo, err := getMachineInfo(sysfs, fsInfo, inHostNamespace)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user