Skip to content

Commit

Permalink
fix: correctly expand parameters in the URL
Browse files Browse the repository at this point in the history
This fixes multiple issues:

* `log.Fatalf` in the machined code leads to kernel panic
* return URL if some expansion fails
* correctly handle destroyed event (wait for the next one)

Fixes #6807

Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
  • Loading branch information
smira committed Feb 2, 2023
1 parent af21860 commit 38a5119
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (m *Metal) Configuration(ctx context.Context, r state.State) ([]byte, error
getURL := func() string {
downloadEndpoint, err := PopulateURLParameters(ctx, *option, r)
if err != nil {
log.Fatalf("failed to populate talos.config fetch URL: %q ; %s", *option, err.Error())
log.Printf("failed to populate talos.config fetch URL: %q ; %s", *option, err.Error())
}

log.Printf("fetching machine config from: %q", downloadEndpoint)
Expand Down
14 changes: 9 additions & 5 deletions internal/app/machined/pkg/runtime/v1alpha1/platform/metal/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/cosi-project/runtime/pkg/resource"
"github.com/cosi-project/runtime/pkg/safe"
"github.com/cosi-project/runtime/pkg/state"
"github.com/hashicorp/go-multierror"

"github.com/siderolabs/talos/pkg/machinery/constants"
hardwareResource "github.com/siderolabs/talos/pkg/machinery/resources/hardware"
Expand Down Expand Up @@ -78,25 +79,27 @@ func PopulateURLParameters(ctx context.Context, downloadURL string, r state.Stat
return nil
}

var multiErr *multierror.Error

if err := substitute(constants.UUIDKey, getSystemUUID); err != nil {
return "", err
multiErr = multierror.Append(multiErr, err)
}

if err := substitute(constants.SerialNumberKey, getSystemSerialNumber); err != nil {
return "", err
multiErr = multierror.Append(multiErr, err)
}

if err := substitute(constants.MacKey, getMACAddress); err != nil {
return "", err
multiErr = multierror.Append(multiErr, err)
}

if err := substitute(constants.HostnameKey, getHostname); err != nil {
return "", err
multiErr = multierror.Append(multiErr, err)
}

u.RawQuery = values.Encode()

return u.String(), nil
return u.String(), multiErr.ErrorOrNil()
}

//nolint:gocyclo
Expand All @@ -123,6 +126,7 @@ func getResource[T resource.Resource](ctx context.Context, r state.State, namesp
// ok, proceed
case state.Destroyed, state.Bootstrapped:
// ignore
continue
case state.Errored:
return "", event.Error()
}
Expand Down

0 comments on commit 38a5119

Please sign in to comment.