-
Notifications
You must be signed in to change notification settings - Fork 56
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
Generalise and clean up blueprint customization validation for image types #1216
Draft
achilleas-k
wants to merge
5
commits into
osbuild:main
Choose a base branch
from
achilleas-k:config-validation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add two new methods to the ImageType interface: - SupportedCustomizations(): Returns a list of strings that indicate customizations supported by an image type. - RequiredCustomizations(): Returns a list of strings that indicate the customizations required by an image type.
Add a reverse path field to the CustomizationError that encodes the path to the customization that caused an error. The path is constructed in reverse (bottom-up) for convenience when iterating or recursing through the blueprint structure and is reversed to top-down when printing the error message. This will be used to inform the user of the specific key that was added to a blueprint but wasn't supported (or required and not set) without any confusion arising from keys that share a name (e.g. kernel.name and user.name).
A validation function that takes a list of supported paths to keys and a blueprint and checks that every value set in the blueprint is in the list of supported options. This validator is similar to the existing Customizations.CheckAllowed() function but it doesn't only check for values on one level - it can check for supported values of arbitrary depth. For example, the following value: Customizations.Kernel.Name means that the Name field of the Kernel customization is supported and if no other item is listed, it also implies that the Kernel.Append customization is not supported. This also works with array types, meaning: Customizations.User.Name Customizations.User.SSHKey means that the Name and SSHKey options are supported for the User array, but none of the other fields are supported. Error messages use the new CustomizationError type to print the path to the specific option that caused the error.
A validation function that takes a list of required paths to keys and a blueprint and checks that every value defined in the required list is set in the blueprint. This validator operates in a reverse manner than the validateSupportedConfig() function since it needs to iterate over the list of required keys and check that they are set rather than iterate over the keys that are set and check that they are supported. The format of the required options is the same as for supported. For example, the following value: Customizations.User.Name means that the Name field of the each User defined in the Customizations should be set to a non-empty value. Non-empty (non-zero) values are only checked for certain types: Struct, Pointer, Slice, and String Other types (Int, Bool, etc) can have valid user-specified zero values.
Test specific error messages when testing failure states.
7 tasks
lzap
reviewed
Feb 18, 2025
@@ -4,6 +4,8 @@ import ( | |||
"fmt" | |||
"reflect" | |||
"strings" | |||
|
|||
"golang.org/x/exp/slices" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Part of Go 1.21, at least the used Reverse
function.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Year-old branch that I never finished. I remembered it today during a discussion with @supakeen, @mvo5, and @schuellerf. Opening as draft because I don't want it to disappear or forget about it again.