Skip to content

Commit

Permalink
Remove unecessary assignments and add NoFormat to UKI
Browse files Browse the repository at this point in the history
Signed-off-by: Dimitris Karakasilis <[email protected]>
  • Loading branch information
jimmykarily committed Apr 8, 2024
1 parent a9f3f8c commit 7ece12a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 39 deletions.
5 changes: 3 additions & 2 deletions pkg/action/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ func (i InstallAction) Run() (err error) {
}
}

// Check no-format flag
if i.spec.NoFormat {
i.cfg.Logger.Infof("NoFormat is true, skipping format and partitioning")
// Check force flag against current device
Expand All @@ -153,7 +152,9 @@ func (i InstallAction) Run() (err error) {
return fmt.Errorf("use `force` flag to run an installation over the current running deployment")
}

if i.spec.Target == "" {
if i.spec.Target == "" || i.spec.Target == "auto" {
// This needs to run after the pre-install stage to give the user the
// opportunity to prepare the target disk in the pre-install stage.
device, err := config.DetectPreConfiguredDevice(i.cfg.Logger)
if err != nil {
return fmt.Errorf("no target device specified and no device found: %s", err)
Expand Down
29 changes: 3 additions & 26 deletions pkg/config/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,26 +567,10 @@ func ReadInstallSpecFromConfig(c *Config) (*v1.InstallSpec, error) {
}
installSpec := sp.(*v1.InstallSpec)

// TODO: Do the same for UKI
if installSpec.Target == "" || installSpec.Target == "auto" {
if (installSpec.Target == "" || installSpec.Target == "auto") && !installSpec.NoFormat {
installSpec.Target = detectLargestDevice()
}

if installSpec.NoFormat {
installSpec.Target = ""
}

// Workaround!
// If we set the "auto" for the device in the cloudconfig the value will be proper in the Config.Install.Device
// But on the cloud-config it will still appear as "auto" as we dont modify that
// Unfortunately as we load the full cloud-config and unmarshall it into our spec, we cannot infer from there
// What device was choosen, and re-choosing again could lead to different results
// So instead we do the check here and override the installSpec.Target with the Config.Install.Device
// as its the soonest we have access to both
if installSpec.Target == "auto" {
installSpec.Target = c.Install.Device
}

return installSpec, nil
}

Expand Down Expand Up @@ -678,15 +662,8 @@ func ReadUkiInstallSpecFromConfig(c *Config) (*v1.InstallUkiSpec, error) {
}
installSpec := sp.(*v1.InstallUkiSpec)

// Workaround!
// If we set the "auto" for the device in the cloudconfig the value will be proper in the Config.Install.Device
// But on the cloud-config it will still appear as "auto" as we dont modify that
// Unfortunately as we load the full cloud-config and unmarshall it into our spec, we cannot infer from there
// What device was choosen, and re-choosing again could lead to different results
// So instead we do the check here and override the installSpec.Target with the Config.Install.Device
// as its the soonest we have access to both
if installSpec.Target == "auto" {
installSpec.Target = c.Install.Device
if (installSpec.Target == "" || installSpec.Target == "auto") && !installSpec.NoFormat {
installSpec.Target = detectLargestDevice()
}

return installSpec, nil
Expand Down
1 change: 1 addition & 0 deletions pkg/types/v1/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ type InstallUkiSpec struct {
PowerOff bool `yaml:"poweroff,omitempty" mapstructure:"poweroff"`
Partitions ElementalPartitions `yaml:"partitions,omitempty" mapstructure:"partitions"`
ExtraPartitions PartitionList `yaml:"extra-partitions,omitempty" mapstructure:"extra-partitions"`
NoFormat bool `yaml:"no-format,omitempty" mapstructure:"no-format"`
CloudInit []string `yaml:"cloud-init,omitempty" mapstructure:"cloud-init"`
SkipEntries []string `yaml:"skip-entries,omitempty" mapstructure:"skip-entries"`
}
Expand Down
37 changes: 26 additions & 11 deletions pkg/uki/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,32 @@ func (i *InstallAction) Run() (err error) {
i.cfg.Logger.Errorf("running kairos-uki-install.pre hook script: %s", err.Error())
}

// Deactivate any active volume on target
err = e.DeactivateDevices()
if err != nil {
i.cfg.Logger.Errorf("deactivating devices: %s", err.Error())
return err
}
// Partition device
err = e.PartitionAndFormatDevice(i.spec)
if err != nil {
i.cfg.Logger.Errorf("partitioning and formating devices: %s", err.Error())
return err
if i.spec.NoFormat {
i.cfg.Logger.Infof("NoFormat is true, skipping format and partitioning")
if i.spec.Target == "" || i.spec.Target == "auto" {
// This needs to run after the pre-install stage to give the user the
// opportunity to prepare the target disk in the pre-install stage.
device, err := config.DetectPreConfiguredDevice(i.cfg.Logger)
if err != nil {
return fmt.Errorf("no target device specified and no device found: %s", err)
}
i.cfg.Logger.Infof("No target device specified, using pre-configured device: %s", device)
i.spec.Target = device
}
} else {
// Deactivate any active volume on target
err = e.DeactivateDevices()
if err != nil {
i.cfg.Logger.Errorf("deactivating devices: %s", err.Error())
return err
}

// Partition device
err = e.PartitionAndFormatDevice(i.spec)
if err != nil {
i.cfg.Logger.Errorf("partitioning and formating devices: %s", err.Error())
return err
}
}

err = e.MountPartitions(i.spec.GetPartitions().PartitionsByMountPoint(false))
Expand Down

0 comments on commit 7ece12a

Please sign in to comment.