Files
immucore/internal/utils/cloudinit.go
Itxaka 1d36b86c48 fix: Correct typos in kernel driver constants (#559)
* fix: Correct typos in kernel driver constants

- Fixed typos in driver names:
  - Changed `ahcpi-plaftorm` to `ahcpi-platform`
  - Changed `libahcpi-platform` to `libahci-platform`
- Added new drivers for Thor support:
  - `tegra-bpmp`
  - `tegra-bpmp-thermal`
  - `phy-tegra194-p2u`
  - `pcie-tegra264`
- Updated modprobe command to include verbose output for better debugging

Signed-off-by: Itxaka <itxaka@kairos.io>

* fix: Update error handling and dependencies

- Refactored error handling in `onlyYAMLPartialErrors` to use `errors.AsType` for better type assertion.
- Updated disk retrieval in `dag_normal_boot.go` to use a new logger instance.
- Modified `CreateDevices` in `ghw_mock.go` to use context with value for `ghw.chroot`.
- Bumped dependencies in `go.mod` to latest versions for improved stability and features.

Signed-off-by: Itxaka <itxaka@kairos.io>

* Revert ghw change

Signed-off-by: Itxaka <itxaka@kairos.io>

* go mod tidy

Signed-off-by: Itxaka <itxaka@kairos.io>

---------

Signed-off-by: Itxaka <itxaka@kairos.io>
2026-05-12 14:09:09 +02:00

99 lines
2.8 KiB
Go

package utils
import (
"errors"
"fmt"
"os"
"github.com/hashicorp/go-multierror"
"github.com/kairos-io/immucore/internal/constants"
"github.com/mudler/yip/pkg/console"
"github.com/mudler/yip/pkg/executor"
"github.com/mudler/yip/pkg/schema"
"github.com/twpayne/go-vfs/v4"
"gopkg.in/yaml.v3"
)
func RunStage(stage string) error {
var allErrors, err error
var cmdLineYipURI string
// Set debug logger
yip := executor.NewExecutor(executor.WithLogger(KLog))
c := ImmucoreConsole{}
stageBefore := fmt.Sprintf("%s.before", stage)
stageAfter := fmt.Sprintf("%s.after", stage)
// Deprecated? Is nowhere on the docs....
cosSetup := ReadCMDLineArg("cos.setup")
if len(cosSetup) > 1 {
cmdLineYipURI = cosSetup[1]
}
// Run all stages for each of the default cloud config paths + extra cloud config paths
for _, s := range []string{stageBefore, stage, stageAfter} {
err = yip.Run(s, vfs.OSFS, c, constants.GetCloudInitPaths()...)
if err != nil {
allErrors = multierror.Append(allErrors, err)
}
}
// Run the stages if cmdline contains the cos.setup stanza
if cmdLineYipURI != "" {
cmdLineArgs := []string{cmdLineYipURI}
for _, s := range []string{stageBefore, stage, stageAfter} {
err = yip.Run(s, vfs.OSFS, c, cmdLineArgs...)
if err != nil {
allErrors = multierror.Append(allErrors, err)
}
}
}
// Enable dot notation
// This helps to parse the cmdline in dot notation (stage.name.command) from cmdline
// IMHO this should be deprecated, plenty of other places to set the stages config
yip.Modifier(schema.DotNotationModifier)
// Read and parse the cmdline looking for yip config in there
cmdLineOut, err := os.ReadFile("/proc/cmdline")
if err == nil {
for _, s := range []string{stageBefore, stage, stageAfter} {
err = yip.Run(s, vfs.OSFS, console.NewStandardConsole(), string(cmdLineOut))
if err != nil {
allErrors = checkYAMLError(allErrors, err)
}
}
}
// Set back the modifier to nil
yip.Modifier(nil)
// Not doing anything with the errors yet, need to know which ones are permissible (no metadata, marshall errors, etc..)
return nil
}
func onlyYAMLPartialErrors(er error) bool {
if merr, ok := errors.AsType[*multierror.Error](er); ok {
for _, e := range merr.Errors {
// Skip partial unmarshalling errors
// TypeError is throwed when it is possible to read the yaml partially
// XXX: Seems errors.Is and errors.As are not working as expected here.
// Even if the underlying type is yaml.TypeError.
var d *yaml.TypeError
if fmt.Sprintf("%T", e) != fmt.Sprintf("%T", d) {
return false
}
}
}
return true
}
func checkYAMLError(allErrors, err error) error {
if !onlyYAMLPartialErrors(err) {
// here we absorb errors only if are related to YAML unmarshalling
// As cmdline is parsed out as a yaml file
allErrors = multierror.Append(allErrors, err)
}
return allErrors
}