-
Notifications
You must be signed in to change notification settings - Fork 671
Reject shrinking disk during YAML validation #3596
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -595,3 +595,37 @@ | |
logrus.Warn("`mountInotify` is experimental") | ||
} | ||
} | ||
|
||
// ValidateYAMLAgainstLatestConfig validates the values between the latest YAML and the updated(New) YAML. | ||
func ValidateYAMLAgainstLatestConfig(yNew, yLatest []byte) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's cover this function with unit tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On it!. |
||
var l, n LimaYAML | ||
var err error | ||
if err = Unmarshal(yLatest, &l, "Unmarshal latest YAML bytes"); err != nil { | ||
return err | ||
} | ||
if err = Unmarshal(yNew, &n, "Unmarshal new YAML bytes); err != nil { | ||
Check failure on line 606 in pkg/limayaml/validate.go
|
||
return err | ||
} | ||
|
||
// Handle editing the template without a disk value | ||
if n.Disk == nil || l.Disk == nil { | ||
return nil | ||
} | ||
|
||
// Disk value must be provided, as it is required when creating an instance. | ||
nDisk, err := units.RAMInBytes(*n.Disk) | ||
if err != nil { | ||
return err | ||
} | ||
lDisk, err := units.RAMInBytes(*l.Disk) | ||
if err != nil { | ||
Check failure on line 621 in pkg/limayaml/validate.go
|
||
return err | ||
Check failure on line 622 in pkg/limayaml/validate.go
|
||
} | ||
Check failure on line 623 in pkg/limayaml/validate.go
|
||
songponssw marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Reject shrinking disk | ||
if nDisk < lDisk { | ||
return fmt.Errorf("field `disk`: shrinking the disk (%v --> %v) is not supported", *l.Disk, *n.Disk) | ||
Check failure on line 627 in pkg/limayaml/validate.go
|
||
} | ||
|
||
return nil | ||
} |
Uh oh!
There was an error while loading. Please reload this page.