-
Notifications
You must be signed in to change notification settings - Fork 549
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
fix: use imager incoming version for extension validation #9696
Merged
talos-bot
merged 1 commit into
siderolabs:main
from
frezbo:fix/use-imager-version-for-extension-validation
Nov 12, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,24 +16,83 @@ import ( | |
"github.com/siderolabs/talos/pkg/machinery/version" | ||
) | ||
|
||
// Validate the extension: compatibility, contents, etc. | ||
func (ext *Extension) Validate() error { | ||
if err := ext.validateConstraints(); err != nil { | ||
return err | ||
// ValidationOptions are used to configure the validation process. | ||
type ValidationOptions struct { | ||
// ValidateContstraints enables validation of the extension constraints. | ||
ValidateContstraints bool | ||
// ValidateContents enables validation of the extension contents. | ||
ValidateContents bool | ||
|
||
// TalosVersion is the version of Talos to validate against. | ||
TalosVersion *semver.Version | ||
} | ||
|
||
// WithValidateConstraints enables validation of the extension constraints. | ||
func WithValidateConstraints() ValidationOption { | ||
return func(o *ValidationOptions) error { | ||
o.ValidateContstraints = true | ||
|
||
return nil | ||
} | ||
} | ||
|
||
// WithValidateContents enables validation of the extension contents. | ||
func WithValidateContents() ValidationOption { | ||
return func(o *ValidationOptions) error { | ||
o.ValidateContents = true | ||
|
||
return nil | ||
} | ||
} | ||
|
||
// WithTalosVersion sets the Talos version to validate against. | ||
func WithTalosVersion(version semver.Version) ValidationOption { | ||
return func(o *ValidationOptions) error { | ||
o.TalosVersion = &version | ||
|
||
return ext.validateContents() | ||
return nil | ||
} | ||
} | ||
|
||
func (ext *Extension) validateConstraints() error { | ||
constraint := ext.Manifest.Metadata.Compatibility.Talos.Version | ||
// ValidationOption is a function that configures the validation options. | ||
type ValidationOption func(*ValidationOptions) error | ||
|
||
if constraint != "" { | ||
talosVersion, err := semver.ParseTolerant(version.Tag) | ||
// Validate the extension: compatibility, contents, etc. | ||
func (ext *Extension) Validate(opts ...ValidationOption) 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. did this, so |
||
validationOptions := &ValidationOptions{} | ||
|
||
for _, opt := range opts { | ||
if err := opt(validationOptions); err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
if validationOptions.TalosVersion == nil { | ||
version, err := semver.ParseTolerant(version.Tag) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
validationOptions.TalosVersion = &version | ||
} | ||
|
||
if validationOptions.ValidateContstraints { | ||
if err := ext.validateConstraints(*validationOptions.TalosVersion); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
if validationOptions.ValidateContents { | ||
return ext.validateContents() | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (ext *Extension) validateConstraints(talosVersion semver.Version) error { | ||
constraint := ext.Manifest.Metadata.Compatibility.Talos.Version | ||
|
||
if constraint != "" { | ||
versionConstraint, err := semver.ParseRange(trim(constraint)) | ||
if err != nil { | ||
return fmt.Errorf("error parsing Talos version constraint: %w", err) | ||
|
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 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.
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.
I can drop this since we only use it for the deprecated
.machine.install.extensions
https://github.com/siderolabs/talos/pull/9696/files#diff-9adbdc7691682c62b382f9040db20e4e0d54e5be12c74378bef14a586a4adf20R22