Skip to content

Commit 166e0d5

Browse files
committed
fcos translate.go: add warn on small or constrained root partition
1 parent f8d7a46 commit 166e0d5

File tree

4 files changed

+217
-8
lines changed

4 files changed

+217
-8
lines changed

config/common/errors.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ var (
3737
ErrNodeExists = errors.New("matching filesystem node has existing contents or different type")
3838
ErrNoFilesDir = errors.New("local file paths are relative to a files directory that must be specified with -d/--files-dir")
3939
ErrTreeNotDirectory = errors.New("root of tree must be a directory")
40+
ErrRootTooSmall = errors.New("root should have 8GiB of space available")
41+
ErrRootNotLastPartition = errors.New("root should be last partition number to allow for growth")
4042
ErrTreeNoLocal = errors.New("local is required")
4143

4244
// filesystem nodes

config/fcos/v1_5_exp/translate.go

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,31 @@ func (c Config) ToIgn3_4Unvalidated(options common.TranslateOptions) (types.Conf
6868
return types.Config{}, translate.TranslationSet{}, r
6969
}
7070
r.Merge(c.processBootDevice(&ret, &ts, options))
71+
7172
for i, disk := range ret.Storage.Disks {
72-
// In the boot_device.mirror case, nothing specifies partition numbers
73-
// so match existing partitions only when `wipeTable` is false
74-
if !util.IsTrue(disk.WipeTable) {
75-
for j, partition := range disk.Partitions {
76-
// check for reserved partlabels
77-
if partition.Label != nil {
73+
for p, partition := range disk.Partitions {
74+
if partition.Label != nil {
75+
if *partition.Label == "root" {
76+
if partition.SizeMiB != nil && *partition.SizeMiB < 8192 {
77+
r.AddOnWarn(path.New("json", "storage", "disks", i, "partitions", p, "sizeMiB", *partition.SizeMiB), common.ErrRootTooSmall)
78+
} else {
79+
for _, op := range disk.Partitions {
80+
if op.Number > partition.Number {
81+
if op.StartMiB == nil {
82+
r.AddOnWarn(path.New("json", "storage", "disks", i, "partitions", p, "number", partition.Number), common.ErrRootNotLastPartition)
83+
}
84+
}
85+
}
86+
}
87+
}
88+
// Don't warn if wipeTable is set, matching later spec versions
89+
if !util.IsTrue(disk.WipeTable) {
90+
// check for reserved partlabels
7891
if (*partition.Label == "BIOS-BOOT" && partition.Number != 1) || (*partition.Label == "PowerPC-PReP-boot" && partition.Number != 1) || (*partition.Label == "EFI-SYSTEM" && partition.Number != 2) || (*partition.Label == "boot" && partition.Number != 3) || (*partition.Label == "root" && partition.Number != 4) {
79-
r.AddOnWarn(path.New("json", "storage", "disks", i, "partitions", j, "label"), common.ErrWrongPartitionNumber)
92+
r.AddOnWarn(path.New("json", "storage", "disks", i, "partitions", p, "label"), common.ErrWrongPartitionNumber)
8093
}
8194
}
95+
8296
}
8397
}
8498
}

config/fcos/v1_5_exp/translate_test.go

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,198 @@ func TestTranslateBootDevice(t *testing.T) {
146146
},
147147
},
148148
},
149+
// root partition too small
150+
{
151+
Config{
152+
Config: base.Config{
153+
Storage: base.Storage{
154+
Disks: []base.Disk{
155+
{
156+
Device: "/dev/vda",
157+
Partitions: []base.Partition{
158+
{
159+
Label: util.StrToPtr("root"),
160+
SizeMiB: util.IntToPtr(500),
161+
Resize: util.BoolToPtr(true),
162+
Number: 4,
163+
},
164+
{
165+
Label: util.StrToPtr("var-home"),
166+
SizeMiB: util.IntToPtr(10240),
167+
},
168+
},
169+
},
170+
},
171+
Filesystems: []base.Filesystem{
172+
{
173+
Device: "/dev/disk/by-partlabel/var-home",
174+
Format: util.StrToPtr("xfs"),
175+
Path: util.StrToPtr("/var/home"),
176+
Label: util.StrToPtr("var-home"),
177+
WipeFilesystem: util.BoolToPtr(false),
178+
},
179+
},
180+
},
181+
},
182+
},
183+
types.Config{
184+
Ignition: types.Ignition{
185+
Version: "3.4.0-experimental",
186+
},
187+
Storage: types.Storage{
188+
Disks: []types.Disk{
189+
{
190+
Device: "/dev/vda",
191+
Partitions: []types.Partition{
192+
{
193+
Label: util.StrToPtr("root"),
194+
SizeMiB: util.IntToPtr(500),
195+
Resize: util.BoolToPtr(true),
196+
Number: 4,
197+
},
198+
{
199+
Label: util.StrToPtr("var-home"),
200+
SizeMiB: util.IntToPtr(10240),
201+
},
202+
},
203+
},
204+
},
205+
Filesystems: []types.Filesystem{
206+
{
207+
Device: "/dev/disk/by-partlabel/var-home",
208+
Format: util.StrToPtr("xfs"),
209+
Path: util.StrToPtr("/var/home"),
210+
Label: util.StrToPtr("var-home"),
211+
WipeFilesystem: util.BoolToPtr(false),
212+
},
213+
},
214+
},
215+
},
216+
[]translate.Translation{
217+
{path.New("yaml", "version"), path.New("json", "ignition", "version")},
218+
{path.New("yaml", "storage", "disks", 0, "partitions", 0, "label"), path.New("json", "storage", "disks", 0, "partitions", 0, "label")},
219+
{path.New("yaml", "storage", "disks", 0, "partitions", 0, "size_mib"), path.New("json", "storage", "disks", 0, "partitions", 0, "sizeMiB")},
220+
{path.New("yaml", "storage", "disks", 0, "partitions", 0, "resize"), path.New("json", "storage", "disks", 0, "partitions", 0, "resize")},
221+
{path.New("yaml", "storage", "disks", 0, "partitions", 1, "label"), path.New("json", "storage", "disks", 0, "partitions", 1, "label")},
222+
{path.New("yaml", "storage", "disks", 0, "partitions", 1, "size_mib"), path.New("json", "storage", "disks", 0, "partitions", 1, "sizeMiB")},
223+
{path.New("yaml", "storage", "disks", 0, "partitions", 0), path.New("json", "storage", "disks", 0, "partitions", 0)},
224+
{path.New("yaml", "storage", "disks", 0), path.New("json", "storage", "disks", 0)},
225+
{path.New("yaml", "storage", "filesystems", 0, "device"), path.New("json", "storage", "filesystems", 0, "device")},
226+
{path.New("yaml", "storage", "filesystems", 0, "format"), path.New("json", "storage", "filesystems", 0, "format")},
227+
{path.New("yaml", "storage", "filesystems", 0, "path"), path.New("json", "storage", "filesystems", 0, "path")},
228+
{path.New("yaml", "storage", "filesystems", 0, "label"), path.New("json", "storage", "filesystems", 0, "label")},
229+
{path.New("yaml", "storage", "filesystems", 0, "wipe_filesystem"), path.New("json", "storage", "filesystems", 0, "wipeFilesystem")},
230+
{path.New("yaml", "storage", "filesystems", 0), path.New("json", "storage", "filesystems", 0)},
231+
{path.New("yaml", "storage", "filesystems"), path.New("json", "storage", "filesystems")},
232+
{path.New("yaml", "storage"), path.New("json", "storage")},
233+
},
234+
report.Report{
235+
Entries: []report.Entry{
236+
{
237+
Kind: report.Warn,
238+
Message: common.ErrRootTooSmall.Error(),
239+
Context: path.New("json", "storage", "disks", 0, "partitions", 0, "sizeMiB", 500),
240+
},
241+
},
242+
},
243+
},
244+
// root partition constrained
245+
{
246+
Config{
247+
Config: base.Config{
248+
Storage: base.Storage{
249+
Disks: []base.Disk{
250+
{
251+
Device: "/dev/vda",
252+
Partitions: []base.Partition{
253+
{
254+
Label: util.StrToPtr("root"),
255+
SizeMiB: util.IntToPtr(10000),
256+
Resize: util.BoolToPtr(true),
257+
Number: 4,
258+
},
259+
{
260+
Label: util.StrToPtr("var-home"),
261+
SizeMiB: util.IntToPtr(10240),
262+
Number: 5,
263+
},
264+
},
265+
},
266+
},
267+
Filesystems: []base.Filesystem{
268+
{
269+
Device: "/dev/disk/by-partlabel/var-home",
270+
Format: util.StrToPtr("xfs"),
271+
Path: util.StrToPtr("/var/home"),
272+
Label: util.StrToPtr("var-home"),
273+
WipeFilesystem: util.BoolToPtr(false),
274+
},
275+
},
276+
},
277+
},
278+
},
279+
types.Config{
280+
Ignition: types.Ignition{
281+
Version: "3.4.0-experimental",
282+
},
283+
Storage: types.Storage{
284+
Disks: []types.Disk{
285+
{
286+
Device: "/dev/vda",
287+
Partitions: []types.Partition{
288+
{
289+
Label: util.StrToPtr("root"),
290+
SizeMiB: util.IntToPtr(10000),
291+
Resize: util.BoolToPtr(true),
292+
Number: 4,
293+
},
294+
{
295+
Label: util.StrToPtr("var-home"),
296+
SizeMiB: util.IntToPtr(10240),
297+
Number: 5,
298+
},
299+
},
300+
},
301+
},
302+
Filesystems: []types.Filesystem{
303+
{
304+
Device: "/dev/disk/by-partlabel/var-home",
305+
Format: util.StrToPtr("xfs"),
306+
Path: util.StrToPtr("/var/home"),
307+
Label: util.StrToPtr("var-home"),
308+
WipeFilesystem: util.BoolToPtr(false),
309+
},
310+
},
311+
},
312+
},
313+
[]translate.Translation{
314+
{path.New("yaml", "version"), path.New("json", "ignition", "version")},
315+
{path.New("yaml", "storage", "disks", 0, "partitions", 0, "label"), path.New("json", "storage", "disks", 0, "partitions", 0, "label")},
316+
{path.New("yaml", "storage", "disks", 0, "partitions", 0, "size_mib"), path.New("json", "storage", "disks", 0, "partitions", 0, "sizeMiB")},
317+
{path.New("yaml", "storage", "disks", 0, "partitions", 0, "resize"), path.New("json", "storage", "disks", 0, "partitions", 0, "resize")},
318+
{path.New("yaml", "storage", "disks", 0, "partitions", 1, "label"), path.New("json", "storage", "disks", 0, "partitions", 1, "label")},
319+
{path.New("yaml", "storage", "disks", 0, "partitions", 1, "size_mib"), path.New("json", "storage", "disks", 0, "partitions", 1, "sizeMiB")},
320+
{path.New("yaml", "storage", "disks", 0, "partitions", 0), path.New("json", "storage", "disks", 0, "partitions", 0)},
321+
{path.New("yaml", "storage", "disks", 0), path.New("json", "storage", "disks", 0)},
322+
{path.New("yaml", "storage", "filesystems", 0, "device"), path.New("json", "storage", "filesystems", 0, "device")},
323+
{path.New("yaml", "storage", "filesystems", 0, "format"), path.New("json", "storage", "filesystems", 0, "format")},
324+
{path.New("yaml", "storage", "filesystems", 0, "path"), path.New("json", "storage", "filesystems", 0, "path")},
325+
{path.New("yaml", "storage", "filesystems", 0, "label"), path.New("json", "storage", "filesystems", 0, "label")},
326+
{path.New("yaml", "storage", "filesystems", 0, "wipe_filesystem"), path.New("json", "storage", "filesystems", 0, "wipeFilesystem")},
327+
{path.New("yaml", "storage", "filesystems", 0), path.New("json", "storage", "filesystems", 0)},
328+
{path.New("yaml", "storage", "filesystems"), path.New("json", "storage", "filesystems")},
329+
{path.New("yaml", "storage"), path.New("json", "storage")},
330+
},
331+
report.Report{
332+
Entries: []report.Entry{
333+
{
334+
Kind: report.Warn,
335+
Message: common.ErrRootNotLastPartition.Error(),
336+
Context: path.New("json", "storage", "disks", 0, "partitions", 0, "number", 4),
337+
},
338+
},
339+
},
340+
},
149341
// LUKS, x86_64
150342
{
151343
Config{

docs/release-notes.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ nav_order: 9
1717

1818

1919
### Misc. changes
20-
20+
- Warn on root size is too small _(fcos)_
21+
- Warn on root constrained by another partition _(fcos)_
2122

2223
### Docs changes
2324

0 commit comments

Comments
 (0)