Skip to content
This repository has been archived by the owner on Aug 19, 2023. It is now read-only.

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 siderolabs#3676

Signed-off-by: Kevin Hellemun <17928966+OGKevin@users.noreply.github.com>
  • Loading branch information
OGKevin committed May 27, 2021
1 parent e0f5b1e commit 3a919b3
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions internal/app/machined/pkg/runtime/v1alpha1/platform/metal/metal.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package metal
import (
"context"
"fmt"
"github.com/google/uuid"
"io/ioutil"
"log"
"net"
Expand Down Expand Up @@ -48,26 +49,25 @@ 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 talos.config url: %w", 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
}

uuid, err := s.SystemInformation().UUID()
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
}

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

id, err := s.SystemInformation().UUID()
if err != nil {
return uuid.Nil, err
}

return id, nil
}

// 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 3a919b3

Please sign in to comment.