Uki upgrade (#182)

This commit is contained in:
Itxaka
2023-12-18 11:38:26 +01:00
committed by GitHub
parent 2be11b827e
commit 3254b8a36e
10 changed files with 152 additions and 33 deletions

View File

@@ -496,7 +496,7 @@ func NewUkiInstallSpec(cfg *Config) (*v1.InstallUkiSpec, error) {
// Calculate the partitions afterwards so they use the image sizes for the final partition sizes
spec.Partitions.EFI = &v1.Partition{
FilesystemLabel: constants.EfiLabel,
Size: constants.ImgSize, // TODO: Fix this and set proper size based on the source size
Size: constants.ImgSize * 2, // TODO: Fix this and set proper size based on the source size
Name: constants.EfiPartName,
FS: constants.EfiFs,
MountPoint: constants.EfiDir,
@@ -521,7 +521,7 @@ func NewUkiInstallSpec(cfg *Config) (*v1.InstallUkiSpec, error) {
// TODO: Which key to use? install or install-uki?
err := unmarshallFullSpec(cfg, "install", spec)
// TODO: Get the actual source size to calculate the image size and partitions size for at least 3 UKI images
return spec, err
}
@@ -535,6 +535,28 @@ func ReadUkiInstallSpecFromConfig(c *Config) (*v1.InstallUkiSpec, error) {
return installSpec, nil
}
func NewUkiUpgradeSpec(cfg *Config) (*v1.UpgradeUkiSpec, error) {
spec := &v1.UpgradeUkiSpec{}
err := unmarshallFullSpec(cfg, "upgrade", spec)
// Get the actual source size to calculate the image size and partitions size
size, err := GetSourceSize(cfg, spec.Active.Source)
if err != nil {
cfg.Logger.Warnf("Failed to infer size for images: %s", err.Error())
spec.Active.Size = constants.ImgSize
} else {
cfg.Logger.Infof("Setting image size to %dMb", size)
spec.Active.Size = uint(size)
}
spec.EfiPartition = &v1.Partition{
FilesystemLabel: constants.EfiLabel,
FS: constants.EfiFs,
Path: constants.UkiEfiDiskByLabel,
MountPoint: constants.UkiEfiDir,
}
return spec, err
}
// ReadUkiUpgradeFromConfig will return a proper v1.UpgradeUkiSpec based on an agent Config
func ReadUkiUpgradeFromConfig(c *Config) (*v1.UpgradeUkiSpec, error) {
sp, err := ReadSpecFromCloudConfig(c, "upgrade-uki")
@@ -653,8 +675,7 @@ func ReadSpecFromCloudConfig(r *Config, spec string) (v1.Spec, error) {
// TODO: Fill with proper defaults
sp = &v1.ResetUkiSpec{}
case "upgrade-uki":
// TODO: Fill with proper defaults
sp = &v1.UpgradeUkiSpec{}
sp, err = NewUkiUpgradeSpec(r)
default:
return nil, fmt.Errorf("spec not valid: %s", spec)
}