1
0
mirror of https://github.com/kairos-io/kairos-agent.git synced 2025-05-12 10:24:23 +00:00

Prevent unwanted yaml fields to be marshalled ()

Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com>
This commit is contained in:
Mauro Morales 2024-05-07 11:38:57 +02:00 committed by GitHub
parent fa7b95bee2
commit d485910de1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 62 additions and 10 deletions
pkg

View File

@ -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

View File

@ -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