Skip to content

Sorting chart versions#16384

Merged
momesgin merged 8 commits intorancher:masterfrom
momesgin:14817-sort-chart-versions
Feb 9, 2026
Merged

Sorting chart versions#16384
momesgin merged 8 commits intorancher:masterfrom
momesgin:14817-sort-chart-versions

Conversation

@momesgin
Copy link
Copy Markdown
Member

@momesgin momesgin commented Jan 15, 2026

Summary

Fixes #14817

Occurred changes and/or fixed issues

We were relying on the order of the versions we received from the API but now we apply sorting to make sure the order is always correct.

Technical notes summary

  • Added compareChartVersions helper that uses semver library:
    • It prioritizes standard semver comparison (semver.compare).
    • If main versions are equal, it checks for Rancher's "up" build metadata (e.g., +upX.Y.Z). If found, it strips "up" and compares the inner versions recursively. This ensures ...-rc versions inside "up" are correctly treated as older than stable.
    • As a fallback for other build metadata, it uses semver.compareBuild to sort alphabetically.
  • Updated shell/mixins/chart.js to use compareChartVersions for both sorting versions (mappedVersions) and determining the action(e.g. upgrade/downgrade...).
  • Removed isUpgradeFromPreToStable helper from utils/version.js as it is now covered by the new logic.
  • Expanded unit tests in shell/mixins/__tests__/chart.test.ts to cover various scenarios.

Areas or cases that should be tested

  • Chart Detail Page:
    • Verify that the "Chart Versions" list is sorted in descending order (newest first).
    • Check charts with mixed version types (stable, rc, alpha, beta, dev).
    • Check charts with Rancher-specific "up" versions (e.g., Monitoring chart).
  • Upgrade/Downgrade Button:
    • Install a pre-release version of a chart (e.g., ...-rc).
    • Go to the detail page of the same chart. Select different versions and check if the button displays the correct wording(e.g. Upgrade.., Edit.., Downgrade...)

Areas which could experience regressions

  • Try installing charts with different types of versioning, like simple standard version, rc versions etc
  • On chart detail page make sure:
    • the order of the versions is correct
    • the button displays the correct wording(e.g. Upgrade.., Edit.., Downgrade...)
  • On the install page make sure:
    • the order of versions is correct in the dropdown
    • we display the correct wording(e.g. Upgrade.., Edit.., Downgrade...)

Screenshot/Video

Checklist

  • The PR is linked to an issue and the linked issue has a Milestone, or no issue is needed
  • The PR has a Milestone
  • The PR template has been filled out
  • The PR has been self reviewed
  • The PR has a reviewer assigned
  • The PR has automated tests or clear instructions for manual tests and the linked issue has appropriate QA labels, or tests are not needed
  • The PR has reviewed with UX and tested in light and dark mode, or there are no UX changes
  • The PR has been reviewed in terms of Accessibility
  • The PR has considered, and if applicable tested with, the three Global Roles Admin, Standard User and User Base

@momesgin momesgin added this to the v2.14.0 milestone Jan 15, 2026
@momesgin momesgin requested a review from Copilot January 15, 2026 22:14
@momesgin momesgin self-assigned this Jan 15, 2026
@momesgin momesgin added the QA/manual-test Indicates issue requires manually testing label Jan 15, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses incorrect version sorting for Helm charts by implementing a new compareChartVersions helper function that properly handles Rancher's special "up" build metadata and standard semver comparisons. The change fixes issue #14817 where release candidate versions were being displayed out of order on the chart detail page.

Changes:

  • Added compareChartVersions function to handle semver comparison with special logic for Rancher's "up" metadata
  • Updated chart version sorting in mappedVersions computed property and upgrade/downgrade action determination
  • Removed obsolete isUpgradeFromPreToStable helper function and its tests

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
shell/utils/chart.js Added new compareChartVersions function with semver comparison and Rancher "up" metadata handling
shell/mixins/chart.js Updated to use compareChartVersions for sorting versions and determining upgrade/downgrade actions
shell/utils/version.js Removed obsolete isUpgradeFromPreToStable function
shell/utils/tests/version.test.ts Removed tests for deleted isUpgradeFromPreToStable function
shell/mixins/tests/chart.test.ts Added comprehensive test coverage for new sorting logic and action determination with various version formats

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

* @param {string} v2 - The second version string.
* @returns {number} - 0 if equal, -1 if v1 < v2, 1 if v1 > v2.
*/
export function compareChartVersions(v1, v2) {
Copy link

Copilot AI Jan 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new compareChartVersions function lacks direct unit tests. While it's tested indirectly through the chart.test.ts tests for mappedVersions and action, consider adding dedicated unit tests in shell/utils/__tests__/chart.test.ts to cover edge cases such as null/undefined inputs, malformed versions, and various 'up' metadata patterns.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one would be good to do. It's a granular function so having explicit tests for the issue would help

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@momesgin
Copy link
Copy Markdown
Member Author

momesgin commented Jan 16, 2026

@richard-cox I addressed the initial feedback from Copilot but then I mistakenly re-requested a review which caused it to came back with the current code change requests that I think are not necessary. Let me know what you think.

@momesgin momesgin changed the title sorting versions of charts Sorting chart versions Jan 22, 2026
Copy link
Copy Markdown
Member

@richard-cox richard-cox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some minor tweaks needed.

FWIW i couldn't find any rancher or partner charts with RC now (that are applicable to the latest version of rancher). in the end i just used our rancher latest repo

* @param {string} v2 - The second version string.
* @returns {number} - 0 if equal, -1 if v1 < v2, 1 if v1 > v2.
*/
export function compareChartVersions(v1, v2) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one would be good to do. It's a granular function so having explicit tests for the issue would help

@momesgin momesgin requested a review from richard-cox February 3, 2026 04:24
let diff = semver.compare(v1, v2, { loose: true });

if (diff === 0) {
const vC = semver.parse(v1, { loose: true });
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v + c are still used throughout this method, instead of v1 and v2

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry I misread your earlier comment on this, done.

@momesgin momesgin requested a review from richard-cox February 3, 2026 19:14
@momesgin momesgin removed QA/manual-test Indicates issue requires manually testing labels Feb 4, 2026
@momesgin momesgin merged commit d2b0090 into rancher:master Feb 9, 2026
117 of 122 checks passed
@momesgin momesgin deleted the 14817-sort-chart-versions branch February 9, 2026 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Chart detail page incorrectly sorts versions with rc's

3 participants