Skip to content

Commit 4532c86

Browse files
committed
rename function
Signed-off-by: Songpon Srisawai <[email protected]>
1 parent 700ead3 commit 4532c86

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

cmd/limactl/edit.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,10 @@ func editAction(cmd *cobra.Command, args []string) error {
118118
return err
119119
}
120120
if err := limayaml.Validate(y, true); err != nil {
121-
rejectedYAML := "lima.REJECTED.yaml"
122-
if writeErr := os.WriteFile(rejectedYAML, yBytes, 0o644); writeErr != nil {
123-
return fmt.Errorf("the YAML is invalid, attempted to save the buffer as %q but failed: %w: %w", rejectedYAML, writeErr, err)
124-
}
125-
// TODO: may need to support editing the rejected YAML
126-
return fmt.Errorf("the YAML is invalid, saved the buffer as %q: %w", rejectedYAML, err)
121+
return saveRejectedYAML(yBytes, err)
127122
}
128123

129-
if err := limayaml.ValidateYAMLAgainstLatest(yBytes, yContent); err != nil {
124+
if err := limayaml.ValidateYAMLAgainstLatestConfig(yBytes, yContent); err != nil {
130125
return saveRejectedYAML(yBytes, err)
131126
}
132127

@@ -177,6 +172,7 @@ func editBashComplete(cmd *cobra.Command, _ []string, _ string) ([]string, cobra
177172
return bashCompleteInstanceNames(cmd)
178173
}
179174

175+
// saveRejectedYAML writes the rejected config and returns an error.
180176
func saveRejectedYAML(y []byte, origErr error) error {
181177
rejectedYAML := "lima.REJECTED.yaml"
182178
if writeErr := os.WriteFile(rejectedYAML, y, 0o644); writeErr != nil {

pkg/limayaml/validate.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,8 @@ func warnExperimental(y *LimaYAML) {
596596
}
597597
}
598598

599-
// ValidateYAMLAgainstLatest validates the values between the latest YAML and the updated(New) YAML.
600-
func ValidateYAMLAgainstLatest(yNew, yLatest []byte) error {
599+
// ValidateYAMLAgainstLatestConfig validates the values between the latest YAML and the updated(New) YAML.
600+
func ValidateYAMLAgainstLatestConfig(yNew, yLatest []byte) error {
601601
var l, n LimaYAML
602602
var err error
603603
if err = Unmarshal(yLatest, &l, "Unmarshal latest YAML bytes"); err != nil {
@@ -607,12 +607,17 @@ func ValidateYAMLAgainstLatest(yNew, yLatest []byte) error {
607607
return err
608608
}
609609

610-
// Skip validation if both fields are unset.
611-
if n.Disk == nil && l.Disk == nil {
612-
return nil
610+
// Disk value must be provided, as it is required when creating an instance.
611+
nDisk, err := units.RAMInBytes(*n.Disk)
612+
if err != nil {
613+
return err
614+
}
615+
lDisk, err := units.RAMInBytes(*l.Disk)
616+
if err != nil {
617+
return err
613618
}
614-
nDisk, _ := units.RAMInBytes(*n.Disk)
615-
lDisk, _ := units.RAMInBytes(*l.Disk)
619+
620+
// Reject shrinking disk
616621
if nDisk < lDisk {
617622
return fmt.Errorf("field `disk`: shrinking the disk (%v --> %v) is not supported", *l.Disk, *n.Disk)
618623
}

0 commit comments

Comments
 (0)