MCPcopy
hub / github.com/runfinch/finch / validate

Function validate

pkg/config/validate_darwin.go:17–84  ·  view source on GitHub ↗
(cfg *Finch, log flog.Logger, systemDeps LoadSystemDeps, mem fmemory.Memory)

Source from the content-addressed store, hash-verified

15)
16
17func validate(cfg *Finch, log flog.Logger, systemDeps LoadSystemDeps, mem fmemory.Memory) error {
18 if *cfg.CPUs <= 0 {
19 return fmt.Errorf(
20 "specified number of CPUs (%d) must be greater than 0",
21 *cfg.CPUs,
22 )
23 }
24
25 memInt, err := units.RAMInBytes(*cfg.Memory)
26 if err != nil {
27 return fmt.Errorf("failed to parse memory to uint: %w", err)
28 }
29
30 if memInt <= 0 {
31 return fmt.Errorf(
32 "specified amount of memory (%s) must be greater than 0GiB",
33 *cfg.Memory,
34 )
35 }
36
37 totalCPUs := systemDeps.NumCPU()
38 if *cfg.CPUs > totalCPUs {
39 log.Infof(
40 "The specified number of CPUs (%d) is greater than CPUs available on this system (%d),\n"+
41 "which may lead to severe performance degradation",
42 *cfg.CPUs,
43 totalCPUs,
44 )
45 }
46
47 totalMem := mem.TotalMemory()
48 if uint64(memInt) > totalMem {
49 log.Infof(
50 "The specified amount of memory (%s) is greater than the memory available on this system (%s),\n"+
51 "which may lead to severe performance degradation",
52 *cfg.Memory,
53 units.BytesSize(float64(totalMem)),
54 )
55 }
56
57 if cfg.BootDisk != nil {
58 bootDiskInt, err := units.RAMInBytes(*cfg.BootDisk)
59 if err != nil {
60 return fmt.Errorf("failed to parse bootdisk to uint: %w", err)
61 }
62 if bootDiskInt <= 10*1024*1024*1024 {
63 return fmt.Errorf(
64 "specified size of boot disk (%s) must be greater than 10GiB",
65 *cfg.BootDisk,
66 )
67 }
68 }
69
70 if cfg.DataDisk != nil {
71 dataDiskInt, err := units.RAMInBytes(*cfg.DataDisk)
72 if err != nil {
73 return fmt.Errorf("failed to parse datadisk to uint: %w", err)
74 }

Callers 4

TestValidateFunction · 0.70
ModifyFinchConfigFunction · 0.70
loadFinchConfigFunction · 0.70
LoadFunction · 0.70

Calls 4

ErrorfMethod · 0.65
NumCPUMethod · 0.65
InfofMethod · 0.65
TotalMemoryMethod · 0.65

Tested by 1

TestValidateFunction · 0.56