fix: only fetch machine uuid if it's not set

During boot sequence, if `talos.config`'s url has the uuid parameter, the uuid
value is retrieved via SMBIOS. However, at this part of the code it can happen
that the uuid is already set and valid. If this is the case, instead of
re-fetching the uuid, the one that is already set can be used.

closes #3676

Signed-off-by: Kevin Hellemun <17928966+OGKevin@users.noreply.github.com>
This commit is contained in:
Kevin Hellemun 2021-05-27 21:06:45 +02:00 committed by talos-bot
parent f112a540b0
commit 73fbb4b523

View File

@ -13,6 +13,7 @@ import (
"net/url"
"path/filepath"
"github.com/google/uuid"
"github.com/talos-systems/go-blockdevice/blockdevice/filesystem"
"github.com/talos-systems/go-blockdevice/blockdevice/probe"
"github.com/talos-systems/go-procfs/procfs"
@ -48,26 +49,27 @@ func (m *Metal) Configuration(ctx context.Context) ([]byte, error) {
u, err := url.Parse(*option)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to parse %s: %w", constants.KernelParamConfig, err)
}
values := u.Query()
if len(values) > 0 {
for key := range values {
for key, qValues := range values {
switch key {
case "uuid":
s, err := smbios.New()
if err != nil {
return nil, err
if len(qValues) != 1 {
uid, err := getSystemUUID()
if err != nil {
return nil, err
}
values.Set("uuid", uid.String())
break
}
uuid, err := s.SystemInformation().UUID()
if err != nil {
return nil, err
}
values.Set("uuid", uuid.String())
values.Set("uuid", qValues[0])
default:
log.Printf("unsupported query parameter: %q", key)
}
@ -86,6 +88,15 @@ func (m *Metal) Configuration(ctx context.Context) ([]byte, error) {
}
}
func getSystemUUID() (uuid.UUID, error) {
s, err := smbios.New()
if err != nil {
return uuid.Nil, err
}
return s.SystemInformation().UUID()
}
// Hostname implements the platform.Platform interface.
func (m *Metal) Hostname(context.Context) (hostname []byte, err error) {
return nil, nil