Skip to content

Commit 755e537

Browse files
committed
prevent user from editing vm-type
Signed-off-by: Ansuman Sahoo <[email protected]>
1 parent ff15b74 commit 755e537

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

cmd/limactl/edit.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ func editAction(cmd *cobra.Command, args []string) error {
114114
logrus.Info("Aborting, no changes made to the instance")
115115
return nil
116116
}
117+
if err := limayaml.ValidateAgainstLatestConfig(yBytes, yContent); err != nil {
118+
return saveRejectedYAML(yBytes, err)
119+
}
120+
117121
y, err := limayaml.LoadWithWarnings(yBytes, filePath)
118122
if err != nil {
119123
return err
@@ -122,10 +126,6 @@ func editAction(cmd *cobra.Command, args []string) error {
122126
return saveRejectedYAML(yBytes, err)
123127
}
124128

125-
if err := limayaml.ValidateAgainstLatestConfig(yBytes, yContent); err != nil {
126-
return saveRejectedYAML(yBytes, err)
127-
}
128-
129129
if err := os.WriteFile(filePath, yBytes, 0o644); err != nil {
130130
return err
131131
}

pkg/limayaml/load.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ func load(b []byte, filePath string, warn bool) (*limatype.LimaYAML, error) {
7373

7474
FillDefault(&y, &d, &o, filePath, warn)
7575

76-
if err := ResolveVMType(&y, filePath); err != nil {
76+
if err := ValidateVMType(&y, filePath); err != nil {
7777
logrus.WithError(err).Warnf("Failed to accept config for %q", filePath)
7878
return nil, fmt.Errorf("failed to accept config for %q: %w", filePath, err)
7979
}
8080

8181
return &y, nil
8282
}
8383

84-
func ResolveVMType(y *limatype.LimaYAML, filePath string) error {
84+
func ValidateVMType(y *limatype.LimaYAML, filePath string) error {
8585
if y.VMType != nil && *y.VMType != "" {
8686
vmType := *y.VMType
8787
_, intDriver, exists := registry.Get(vmType)
@@ -112,7 +112,7 @@ func ResolveVMType(y *limatype.LimaYAML, filePath string) error {
112112
if registry.CheckInternalOrExternal(vmType) == registry.Internal {
113113
_, intDriver, _ := registry.Get(vmType)
114114
if err := intDriver.AcceptConfig(y, filePath); err == nil {
115-
logrus.Infof("ResolveVMType: resolved VMType %q", vmType)
115+
logrus.Debugf("ResolveVMType: resolved VMType %q", vmType)
116116
y.VMType = ptr.Of(vmType)
117117
return nil
118118
}

pkg/limayaml/validate.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,10 @@ func ValidateAgainstLatestConfig(yNew, yLatest []byte) error {
605605
return err
606606
}
607607

608+
if *n.VMType != *l.VMType {
609+
return fmt.Errorf("cannot change VMType from %v to %v, please create a new instance with the desired VMType", *l.VMType, *n.VMType)
610+
}
611+
608612
// Handle editing the template without a disk value
609613
if n.Disk == nil || l.Disk == nil {
610614
return nil

0 commit comments

Comments
 (0)