mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-08-28 12:51:42 +00:00
Prevent unwanted yaml fields to be marshalled (#323)
Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com>
This commit is contained in:
parent
fa7b95bee2
commit
d485910de1
@ -17,7 +17,6 @@ package config_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/kairos-io/kairos-sdk/collector"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
@ -28,8 +27,10 @@ import (
|
|||||||
v1mocks "github.com/kairos-io/kairos-agent/v2/tests/mocks"
|
v1mocks "github.com/kairos-io/kairos-agent/v2/tests/mocks"
|
||||||
"github.com/twpayne/go-vfs/v4"
|
"github.com/twpayne/go-vfs/v4"
|
||||||
"github.com/twpayne/go-vfs/v4/vfst"
|
"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-agent/v2/pkg/config"
|
||||||
|
"github.com/kairos-io/kairos-sdk/collector"
|
||||||
. "github.com/kairos-io/kairos-sdk/schema"
|
. "github.com/kairos-io/kairos-sdk/schema"
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
@ -114,6 +115,57 @@ var _ = Describe("Schema", func() {
|
|||||||
structFieldsContainedInOtherStruct(Bundle{}, BundleSchema{})
|
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() {
|
Describe("Write and load installation state", func() {
|
||||||
var config *Config
|
var config *Config
|
||||||
var runner *v1mocks.FakeRunner
|
var runner *v1mocks.FakeRunner
|
||||||
|
@ -218,14 +218,14 @@ func (r *EmptySpec) ShouldShutdown() bool { return false }
|
|||||||
|
|
||||||
// Partition struct represents a partition with its commonly configurable values, size in MiB
|
// Partition struct represents a partition with its commonly configurable values, size in MiB
|
||||||
type Partition struct {
|
type Partition struct {
|
||||||
Name string
|
Name string `yaml:"-"`
|
||||||
FilesystemLabel string `yaml:"label,omitempty" mapstructure:"label"`
|
FilesystemLabel string `yaml:"label,omitempty" mapstructure:"label"`
|
||||||
Size uint `yaml:"size,omitempty" mapstructure:"size"`
|
Size uint `yaml:"size,omitempty" mapstructure:"size"`
|
||||||
FS string `yaml:"fs,omitempty" mapstrcuture:"fs"`
|
FS string `yaml:"fs,omitempty" mapstrcuture:"fs"`
|
||||||
Flags []string `yaml:"flags,omitempty" mapstrcuture:"flags"`
|
Flags []string `yaml:"flags,omitempty" mapstrcuture:"flags"`
|
||||||
MountPoint string
|
MountPoint string `yaml:"-"`
|
||||||
Path string
|
Path string `yaml:"-"`
|
||||||
Disk string
|
Disk string `yaml:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type PartitionList []*Partition
|
type PartitionList []*Partition
|
||||||
@ -261,8 +261,8 @@ func (pl PartitionList) GetByLabel(label string) *Partition {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ElementalPartitions struct {
|
type ElementalPartitions struct {
|
||||||
BIOS *Partition
|
BIOS *Partition `yaml:"-"`
|
||||||
EFI *Partition
|
EFI *Partition `yaml:"-"`
|
||||||
OEM *Partition `yaml:"oem,omitempty" mapstructure:"oem"`
|
OEM *Partition `yaml:"oem,omitempty" mapstructure:"oem"`
|
||||||
Recovery *Partition `yaml:"recovery,omitempty" mapstructure:"recovery"`
|
Recovery *Partition `yaml:"recovery,omitempty" mapstructure:"recovery"`
|
||||||
State *Partition `yaml:"state,omitempty" mapstructure:"state"`
|
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
|
// Image struct represents a file system image with its commonly configurable values, size in MiB
|
||||||
type Image struct {
|
type Image struct {
|
||||||
File string
|
File string `yaml:"-"`
|
||||||
Label string `yaml:"label,omitempty" mapstructure:"label"`
|
Label string `yaml:"label,omitempty" mapstructure:"label"`
|
||||||
Size uint `yaml:"size,omitempty" mapstructure:"size"`
|
Size uint `yaml:"size,omitempty" mapstructure:"size"`
|
||||||
FS string `yaml:"fs,omitempty" mapstructure:"fs"`
|
FS string `yaml:"fs,omitempty" mapstructure:"fs"`
|
||||||
Source *ImageSource `yaml:"uri,omitempty" mapstructure:"uri"`
|
Source *ImageSource `yaml:"uri,omitempty" mapstructure:"uri"`
|
||||||
MountPoint string
|
MountPoint string `yaml:"-"`
|
||||||
LoopDevice string
|
LoopDevice string `yaml:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// InstallState tracks the installation data of the whole system
|
// InstallState tracks the installation data of the whole system
|
||||||
|
Loading…
Reference in New Issue
Block a user