Skip to content

Commit

Permalink
optimize the version check to be only when semver constraint check su…
Browse files Browse the repository at this point in the history
…cceeded
  • Loading branch information
Skarlso committed Jan 16, 2025
1 parent 67eac02 commit 6d5dced
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions pkg/ocm/ocm.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,15 @@ func (c *Client) GetLatestValidComponentVersion(

for _, v := range versions {
if valid, _ := constraint.Validate(v.Semver); valid {
// make sure we don't do any lookup if we don't need to
if len(obj.Spec.Verify) > 0 {
if _, err := c.VerifyComponent(ctx, octx, obj, v.Version); err != nil {
logger.Error(err, "ignoring version as it failed verification", "version", v.Version, "component", obj.Spec.Component)

continue
}
}

return v.Version, nil
}
}
Expand Down Expand Up @@ -489,15 +498,6 @@ func (c *Client) ListComponentVersions(

var result []Version
for _, v := range versions {
// make sure we don't do any lookup if we don't need to
if len(obj.Spec.Verify) > 0 {
if _, err := c.VerifyComponent(ctx, octx, obj, v); err != nil {
logger.Error(err, "ignoring version as it failed verification", "version", v, "component", obj.Spec.Component)

continue
}
}

parsed, err := semver.NewVersion(v)
if err != nil {
logger.Error(err, "ignoring version as it was invalid semver", "version", v)
Expand Down

0 comments on commit 6d5dced

Please sign in to comment.