From 6dfa63364cdce5d9d30629163a9a5e21f6e30934 Mon Sep 17 00:00:00 2001 From: Sohan Kunkerkar Date: Fri, 10 Sep 2021 14:59:04 -0400 Subject: [PATCH] config/fcos: warn if the partition number for root isn't correct Fixes https://github.com/coreos/butane/issues/243 This change warns if the partition number for the root label is not specified or wrongly mentioned. --- config/common/errors.go | 3 +++ config/fcos/v1_3/translate.go | 7 +++++++ config/fcos/v1_4/translate.go | 7 +++++++ config/fcos/v1_5_exp/translate.go | 7 +++++++ 4 files changed, 24 insertions(+) diff --git a/config/common/errors.go b/config/common/errors.go index ffcc37be..63c9aece 100644 --- a/config/common/errors.go +++ b/config/common/errors.go @@ -47,6 +47,9 @@ var ( ErrUnknownBootDeviceLayout = errors.New("layout must be one of: aarch64, ppc64le, x86_64") ErrTooFewMirrorDevices = errors.New("mirroring requires at least two devices") + // partition + ErrWrongPartitionNumberForRoot = errors.New("new partition using reserved label \"root\"") + // MachineConfigs ErrFieldElided = errors.New("field ignored in raw mode") ErrNameRequired = errors.New("metadata.name is required") diff --git a/config/fcos/v1_3/translate.go b/config/fcos/v1_3/translate.go index 186a99f8..fca0cd82 100644 --- a/config/fcos/v1_3/translate.go +++ b/config/fcos/v1_3/translate.go @@ -64,6 +64,13 @@ func (c Config) ToIgn3_2Unvalidated(options common.TranslateOptions) (types.Conf return types.Config{}, translate.TranslationSet{}, r } r.Merge(c.processBootDevice(&ret, &ts, options)) + for _, disk := range ret.Storage.Disks { + for _, partition := range disk.Partitions { + if *partition.Label == "root" && partition.Number != 4 { + r.AddOnWarn(path.New("json", "fcos", "partition"), common.ErrWrongPartitionNumberForRoot) + } + } + } return ret, ts, r } diff --git a/config/fcos/v1_4/translate.go b/config/fcos/v1_4/translate.go index 3c0d7910..8ae7ec52 100644 --- a/config/fcos/v1_4/translate.go +++ b/config/fcos/v1_4/translate.go @@ -64,6 +64,13 @@ func (c Config) ToIgn3_3Unvalidated(options common.TranslateOptions) (types.Conf return types.Config{}, translate.TranslationSet{}, r } r.Merge(c.processBootDevice(&ret, &ts, options)) + for _, disk := range ret.Storage.Disks { + for _, partition := range disk.Partitions { + if *partition.Label == "root" && partition.Number != 4 { + r.AddOnWarn(path.New("json", "fcos", "partition"), common.ErrWrongPartitionNumberForRoot) + } + } + } return ret, ts, r } diff --git a/config/fcos/v1_5_exp/translate.go b/config/fcos/v1_5_exp/translate.go index 661e68a7..2f35a622 100644 --- a/config/fcos/v1_5_exp/translate.go +++ b/config/fcos/v1_5_exp/translate.go @@ -64,6 +64,13 @@ func (c Config) ToIgn3_4Unvalidated(options common.TranslateOptions) (types.Conf return types.Config{}, translate.TranslationSet{}, r } r.Merge(c.processBootDevice(&ret, &ts, options)) + for _, disk := range ret.Storage.Disks { + for _, partition := range disk.Partitions { + if *partition.Label == "root" && partition.Number != 4 { + r.AddOnWarn(path.New("json", "fcos", "partition"), common.ErrWrongPartitionNumberForRoot) + } + } + } return ret, ts, r }