mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-09-25 05:09:47 +00:00
Unmarshal yaml after auto size calculation and fix tests
because we want the user's preferences to be applied last, thus overriding whatever calculations we may do automatically. Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me>
This commit is contained in:
@@ -60,6 +60,7 @@ func NewInstallSpec(cfg *Config) (*v1.InstallSpec, error) {
|
||||
activeImg.File = filepath.Join(constants.StateDir, "cOS", constants.ActiveImgFile)
|
||||
activeImg.FS = constants.LinuxImgFs
|
||||
activeImg.MountPoint = constants.ActiveDir
|
||||
|
||||
if isoRootExists {
|
||||
activeImg.Source = v1.NewDirSrc(constants.IsoBaseTree)
|
||||
} else {
|
||||
@@ -98,11 +99,6 @@ func NewInstallSpec(cfg *Config) (*v1.InstallSpec, error) {
|
||||
Passive: passiveImg,
|
||||
}
|
||||
|
||||
err := unmarshallFullSpec(cfg, "install", spec)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed unmarshalling the full spec: %w", err)
|
||||
}
|
||||
|
||||
// Get the actual source size to calculate the image size and partitions size
|
||||
size, err := GetSourceSize(cfg, spec.Active.Source)
|
||||
if err != nil {
|
||||
@@ -114,6 +110,11 @@ func NewInstallSpec(cfg *Config) (*v1.InstallSpec, error) {
|
||||
spec.Recovery.Size = uint(size)
|
||||
}
|
||||
|
||||
err = unmarshallFullSpec(cfg, "install", spec)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed unmarshalling the full spec: %w", err)
|
||||
}
|
||||
|
||||
// Calculate the partitions afterwards so they use the image sizes for the final partition sizes
|
||||
spec.Partitions = NewInstallElementalPartitions(spec)
|
||||
|
||||
@@ -270,13 +271,13 @@ func NewUpgradeSpec(cfg *Config) (*v1.UpgradeSpec, error) {
|
||||
State: installState,
|
||||
}
|
||||
|
||||
setUpgradeSourceSize(cfg, spec)
|
||||
|
||||
err = unmarshallFullSpec(cfg, "upgrade", spec)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed unmarshalling the full spec: %w", err)
|
||||
}
|
||||
|
||||
setUpgradeSourceSize(cfg, spec)
|
||||
|
||||
return spec, nil
|
||||
}
|
||||
|
||||
@@ -429,11 +430,6 @@ func NewResetSpec(cfg *Config) (*v1.ResetSpec, error) {
|
||||
State: installState,
|
||||
}
|
||||
|
||||
err = unmarshallFullSpec(cfg, "reset", spec)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed unmarshalling the full spec: %w", err)
|
||||
}
|
||||
|
||||
// Get the actual source size to calculate the image size and partitions size
|
||||
size, err := GetSourceSize(cfg, spec.Active.Source)
|
||||
if err != nil {
|
||||
@@ -444,6 +440,11 @@ func NewResetSpec(cfg *Config) (*v1.ResetSpec, error) {
|
||||
spec.Passive.Size = uint(size)
|
||||
}
|
||||
|
||||
err = unmarshallFullSpec(cfg, "reset", spec)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed unmarshalling the full spec: %w", err)
|
||||
}
|
||||
|
||||
return spec, nil
|
||||
}
|
||||
|
||||
|
@@ -463,6 +463,8 @@ upgrade:
|
||||
recovery: true
|
||||
system:
|
||||
uri: docker:test/image:latest
|
||||
recovery-system:
|
||||
uri: docker:test/image:latest
|
||||
cloud-init-paths:
|
||||
- /what
|
||||
`)
|
||||
@@ -502,6 +504,12 @@ cloud-init-paths:
|
||||
ghwTest = v1mock.GhwMock{}
|
||||
ghwTest.AddDisk(mainDisk)
|
||||
ghwTest.CreateDevices()
|
||||
|
||||
fs, cleanup, err = vfst.NewTestFS(nil)
|
||||
err = fsutils.MkdirAll(fs, filepath.Dir(constants.IsoBaseTree), constants.DirPerm)
|
||||
Expect(err).ShouldNot(HaveOccurred())
|
||||
_, err = fs.Create(constants.IsoBaseTree)
|
||||
Expect(err).ShouldNot(HaveOccurred())
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
@@ -509,7 +517,11 @@ cloud-init-paths:
|
||||
ghwTest.Clean()
|
||||
})
|
||||
It("Reads properly the cloud config for install", func() {
|
||||
cfg, err := config.Scan(collector.Directories([]string{dir}...), collector.NoLogs)
|
||||
cfg, err := config.Scan(collector.Directories([]string{dir}...),
|
||||
collector.NoLogs,
|
||||
)
|
||||
cfg.Fs = fs
|
||||
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
// Once we got the cfg override the fs to our test fs
|
||||
cfg.Runner = runner
|
||||
|
Reference in New Issue
Block a user