Skip to content

Commit

Permalink
fix: only fetch machine uuid if it's not set
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
OGKevin authored and talos-bot committed May 31, 2021
1 parent f112a54 commit 73fbb4b
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions internal/app/machined/pkg/runtime/v1alpha1/platform/metal/metal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

uuid, err := s.SystemInformation().UUID()
if err != nil {
return nil, err
values.Set("uuid", uid.String())

break
}

values.Set("uuid", uuid.String())
values.Set("uuid", qValues[0])
default:
log.Printf("unsupported query parameter: %q", key)
}
Expand All @@ -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
Expand Down

0 comments on commit 73fbb4b

Please sign in to comment.