diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index d005cf03..ce2cd1b8 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -17,7 +17,6 @@ package config_test import ( "fmt" - "github.com/kairos-io/kairos-sdk/collector" "path/filepath" "reflect" "strings" @@ -28,8 +27,10 @@ import ( v1mocks "github.com/kairos-io/kairos-agent/v2/tests/mocks" "github.com/twpayne/go-vfs/v4" "github.com/twpayne/go-vfs/v4/vfst" + "gopkg.in/yaml.v3" . "github.com/kairos-io/kairos-agent/v2/pkg/config" + "github.com/kairos-io/kairos-sdk/collector" . "github.com/kairos-io/kairos-sdk/schema" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -114,6 +115,57 @@ var _ = Describe("Schema", func() { structFieldsContainedInOtherStruct(Bundle{}, BundleSchema{}) }) }) + + Describe("Install unmarshall for payloads", func() { + It("produces a yaml without empty fields", func() { + wants := `install: + poweroff: true + bind_mounts: + - /var/lib/ceph + - /var/lib/osd + partitions: + oem: + size: 5120 + fs: ext4 + system: + size: 8192 + recovery-system: + size: 10000 + passive: + size: 8192 +` + config := Config{ + Install: &Install{ + Poweroff: true, + BindMounts: []string{ + "/var/lib/ceph", + "/var/lib/osd", + }, + Active: v1.Image{ + Size: 8192, + }, + Passive: v1.Image{ + Size: 8192, + }, + Recovery: v1.Image{ + Size: 10000, + }, + Partitions: v1.ElementalPartitions{ + OEM: &v1.Partition{ + Size: 5120, + FS: "ext4", + }, + }, + }, + } + + got, err := yaml.Marshal(config) + Expect(Expect(err).NotTo(HaveOccurred())) + + Expect(string(got)).To(Equal(wants)) + }) + }) + Describe("Write and load installation state", func() { var config *Config var runner *v1mocks.FakeRunner diff --git a/pkg/types/v1/config.go b/pkg/types/v1/config.go index d16bf894..c4fbe73a 100644 --- a/pkg/types/v1/config.go +++ b/pkg/types/v1/config.go @@ -218,14 +218,14 @@ func (r *EmptySpec) ShouldShutdown() bool { return false } // Partition struct represents a partition with its commonly configurable values, size in MiB type Partition struct { - Name string + Name string `yaml:"-"` FilesystemLabel string `yaml:"label,omitempty" mapstructure:"label"` Size uint `yaml:"size,omitempty" mapstructure:"size"` FS string `yaml:"fs,omitempty" mapstrcuture:"fs"` Flags []string `yaml:"flags,omitempty" mapstrcuture:"flags"` - MountPoint string - Path string - Disk string + MountPoint string `yaml:"-"` + Path string `yaml:"-"` + Disk string `yaml:"-"` } type PartitionList []*Partition @@ -261,8 +261,8 @@ func (pl PartitionList) GetByLabel(label string) *Partition { } type ElementalPartitions struct { - BIOS *Partition - EFI *Partition + BIOS *Partition `yaml:"-"` + EFI *Partition `yaml:"-"` OEM *Partition `yaml:"oem,omitempty" mapstructure:"oem"` Recovery *Partition `yaml:"recovery,omitempty" mapstructure:"recovery"` State *Partition `yaml:"state,omitempty" mapstructure:"state"` @@ -434,13 +434,13 @@ func (ep ElementalPartitions) PartitionsByMountPoint(descending bool, excludes . // Image struct represents a file system image with its commonly configurable values, size in MiB type Image struct { - File string + File string `yaml:"-"` Label string `yaml:"label,omitempty" mapstructure:"label"` Size uint `yaml:"size,omitempty" mapstructure:"size"` FS string `yaml:"fs,omitempty" mapstructure:"fs"` Source *ImageSource `yaml:"uri,omitempty" mapstructure:"uri"` - MountPoint string - LoopDevice string + MountPoint string `yaml:"-"` + LoopDevice string `yaml:"-"` } // InstallState tracks the installation data of the whole system